mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #2520 from pandamicro/optimize
Add transform system to reduce matrix update overhead
This commit is contained in:
@@ -30,8 +30,10 @@ const AutoReleaseUtils = require('./load-pipeline/auto-release-utils');
|
||||
const ComponentScheduler = require('./component-scheduler');
|
||||
const NodeActivator = require('./node-activator');
|
||||
const EventListeners = require('./event/event-listeners');
|
||||
const Obj = require('./platform/CCObject');
|
||||
const renderer = require('./renderer');
|
||||
const eventManager = require('./event-manager');
|
||||
const transformSys = require('./systems/transform');
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -440,7 +442,7 @@ cc.Director.prototype = {
|
||||
this._scene = null;
|
||||
|
||||
// purge destroyed nodes belongs to old scene
|
||||
cc.Object._deferredDestroy();
|
||||
Obj._deferredDestroy();
|
||||
CC_BUILD && CC_DEBUG && console.timeEnd('Destroy');
|
||||
|
||||
if (onBeforeLoadScene) {
|
||||
@@ -913,6 +915,7 @@ cc.Director.prototype = {
|
||||
* Run main loop of director
|
||||
*/
|
||||
mainLoop: CC_EDITOR ? function (deltaTime, updateAnimate) {
|
||||
// Update
|
||||
if (!this._paused) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
|
||||
@@ -926,13 +929,19 @@ cc.Director.prototype = {
|
||||
this._compScheduler.lateUpdatePhase(deltaTime);
|
||||
|
||||
this.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
|
||||
transformSys.update();
|
||||
}
|
||||
|
||||
this.emit(cc.Director.EVENT_BEFORE_DRAW);
|
||||
// Render
|
||||
this.emit(cc.Director.EVENT_BEFORE_DRAW);
|
||||
renderer.render(this._scene);
|
||||
this._totalFrames++;
|
||||
|
||||
// After draw
|
||||
this.emit(cc.Director.EVENT_AFTER_DRAW);
|
||||
transformSys.afterDraw();
|
||||
|
||||
this._totalFrames++;
|
||||
|
||||
} : function () {
|
||||
if (this._purgeDirectorInNextLoop) {
|
||||
@@ -943,6 +952,7 @@ cc.Director.prototype = {
|
||||
// calculate "global" dt
|
||||
this.calculateDeltaTime();
|
||||
|
||||
// Update
|
||||
if (!this._paused) {
|
||||
this.emit(cc.Director.EVENT_BEFORE_UPDATE);
|
||||
// Call start for new added components
|
||||
@@ -956,15 +966,21 @@ cc.Director.prototype = {
|
||||
// User can use this event to do things after update
|
||||
this.emit(cc.Director.EVENT_AFTER_UPDATE);
|
||||
// Destroy entities that have been removed recently
|
||||
cc.Object._deferredDestroy();
|
||||
Obj._deferredDestroy();
|
||||
// Update transform for all dirty nodes
|
||||
transformSys.update();
|
||||
}
|
||||
this.emit(cc.Director.EVENT_BEFORE_DRAW);
|
||||
|
||||
// Render
|
||||
this.emit(cc.Director.EVENT_BEFORE_DRAW);
|
||||
renderer.render(this._scene);
|
||||
this._totalFrames++;
|
||||
|
||||
// After draw
|
||||
this.emit(cc.Director.EVENT_AFTER_DRAW);
|
||||
|
||||
transformSys.afterDraw();
|
||||
|
||||
eventManager.frameUpdateListeners();
|
||||
this._totalFrames++;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
+30
-68
@@ -35,6 +35,7 @@ const eventManager = require('./event-manager');
|
||||
const macro = require('./platform/CCMacro');
|
||||
const misc = require('./utils/misc');
|
||||
const Event = require('./event/event');
|
||||
const transformSys = require('./systems/transform');
|
||||
|
||||
const Flags = cc.Object.Flags;
|
||||
const Destroying = Flags.Destroying;
|
||||
@@ -43,7 +44,6 @@ const POSITION_CHANGED = 'position-changed';
|
||||
const SIZE_CHANGED = 'size-changed';
|
||||
const ANCHOR_CHANGED = 'anchor-changed';
|
||||
const ROTATION_CHANGED = 'rotation-changed';
|
||||
const WORLD_MATRIX_CHANGED = 'world-matrix-changed';
|
||||
const SCALE_CHANGED = 'scale-changed';
|
||||
const CHILD_REORDER = 'child-reorder';
|
||||
|
||||
@@ -421,7 +421,7 @@ var Node = cc.Class({
|
||||
}
|
||||
|
||||
localPosition.x = value;
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
|
||||
// fast check event
|
||||
var cache = this._hasListenerCache;
|
||||
@@ -464,7 +464,7 @@ var Node = cc.Class({
|
||||
}
|
||||
|
||||
localPosition.y = value;
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
|
||||
// fast check event
|
||||
var cache = this._hasListenerCache;
|
||||
@@ -494,7 +494,7 @@ var Node = cc.Class({
|
||||
if (value !== localPosition.z) {
|
||||
if (!CC_EDITOR || isFinite(value)) {
|
||||
localPosition.z = value;
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
}
|
||||
else {
|
||||
cc.error(ERR_INVALID_NUMBER, 'new z');
|
||||
@@ -524,7 +524,7 @@ var Node = cc.Class({
|
||||
this._rotationX = this._rotationY = value;
|
||||
// Update quaternion from rotation
|
||||
math.quat.fromEuler(this._quat, 0, 0, -value);
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[ROTATION_CHANGED]) {
|
||||
@@ -557,7 +557,7 @@ var Node = cc.Class({
|
||||
else {
|
||||
math.quat.fromEuler(this._quat, value, this._rotationY, 0);
|
||||
}
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[ROTATION_CHANGED]) {
|
||||
@@ -590,7 +590,7 @@ var Node = cc.Class({
|
||||
else {
|
||||
math.quat.fromEuler(this._quat, this._rotationX, value, 0);
|
||||
}
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[ROTATION_CHANGED]) {
|
||||
@@ -625,7 +625,7 @@ var Node = cc.Class({
|
||||
set (value) {
|
||||
if (this._scale.x !== value) {
|
||||
this._scale.x = value;
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[SCALE_CHANGED]) {
|
||||
@@ -651,7 +651,7 @@ var Node = cc.Class({
|
||||
set (value) {
|
||||
if (this._scale.y !== value) {
|
||||
this._scale.y = value;
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[SCALE_CHANGED]) {
|
||||
@@ -676,7 +676,7 @@ var Node = cc.Class({
|
||||
},
|
||||
set (value) {
|
||||
this._skewX = value;
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -695,7 +695,7 @@ var Node = cc.Class({
|
||||
},
|
||||
set (value) {
|
||||
this._skewY = value;
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -908,8 +908,8 @@ var Node = cc.Class({
|
||||
|
||||
this._matrix = mathPools.mat4.get();
|
||||
this._worldMatrix = mathPools.mat4.get();
|
||||
this._localMatDirty = true;
|
||||
this._worldMatDirty = true;
|
||||
this._localMatDirty = false;
|
||||
this._worldMatDirty = false;
|
||||
|
||||
this._cullingMask = 1 << this.groupIndex;
|
||||
},
|
||||
@@ -983,6 +983,9 @@ var Node = cc.Class({
|
||||
var actionManager = ActionManagerExist ? cc.director.getActionManager() : null;
|
||||
if (active) {
|
||||
// activate
|
||||
// Force update transform
|
||||
transformSys.setNodeDirty(this);
|
||||
// ActionManager & EventManager
|
||||
actionManager && actionManager.resumeTarget(this);
|
||||
eventManager.resumeTarget(this);
|
||||
if (this._touchListener) {
|
||||
@@ -1281,7 +1284,7 @@ var Node = cc.Class({
|
||||
testPt = cc.v2(point);
|
||||
}
|
||||
|
||||
this._updateWorldMatrix();
|
||||
transformSys._updateWorldMatrix(this);
|
||||
math.mat4.invert(_mat4_temp, this._worldMatrix);
|
||||
math.vec2.transformMat4(testPt, testPt, _mat4_temp);
|
||||
testPt.x += this._anchorPoint.x * this._contentSize.width;
|
||||
@@ -1531,7 +1534,7 @@ var Node = cc.Class({
|
||||
else {
|
||||
return cc.error(ERR_INVALID_NUMBER, 'y of new position');
|
||||
}
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
|
||||
// fast check event
|
||||
var cache = this._hasListenerCache;
|
||||
@@ -1583,7 +1586,7 @@ var Node = cc.Class({
|
||||
if (this._scale.x !== scaleX || this._scale.y !== scaleY) {
|
||||
this._scale.x = scaleX;
|
||||
this._scale.y = scaleY;
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
|
||||
var cache = this._hasListenerCache;
|
||||
if (cache && cache[SCALE_CHANGED]) {
|
||||
@@ -1721,7 +1724,7 @@ var Node = cc.Class({
|
||||
locAnchorPoint.x = point;
|
||||
locAnchorPoint.y = y;
|
||||
}
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
this.emit(ANCHOR_CHANGED);
|
||||
},
|
||||
|
||||
@@ -1789,7 +1792,7 @@ var Node = cc.Class({
|
||||
math.vec3.copy(this._position, pos);
|
||||
}
|
||||
|
||||
this._localMatDirty = true;
|
||||
transformSys.setNodeDirty(this);
|
||||
|
||||
// fast check event
|
||||
var cache = this._hasListenerCache;
|
||||
@@ -1901,44 +1904,6 @@ var Node = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
_calculWorldMatrix () {
|
||||
// Avoid as much function call as possible
|
||||
if (this._localMatDirty) {
|
||||
this._updateLocalMatrix();
|
||||
}
|
||||
|
||||
// Assume parent world matrix is correct
|
||||
if (this._parent) {
|
||||
let parentMat = this._parent._worldMatrix;
|
||||
math.mat4.mul(this._worldMatrix, parentMat, this._matrix);
|
||||
}
|
||||
else {
|
||||
math.mat4.copy(this._worldMatrix, this._matrix);
|
||||
}
|
||||
this._worldMatDirty = false;
|
||||
|
||||
this.emit(WORLD_MATRIX_CHANGED);
|
||||
|
||||
for (let i = 0, len = this._children.length; i < len; ++i) {
|
||||
let child = this._children[i];
|
||||
child._calculWorldMatrix();
|
||||
}
|
||||
},
|
||||
|
||||
_updateWorldMatrix () {
|
||||
let curr = this;
|
||||
let changedRoot = null;
|
||||
while (curr) {
|
||||
if (curr._localMatDirty || curr._worldMatDirty) {
|
||||
changedRoot = curr;
|
||||
}
|
||||
curr = curr._parent;
|
||||
}
|
||||
if (changedRoot) {
|
||||
changedRoot._calculWorldMatrix();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en
|
||||
* Get the local transform matrix (4x4), based on parent node coordinates
|
||||
@@ -1967,7 +1932,7 @@ var Node = cc.Class({
|
||||
* node.getLocalMatrix(mat4);
|
||||
*/
|
||||
getWorldMatrix (out) {
|
||||
this._updateWorldMatrix();
|
||||
transformSys._updateWorldMatrix(this);
|
||||
return math.mat4.copy(out, this._worldMatrix);
|
||||
},
|
||||
|
||||
@@ -1981,7 +1946,7 @@ var Node = cc.Class({
|
||||
* var newVec2 = node.convertToNodeSpace(cc.v2(100, 100));
|
||||
*/
|
||||
convertToNodeSpace (worldPoint) {
|
||||
this._updateWorldMatrix();
|
||||
transformSys._updateWorldMatrix(this);
|
||||
math.mat4.invert(_mat4_temp, this._worldMatrix);
|
||||
let out = new cc.Vec2();
|
||||
math.vec2.transformMat4(out, worldPoint, _mat4_temp);
|
||||
@@ -2000,7 +1965,7 @@ var Node = cc.Class({
|
||||
* var newVec2 = node.convertToWorldSpace(cc.v2(100, 100));
|
||||
*/
|
||||
convertToWorldSpace (nodePoint) {
|
||||
this._updateWorldMatrix();
|
||||
transformSys._updateWorldMatrix(this);
|
||||
let out = new cc.Vec2(
|
||||
nodePoint.x - this._anchorPoint.x * this._contentSize.width,
|
||||
nodePoint.y - this._anchorPoint.y * this._contentSize.height
|
||||
@@ -2022,7 +1987,7 @@ var Node = cc.Class({
|
||||
* var newVec2 = node.convertToNodeSpaceAR(cc.v2(100, 100));
|
||||
*/
|
||||
convertToNodeSpaceAR (worldPoint) {
|
||||
this._updateWorldMatrix();
|
||||
transformSys._updateWorldMatrix(this);
|
||||
math.mat4.invert(_mat4_temp, this._worldMatrix);
|
||||
let out = new cc.Vec2();
|
||||
return math.vec2.transformMat4(out, worldPoint, _mat4_temp);
|
||||
@@ -2042,7 +2007,7 @@ var Node = cc.Class({
|
||||
* var newVec2 = node.convertToWorldSpaceAR(cc.v2(100, 100));
|
||||
*/
|
||||
convertToWorldSpaceAR (nodePoint) {
|
||||
this._updateWorldMatrix();
|
||||
transformSys._updateWorldMatrix(this);
|
||||
let out = new cc.Vec2();
|
||||
return math.vec2.transformMat4(out, nodePoint, this._worldMatrix);
|
||||
},
|
||||
@@ -2116,7 +2081,7 @@ var Node = cc.Class({
|
||||
if (!out) {
|
||||
out = AffineTrans.identity();
|
||||
}
|
||||
this._updateWorldMatrix();
|
||||
transformSys._updateWorldMatrix(this);
|
||||
|
||||
var contentSize = this._contentSize;
|
||||
_vec3_temp.x = -this._anchorPoint.x * contentSize.width;
|
||||
@@ -2147,7 +2112,7 @@ var Node = cc.Class({
|
||||
if (!out) {
|
||||
out = AffineTrans.identity();
|
||||
}
|
||||
this._updateWorldMatrix();
|
||||
transformSys._updateWorldMatrix(this);
|
||||
return AffineTrans.fromMat4(out, this._matrix);
|
||||
},
|
||||
|
||||
@@ -2190,7 +2155,7 @@ var Node = cc.Class({
|
||||
if (!out) {
|
||||
out = AffineTrans.identity();
|
||||
}
|
||||
this._updateWorldMatrix();
|
||||
transformSys._updateWorldMatrix(this);
|
||||
math.mat4.invert(_mat4_temp, this._worldMatrix);
|
||||
return AffineTrans.fromMat4(out, _mat4_temp);
|
||||
},
|
||||
@@ -2259,7 +2224,7 @@ var Node = cc.Class({
|
||||
*/
|
||||
getBoundingBoxToWorld () {
|
||||
if (this._parent) {
|
||||
this._parent._updateWorldMatrix();
|
||||
transformSys._updateWorldMatrix(this._parent);
|
||||
return this._getBoundingBoxTo(this._parent._worldMatrix);
|
||||
}
|
||||
else {
|
||||
@@ -2398,9 +2363,6 @@ var Node = cc.Class({
|
||||
},
|
||||
|
||||
onRestore: CC_EDITOR && function () {
|
||||
this._localMatDirty = true;
|
||||
this._worldMatDirty = true;
|
||||
|
||||
this._onRestoreBase();
|
||||
|
||||
var actionManager = cc.director.getActionManager();
|
||||
|
||||
@@ -291,8 +291,8 @@ let Camera = cc.Class({
|
||||
},
|
||||
|
||||
onEnable () {
|
||||
this.node.on('world-matrix-changed', this._onMatrixDirty, this);
|
||||
this._matrixDirty = true;
|
||||
cc.director.on(cc.Director.EVENT_AFTER_DRAW, this.afterDraw, this);
|
||||
|
||||
if (game.renderType === game.RENDER_TYPE_WEBGL) {
|
||||
renderer.scene.addCamera(this._camera);
|
||||
@@ -301,7 +301,7 @@ let Camera = cc.Class({
|
||||
},
|
||||
|
||||
onDisable () {
|
||||
this.node.off('world-matrix-changed', this._onMatrixDirty, this);
|
||||
cc.director.off(cc.Director.EVENT_AFTER_DRAW, this.afterDraw, this);
|
||||
|
||||
if (game.renderType === game.RENDER_TYPE_WEBGL) {
|
||||
renderer.scene.removeCamera(this._camera);
|
||||
@@ -432,17 +432,19 @@ let Camera = cc.Class({
|
||||
root = root || cc.director.getScene();
|
||||
if (!root) return null;
|
||||
|
||||
this.lateUpdate();
|
||||
// force update node world matrix
|
||||
this.node.getWorldMatrix(_mat4_temp_1);
|
||||
this.afterDraw();
|
||||
renderer._walker.visit(root);
|
||||
renderer._forward.renderCamera(this._camera, renderer.scene);
|
||||
},
|
||||
|
||||
lateUpdate: !CC_EDITOR && function () {
|
||||
afterDraw: !CC_EDITOR && function () {
|
||||
let node = this.node;
|
||||
node.getWorldMatrix(_mat4_temp_1);
|
||||
|
||||
if (!this._matrixDirty) return;
|
||||
|
||||
if (!this._matrixDirty && !node._worldMatUpdated)
|
||||
return;
|
||||
|
||||
let camera = this._camera;
|
||||
let fov = Math.atan(Math.tan(this._fov/2) / this.zoomRatio)*2;
|
||||
camera.setFov(fov);
|
||||
@@ -454,8 +456,8 @@ let Camera = cc.Class({
|
||||
height = targetTexture.height;
|
||||
}
|
||||
|
||||
_vec3_temp_1.x = _mat4_temp_1.m12;
|
||||
_vec3_temp_1.y = _mat4_temp_1.m13;
|
||||
_vec3_temp_1.x = node._worldMatrix.m12;
|
||||
_vec3_temp_1.y = node._worldMatrix.m13;
|
||||
_vec3_temp_1.z = 0;
|
||||
|
||||
node.z = height / 1.1566;
|
||||
|
||||
@@ -494,7 +494,6 @@ var Label = cc.Class({
|
||||
|
||||
if (!this._renderData) {
|
||||
this._renderData = this._assembler.createData(this);
|
||||
this._renderData.worldMatDirty = true;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -487,7 +487,6 @@ var Sprite = cc.Class({
|
||||
|
||||
this.node.on('size-changed', this._onNodeSizeDirty, this);
|
||||
this.node.on('anchor-changed', this._onNodeSizeDirty, this);
|
||||
this.node.on('world-matrix-changed', this._onNodeMatrixDirty, this);
|
||||
},
|
||||
|
||||
onDisable: function () {
|
||||
@@ -495,7 +494,6 @@ var Sprite = cc.Class({
|
||||
|
||||
this.node.off('size-changed', this._onNodeSizeDirty, this);
|
||||
this.node.off('anchor-changed', this._onNodeSizeDirty, this);
|
||||
this.node.off('world-matrix-changed', this._onNodeMatrixDirty, this);
|
||||
},
|
||||
|
||||
_onNodeSizeDirty () {
|
||||
@@ -504,12 +502,6 @@ var Sprite = cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
_onNodeMatrixDirty () {
|
||||
if (this._renderData) {
|
||||
this._renderData.worldMatDirty = true;
|
||||
}
|
||||
},
|
||||
|
||||
_updateAssembler: function () {
|
||||
let assembler = Sprite._assembler.getAssembler(this);
|
||||
|
||||
@@ -520,7 +512,6 @@ var Sprite = cc.Class({
|
||||
|
||||
if (!this._renderData) {
|
||||
this._renderData = this._assembler.createData(this);
|
||||
this._renderData.worldMatDirty = true;
|
||||
this._renderData.material = this._material;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -49,7 +49,6 @@ const sin = Math.sin;
|
||||
const atan2 = Math.atan2;
|
||||
const abs = Math.abs;
|
||||
|
||||
let _matrix = math.mat4.create();
|
||||
let _renderData = null;
|
||||
let _impl = null;
|
||||
let _curColor = 0;
|
||||
@@ -95,9 +94,9 @@ let graphicsAssembler = js.addon({
|
||||
z = node._position.z;
|
||||
|
||||
// vertex buffer
|
||||
node.getWorldMatrix(_matrix);
|
||||
let a = _matrix.m00, b = _matrix.m01, c = _matrix.m04, d = _matrix.m05,
|
||||
tx = _matrix.m12, ty = _matrix.m13;
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
|
||||
let nodeColor = node.color,
|
||||
nodeR = nodeColor.r / 255,
|
||||
|
||||
@@ -41,7 +41,6 @@ module.exports = js.addon({
|
||||
let z = node._position.z;
|
||||
let color = node.color._val;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00,
|
||||
b = matrix.m01,
|
||||
|
||||
@@ -56,7 +56,6 @@ module.exports = js.addon({
|
||||
let z = node._position.z;
|
||||
let color = cc.Color.WHITE._val;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00,
|
||||
b = matrix.m01,
|
||||
|
||||
@@ -104,7 +104,6 @@ var motionStreakAssembler = js.addon({
|
||||
let stroke = comp._stroke / 2;
|
||||
|
||||
let node = comp.node;
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00, b = matrix.m01, c = matrix.m04, d = matrix.m05,
|
||||
tx = matrix.m12, ty = matrix.m13;
|
||||
|
||||
@@ -63,7 +63,7 @@ module.exports = {
|
||||
if (vertDirty) {
|
||||
this.updateVerts(sprite, fillStart, fillEnd);
|
||||
}
|
||||
if (vertDirty || renderData.worldMatDirty) {
|
||||
if (vertDirty || sprite.node._worldMatUpdated) {
|
||||
this.updateWorldVerts(sprite);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -52,7 +52,7 @@ module.exports = {
|
||||
if (vertDirty) {
|
||||
this.updateVerts(sprite);
|
||||
}
|
||||
if (vertDirty || renderData.worldMatDirty) {
|
||||
if (vertDirty || sprite.node._worldMatUpdated) {
|
||||
this.updateWorldVerts(sprite);
|
||||
}
|
||||
},
|
||||
@@ -136,8 +136,6 @@ module.exports = {
|
||||
world.x = local.x * a + local.y * c + tx;
|
||||
world.y = local.x * b + local.y * d + ty;
|
||||
}
|
||||
|
||||
renderData.worldMatDirty = false;
|
||||
},
|
||||
|
||||
fillBuffers (sprite, batchData, vertexId, vbuf, uintbuf, ibuf) {
|
||||
|
||||
@@ -40,7 +40,7 @@ module.exports = js.addon({
|
||||
if (vertDirty) {
|
||||
this.updateVerts(sprite);
|
||||
}
|
||||
if (vertDirty || renderData.worldMatDirty) {
|
||||
if (vertDirty || sprite.node._worldMatUpdated) {
|
||||
this.updateWorldVerts(sprite);
|
||||
}
|
||||
},
|
||||
@@ -138,8 +138,6 @@ module.exports = js.addon({
|
||||
world.x = local.x * a + local.y * c + tx;
|
||||
world.y = local.x * b + local.y * d + ty;
|
||||
}
|
||||
|
||||
renderData.worldMatDirty = false;
|
||||
},
|
||||
|
||||
updateVerts (sprite) {
|
||||
|
||||
@@ -170,8 +170,6 @@ module.exports = {
|
||||
world.v = rowD.v;
|
||||
}
|
||||
}
|
||||
|
||||
renderData.worldMatDirty = false;
|
||||
},
|
||||
|
||||
update: simpleRenderUtil.update
|
||||
|
||||
@@ -139,7 +139,6 @@ module.exports = {
|
||||
let row = Math.ceil(vRepeat),
|
||||
col = Math.ceil(hRepeat);
|
||||
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
let a = matrix.m00,
|
||||
b = matrix.m01,
|
||||
|
||||
@@ -42,10 +42,6 @@ RenderComponentWalker.prototype = {
|
||||
reset() {},
|
||||
|
||||
_handleRender (node) {
|
||||
if (node._localMatDirty) {
|
||||
node._calculWorldMatrix();
|
||||
}
|
||||
|
||||
let comp = node._renderComponent;
|
||||
let opacity = node.opacity;
|
||||
let assembler = comp && comp.constructor._assembler;
|
||||
|
||||
@@ -139,10 +139,6 @@ RenderComponentWalker.prototype = {
|
||||
},
|
||||
|
||||
_handleRender (node) {
|
||||
if (node._localMatDirty) {
|
||||
node._calculWorldMatrix();
|
||||
}
|
||||
|
||||
if (node.groupIndex !== 0) {
|
||||
this._curCameraNode = node;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 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 math = renderEngine.math;
|
||||
|
||||
let transformSys = {
|
||||
_dirtyNodes: [],
|
||||
_updatedNodes: [],
|
||||
|
||||
_calculWorldMatrix (node) {
|
||||
// Avoid as much function call as possible
|
||||
if (node._localMatDirty) {
|
||||
node._updateLocalMatrix();
|
||||
}
|
||||
|
||||
// Assume parent world matrix is correct
|
||||
if (node._parent) {
|
||||
let parentMat = node._parent._worldMatrix;
|
||||
math.mat4.mul(node._worldMatrix, parentMat, node._matrix);
|
||||
}
|
||||
else {
|
||||
math.mat4.copy(node._worldMatrix, node._matrix);
|
||||
}
|
||||
node._worldMatDirty = false;
|
||||
node._worldMatUpdated = true;
|
||||
// For resetting _worldMatUpdated flag in afterDraw
|
||||
this._updatedNodes.push(node);
|
||||
|
||||
let children = node._children;
|
||||
for (let i = 0, len = children.length; i < len; ++i) {
|
||||
let child = children[i];
|
||||
this._calculWorldMatrix(child);
|
||||
}
|
||||
},
|
||||
|
||||
_updateWorldMatrix (node) {
|
||||
let changedRoot = null;
|
||||
while (node) {
|
||||
if (node._localMatDirty || node._worldMatDirty) {
|
||||
changedRoot = node;
|
||||
}
|
||||
node = node._parent;
|
||||
}
|
||||
if (changedRoot) {
|
||||
this._calculWorldMatrix(changedRoot);
|
||||
}
|
||||
},
|
||||
|
||||
setNodeDirty (node) {
|
||||
if (!node._localMatDirty) {
|
||||
node._localMatDirty = true;
|
||||
if (!this._dirtyNodes[node._level]) {
|
||||
this._dirtyNodes[node._level] = [];
|
||||
}
|
||||
this._dirtyNodes[node._level].push(node);
|
||||
}
|
||||
},
|
||||
|
||||
setWorldDirty (node) {
|
||||
if (!node._worldMatDirty) {
|
||||
node._worldMatDirty = true;
|
||||
if (!this._dirtyNodes[node._level]) {
|
||||
this._dirtyNodes[node._level] = [];
|
||||
}
|
||||
this._dirtyNodes[node._level].push(node);
|
||||
}
|
||||
},
|
||||
|
||||
_updateLevel (nodes) {
|
||||
let node;
|
||||
for (let i = 0, n = nodes.length; i < n; i++) {
|
||||
node = nodes[i];
|
||||
if (node._localMatDirty || node._worldMatDirty) {
|
||||
this._calculWorldMatrix(node);
|
||||
}
|
||||
}
|
||||
nodes.length = 0;
|
||||
},
|
||||
|
||||
update () {
|
||||
let levels = this._dirtyNodes;
|
||||
for (let i = 0, l = levels.length; i < l; i++) {
|
||||
this._updateLevel(levels[i]);
|
||||
}
|
||||
},
|
||||
|
||||
afterDraw () {
|
||||
for (let i = 0, l = this._updatedNodes.length; i < l; i++) {
|
||||
this._updatedNodes[i]._worldMatUpdated = false;
|
||||
}
|
||||
this._updatedNodes.length = 0;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = transformSys;
|
||||
@@ -128,6 +128,14 @@ var BaseNode = cc.Class({
|
||||
|
||||
_active: true,
|
||||
|
||||
/**
|
||||
* @property _level
|
||||
* @type {Number}
|
||||
* @default 0
|
||||
* @private
|
||||
*/
|
||||
_level: 0,
|
||||
|
||||
/**
|
||||
* @property _components
|
||||
* @type {Component[]}
|
||||
@@ -353,6 +361,7 @@ var BaseNode = cc.Class({
|
||||
if (CC_DEBUG && (value._objFlags & Deactivating)) {
|
||||
cc.errorID(3821);
|
||||
}
|
||||
this._level = value._level + 1;
|
||||
eventManager._setDirtyForNode(this);
|
||||
value._children.push(this);
|
||||
value.emit(CHILD_ADDED, this);
|
||||
|
||||
@@ -110,7 +110,7 @@ let tmxAssembler = js.addon({
|
||||
let appx = node._anchorPoint.x * node._contentSize.width,
|
||||
appy = node._anchorPoint.y * node._contentSize.height;
|
||||
|
||||
node.getWorldMatrix(_mat4_temp);
|
||||
mat4.copy(_mat4_temp, node._worldMatrix);
|
||||
vec3.set(_vec3_temp, -appx, -appy, 0);
|
||||
mat4.translate(_mat4_temp, _mat4_temp, _vec3_temp);
|
||||
|
||||
|
||||
@@ -366,7 +366,6 @@ let VideoPlayerImpl = cc.Class({
|
||||
updateMatrix (node) {
|
||||
if (!this._video || !this._visible) return;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
var mat = node._worldMatrix;
|
||||
if (!this._forceUpdate &&
|
||||
this._m00 === mat.m00 && this._m01 === mat.m01 && this._m04 === mat.m04 && this._m05 === mat.m05 && this._m12 === mat.m12 && this._m13 === mat.m13 &&
|
||||
|
||||
@@ -299,7 +299,6 @@ var WebViewImpl = cc.Class({
|
||||
updateMatrix (node) {
|
||||
if (!this._div || !this._visible) return;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
var mat = node._worldMatrix;
|
||||
if (!this._forceUpdate &&
|
||||
this._m00 === mat.m00 && this._m01 === mat.m01 && this._m04 === mat.m04 && this._m05 === mat.m05 && this._m12 === mat.m12 && this._m13 === mat.m13 &&
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
const renderEngine = require('../../cocos2d/core/renderer/render-engine');
|
||||
const math = renderEngine.math;
|
||||
const transformSys = require('../../cocos2d/core/systems/transform');
|
||||
|
||||
const BlendFactor = require('../../cocos2d/core/platform/CCMacro');
|
||||
const BinaryOffset = dragonBones.BinaryOffset;
|
||||
@@ -354,7 +355,7 @@ dragonBones.CCSlot = cc.Class({
|
||||
let node = this._display.node;
|
||||
math.mat4.copy(node._matrix, t);
|
||||
node._localMatDirty = false;
|
||||
node._worldMatDirty = true;
|
||||
transformSys.setWorldDirty(node);
|
||||
}
|
||||
|
||||
this._updateVertices();
|
||||
|
||||
@@ -17,7 +17,6 @@ let armatureAssembler = {
|
||||
ctx.save();
|
||||
|
||||
let node = comp.node;
|
||||
node._updateWorldMatrix();
|
||||
let matrix = node._worldMatrix;
|
||||
|
||||
let texture = comp.dragonAtlasAsset.texture;
|
||||
|
||||
@@ -100,7 +100,6 @@ let armatureAssembler = js.addon({
|
||||
let node = comp.node;
|
||||
_z = node._position.z;
|
||||
|
||||
node._updateWorldMatrix();
|
||||
_worldMatrix = node._worldMatrix;
|
||||
_a = _worldMatrix.m00; _b = _worldMatrix.m01; _c = _worldMatrix.m04; _d = _worldMatrix.m05;
|
||||
_tx = _worldMatrix.m12; _ty = _worldMatrix.m13;
|
||||
|
||||
Reference in New Issue
Block a user