diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index ffee143848..581d4b2b0f 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -66,7 +66,6 @@ let BuiltinGroupIndex = cc.Enum({ DEBUG: 31 }) - /** * !#en Node's local dirty properties flag * !#zh Node 的本地属性 dirty 状态位 @@ -731,6 +730,26 @@ var Node = cc.Class({ } }, + /** + * !#en The rotation as Euler angles in degrees, used in 2.5D project. + * !#zh 该节点的欧拉角度,用于 2.5D 项目。 + * @property eulerAngles + * @type {Vec3} + */ + eulerAngles: { + get () { + return cc.v3(this._rotationX, this._rotationY, this._rotationZ); + }, + set (v) { + this._rotationX = v.x; + this._rotationY = v.y; + this._rotationZ = v.z; + math.quat.fromEuler(this._quat, v.x, v.y, v.z); + this.setLocalDirty(LocalDirtyFlag.ROTATION); + this._renderFlag |= RenderFlow.FLAG_TRANSFORM; + } + }, + /** * !#en Rotation on x axis. * !#zh 该节点 X 轴旋转角度。 @@ -1125,6 +1144,8 @@ var Node = cc.Class({ this._eventMask = 0; this._cullingMask = 1 << this.groupIndex; + + this._rotationZ = 0; }, statics: { @@ -1327,9 +1348,11 @@ var Node = cc.Class({ if (!this._activeInHierarchy) { // deactivate ActionManager and EventManager by default - if (ActionManagerExist) { - cc.director.getActionManager().pauseTarget(this); - } + + // ActionManager may not be inited in the editor worker. + let manager = cc.director.getActionManager(); + manager && manager.pauseTarget(this); + eventManager.pauseTarget(this); } @@ -2469,27 +2492,7 @@ var Node = cc.Class({ // Assume parent world matrix is correct let parent = this._parent; if (parent) { - let pt = parent._worldMatrix; - let t = this._matrix; - let wt = this._worldMatrix; - let aa=t.m00, ab=t.m01, ac=t.m04, ad=t.m05, atx=t.m12, aty=t.m13; - let ba=pt.m00, bb=pt.m01, bc=pt.m04, bd=pt.m05, btx=pt.m12, bty=pt.m13; - if (bb !== 0 || bc !== 0) { - wt.m00 = aa * ba + ab * bc; - wt.m01 = aa * bb + ab * bd; - wt.m04 = ac * ba + ad * bc; - wt.m05 = ac * bb + ad * bd; - wt.m12 = ba * atx + bc * aty + btx; - wt.m13 = bb * atx + bd * aty + bty; - } - else { - wt.m00 = aa * ba; - wt.m01 = ab * bd; - wt.m04 = ac * ba; - wt.m05 = ad * bd; - wt.m12 = ba * atx + btx; - wt.m13 = bd * aty + bty; - } + this._mulMat(this._worldMatrix, parent._worldMatrix, this._matrix); } else { math.mat4.copy(this._worldMatrix, this._matrix); @@ -2497,6 +2500,27 @@ var Node = cc.Class({ this._worldMatDirty = false; }, + _mulMat (out, a, b) { + let aa=a.m00, ab=a.m01, ac=a.m04, ad=a.m05, atx=a.m12, aty=a.m13; + let ba=b.m00, bb=b.m01, bc=b.m04, bd=b.m05, btx=b.m12, bty=b.m13; + if (ab !== 0 || ac !== 0) { + out.m00 = ba * aa + bb * ac; + out.m01 = ba * ab + bb * ad; + out.m04 = bc * aa + bd * ac; + out.m05 = bc * ab + bd * ad; + out.m12 = aa * btx + ac * bty + atx; + out.m13 = ab * btx + ad * bty + aty; + } + else { + out.m00 = ba * aa; + out.m01 = bb * ad; + out.m04 = bc * aa; + out.m05 = bd * ad; + out.m12 = aa * btx + atx; + out.m13 = ad * bty + aty; + } + }, + _updateWorldMatrix () { if (this._parent) { this._parent._updateWorldMatrix(); diff --git a/cocos2d/core/assets/CCMesh.js b/cocos2d/core/assets/CCMesh.js new file mode 100644 index 0000000000..10fa0fe310 --- /dev/null +++ b/cocos2d/core/assets/CCMesh.js @@ -0,0 +1,92 @@ +/**************************************************************************** + 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. + ****************************************************************************/ + + /** + * @module cc + */ +/** + * !#en Mesh Asset. + * !#zh 网格资源。 + * @class Mesh + * @extends Asset + */ +var Mesh = cc.Class({ + name: 'cc.Mesh', + extends: cc.Asset, + + properties: { + _modelSetter: { + set: function (model) { + this.initWithModel(model); + } + }, + + /** + * !#en Get ir set the sub meshes. + * !#zh 设置或者获取子网格。 + * @property {[renderEngine.InputAssembler]} subMeshes + */ + subMeshes: { + get () { + return this._subMeshes; + }, + set (v) { + this._subMeshes = v; + } + } + }, + + ctor () { + this._modelUuid = ''; + this._meshID = -1; + this._model = null; + + this._subMeshes = []; + }, + + initWithModel (model) { + if (!model) return; + this._model = model; + this._model.initMesh(this); + }, + + _serialize: CC_EDITOR && function () { + return { + modelUuid: this._modelUuid, + meshID: this._meshID + } + }, + + _deserialize (data, handle) { + this._modelUuid = data.modelUuid; + this._meshID = data.meshID; + + if (this._modelUuid) { + handle.result.push(this, '_modelSetter', this._modelUuid); + } + } +}); + +cc.Mesh = module.exports = Mesh; diff --git a/cocos2d/core/assets/CCModel.js b/cocos2d/core/assets/CCModel.js new file mode 100644 index 0000000000..e349553b20 --- /dev/null +++ b/cocos2d/core/assets/CCModel.js @@ -0,0 +1,249 @@ +/**************************************************************************** + 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. + ****************************************************************************/ + +const renderEngine = require('../renderer/render-engine'); +const renderer = require('../renderer'); +const gfx = renderEngine.gfx; +const vec3 = cc.vmath.vec3; + +const _type2size = { + SCALAR: 1, + VEC2: 2, + VEC3: 3, + VEC4: 4, + MAT2: 4, + MAT3: 9, + MAT4: 16, +}; + +var Model = cc.Class({ + name: 'cc.Model', + extends: cc.Asset, + + ctor () { + this._bin = null; + }, + + properties: { + _nativeAsset: { + get () { + return this._bin; + }, + set (bin) { + this._bin = bin.buffer; + }, + override: true + }, + + _gltf: { + default: {} + } + }, + + _createVB (bin, gltf, accessors, attributes) { + // create vertex-format + let vfmt = []; + let vcount = 0; + + let byteOffset = 10e7, maxByteOffset = 0; + + if (attributes.POSITION !== undefined) { + let acc = accessors[attributes.POSITION]; + let vbView = gltf.bufferViews[acc.bufferView]; + vcount = acc.count; + + vfmt.push({ + name: gfx.ATTR_POSITION, type: acc.componentType, num: _type2size[acc.type], + byteLength: vbView.byteLength, byteOffset: vbView.byteOffset + }); + + byteOffset = Math.min(byteOffset, vbView.byteOffset); + maxByteOffset = Math.max(maxByteOffset, vbView.byteOffset + vbView.byteLength); + } + + if (attributes.NORMAL !== undefined) { + let acc = accessors[attributes.NORMAL]; + let vbView = gltf.bufferViews[acc.bufferView]; + + vfmt.push({ + name: gfx.ATTR_NORMAL, type: acc.componentType, num: _type2size[acc.type], + byteLength: vbView.byteLength, byteOffset: vbView.byteOffset + }); + + byteOffset = Math.min(byteOffset, vbView.byteOffset); + maxByteOffset = Math.max(maxByteOffset, vbView.byteOffset + vbView.byteLength); + } + + if (attributes.TANGENT !== undefined) { + let acc = accessors[attributes.TANGENT]; + let vbView = gltf.bufferViews[acc.bufferView]; + vfmt.push({ + name: gfx.ATTR_TANGENT, type: acc.componentType, num: _type2size[acc.type], + byteLength: vbView.byteLength, byteOffset: vbView.byteOffset + }); + + byteOffset = Math.min(byteOffset, vbView.byteOffset); + maxByteOffset = Math.max(maxByteOffset, vbView.byteOffset + vbView.byteLength); + } + + if (attributes.COLOR_0 !== undefined) { + let acc = accessors[attributes.COLOR_0]; + let vbView = gltf.bufferViews[acc.bufferView]; + vfmt.push({ + name: gfx.ATTR_COLOR0, type: acc.componentType, num: _type2size[acc.type], + byteLength: vbView.byteLength, byteOffset: vbView.byteOffset + }); + + byteOffset = Math.min(byteOffset, vbView.byteOffset); + maxByteOffset = Math.max(maxByteOffset, vbView.byteOffset + vbView.byteLength); + } + + if (attributes.TEXCOORD_0 !== undefined) { + let acc = accessors[attributes.TEXCOORD_0]; + let vbView = gltf.bufferViews[acc.bufferView]; + vfmt.push({ + name: gfx.ATTR_UV0, type: acc.componentType, num: _type2size[acc.type], + byteLength: vbView.byteLength, byteOffset: vbView.byteOffset + }); + + byteOffset = Math.min(byteOffset, vbView.byteOffset); + maxByteOffset = Math.max(maxByteOffset, vbView.byteOffset + vbView.byteLength); + } + + if (attributes.TEXCOORD_1 !== undefined) { + let acc = accessors[attributes.TEXCOORD_1]; + let vbView = gltf.bufferViews[acc.bufferView]; + vfmt.push({ + name: gfx.ATTR_UV1, type: acc.componentType, num: _type2size[acc.type], + byteLength: vbView.byteLength, byteOffset: vbView.byteOffset + }); + + byteOffset = Math.min(byteOffset, vbView.byteOffset); + maxByteOffset = Math.max(maxByteOffset, vbView.byteOffset + vbView.byteLength); + } + + if (attributes.TEXCOORD_2 !== undefined) { + let acc = accessors[attributes.TEXCOORD_2]; + let vbView = gltf.bufferViews[acc.bufferView]; + vfmt.push({ + name: gfx.ATTR_UV2, type: acc.componentType, num: _type2size[acc.type], + byteLength: vbView.byteLength, byteOffset: vbView.byteOffset + }); + + byteOffset = Math.min(byteOffset, vbView.byteOffset); + maxByteOffset = Math.max(maxByteOffset, vbView.byteOffset + vbView.byteLength); + } + + if (attributes.TEXCOORD_3 !== undefined) { + let acc = accessors[attributes.TEXCOORD_3]; + let vbView = gltf.bufferViews[acc.bufferView]; + vfmt.push({ + name: gfx.ATTR_UV3, type: acc.componentType, num: _type2size[acc.type], + byteLength: vbView.byteLength, byteOffset: vbView.byteOffset + }); + + byteOffset = Math.min(byteOffset, vbView.byteOffset); + maxByteOffset = Math.max(maxByteOffset, vbView.byteOffset + vbView.byteLength); + } + + if (attributes.JOINTS_0 !== undefined) { + let acc = accessors[attributes.JOINTS_0]; + let vbView = gltf.bufferViews[acc.bufferView]; + vfmt.push({ + name: gfx.ATTR_JOINTS, type: acc.componentType, num: _type2size[acc.type], + byteLength: vbView.byteLength, byteOffset: vbView.byteOffset + }); + + byteOffset = Math.min(byteOffset, vbView.byteOffset); + maxByteOffset = Math.max(maxByteOffset, vbView.byteOffset + vbView.byteLength); + } + + if (attributes.WEIGHTS_0 !== undefined) { + let acc = accessors[attributes.WEIGHTS_0]; + let vbView = gltf.bufferViews[acc.bufferView]; + vfmt.push({ + name: gfx.ATTR_WEIGHTS, type: acc.componentType, num: _type2size[acc.type], + byteLength: vbView.byteLength, byteOffset: vbView.byteOffset + }); + + byteOffset = Math.min(byteOffset, vbView.byteOffset); + maxByteOffset = Math.max(maxByteOffset, vbView.byteOffset + vbView.byteLength); + } + + let gfxVFmt = new gfx.VertexFormat(vfmt); + let els = gfxVFmt._elements; + for (let i = 0; i < els.length; i++) { + let el = els[i]; + el.offset = vfmt[i].byteOffset - byteOffset; + el.stride = el.bytes; + } + + // create vertex-buffer + let vbData = new Uint8Array(bin, byteOffset, maxByteOffset - byteOffset); + let vb = new gfx.VertexBuffer( + renderer.device, + gfxVFmt, + gfx.USAGE_STATIC, + vbData, + vcount + ); + + return vb; + }, + + initMesh (meshAsset) { + const index = meshAsset._meshID; + + const bin = this._bin; + const gltf = this._gltf; + const gltfMesh = gltf.meshes[index]; + const accessors = gltf.accessors; + + // create index-buffer + meshAsset._subMeshes.length = gltfMesh.primitives.length; + for (let i = 0; i < gltfMesh.primitives.length; ++i) { + let primitive = gltfMesh.primitives[i]; + + if (primitive.indices === undefined) continue; + + let ibAcc = accessors[primitive.indices]; + let ibView = gltf.bufferViews[ibAcc.bufferView]; + let ibData = new Uint8Array(bin, ibView.byteOffset, ibView.byteLength); + + let vb = this._createVB(bin, gltf, accessors, primitive.attributes); + let ib = new gfx.IndexBuffer( + renderer.device, + ibAcc.componentType, + gfx.USAGE_STATIC, + ibData, + ibAcc.count + ); + + meshAsset._subMeshes[i] = new renderEngine.InputAssembler(vb, ib); + } + } +}); + +module.exports = Model; diff --git a/cocos2d/core/assets/index.js b/cocos2d/core/assets/index.js index 2395baab50..1abe217280 100644 --- a/cocos2d/core/assets/index.js +++ b/cocos2d/core/assets/index.js @@ -40,3 +40,5 @@ require('./CCBitmapFont'); require('./CCLabelAtlas'); require('./CCTextAsset'); require('./CCJsonAsset'); +require('./CCModel'); +require('./CCMesh'); diff --git a/cocos2d/core/camera/CCCamera.js b/cocos2d/core/camera/CCCamera.js index bb0d321b20..4a2d6d53fa 100644 --- a/cocos2d/core/camera/CCCamera.js +++ b/cocos2d/core/camera/CCCamera.js @@ -202,7 +202,7 @@ let Camera = cc.Class({ set (value) { this._depth = value; if (this._camera) { - this._camera.setDepth(value); + this._camera._sortDepth = value; } } }, @@ -290,7 +290,7 @@ let Camera = cc.Class({ camera.dirty = true; camera._cullingMask = camera.view._cullingMask = 1 << cc.Node.BuiltinGroupIndex.DEBUG; - camera.setDepth(cc.macro.MAX_ZINDEX); + camera._sortDepth = cc.macro.MAX_ZINDEX; camera.setClearFlags(0); camera.setColor(0,0,0,0); @@ -342,7 +342,7 @@ let Camera = cc.Class({ if (this._camera) { this._camera.setNode(this.node); this._camera.setClearFlags(this._clearFlags); - this._camera.setDepth(this._depth); + this._camera._sortDepth = this._depth; this._updateBackgroundColor(); this._updateCameraMask(); this._updateTargetTexture(); diff --git a/cocos2d/core/components/CCMeshRenderer.js b/cocos2d/core/components/CCMeshRenderer.js new file mode 100644 index 0000000000..9d8eef65cd --- /dev/null +++ b/cocos2d/core/components/CCMeshRenderer.js @@ -0,0 +1,101 @@ +/**************************************************************************** + 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. + ****************************************************************************/ + +const RenderComponent = require('./CCRenderComponent'); +const Mesh = require('../assets/CCMesh'); +const renderEngine = require('../renderer/render-engine'); +const gfx = renderEngine.gfx; +const RenderFlow = require('../renderer/render-flow'); + +let MeshRenderer = cc.Class({ + name: 'cc.MeshRenderer', + extends: RenderComponent, + + editor: CC_EDITOR && { + menu: 'i18n:MAIN_MENU.component.renderers/MeshRenderer', + }, + + properties: { + _mesh: { + default: null, + type: Mesh + }, + + mesh: { + get () { + return this._mesh; + }, + set (v) { + if (this._mesh === v) return; + this._mesh = v; + this.activeMaterials(); + this.markForUpdateRenderData(true); + this.node._renderFlag |= RenderFlow.FLAG_TRANSFORM; + }, + type: Mesh + }, + + textures: { + default: [], + type: cc.Texture2D + } + }, + + ctor () { + this._renderDatas = []; + this._materials = []; + }, + + onEnable () { + this._super(); + this.activeMaterials(); + }, + + activeMaterials () { + this._materials.length = 0; + if (!this._mesh) { + this.disableRender(); + return; + } + + let subMeshes = this._mesh._subMeshes; + for (let i = 0; i < subMeshes.length; i++) { + let material = new renderEngine.SpriteMaterial(); + material.useModel = true; + material.color = cc.Color.WHITE; + if (cc.macro.ENABLE_3D) { + material.use2DPos = false; + material._mainTech._passes[0].setDepth(true, true); + } + this._materials.push(material); + } + this._material = this._materials[0]; + + this.markForUpdateRenderData(true); + this.markForRender(true); + } +}); + +cc.MeshRenderer = module.exports = MeshRenderer; diff --git a/cocos2d/core/components/index.js b/cocos2d/core/components/index.js index c268c1a4bf..14f581aedc 100644 --- a/cocos2d/core/components/index.js +++ b/cocos2d/core/components/index.js @@ -52,7 +52,8 @@ var components = [ require('./CCToggle'), require('./CCBlockInputEvents'), require('./CCMotionStreak'), - require('./WXSubContextView') + require('./WXSubContextView'), + require('./CCMeshRenderer') ]; module.exports = components; \ No newline at end of file diff --git a/cocos2d/core/load-pipeline/downloader.js b/cocos2d/core/load-pipeline/downloader.js index 287f630284..18281d5904 100644 --- a/cocos2d/core/load-pipeline/downloader.js +++ b/cocos2d/core/load-pipeline/downloader.js @@ -248,6 +248,7 @@ var defaultMap = { // Binary 'binary' : downloadBinary, + 'bin': downloadBinary, 'default' : downloadText }; diff --git a/cocos2d/core/renderer/render-engine.js b/cocos2d/core/renderer/render-engine.js index 77926e01fe..663412e96c 100644 --- a/cocos2d/core/renderer/render-engine.js +++ b/cocos2d/core/renderer/render-engine.js @@ -11006,6 +11006,7 @@ var Camera = function Camera() { this._color = color4.new(0.2, 0.3, 0.47, 1); this._depth = 1; this._stencil = 0; + this._sortDepth = 0; this._clearFlags = enums.CLEAR_COLOR | enums.CLEAR_DEPTH; // culling mask @@ -13595,8 +13596,8 @@ var ForwardRenderer = (function (superclass) { this._reset(); scene._cameras.sort(function (a, b) { - if (a._depth > b._depth) { return 1; } - else if (a._depth < b._depth) { return -1; } + if (a._sortDepth > b._sortDepth) { return 1; } + else if (a._sortDepth < b._sortDepth) { return -1; } else { return 0; } }); @@ -14122,7 +14123,7 @@ var SpriteMaterial = (function (Material$$1) { }; prototypeAccessors.useTexture.get = function () { - this._effect.getDefine('useTexture'); + return this._effect.getDefine('useTexture'); }; prototypeAccessors.useTexture.set = function (val) { @@ -14130,7 +14131,7 @@ var SpriteMaterial = (function (Material$$1) { }; prototypeAccessors.useModel.get = function () { - this._effect.getDefine('useModel'); + return this._effect.getDefine('useModel'); }; prototypeAccessors.useModel.set = function (val) { @@ -14138,7 +14139,7 @@ var SpriteMaterial = (function (Material$$1) { }; prototypeAccessors.use2DPos.get = function () { - this._effect.getDefine('use2DPos'); + return this._effect.getDefine('use2DPos'); }; prototypeAccessors.use2DPos.set = function (val) { @@ -14146,7 +14147,7 @@ var SpriteMaterial = (function (Material$$1) { }; prototypeAccessors.useColor.get = function () { - this._effect.getDefine('useColor'); + return this._effect.getDefine('useColor'); }; prototypeAccessors.useColor.set = function (val) { diff --git a/cocos2d/core/renderer/render-flow.js b/cocos2d/core/renderer/render-flow.js index 4c709b12f4..14e020a7b6 100644 --- a/cocos2d/core/renderer/render-flow.js +++ b/cocos2d/core/renderer/render-flow.js @@ -31,27 +31,6 @@ _proto._localTransform = function (node) { this._next._func(node); }; -function mul (out, a, b) { - let aa=a.m00, ab=a.m01, ac=a.m04, ad=a.m05, atx=a.m12, aty=a.m13; - let ba=b.m00, bb=b.m01, bc=b.m04, bd=b.m05, btx=b.m12, bty=b.m13; - if (bb !== 0 || bc !== 0) { - out.m00 = aa * ba + ab * bc; - out.m01 = aa * bb + ab * bd; - out.m04 = ac * ba + ad * bc; - out.m05 = ac * bb + ad * bd; - out.m12 = ba * atx + bc * aty + btx; - out.m13 = bb * atx + bd * aty + bty; - } - else { - out.m00 = aa * ba; - out.m01 = ab * bd; - out.m04 = ac * ba; - out.m05 = ad * bd; - out.m12 = ba * atx + btx; - out.m13 = bd * aty + bty; - } -} - _proto._worldTransform = function (node) { _walker.worldMatDirty ++; @@ -60,7 +39,7 @@ _proto._worldTransform = function (node) { t.m12 = position.x; t.m13 = position.y; - mul(node._worldMatrix, t, node._parent._worldMatrix); + node._mulMat(node._worldMatrix, node._parent._worldMatrix, t); node._renderFlag &= ~WORLD_TRANSFORM; this._next._func(node); diff --git a/cocos2d/core/renderer/webgl/assemblers/index.js b/cocos2d/core/renderer/webgl/assemblers/index.js index 65a9b28071..dddb67cc92 100644 --- a/cocos2d/core/renderer/webgl/assemblers/index.js +++ b/cocos2d/core/renderer/webgl/assemblers/index.js @@ -28,3 +28,4 @@ require('./mask-assembler'); require('./graphics'); require('./label'); require('./motion-streak'); +require('./mesh-renderer'); diff --git a/cocos2d/core/renderer/webgl/assemblers/mesh-renderer.js b/cocos2d/core/renderer/webgl/assemblers/mesh-renderer.js new file mode 100644 index 0000000000..b676966d97 --- /dev/null +++ b/cocos2d/core/renderer/webgl/assemblers/mesh-renderer.js @@ -0,0 +1,73 @@ +/**************************************************************************** + 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. + ****************************************************************************/ + +const MeshRenderer = require('../../../components/CCMeshRenderer'); +const RenderFlow = require('../../render-flow'); +const vfmtPosUvColor = require('../vertex-format').vfmtPosUvColor; + +let meshRendererAssembler = { + useModel: true, + updateRenderData (comp) { + let renderDatas = comp._renderDatas; + renderDatas.length = 0; + if (!comp.mesh) return; + let submeshes = comp.mesh._subMeshes; + for (let i = 0; i < submeshes.length; i++) { + let IARenderData = cc.renderer.renderEngine.IARenderData; + let data = new IARenderData(); + data.material = comp._materials[i]; + data.ia = submeshes[i]; + renderDatas.push(data); + } + }, + + fillBuffers (comp, renderer) { + if (!comp.mesh) return; + + renderer._flush(); + + let tmpNode = renderer.node; + let tmpMaterial = renderer.material; + renderer.node = comp.node; + + let textures = comp.textures; + let materials = comp._materials; + let renderDatas = comp._renderDatas; + for (let i = 0; i < renderDatas.length; i++) { + let renderData = renderDatas[i]; + if (!textures[i]) { + continue; + } + renderData.material.texture = textures[i]; + renderer.material = renderData.material; + renderer._flushIA(renderData); + } + + renderer.node = tmpNode; + renderer.material = tmpMaterial; + } +}; + +module.exports = MeshRenderer._assembler = meshRendererAssembler; diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 7e72ba3416..f47ed5100e 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -354,7 +354,7 @@ var BaseNode = cc.Class({ if (this._parent === value) { return; } - if (CC_EDITOR && !cc.engine.isPlaying) { + if (CC_EDITOR && cc.engine && !cc.engine.isPlaying) { if (_Scene.DetectConflict.beforeAddChild(this)) { return; } diff --git a/cocos2d/core/utils/polyfill-3d.js b/cocos2d/core/utils/polyfill-3d.js index 7263669444..3dd8e2e68e 100644 --- a/cocos2d/core/utils/polyfill-3d.js +++ b/cocos2d/core/utils/polyfill-3d.js @@ -161,7 +161,7 @@ function getQuat () { * @param {Number} w w value of quternion */ function setQuat (quat, y, z, w) { - let x; + let x = quat; if (y === undefined) { x = quat.x; y = quat.y; @@ -250,6 +250,7 @@ cc._polyfill3D = module.exports = { proto.setScale = setScale; proto.getQuat = getQuat; proto.setQuat = setQuat; + proto._mulMat = cc.vmath.mat4.mul; this.enabled = true; } }, @@ -260,4 +261,4 @@ cc._polyfill3D = module.exports = { this.enabled = false; } } -} \ No newline at end of file +}