<|start_filename|>engine/assemblers/mesh-renderer.js<|end_filename|>
(function(){
    let Mesh = cc.MeshRenderer;
    if (Mesh === undefined) return;
    let proto = cc.MeshRenderer.__assembler__.prototype;
    let _init = proto.init;
    cc.js.mixin(proto, {
        initVertexFormat () {},
        
        _extendNative () {
            renderer.MeshAssembler.prototype.ctor.call(this);
        },

        init (comp) {
            _init.call(this, comp);
            this.updateMeshData(true);
        },

        setRenderNode (node) {
            this.setNode(node._proxy);
        },

        updateRenderData (comp) {
            this.updateMeshData();
            comp.node._renderFlag |= cc.RenderFlow.FLAG_UPDATE_RENDER_DATA;
        },

        updateMeshData (force) {
            let comp = this._renderComp;
            let mesh = comp.mesh;
            if (!mesh || !mesh.loaded) return;

            let subdatas = comp.mesh.subDatas;
            for(let i = 0, len = subdatas.length; i < len; i++) {
                let data = subdatas[i];
                if (force || data.vDirty || data.iDirty) {
                    this.updateIAData(i, data.vfm._nativeObj, data.vData, data.iData);
                    data.vDirty = false;
                    data.iDirty = false;
                }
            }
        }
    }, renderer.MeshAssembler.prototype);
})();

<|start_filename|>engine/assemblers/label/3d/letter.js<|end_filename|>
(function(){
    if(!cc.Label.__assembler__.Letter3D) return;

    let proto = cc.Label.__assembler__.Letter3D.prototype;

    Object.assign(proto, { 
        updateWorldVerts (comp) {
            let local = this._local;
            let world = this._renderData.vDatas[0];
    
            let floatsPerVert = this.floatsPerVert;
            for (let offset = 0, l = world.length; offset < l; offset += floatsPerVert) {
                world[offset] = local[offset];
                world[offset+1] = local[offset+1];
                world[offset+2] = 0;
            }
        }
    })
})()

<|start_filename|>engine/assemblers/particle-3d-assembler.js<|end_filename|>
(function(){
    let PS = cc.ParticleSystem3D;
    if (PS === undefined) return;
    let proto = PS.__assembler__.prototype;
    let _init = proto.init;
    let _updateRenderData = proto.updateRenderData;

    cc.js.mixin(proto, {
        initVertexFormat () {},
        
        _extendNative () {
            renderer.Particle3DAssembler.prototype.ctor.call(this);
        },

        init (comp) {
            _init.call(this, comp);

            this._renderDataList = new renderer.RenderDataList();
            this.setRenderDataList(this._renderDataList);
            this.ignoreOpacityFlag();
            this.updateMeshData();
            this.setUseModel(true);
        },

        updateRenderData (comp) {   
            _updateRenderData.call(this, comp);

            if (comp._vertsDirty) {
                this.updateMeshData();
                comp._vertsDirty = false;
            }
        },

        setRenderNode (node) {
            this.setNode(node._proxy);
        },

        updateMeshData () {
            if (!this._model) {
                return;
            }

            let subdatas = this._model._subDatas;
            for(let i = 0, len = subdatas.length; i < len; i++) {
                let data = subdatas[i];
                if (data.vDirty && data.enable) {
                    this._renderDataList.updateMesh(i, data.vData, data.iData);
                }
            }

            this.setVertexFormat(subdatas[0].vfm._nativeObj);
            this.setSimulationSpace(this._particleSystem.simulationSpace);

            if (subdatas[1] && subdatas[1].enable) {
                this.setTrailVertexFormat(subdatas[1].vfm._nativeObj);
                this.setTrailModuleSpace(this._particleSystem.trailModule.space);
            }
        },

        setSimulationSpace (space) {
            this.setParticleSpace(space);
        },

        setTrailModuleSpace (space) {
            this.setTrailSpace(space);
        },

        updateIA (index, count, vDirty, iDirty) {
            this.updateIndicesRange(index, 0, count);
        }

    }, renderer.Particle3DAssembler.prototype);
})();

