From 4ebe2f8ea7d4cb8aad62bb5d964c51709b400177 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Fri, 21 Sep 2018 11:05:13 +0800 Subject: [PATCH] follow 2d convention on transform APIs (#3291) --- .babelrc | 6 ---- .eslintrc.json | 5 +++ cocos/3d/assets/animation-clip.js | 30 ++++++++--------- cocos/3d/assets/utils/gltf-utils.js | 12 +++---- cocos/3d/debugger/draw-mng.js | 4 +-- cocos/3d/debugger/index.js | 6 ++-- cocos/3d/debugger/orbit-camera.js | 14 ++++---- cocos/3d/framework/skeleton-instance.js | 6 ++-- cocos/components/CCCanvas.js | 4 +-- cocos/renderer/renderers/forward-renderer.js | 2 +- cocos/renderer/scene/camera.js | 4 +-- cocos/scene-graph/node.js | 34 ++++++++++---------- 12 files changed, 63 insertions(+), 64 deletions(-) delete mode 100644 .babelrc diff --git a/.babelrc b/.babelrc deleted file mode 100644 index f8e471b57b..0000000000 --- a/.babelrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "plugins": [ - "transform-decorators-legacy", - "transform-class-properties" - ] -} diff --git a/.eslintrc.json b/.eslintrc.json index 7332c23cfd..705297c9a8 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,11 @@ { "extends": "eslint:recommended", "parser": "babel-eslint", + "parserOptions": { + "ecmaFeatures": { + "legacyDecorators": true + } + }, "rules": { "comma-dangle": 0, "no-console": 0, diff --git a/cocos/3d/assets/animation-clip.js b/cocos/3d/assets/animation-clip.js index cb6d0f4779..b68375d083 100644 --- a/cocos/3d/assets/animation-clip.js +++ b/cocos/3d/assets/animation-clip.js @@ -144,15 +144,15 @@ export default class AnimationClip extends Asset { } if (jointFrames.translations) { - joint.setLocalPos(jointFrames.translations[0]); + joint.setPosition(jointFrames.translations[0]); } if (jointFrames.rotations) { - joint.setLocalRot(jointFrames.rotations[0]); + joint.setRotation(jointFrames.rotations[0]); } if (jointFrames.scales) { - joint.setLocalScale(jointFrames.scales[0]); + joint.setScale(jointFrames.scales[0]); } } } else { @@ -172,7 +172,7 @@ export default class AnimationClip extends Asset { let b = jointFrames.translations[hiIdx]; vec3.lerp(tmpvec3, a, b, ratio); - joint.setLocalPos(tmpvec3); + joint.setPosition(tmpvec3); } if (jointFrames.rotations) { @@ -180,7 +180,7 @@ export default class AnimationClip extends Asset { let b = jointFrames.rotations[hiIdx]; quat.slerp(tmpquat, a, b, ratio); - joint.setLocalRot(tmpquat); + joint.setRotation(tmpquat); } if (jointFrames.scales) { @@ -188,7 +188,7 @@ export default class AnimationClip extends Asset { let b = jointFrames.scales[hiIdx]; vec3.lerp(tmpvec3, a, b, ratio); - joint.setLocalScale(tmpvec3); + joint.setScale(tmpvec3); } } } @@ -345,17 +345,17 @@ class SamplingStateJointState { /** * @type {vec3} */ - this._originalPos = joint.getLocalPos(); + this._originalPos = joint.getPosition(); /** * @type {vec3} */ - this._originalScale = joint.getLocalScale(); + this._originalScale = joint.getScale(); /** * @type {quat} */ - this._originalRot = joint.getLocalRot(); + this._originalRot = joint.getRotation(); /** * @type {Number} @@ -374,9 +374,9 @@ class SamplingStateJointState { } reset() { - this._joint.setLocalPos(0, 0, 0); - this._joint.setLocalScale(1, 1, 1); - this._joint.setLocalRot(0, 0, 0, 1); + this._joint.setPosition(0, 0, 0); + this._joint.setScale(1, 1, 1); + this._joint.setRotation(0, 0, 0, 1); this._sumPosWeight = 0.0; this._sumScaleWeight = 0.0; this._sumRotWeight = 0.0; @@ -384,13 +384,13 @@ class SamplingStateJointState { blendPosition(pos, weight) { vec3.scaleAndAdd(tmpvec3, this._joint._lpos, pos, weight); - this._joint.setLocalPos(tmpvec3); + this._joint.setPosition(tmpvec3); this._sumPosWeight += weight; } blendScale(scale, weight) { vec3.scaleAndAdd(tmpvec3, this._joint._lscale, scale, weight); - this._joint.setLocalScale(tmpvec3); + this._joint.setScale(tmpvec3); this._sumScaleWeight += weight; } @@ -401,7 +401,7 @@ class SamplingStateJointState { blendRotation(rot, weight) { let t = weight / (this._sumRotWeight + weight); quat.slerp(tmpquat, this._joint._lrot, rot, t); - this._joint.setLocalRot(tmpquat); + this._joint.setRotation(tmpquat); this._sumRotWeight += weight; } diff --git a/cocos/3d/assets/utils/gltf-utils.js b/cocos/3d/assets/utils/gltf-utils.js index c374e9445f..a0a85ba622 100644 --- a/cocos/3d/assets/utils/gltf-utils.js +++ b/cocos/3d/assets/utils/gltf-utils.js @@ -400,7 +400,7 @@ export function createEntities(app, gltfNodes) { let node = app.createEntity(gltfNode.name); if (gltfNode.translation) { - node.setLocalPos( + node.setPosition( gltfNode.translation[0], gltfNode.translation[1], gltfNode.translation[2] @@ -408,7 +408,7 @@ export function createEntities(app, gltfNodes) { } if (gltfNode.rotation) { - node.setLocalRot( + node.setRotation( gltfNode.rotation[0], gltfNode.rotation[1], gltfNode.rotation[2], @@ -417,7 +417,7 @@ export function createEntities(app, gltfNodes) { } if (gltfNode.scale) { - node.setLocalScale( + node.setScale( gltfNode.scale[0], gltfNode.scale[1], gltfNode.scale[2] @@ -489,7 +489,7 @@ function _createNode(gltfNode) { let node = new Node(gltfNode.name); if (gltfNode.translation) { - node.setLocalPos( + node.setPosition( gltfNode.translation[0], gltfNode.translation[1], gltfNode.translation[2] @@ -497,7 +497,7 @@ function _createNode(gltfNode) { } if (gltfNode.rotation) { - node.setLocalRot( + node.setRotation( gltfNode.rotation[0], gltfNode.rotation[1], gltfNode.rotation[2], @@ -506,7 +506,7 @@ function _createNode(gltfNode) { } if (gltfNode.scale) { - node.setLocalScale( + node.setScale( gltfNode.scale[0], gltfNode.scale[1], gltfNode.scale[2] diff --git a/cocos/3d/debugger/draw-mng.js b/cocos/3d/debugger/draw-mng.js index 73f21e73ee..8bfeafa351 100644 --- a/cocos/3d/debugger/draw-mng.js +++ b/cocos/3d/debugger/draw-mng.js @@ -314,8 +314,8 @@ export default class DrawMng { addSphere(pos, radius, color, duration = 0.0, depthTest = true) { let primitive = this._primitives.add(); primitive.model.setInputAssembler(this._sphereIA); - primitive.model._node.setLocalPos(pos); - primitive.model._node.setLocalScale(radius, radius, radius); + primitive.model._node.setPosition(pos); + primitive.model._node.setScale(radius, radius, radius); primitive.duration = duration; primitive.depthTest = depthTest; diff --git a/cocos/3d/debugger/index.js b/cocos/3d/debugger/index.js index a0f5a9b463..fa87aae2bf 100644 --- a/cocos/3d/debugger/index.js +++ b/cocos/3d/debugger/index.js @@ -136,9 +136,9 @@ export default class Debugger { this._debugInput.enabled = true; // setup debug camera - this._orbit._node.setLocalPos(mainCam._entity._lpos); - this._orbit._node.setLocalRot(mainCam._entity._lrot); - this._orbit._node.setLocalScale(mainCam._entity._lscale); + this._orbit._node.setPosition(mainCam._entity._lpos); + this._orbit._node.setRotation(mainCam._entity._lrot); + this._orbit._node.setScale(mainCam._entity._lscale); this._orbit.reset(); this._app.scene.setDebugCamera(this._camera); diff --git a/cocos/3d/debugger/orbit-camera.js b/cocos/3d/debugger/orbit-camera.js index df6c05ec1c..a585e53d8d 100644 --- a/cocos/3d/debugger/orbit-camera.js +++ b/cocos/3d/debugger/orbit-camera.js @@ -22,7 +22,7 @@ export default class OrbitCamera { constructor(input) { this._input = input; this._node = new Node('debug-camera'); - this._node.setLocalPos(10, 10, 10); + this._node.setPosition(10, 10, 10); this._node.lookAt(vec3.create(0, 0, 0)); this._df = 0; @@ -39,10 +39,10 @@ export default class OrbitCamera { this._curEye = vec3.create(0, 0, 0); this._destEye = vec3.create(0, 0, 0); - this._node.getWorldRot(this._curRot); + this._node.getWorldRotation(this._curRot); this._destRot = quat.clone(this._curRot); - this._node.getWorldPos(this._curEye); + this._node.getWorldPosition(this._curEye); this._destEye = vec3.clone(this._curEye); } @@ -56,10 +56,10 @@ export default class OrbitCamera { this._rotX = 0; this._rotY = 0; - this._node.getWorldRot(this._curRot); + this._node.getWorldRotation(this._curRot); this._destRot = quat.clone(this._curRot); - this._node.getWorldPos(this._curEye); + this._node.getWorldPosition(this._curEye); this._destEye = vec3.clone(this._curEye); } @@ -238,8 +238,8 @@ export default class OrbitCamera { vec3.lerp(this._curEye, this._curEye, eye, dt * damping); // - this._node.setWorldPos(this._curEye); - this._node.setWorldRot(this._curRot); + this._node.setWorldPosition(this._curEye); + this._node.setWorldRotation(this._curRot); } } \ No newline at end of file diff --git a/cocos/3d/framework/skeleton-instance.js b/cocos/3d/framework/skeleton-instance.js index f642ad9523..d94182dc5e 100644 --- a/cocos/3d/framework/skeleton-instance.js +++ b/cocos/3d/framework/skeleton-instance.js @@ -68,13 +68,13 @@ export default class SkeletonInstance { let jointTo = toSkel._joints[i]; vec3.lerp(_v3_tmp, jointFrom._lpos, jointTo._lpos, alpha); - joint.setLocalPos(_v3_tmp); + joint.setPosition(_v3_tmp); vec3.lerp(_v3_tmp, jointFrom._lscale, jointTo._lscale, alpha); - joint.setLocalScale(_v3_tmp); + joint.setScale(_v3_tmp); quat.lerp(_qt_tmp, jointFrom._lrot, jointTo._lrot, alpha); - joint.setLocalRot(_qt_tmp); + joint.setRotation(_qt_tmp); } } diff --git a/cocos/components/CCCanvas.js b/cocos/components/CCCanvas.js index 10b2f242bb..ad824d5d66 100644 --- a/cocos/components/CCCanvas.js +++ b/cocos/components/CCCanvas.js @@ -195,7 +195,7 @@ export default class Canvas extends Component { var designSize, nodeSize; if (CC_EDITOR) { nodeSize = designSize = cc.engine.getDesignResolutionSize(); - this.node.setLocalPos(designSize.width * 0.5, designSize.height * 0.5); + this.node.setPosition(designSize.width * 0.5, designSize.height * 0.5, 1); } else { var canvasSize = nodeSize = cc.visibleRect; @@ -208,7 +208,7 @@ export default class Canvas extends Component { offsetX = (designSize.width - canvasSize.width) * 0.5; offsetY = (designSize.height - canvasSize.height) * 0.5; } - this.node.setLocalPos(canvasSize.width * 0.5 + offsetX, canvasSize.height * 0.5 + offsetY); + this.node.setPosition(canvasSize.width * 0.5 + offsetX, canvasSize.height * 0.5 + offsetY, 1); } this.node.width = nodeSize.width; this.node.height = nodeSize.height; diff --git a/cocos/renderer/renderers/forward-renderer.js b/cocos/renderer/renderers/forward-renderer.js index d39532d54c..17906ee86f 100644 --- a/cocos/renderer/renderers/forward-renderer.js +++ b/cocos/renderer/renderers/forward-renderer.js @@ -325,7 +325,7 @@ export default class ForwardRenderer extends BaseRenderer { let item = items.data[i]; // TODO: we should use mesh center instead! - item.node.getWorldPos(_v3_tmp1); + item.node.getWorldPosition(_v3_tmp1); vec3.sub(_v3_tmp1, _v3_tmp1, _camPos); item.sortKey = vec3.dot(_v3_tmp1, _camFwd); diff --git a/cocos/renderer/scene/camera.js b/cocos/renderer/scene/camera.js index dd123ee88e..d8cbda3384 100644 --- a/cocos/renderer/scene/camera.js +++ b/cocos/renderer/scene/camera.js @@ -402,7 +402,7 @@ export default class Camera { vec3.transformMat4(out, out, _matInvViewProj); // - this._node.getWorldPos(_tmp_v3); + this._node.getWorldPosition(_tmp_v3); vec3.lerp(out, _tmp_v3, out, screenPos.z / this._far); } else { let range = this._farClip - this._nearClip; @@ -427,7 +427,7 @@ export default class Camera { * @returns {Ray} the resulting ray */ screenPointToRay(screenPos, width, height) { - this._node.getWorldPos(_tmp3_v3); + this._node.getWorldPosition(_tmp3_v3); this.screenToWorld(_tmp2_v3, screenPos, width, height); vec3.normalize(_tmp2_v3, vec3.sub(_tmp2_v3, _tmp2_v3, _tmp3_v3)); return ray.create(_tmp3_v3.x, _tmp3_v3.y, _tmp3_v3.z, _tmp2_v3.x, _tmp2_v3.y, _tmp2_v3.z); diff --git a/cocos/scene-graph/node.js b/cocos/scene-graph/node.js index fb8d336908..b2419954fd 100644 --- a/cocos/scene-graph/node.js +++ b/cocos/scene-graph/node.js @@ -68,12 +68,12 @@ export default class Node extends BaseNode { * @param {vec3} up the up vector, default to (0,1,0) */ lookAt(pos, up) { - this.getWorldPos(v3_a); + this.getWorldPosition(v3_a); vec3.sub(v3_a, v3_a, pos); // NOTE: we use -z for view-dir vec3.normalize(v3_a, v3_a); quat.fromViewUp(q_a, v3_a, up); - this.setWorldRot(q_a); + this.setWorldRotation(q_a); } /** @@ -150,7 +150,7 @@ export default class Node extends BaseNode { * @param {?number} [y] the y component of the new local position * @param {?number} [z] the z component of the new local position */ - setLocalPos(val, y, z) { + setPosition(val, y, z) { if (arguments.length === 1) { vec3.copy(this._lpos, val); } else if (arguments.length === 3) { @@ -165,7 +165,7 @@ export default class Node extends BaseNode { * @param {?vec3} out the receiving vector * @return {vec3} the resulting vector */ - getLocalPos(out) { + getPosition(out) { if (out) { return vec3.set(out, this._lpos.x, this._lpos.y, this._lpos.z); } else { @@ -180,7 +180,7 @@ export default class Node extends BaseNode { * @param {?number} [z] the z component of the new local rotation * @param {?number} [w] the w component of the new local rotation */ - setLocalRot(val, y, z, w) { + setRotation(val, y, z, w) { if (arguments.length === 1) { quat.copy(this._lrot, val); } else if (arguments.length === 4) { @@ -196,7 +196,7 @@ export default class Node extends BaseNode { * @param {?number} y the y component of the new local rotation * @param {?number} z the z component of the new local rotation */ - setLocalRotFromEuler(x, y, z) { + setRotationFromEuler(x, y, z) { quat.fromEuler(this._lrot, x, y, z); quat.copy(this._rot, this._lrot); this.invalidateChildren(); @@ -207,7 +207,7 @@ export default class Node extends BaseNode { * @param {?quat} out the receiving quaternion * @return {quat} the resulting quaternion */ - getLocalRot(out) { + getRotation(out) { if (out) { return quat.set(out, this._lrot.x, this._lrot.y, this._lrot.z); } else { @@ -221,7 +221,7 @@ export default class Node extends BaseNode { * @param {?number} [y] the y component of the new local scale * @param {?number} [z] the z component of the new local scale */ - setLocalScale(val, y, z) { + setScale(val, y, z) { if (arguments.length === 1) { vec3.copy(this._lscale, val); } else if (arguments.length === 3) { @@ -236,7 +236,7 @@ export default class Node extends BaseNode { * @param {?vec3} out the receiving vector * @return {vec3} the resulting vector */ - getLocalScale(out) { + getScale(out) { if (out) { return vec3.set(out, this._lscale.x, this._lscale.y, this._lscale.z); } else { @@ -250,14 +250,14 @@ export default class Node extends BaseNode { * @param {?number} y the y component of the new world position * @param {?number} z the z component of the new world position */ - setWorldPos(val, y, z) { + setWorldPosition(val, y, z) { if (arguments.length === 1) { vec3.copy(this._pos, val); } else if (arguments.length === 3) { vec3.set(this._pos, val, y, z); } if (this._parent) { - this._parent.getWorldPos(v3_a); + this._parent.getWorldPosition(v3_a); vec3.sub(this._lpos, this._pos, v3_a); } else { vec3.copy(this._lpos, this._pos); @@ -270,7 +270,7 @@ export default class Node extends BaseNode { * @param {?vec3} out the receiving vector * @return {vec3} the resulting vector */ - getWorldPos(out) { + getWorldPosition(out) { this.updateWorldTransform(); if (out) { return vec3.copy(out, this._pos); @@ -286,14 +286,14 @@ export default class Node extends BaseNode { * @param {?number} z the z component of the new world rotation * @param {?number} w the w component of the new world rotation */ - setWorldRot(val, y, z, w) { + setWorldRotation(val, y, z, w) { if (arguments.length === 1) { quat.copy(this._rot, val); } else if (arguments.length === 4) { quat.set(this._rot, val, y, z, w); } if (this._parent) { - this._parent.getWorldRot(q_a); + this._parent.getWorldRotation(q_a); quat.mul(this._lrot, this._rot, quat.conjugate(q_a, q_a)); } else { quat.copy(this._lrot, this._rot); @@ -307,10 +307,10 @@ export default class Node extends BaseNode { * @param {?number} y the y component of the new world rotation * @param {?number} z the z component of the new world rotation */ - setWorldRotFromEuler(x, y, z) { + setWorldRotationFromEuler(x, y, z) { quat.fromEuler(this._rot, x, y, z); if (this._parent) { - this._parent.getWorldRot(q_a); + this._parent.getWorldRotation(q_a); quat.mul(this._lrot, this._rot, quat.conjugate(q_a, q_a)); } else { quat.copy(this._lrot, this._rot); @@ -323,7 +323,7 @@ export default class Node extends BaseNode { * @param {?quat} out the receiving quaternion * @return {quat} the resulting quaternion */ - getWorldRot(out) { + getWorldRotation(out) { this.updateWorldTransform(); if (out) { return quat.copy(out, this._rot);