diff --git a/cocos/3d/framework/skinning-model-component.ts b/cocos/3d/framework/skinning-model-component.ts index 9b36767fdf..e647da427f 100644 --- a/cocos/3d/framework/skinning-model-component.ts +++ b/cocos/3d/framework/skinning-model-component.ts @@ -94,15 +94,6 @@ export class SkinningModelComponent extends ModelComponent { return 0; } - public onLoad () { - super.onLoad(); - if (this._skinningRoot && this._skinningRoot.getComponent(AnimationComponent)) { return; } - // find the lowest AnimationComponent node as the new skinning root - let root: Node | null = this.node; - while (root && !root.getComponent(AnimationComponent)) { root = root.parent; } - this._skinningRoot = root; - } - public uploadAnimationClip (clip: SkeletalAnimationClip) { if (this._model) { (this._model as SkinningModel).uploadAnimationClip(clip); } } diff --git a/cocos/3d/ui/assembler/sprite/simple.ts b/cocos/3d/ui/assembler/sprite/simple.ts index 3b11a528f7..6d9da866a9 100644 --- a/cocos/3d/ui/assembler/sprite/simple.ts +++ b/cocos/3d/ui/assembler/sprite/simple.ts @@ -29,14 +29,11 @@ */ import { Vec3 } from '../../../../core/value-types'; -import { color4, vec3 } from '../../../../core/vmath'; import { IRenderData, RenderData } from '../../../../renderer/ui/renderData'; import { UI } from '../../../../renderer/ui/ui'; import { Node } from '../../../../scene-graph/node'; import { SpriteComponent } from '../../components'; import { IAssembler } from '../base'; -// const dynamicAtlasManager = require('../../../../utils/dynamic-atlas/manager'); -const matrix = cc.mat4(); const vec3_temps: Vec3[] = []; for (let i = 0; i < 4; i++) { vec3_temps.push(new Vec3()); @@ -109,51 +106,73 @@ export const simple: IAssembler = { vertexId = 0; } - // buffer data may be realloc, need get reference after request. - const vbuf: Float32Array | null = buffer.vData; - // const uintbuf = buffer.uintVData; - const ibuf: Uint16Array | null = buffer.iData; - + // buffer data may be reallocated, need get reference after request. + const vbuf = buffer.vData!; + const ibuf = buffer.iData!; + const vData = sprite!.renderData!.vData!; const data0 = datas[0]; const data3 = datas[3]; - - // // get uv from sprite frame directly - let matrix = node.worldMatrix; - - let vl = data0.x, vr = data3.x, - vb = data0.y, vt = data3.y; - let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05, - tx = matrix.m12, ty = matrix.m13; - - let al = a * vl, ar = a * vr, - bl = b * vl, br = b * vr, - cb = c * vb, ct = c * vt, - db = d * vb, dt = d * vt; - - let vData = sprite!.renderData!.vData; - + /* */ + node.updateWorldTransform(); + // @ts-ignore + const pos = node._pos; const rot = node._rot; const scale = node._scale; + const ax = data0.x * scale.x; const bx = data3.x * scale.x; + const ay = data0.y * scale.y; const by = data3.y * scale.y; + const qx = rot.x; const qy = rot.y; const qz = rot.z; const qw = rot.w; + const qxy = qx * qy; const qzw = qz * qw; + const qxy2 = qx * qx - qy * qy; + const qzw2 = qw * qw - qz * qz; + const cx1 = qzw2 + qxy2; + const cx2 = (qxy - qzw) * 2; + const cy1 = qzw2 - qxy2; + const cy2 = (qxy + qzw) * 2; + const x = pos.x; const y = pos.y; // left bottom - vData![0] = al + cb + tx; - vData![1] = bl + db + ty; + vData[0] = cx1 * ax + cx2 * ay + x; + vData[1] = cy1 * ay + cy2 * ax + y; // right bottom - vData![9] = ar + cb + tx; - vData![10] = br + db + ty; + vData[9] = cx1 * bx + cx2 * ay + x; + vData[10] = cy1 * ay + cy2 * bx + y; // left top - vData![18] = al + ct + tx; - vData![19] = bl + dt + ty; + vData[18] = cx1 * ax + cx2 * by + x; + vData[19] = cy1 * by + cy2 * ax + y; // right top - vData![27] = ar + ct + tx; - vData![28] = br + dt + ty; + vData[27] = cx1 * bx + cx2 * by + x; + vData[28] = cy1 * by + cy2 * bx + y; + /* * + const matrix = node.worldMatrix; + const a = matrix.m00; const b = matrix.m01; + const c = matrix.m04; const d = matrix.m05; + const tx = matrix.m12; const ty = matrix.m13; + const vl = data0.x; const vr = data3.x; + const vb = data0.y; const vt = data3.y; + const al = a * vl; const ar = a * vr; + const bl = b * vl; const br = b * vr; + const cb = c * vb; const ct = c * vt; + const db = d * vb; const dt = d * vt; + // left bottom + vData[0] = al + cb + tx; + vData[1] = bl + db + ty; + // right bottom + vData[9] = ar + cb + tx; + vData[10] = br + db + ty; + // left top + vData[18] = al + ct + tx; + vData[19] = bl + dt + ty; + // right top + vData[27] = ar + ct + tx; + vData[28] = br + dt + ty; + /* */ - vbuf!.set(vData!, vertexOffset); + vbuf.set(vData, vertexOffset); // fill indice data - ibuf![indiceOffset++] = vertexId; - ibuf![indiceOffset++] = vertexId + 1; - ibuf![indiceOffset++] = vertexId + 2; - ibuf![indiceOffset++] = vertexId + 1; - ibuf![indiceOffset++] = vertexId + 3; - ibuf![indiceOffset++] = vertexId + 2; + ibuf[indiceOffset++] = vertexId; + ibuf[indiceOffset++] = vertexId + 1; + ibuf[indiceOffset++] = vertexId + 2; + ibuf[indiceOffset++] = vertexId + 2; + ibuf[indiceOffset++] = vertexId + 1; + ibuf[indiceOffset++] = vertexId + 3; }, updateVerts (sprite: SpriteComponent) { @@ -214,27 +233,30 @@ export const simple: IAssembler = { }, updateUvs (sprite) { - let renderData = sprite.renderData; - let vData = renderData.vData; + const renderData = sprite.renderData; + const vData = renderData.vData!; const uv = sprite!.spriteFrame!.uv; - vData![3] = uv[0]; - vData![4] = uv[1]; - vData![12] = uv[2]; - vData![13] = uv[3]; - vData![21] = uv[4]; - vData![22] = uv[5]; - vData![30] = uv[6]; - vData![31] = uv[7]; + vData[3] = uv[0]; + vData[4] = uv[1]; + vData[12] = uv[2]; + vData[13] = uv[3]; + vData[21] = uv[4]; + vData[22] = uv[5]; + vData[30] = uv[6]; + vData[31] = uv[7]; renderData.uvDirty = false; }, updateColor (sprite) { - let vData = sprite.renderData.vData; + const vData = sprite.renderData.vData; - // - let colorOffset = 5, color = sprite.color; - let colorr = color.r / 255, colorg = color.g / 255, colorb = color.b / 255, colora = color.a / 255; + let colorOffset = 5; + const color = sprite.color; + const colorr = color.r / 255; + const colorg = color.g / 255; + const colorb = color.b / 255; + const colora = color.a / 255; for (let i = 0; i < 4; i++) { vData![colorOffset] = colorr; vData![colorOffset + 1] = colorg; @@ -243,5 +265,5 @@ export const simple: IAssembler = { colorOffset += 9; } - } + }, }; diff --git a/cocos/animation/animation-component.ts b/cocos/animation/animation-component.ts index 70a0a4ac91..60d85bcffa 100644 --- a/cocos/animation/animation-component.ts +++ b/cocos/animation/animation-component.ts @@ -1,3 +1,27 @@ +/* + 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. +*/ /** * @category animation diff --git a/cocos/animation/animation-state.ts b/cocos/animation/animation-state.ts index 5c7b8581bf..af7f1a84f3 100644 --- a/cocos/animation/animation-state.ts +++ b/cocos/animation/animation-state.ts @@ -1,3 +1,28 @@ +/* + 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. +*/ + /** * @category animation */ diff --git a/cocos/animation/skeletal-animation-clip.ts b/cocos/animation/skeletal-animation-clip.ts index c7019caa29..caec1c84b8 100644 --- a/cocos/animation/skeletal-animation-clip.ts +++ b/cocos/animation/skeletal-animation-clip.ts @@ -1,3 +1,27 @@ +/* + 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. +*/ /** * @category animation @@ -90,7 +114,7 @@ export class SkeletalAnimationClip extends AnimationClip { if (!this.curveDatas[path]) { this.curveDatas[path] = {}; } this.curveDatas[path].comps = { [getClassName(comp)]: { frameID: { keys: 0, values, interpolate: false } } }; } else if (!CC_EDITOR) { // rig non-skinning renderables - this._convertToRiggingData(comp, root); + this._convertToRiggingData(comp.node.parent!, root); } } this._keys = [values.map((_, i) => i / this.sample)]; @@ -140,8 +164,7 @@ export class SkeletalAnimationClip extends AnimationClip { } } - private _convertToRiggingData (comp: RenderableComponent, root: Node) { - const targetNode = comp.node.parent!; + private _convertToRiggingData (targetNode: Node, root: Node) { const targetPath = getPathFromRoot(targetNode, root); // find lowest joint animation let animPath = targetPath; diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 8e122a5941..162f91e9a5 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -27,7 +27,7 @@ * @category scene-graph */ -import { UITransformComponent, UIComponent } from '../3d'; +import { UIComponent, UITransformComponent } from '../3d/ui/components'; import { ccclass, property } from '../core/data/class-decorator'; import Event from '../core/event/event'; import { eventManager } from '../core/platform/event-manager'; @@ -108,6 +108,7 @@ export class Node extends BaseNode { protected _eventProcessor: NodeEventProcessor = new cc.NodeEventProcessor(this); protected _eventMask = 0; private _uiTransfromComp: UITransformComponent | null = null; + // tslint:disable-next-line: member-ordering public _uiComp: UIComponent | null = null; /**