<|start_filename|>engine/scene/node.js<|end_filename|>
/****************************************************************************
 Copyright (c) 2018 <NAME>., Ltd.

 http://www.cocos.com

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated engine source code (the "Software"), a limited,
  worldwide, royalty-free, non-assignable, revocable and non-exclusive license
 to use Cocos Creator solely to develop games on your target platforms. You shall
  not use Cocos Creator software for developing other software or tools that's
  used for developing games. You are not granted to publish, distribute,
  sublicense, and/or sell copies of Cocos Creator.

 The software or tools in this License Agreement are licensed, not sold.
 Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

'use strict';

let RenderFlow = cc.RenderFlow;
const LOCAL_TRANSFORM = RenderFlow.FLAG_LOCAL_TRANSFORM;
const COLOR = RenderFlow.FLAG_COLOR;
const UPDATE_RENDER_DATA = RenderFlow.FLAG_UPDATE_RENDER_DATA;

const POSITION_ON = 1 << 0;

cc.Node.prototype.setLocalDirty = function (flag) {
    this._localMatDirty |= flag;
    this._worldMatDirty = true;
    this._dirtyPtr[0] |= RenderFlow.FLAG_TRANSFORM;
};

cc.js.getset(cc.Node.prototype, "_renderFlag", 
    function () {
        return this._dirtyPtr[0];
    },
    function (flag) {
        this._dirtyPtr[0] = flag;
        if (flag & UPDATE_RENDER_DATA || flag & COLOR) {
            cc.RenderFlow.register(this);
        }
    }
);

cc.PrivateNode.prototype._posDirty = function (sendEvent) {
    let parent = this.parent;
    if (parent) {
        // Position correction for transform calculation
        this._trs[0] = this._originPos.x - (parent._anchorPoint.x - 0.5) * parent._contentSize.width;
        this._trs[1] = this._originPos.y - (parent._anchorPoint.y - 0.5) * parent._contentSize.height;
    }

    this.setLocalDirty(cc.Node._LocalDirtyFlag.POSITION);
    if (sendEvent === true && (this._eventMask & POSITION_ON)) {
        this.emit(cc.Node.EventType.POSITION_CHANGED);
    }
};


<|start_filename|>engine/index.js<|end_filename|>
/****************************************************************************
 Copyright (c) 2018 <NAME>., Ltd.

 http://www.cocos.com

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated engine source code (the "Software"), a limited,
  worldwide, royalty-free, non-assignable, revocable and non-exclusive license
 to use Cocos Creator solely to develop games on your target platforms. You shall
  not use Cocos Creator software for developing other software or tools that's
  used for developing games. You are not granted to publish, distribute,
  sublicense, and/or sell copies of Cocos Creator.

 The software or tools in this License Agreement are licensed, not sold.
 Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

require('./jsb-sys.js');
require('./jsb-game.js');
require('./jsb-videoplayer.js');
require('./jsb-webview.js');
require('./jsb-audio.js');
require('./jsb-loader.js');
require('./jsb-editbox.js');
require('./jsb-reflection.js');
require('./jsb-assets-manager.js');
require('./jsb-safearea.js');

if (CC_NATIVERENDERER) {
    require('./jsb-effect.js');
    require('./jsb-effect-variant.js');
    require('./scene/camera.js');
    require('./scene/light.js');
    require('./scene/node-proxy.js');
    require('./scene/render-flow.js');
    // must be required after render flow
    require('./scene/node.js');

    cc.game.on(cc.game.EVENT_ENGINE_INITED, function () {
        require('./scene/mesh-buffer.js');
        require('./scene/quad-buffer.js');
        require('./scene/render-data.js');

        require('./assemblers/assembler.js');
        require('./assemblers/assembler-2d.js');
        require('./assemblers/assembler-3d.js');

        require('./assemblers/sprite/index.js');
        require('./assemblers/label/index.js');
        require('./assemblers/mask-assembler.js');
        require('./assemblers/graphics-assembler.js');
        require('./assemblers/motion-streak.js');
        require('./assemblers/mesh-renderer.js');
        require('./assemblers/particle-3d-assembler.js');

        require('./jsb-dragonbones.js');
        require('./jsb-spine-skeleton.js');
        require('./jsb-particle.js');
        require('./jsb-tiledmap.js');
        require('./jsb-skin-mesh.js');
    });
}

<|start_filename|>engine/jsb-fs-utils.js<|end_filename|>
/****************************************************************************
 Copyright (c) 2017-2019 X<NAME> Software Co., Ltd.

 https://www.cocos.com/

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of fsUtils software and associated engine source code (the "Software"), a limited,
  worldwide, royalty-free, non-assignable, revocable and non-exclusive license
 to use Cocos Creator solely to develop games on your target platforms. You shall
  not use Cocos Creator software for developing other software or tools that's
  used for developing games. You are not granted to publish, distribute,
  sublicense, and/or sell copies of Cocos Creator.

 The software or tools in fsUtils License Agreement are licensed, not sold.
 Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/
var fs = jsb.fileUtils;
let jsb_downloader = null;
let downloading = new cc.AssetManager.Cache();
let tempDir = '';

var fsUtils = {

    fs,

    initJsbDownloader (jsbDownloaderMaxTasks, jsbDownloaderTimeout) {

        jsb_downloader = new jsb.Downloader({
            countOfMaxProcessingTasks: jsbDownloaderMaxTasks || 32,
            timeoutInSeconds: jsbDownloaderTimeout || 30,
            tempFileNameSuffix: '.tmp'
        });

        tempDir = fsUtils.getUserDataPath() + '/temp';
        !fs.isDirectoryExist(tempDir) && fs.createDirectory(tempDir);
        
        jsb_downloader.setOnFileTaskSuccess(task => {
            if (!downloading.has(task.requestURL)) return;
            let { onComplete } = downloading.remove(task.requestURL);
        
            onComplete && onComplete(null, task.storagePath);
        });
        
        jsb_downloader.setOnTaskError((task, errorCode, errorCodeInternal, errorStr) => {
            if (!downloading.has(task.requestURL)) return;
            let { onComplete } = downloading.remove(task.requestURL);
            cc.error(`Download file failed: path: ${task.requestURL} message: ${errorStr}, ${errorCode}`);
            onComplete(new Error(errorStr), null);
        });
        
        jsb_downloader.setOnTaskProgress((task, bytesReceived, totalBytesReceived, totalBytesExpected) => {
            if (!downloading.has(task.requestURL)) return;
            let { onProgress } = downloading.get(task.requestURL);
        
            onProgress && onProgress(totalBytesReceived, totalBytesExpected);
        });
    },

    getUserDataPath () {
        return fs.getWritablePath().replace(/[\/\\]*$/, '');
    },

    checkFsValid () {
        if (!fs) {
            cc.warn('can not get the file system!');
            return false;
        }
        return true;
    },

    deleteFile (filePath, onComplete) {
        var result = fs.removeFile(filePath);
        if (result === true) {
            onComplete && onComplete(null);
        }
        else {
            cc.warn(`Delete file failed: path: ${filePath}`);
            onComplete && onComplete(new Error('delete file failed'));
        }
    },

    downloadFile (remoteUrl, filePath, header, onProgress, onComplete) {
        downloading.add(remoteUrl, { onProgress, onComplete });
        var storagePath = filePath;
        if (!storagePath) storagePath = tempDir + '/' + performance.now() + cc.path.extname(remoteUrl);
        jsb_downloader.createDownloadFileTask(remoteUrl, storagePath, header);
    },

    saveFile (srcPath, destPath, onComplete) {
        var err = null;
        let result = fs.writeDataToFile(fs.getDataFromFile(srcPath), destPath);
        fs.removeFile(srcPath);
        if (!result) {
            err = new Error(`Save file failed: path: ${srcPath}`);
            cc.warn(err.message);
        }
        onComplete && onComplete(err);
    },

    copyFile (srcPath, destPath, onComplete) {
        var err = null;
        let result = fs.writeDataToFile(fs.getDataFromFile(srcPath), destPath);
        if (!result) {
            err = new Error(`Copy file failed: path: ${srcPath}`);
            cc.warn(err.message);
        }
        onComplete && onComplete(err);
    },

    writeFile (path, data, encoding, onComplete) {
        var result = null;
        var err = null;
        if (encoding === 'utf-8' || encoding === 'utf8') {
            result = fs.writeStringToFile(data, path);
        }
        else {
            result = fs.writeDataToFile(data, path);
        }
        if (!result) {
            err = new Error(`Write file failed: path: ${path}`);
            cc.warn(err.message);
        }
        onComplete && onComplete(err);
    },

    writeFileSync (path, data, encoding) {
        var result = null;
        if (encoding === 'utf-8' || encoding === 'utf8') {
            result = fs.writeStringToFile(data, path);
        }
        else {
            result = fs.writeDataToFile(data, path);
        }

        if (!result) {
            cc.warn(`Write file failed: path: ${path}`);
            return new Error(`Write file failed: path: ${path}`);
        }
    },

    readFile (filePath, encoding, onComplete) {
        var content = null, err = null;
        if (encoding === 'utf-8' || encoding === 'utf8') {
            content = fs.getStringFromFile(filePath);
        }
        else {
            content = fs.getDataFromFile(filePath);
        }
        if (!content) {
            err = new Error(`Read file failed: path: ${filePath}`);
            cc.warn(err.message);
        }
        
        onComplete && onComplete (err, content);
    },

    readDir (filePath, onComplete) {
        var files = null, err = null;
        try {
            files = fs.listFiles(filePath);
        }
        catch (e) {
            cc.warn(`Read dir failed: path: ${filePath} message: ${e.message}`);
            err = new Error(e.message);
        }
        onComplete && onComplete(err, files);
    },

    readText (filePath, onComplete) {
        fsUtils.readFile(filePath, 'utf8', onComplete);
    },

    readArrayBuffer (filePath, onComplete) {
        fsUtils.readFile(filePath, '', onComplete);
    },

    readJson (filePath, onComplete) {
        fsUtils.readFile(filePath, 'utf8', function (err, text) {
            var out = null;
            if (!err) {
                try {
                    out = JSON.parse(text);
                }
                catch (e) {
                    cc.warn(`Read json failed: path: ${filePath} message: ${e.message}`);
                    err = new Error(e.message);
                }
            }
            onComplete && onComplete(err, out);
        });
    },

    readJsonSync (path) {
        try {
            var str = fs.getStringFromFile(path);
            return JSON.parse(str);
        }
        catch (e) {
            cc.warn(`Read json failed: path: ${path} message: ${e.message}`);
            return new Error(e.message);
        }
    },

    makeDirSync (path, recursive) {
        let result = fs.createDirectory(path);
        if (!result) {
            cc.warn(`Make directory failed: path: ${path}`);
            return new Error(`Make directory failed: path: ${path}`);
        }
    },

    rmdirSync (dirPath, recursive) {
        let result = fs.removeDirectory(dirPath);
        if (!result) {
            cc.warn(`rm directory failed: path: ${dirPath}`);
            return new Error(`rm directory failed: path: ${dirPath}`);
        }
    },

    exists (filePath, onComplete) {
        var result = fs.isFileExist(filePath);
        onComplete && onComplete(result);
    },

    loadSubpackage (name, onProgress, onComplete) {
        throw new Error('not implement');
    }
};

window.fsUtils = module.exports = fsUtils;

<|start_filename|>engine/jsb-sys.js<|end_filename|>
/****************************************************************************
 Copyright (c) 2013-2016 Chukong Technologies Inc.
 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.

 http://www.cocos.com

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated engine source code (the "Software"), a limited,
  worldwide, royalty-free, non-assignable, revocable and  non-exclusive license
 to use Cocos Creator solely to develop games on your target platforms. You shall
  not use Cocos Creator software for developing other software or tools that's
  used for developing games. You are not granted to publish, distribute,
  sublicense, and/or sell copies of Cocos Creator.

 The software or tools in this License Agreement are licensed, not sold.
 Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/
'use strict';

const sys = cc.sys;

sys.getNetworkType = jsb.Device.getNetworkType;
sys.getBatteryLevel = jsb.Device.getBatteryLevel;
sys.garbageCollect = jsb.garbageCollect;
sys.restartVM = __restartVM;
sys.isObjectValid = __isObjectValid;

sys.getSafeAreaRect = function() {
    // x(top), y(left), z(bottom), w(right)
    var edge = jsb.Device.getSafeAreaEdge();
    var screenSize = cc.view.getFrameSize();

    // Get leftBottom and rightTop point in UI coordinates
    var leftBottom = new cc.Vec2(edge.y, screenSize.height - edge.z);
    var rightTop = new cc.Vec2(screenSize.width - edge.w, edge.x);

    // Returns the real location in view.
    var relatedPos = {left: 0, top: 0, width: screenSize.width, height: screenSize.height};
    cc.view.convertToLocationInView(leftBottom.x, leftBottom.y, relatedPos, leftBottom);
    cc.view.convertToLocationInView(rightTop.x, rightTop.y, relatedPos, rightTop);
    // convert view point to design resolution size
    cc.view._convertPointWithScale(leftBottom);
    cc.view._convertPointWithScale(rightTop);

    return cc.rect(leftBottom.x, leftBottom.y, rightTop.x - leftBottom.x, rightTop.y - leftBottom.y);
};


<|start_filename|>engine/scene/mesh-buffer.js<|end_filename|>
/****************************************************************************
 Copyright (c) 2017-2018 <NAME> Co., Ltd.

 https://www.cocos.com/

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated engine source code (the "Software"), a limited,
 worldwide, royalty-free, non-assignable, revocable and non-exclusive license
 to use Cocos Creator solely to develop games on your target platforms. You shall
 not use Cocos Creator software for developing other software or tools that's
 used for developing games. You are not granted to publish, distribute,
 sublicense, and/or sell copies of Cocos Creator.

 The software or tools in this License Agreement are licensed, not sold.
 Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/
(function(){
    if (!cc.MeshBuffer) return;
    let MeshBuffer = cc.MeshBuffer.prototype;

    MeshBuffer.init = function (batcher, vertexFormat) {
        this.byteOffset = 0;
        this.indiceOffset = 0;
        this.vertexOffset = 0;

        this._vertexFormat = vertexFormat;
        this._vertexBytes = this._vertexFormat._bytes;

        this._vDatas = [];
        this._uintVDatas = [];
        this._iDatas = [];
        this._arrOffset = 0;

        this._vData = null;
        this._uintVData = null;
        this._iData = null;

        this._initVDataCount = 256 * vertexFormat._bytes;// actually 256 * 4 * (vertexFormat._bytes / 4)
        this._initIDataCount = 256 * 6;
        
        this._offsetInfo = {
            byteOffset : 0,
            vertexOffset : 0,
            indiceOffset : 0
        };

        this._renderDataList = new renderer.RenderDataList();
        this._reallocBuffer();
    };

    MeshBuffer.setNativeAssembler = function(assembler) {
        if (assembler !== this._nativeAssembler) {
            this._nativeAssembler = assembler;
            assembler.setRenderDataList(this._renderDataList);
        }
    };

    MeshBuffer._updateVIDatas = function() {
        let offset = this._arrOffset;
        this._vDatas[offset] = this._vData;
        this._uintVDatas[offset] = this._uintVData;
        this._iDatas[offset] = this._iData;
        this._renderDataList.updateMesh(offset, this._vData, this._iData);
    };

    MeshBuffer.getNativeAssembler = function() {
        return this._nativeAssembler;
    };

    MeshBuffer.getCurMeshIndex = function() {
        return this._arrOffset;
    };

    MeshBuffer.uploadData = function() {};

    MeshBuffer.switchBuffer = function() {
        let offset = ++this._arrOffset;

        this.byteOffset = 0;
        this.vertexOffset = 0;
        this.indiceOffset = 0;

        if (offset < this._vDatas.length) {
            this._vData = this._vDatas[offset];
            this._uintVData = this._uintVDatas[offset];
            this._iData = this._iDatas[offset];
        } else {
            this._reallocBuffer();
        }
    };

    MeshBuffer.checkAndSwitchBuffer = function(vertexCount) {
        if (this.vertexOffset + vertexCount > 65535) {
            this.switchBuffer();
            if (!this._nativeAssembler) return;
            this._nativeAssembler.updateIADatas && this._nativeAssembler.updateIADatas(this._arrOffset, this._arrOffset);
        }
    };

    MeshBuffer.used = function(vertexCount, indiceCount) {
        if (!this._nativeAssembler) return;
        this._nativeAssembler.updateVerticesRange(this._arrOffset, 0, vertexCount);
        this._nativeAssembler.updateIndicesRange(this._arrOffset, 0, indiceCount);
    };

    MeshBuffer.request = function(vertexCount, indiceCount) {
        this.requestStatic(vertexCount, indiceCount);
        return this._offsetInfo;
    };

    MeshBuffer._reallocBuffer = function() {
        this._reallocVData(true);
        this._reallocIData(true);
        this._updateVIDatas();
    };

    MeshBuffer._reallocVData = function(copyOldData) {
        let oldVData;
        if (this._vData) {
            oldVData = new Uint8Array(this._vData.buffer);
        }

        this._vData = new Float32Array(this._initVDataCount);
        this._uintVData = new Uint32Array(this._vData.buffer);

        let newData = new Uint8Array(this._uintVData.buffer);

        if (oldVData && copyOldData) {
            for (let i = 0, l = oldVData.length; i < l; i++) {
                newData[i] = oldVData[i];
            }
        }
    };

    MeshBuffer._reallocIData = function(copyOldData) {
        let oldIData = this._iData;

        this._iData = new Uint16Array(this._initIDataCount);

        if (oldIData && copyOldData) {
            let iData = this._iData;
            for (let i = 0, l = oldIData.length; i < l; i++) {
                iData[i] = oldIData[i];
            }
        }
    };

    MeshBuffer.reset = function() {
        this._arrOffset = 0;
        this._vData = this._vDatas[0];
        this._uintVData = this._uintVDatas[0];
        this._iData = this._iDatas[0];

        this.byteOffset = 0;
        this.indiceOffset = 0;
        this.vertexOffset = 0;

        if (!this._nativeAssembler) return;

        for (let i = 0, len = this._vDatas.length; i < len; i++) {
            this._nativeAssembler.updateVerticesRange(i, 0, 0);
            this._nativeAssembler.updateIndicesRange(i, 0, 0);
        }
    };

    MeshBuffer.destroy = function() {
        this.reset();
    };
})();

<|start_filename|>engine/jsb-effect-variant.js<|end_filename|>
// Copyright (c) 2017-2018 <NAME> Co., Ltd.
(function () {
    if (!cc.EffectVariant) return;

    let EffectVariant = cc.EffectVariant;
    let _init = EffectVariant.prototype.init;

    Object.assign(EffectVariant.prototype, {
        init (effect) {
            _init.call(this, effect);

            this._nativeObj = new renderer.EffectVariant(effect._nativeObj);
        },

        _onEffectChanged () {
            let nativeEffect = this._effect ? this._effect._nativeObj : null;
            this._nativeObj.setEffect(nativeEffect);
        },

        updateHash (hash) {
            this._nativeObj.updateHash(hash);
        }
    })
})();


<|start_filename|>engine/jsb-editbox.js<|end_filename|>
/****************************************************************************
 Copyright (c) 2018 <NAME>., Ltd.

 http://www.cocos.com

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated engine source code (the "Software"), a limited,
  worldwide, royalty-free, non-assignable, revocable and non-exclusive license
 to use Cocos Creator solely to develop games on your target platforms. You shall
  not use Cocos Creator software for developing other software or tools that's
  used for developing games. You are not granted to publish, distribute,
  sublicense, and/or sell copies of Cocos Creator.

 The software or tools in this License Agreement are licensed, not sold.
 Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

(function () {
    if (!(cc && cc.EditBox)) {
        return;
    }
    const EditBox = cc.EditBox;
    const js = cc.js;
    const KeyboardReturnType = EditBox.KeyboardReturnType;
    const InputMode = EditBox.InputMode;
    const InputFlag = EditBox.InputFlag;
    const MAX_VALUE = 65535;

    let worldMat = new cc.Mat4(),
        cameraMat = new cc.Mat4();

    function getInputType (type) {
        switch (type) {
            case InputMode.EMAIL_ADDR:
                return 'email';
            case InputMode.NUMERIC:
            case InputMode.DECIMAL:
                return 'number';
            case InputMode.PHONE_NUMBER:
                return 'phone';
            case InputMode.URL:
                return 'url';
            case InputMode.SINGLE_LINE:
            case InputMode.ANY:
            default:
                return 'text';
        }
    }

    function getKeyboardReturnType (type) {
        switch (type) {
            case KeyboardReturnType.DEFAULT:
            case KeyboardReturnType.DONE:
                return 'done';
            case KeyboardReturnType.SEND:
                return 'send';
            case KeyboardReturnType.SEARCH:
                return 'search';
            case KeyboardReturnType.GO:
                return 'go';
            case KeyboardReturnType.NEXT:
                return 'next';
        }
        return 'done';
    }

    const BaseClass = EditBox._ImplClass;
    function JsbEditBoxImpl () {
        BaseClass.call(this);
    }

    js.extend(JsbEditBoxImpl, BaseClass);
    EditBox._ImplClass = JsbEditBoxImpl;

    Object.assign(JsbEditBoxImpl.prototype, {
        init (delegate) {
            if (!delegate) {
                cc.error('EditBox init failed');
                return;
            }
            this._delegate = delegate;
        },

        _onResize () {
            let { x, y, width, height } = this._getRect();
            jsb.inputBox.updateRect(x, y, width, height);
        },

        beginEditing () {
            let self = this;
            let delegate = this._delegate;
            let multiline = (delegate.inputMode === InputMode.ANY);
            let rect = this._getRect();
            let maxLength = (delegate.maxLength < 0 ? MAX_VALUE : delegate.maxLength)
            let inputTypeString = getInputType(delegate.inputMode);
            if (delegate.inputFlag === InputFlag.PASSWORD) {
                inputTypeString = 'password';
            }

            function onConfirm (res) {
                delegate.editBoxEditingReturn();
            }

            function onInput (res) {
                if (delegate._string !== res.value) {
                    delegate.editBoxTextChanged(res.value);
                }
            }

            function onComplete (res) {
                self.endEditing();
            }

            jsb.inputBox.onInput(onInput);
            jsb.inputBox.onConfirm(onConfirm);
            jsb.inputBox.onComplete(onComplete);

            if (!cc.sys.isMobile) {
                this._delegate._hideLabels();
            }
            jsb.inputBox.show({
                defaultValue: delegate._string,
                maxLength: maxLength,
                multiple: multiline,
                confirmHold: false,
                confirmType: getKeyboardReturnType(delegate.returnType),
                inputType: inputTypeString,
                originX: rect.x,
                originY: rect.y,
                width: rect.width,
                height: rect.height
            });
            this._editing = true;
            delegate.editBoxEditingDidBegan();
            if (!cc.sys.isMobile) {
                cc.view.on('canvas-resize', this._onResize, this);
            }
        },

        endEditing () {
            jsb.inputBox.offConfirm();
            jsb.inputBox.offInput();
            jsb.inputBox.offComplete();
            this._editing = false;
            if (!cc.sys.isMobile) {
                this._delegate._showLabels();
            }
            jsb.inputBox.hide();
            this._delegate.editBoxEditingDidEnded();
            if (!cc.sys.isMobile) {
                cc.view.off('canvas-resize', this._onResize, this);
            }
        },

        _getRect () {
            let node = this._delegate.node,
                viewScaleX = cc.view._scaleX, viewScaleY = cc.view._scaleY;
            let dpr = cc.view._devicePixelRatio;
            node.getWorldMatrix(worldMat);

            let camera = cc.Camera.findCamera(node);
            if (!camera) {
                return new cc.Rect();
            }
            camera.getWorldToScreenMatrix2D(cameraMat);
            cc.Mat4.multiply(cameraMat, cameraMat, worldMat);

            let contentSize = node._contentSize;
            let vec3 = cc.v3();
            vec3.x = -node._anchorPoint.x * contentSize.width;
            vec3.y = -node._anchorPoint.y * contentSize.height;


            cc.Mat4.translate(cameraMat, cameraMat, vec3);

            viewScaleX /= dpr;
            viewScaleY /= dpr;

            let finalScaleX = cameraMat.m[0] * viewScaleX;
            let finaleScaleY = cameraMat.m[5] * viewScaleY;

            let viewportRect = cc.view._viewportRect;
            let offsetX = viewportRect.x / dpr,
                offsetY = viewportRect.y / dpr;
            return {
                x: cameraMat.m[12] * viewScaleX + offsetX,
                y: cameraMat.m[13] * viewScaleY + offsetY,
                width: contentSize.width * finalScaleX,
                height: contentSize.height * finaleScaleY
            };
        },
    });
}());

<|start_filename|>engine/assemblers/graphics-assembler.js<|end_filename|>

let proto = cc.Graphics.__assembler__.prototype;

let _init = proto.init;
proto.init = function (renderComp) {
    _init.call(this, renderComp);
    this.ignoreOpacityFlag();
}

proto.genBuffer = function (graphics, cverts) {
    let buffers = this.getBuffers(); 
    let buffer = buffers[this._bufferOffset];
    let meshbuffer = buffer.meshbuffer;

    meshbuffer.requestStatic(cverts, cverts*3);
    this._buffer = buffer;

    meshbuffer.setNativeAssembler(this);
    return buffer;
}

let _stroke = proto.stroke;
proto.stroke = function (graphics) {
    _stroke.call(this, graphics);
    let buffer = this._buffer;
    buffer.meshbuffer.used(buffer.vertexStart, buffer.indiceStart);
}

let _fill = proto.fill;
proto.fill = function (graphics) {
    _fill.call(this, graphics);
    let buffer = this._buffer;
    buffer.meshbuffer.used(buffer.vertexStart, buffer.indiceStart);
}

let _updateIADatas = proto.updateIADatas;
proto.updateIADatas = function (iaIndex, meshIndex) {
    _updateIADatas.call(this, iaIndex, meshIndex);
    // Reset vertexStart and indiceStart when buffer is switched.
    this._buffer.vertexStart = 0;
    this._buffer.indiceStart = 0;
}


<|start_filename|>engine/assemblers/mask-assembler.js<|end_filename|>
/****************************************************************************
 Copyright (c) 2018 <NAME> Co., Ltd.

 http://www.cocos.com

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated engine source code (the "Software"), a limited,
  worldwide, royalty-free, non-assignable, revocable and non-exclusive license
 to use Cocos Creator solely to develop games on your target platforms. You shall
  not use Cocos Creator software for developing other software or tools that's
  used for developing games. You are not granted to publish, distribute,
  sublicense, and/or sell copies of Cocos Creator.

 The software or tools in this License Agreement are licensed, not sold.
 Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

const Mask = cc.Mask;
const RenderFlow = cc.RenderFlow;
const spriteAssembler = cc.Sprite.__assembler__.Simple.prototype;
const graphicsAssembler = cc.Graphics.__assembler__.prototype;


let proto = cc.Mask.__assembler__.prototype;
let _updateRenderData = proto.updateRenderData;
// Avoid constructor being overridden.
renderer.MaskAssembler.prototype.constructor = cc.Mask.__assembler__;

cc.js.mixin(proto, {
    _extendNative () {
        renderer.MaskAssembler.prototype.ctor.call(this);
    },

    initLocal () {
        this._local = new Float32Array(4);
        renderer.MaskAssembler.prototype.setLocalData.call(this, this._local);
    },

    updateRenderData (mask) {
        _updateRenderData.call(this, mask);
    
        mask._clearGraphics._assembler.updateMaterial(0, mask._clearMaterial);
        
        this.setMaskInverted(mask.inverted);
        this.setUseModel(mask._type !== Mask.Type.IMAGE_STENCIL);
        this.setImageStencil(mask._type === Mask.Type.IMAGE_STENCIL);

        if (mask._graphics) {
            mask._graphics._assembler.setUseModel(mask._type !== Mask.Type.IMAGE_STENCIL);
        }

        mask.node._renderFlag |= cc.RenderFlow.FLAG_UPDATE_RENDER_DATA;
    }
}, renderer.MaskAssembler.prototype);

let originCreateGraphics = cc.Mask.prototype._createGraphics;
let originRemoveGraphics = cc.Mask.prototype._removeGraphics;
cc.js.mixin(cc.Mask.prototype, {
    _createGraphics () {
        originCreateGraphics.call(this);
        if (this._graphics) {
            this._assembler.setRenderSubHandle(this._graphics._assembler);
        }

        // TODO: remove clearGraphics
        if (!this._clearGraphics) {
            this._clearGraphics = new cc.Graphics();
            cc.Assembler.init(this._clearGraphics);
            this._clearGraphics.node = new cc.Node();
            this._clearGraphics._activateMaterial();
            this._clearGraphics.lineWidth = 0;
            this._clearGraphics.rect(-1, -1, 2, 2);
            this._clearGraphics.fill();

            this._clearGraphics._assembler.ignoreWorldMatrix();
            this._assembler.setClearSubHandle(this._clearGraphics._assembler);
        }
    },

    _removeGraphics () {
        originRemoveGraphics.call(this);

        // TODO: remove clearGraphics
        if (this._clearGraphics) {
            this._clearGraphics.destroy();
            this._clearGraphics = null;
        }
    }
})



<|start_filename|>engine/jsb-effect.js<|end_filename|>
// Copyright (c) 2017-2018 <NAME> Software Co., Ltd.

const gfx = window.gfx;

// Effect
let Effect = cc.Effect;
let _init = Effect.prototype.init;
let _clone = Effect.prototype.clone;
let _switchTechnique = Effect.prototype.switchTechnique;

Object.assign(Effect.prototype, {
    init (name, techniques, techniqueIndex, asset, createNative) {
        _init.call(this, name, techniques, techniqueIndex, asset);

        if (createNative) {
            this._nativeObj = new renderer.EffectNative();
            this._nativeObj.init(techniques);
            this._nativePtr = this._nativeObj.self();
        }
    },

    clone () {
        let effect = _clone.call(this);
        effect._nativeObj = new renderer.EffectNative();
        effect._nativeObj.copy(this._nativeObj);
        effect._nativePtr = effect._nativeObj.self();
        return effect;
    },

    switchTechnique: function switchTechnique(techniqueIndex) {
        _switchTechnique.call(this, techniqueIndex);
        this._nativeObj.switchTechnique(techniqueIndex);
    }
});

// EffectBase
let EffectBase = cc.EffectBase;
let _setCullMode = EffectBase.prototype.setCullMode;
let _setBlend = EffectBase.prototype.setBlend;
let _setStencilEnabled = EffectBase.prototype.setStencilEnabled;
let _setStencil = EffectBase.prototype.setStencil;
let _setDepth = EffectBase.prototype.setDepth;
let _define = EffectBase.prototype.define;
let _setProperty = EffectBase.prototype.setProperty;

Object.assign(EffectBase.prototype, {
    setCullMode (cullMode = gfx.CULL_BACK, passIdx) {
        _setCullMode.call(this, cullMode, passIdx);
        this._nativeObj.setCullMode(cullMode, passIdx === undefined ? -1 : passIdx);
    },

    setBlend (enabled = false,
        blendEq = gfx.BLEND_FUNC_ADD,
        blendSrc = gfx.BLEND_SRC_ALPHA,
        blendDst = gfx.BLEND_ONE_MINUS_SRC_ALPHA,
        blendAlphaEq = gfx.BLEND_FUNC_ADD,
        blendSrcAlpha = gfx.BLEND_SRC_ALPHA,
        blendDstAlpha = gfx.BLEND_ONE_MINUS_SRC_ALPHA,
        blendColor = 0xffffffff,
        passIdx) {
        _setBlend.call(this, enabled, blendEq, blendSrc, blendDst, blendAlphaEq, blendSrcAlpha, blendDstAlpha, blendColor, passIdx);
        this._nativeObj.setBlend(enabled, blendEq, blendSrc, blendDst, blendAlphaEq, blendSrcAlpha, blendDstAlpha, blendColor, passIdx === undefined ? -1 : passIdx);
    },

    setDepth (depthTest, depthWrite, depthFunc, passIdx) {
        _setDepth.call(this, depthTest, depthWrite, depthFunc, passIdx);
        this._nativeObj.setDepth(depthTest, depthWrite, depthFunc, passIdx === undefined ? -1 : passIdx);
    },

    setStencilEnabled (enabled, passIdx) {
        _setStencilEnabled.call(this, enabled, passIdx);
        this._nativeObj.setStencilTest(enabled, passIdx === undefined ? -1 : passIdx);
    },

    setStencil (enabled = gfx.STENCIL_INHERIT,
        stencilFunc = gfx.DS_FUNC_ALWAYS,
        stencilRef = 0,
        stencilMask = 0xff,
        stencilFailOp = gfx.STENCIL_OP_KEEP,
        stencilZFailOp = gfx.STENCIL_OP_KEEP,
        stencilZPassOp = gfx.STENCIL_OP_KEEP,
        stencilWriteMask = 0xff,
        passIdx) {
        _setStencil.call(this, enabled, stencilFunc, stencilRef, stencilMask, stencilFailOp, stencilZFailOp, stencilZPassOp, stencilWriteMask, passIdx);
        this._nativeObj.setStencil(stencilFunc, stencilRef, stencilMask, stencilFailOp, stencilZFailOp, stencilZPassOp, stencilWriteMask, passIdx === undefined ? -1 : passIdx);
    },

    define (name, value, passIdx, force) {
        _define.call(this, name, value, passIdx, force);
        this._nativeObj.define(name, value, passIdx === undefined ? -1 : passIdx);
    },

    updateHash (hash) {
        this._nativeObj.updateHash(hash);
    },

    setProperty (name, val, passIdx, directly) {
        _setProperty.call(this, name, val, passIdx);

        let prop = this.getProperty(name);
        if (prop !== undefined) {
            this._nativeObj.setProperty(name, prop, passIdx === undefined ? -1 : passIdx, directly);
        }
    }
})


<|start_filename|>builtin/jsb_input.js<|end_filename|>
const EventTarget = require('./jsb-adapter/EventTarget');
const Event = require('./jsb-adapter/Event');

var eventTarget = new EventTarget();

var callbackWrappers = {};
var callbacks = {};
var index = 1;
var callbackWrapper = function(cb) {
    if (!cb)
    	return null;

	var func = function(event) {
		cb({value: event.text})
	};
	cb.___index = index++;
	callbackWrappers[cb.___index] = func;

	return func;
};
var getCallbackWrapper = function(cb) {
	if (cb && cb.___index) {
		var ret = callbackWrappers[cb.___index];
		delete callbackWrappers[cb.___index];
		return ret;
	}
	else
		return null;
};
var removeListener = function(name, cb) {
	if (cb)
	    eventTarget.removeEventListener(name, getCallbackWrapper(cb))
	else {
		// remove all listeners of name
		var cbs = callbacks[name];
		if (! cbs)
			return;

		for (var i = 0, len = cbs.length; i < len; ++i)
			eventTarget.removeEventListener(name, cbs[i]);

		delete callbacks[name];
	}
};
var recordCallback = function(name, cb) {
	if (!cb || !name || name ==='')
		return;

	if (! callbacks[name])
		callbacks[name] = [];

	callbacks[name].push(cb);
}

jsb.inputBox = {
	onConfirm: function(cb) {
		var newCb = callbackWrapper(cb);
		eventTarget.addEventListener('confirm', newCb);
		recordCallback('confirm', newCb);
	},
	offConfirm: function(cb) {
		removeListener('confirm', cb);
	},

	onComplete: function(cb) {
		var newCb = callbackWrapper(cb);
		eventTarget.addEventListener('complete', newCb);
		recordCallback('complete', newCb);
	},
	offComplete: function(cb) {
		removeListener('complete', cb);
	},

	onInput: function(cb) {
		var newCb = callbackWrapper(cb);
		eventTarget.addEventListener('input', newCb);
		recordCallback('input', newCb);
	},
	offInput: function(cb) {
		removeListener('input', cb);
	},

    /**
     * @param {string}		options.defaultValue
     * @param {number}		options.maxLength
     * @param {bool}        options.multiple
     * @param {bool}        options.confirmHold
     * @param {string}      options.confirmType
     * @param {string}      options.inputType
     * 
     * Values of options.confirmType can be [done|next|search|go|send].
     * Values of options.inputType can be [text|email|number|phone|password].
     */
	show: function(options) {
		jsb.showInputBox(options);
	},
	hide: function() {
		jsb.hideInputBox();
	},
	updateRect (x, y, width, height) {
		jsb.updateInputBoxRect(x, y, width, height);
	},
};

jsb.onTextInput = function(eventName, text) {
	var event = new Event(eventName);
	event.text = text;
	eventTarget.dispatchEvent(event);
};
