Skip to content

Commit

Permalink
Bug: deserialized scene should have node transforms invalidated at in…
Browse files Browse the repository at this point in the history
…itial (#16353)

* Bug: deserialized scene should have node transforms invalidated

* Remove transformFlags modification in _onBatchCreated
  • Loading branch information
shrinktofit authored Oct 9, 2023
1 parent 5465d2b commit 767f44a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
1 change: 0 additions & 1 deletion cocos/scene-graph/node.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,6 @@ nodeProto._onActiveNode = function (shouldActiveNow: boolean) {

nodeProto._onBatchCreated = function (dontSyncChildPrefab: boolean) {
this.hasChangedFlags = TRANSFORMBIT_TRS;
this._transformFlags |= TRANSFORMBIT_TRS;
const children = this._children;
const len = children.length;
let child;
Expand Down
3 changes: 1 addition & 2 deletions cocos/scene-graph/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable {
@serializable
protected _euler = new Vec3();

protected _transformFlags = TransformBit.NONE; // does the world transform need to update?
protected _transformFlags = TransformBit.TRS; // does the world transform need to update?
protected _eulerDirty = false;

protected _flagChangeVersion = 0;
Expand Down Expand Up @@ -1883,7 +1883,6 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable {
*/
public _onBatchCreated (dontSyncChildPrefab: boolean): void {
this.hasChangedFlags = TransformBit.TRS;
this._transformFlags |= TransformBit.TRS;
const len = this._children.length;
for (let i = 0; i < len; ++i) {
this._children[i]._siblingIndex = i;
Expand Down
2 changes: 1 addition & 1 deletion native/cocos/core/scene-graph/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ class Node : public CCObject {
// NOTE: TypeArray created in node.jsb.ts _ctor should have the same memory layout
uint32_t _eventMask{0}; // Uint32: 0
uint32_t _layer{static_cast<uint32_t>(Layers::LayerList::DEFAULT)}; // Uint32: 1
uint32_t _transformFlags{0}; // Uint32: 2
uint32_t _transformFlags{static_cast<uint32_t>(TransformBit::TRS)}; // Uint32: 2
index_t _siblingIndex{0}; // Int32: 0
uint8_t _activeInHierarchy{0}; // Uint8: 0
uint8_t _active{1}; // Uint8: 1
Expand Down
26 changes: 26 additions & 0 deletions tests/scene-graph/scene.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { deserialize } from "../../cocos/serialization";
import '../utils/matchers/value-type-asymmetric-matchers';
import { v3 } from "../../cocos/core";
import { Scene } from "../../cocos/scene-graph";

test(`Bugfix cocos/cocos-engine#16352: deserialized scene should have node transforms invalidated`, () => {
const archive = [{
__type__: 'cc.Scene',
_children: [{
__type__: 'cc.Node',
_name: 'Node',
_lscale: {
__type__: 'cc.Vec3',
x: 2,
y: 1,
z: 1,
},
}],
}];

const scene = deserialize(archive) as Scene;

const node = scene.getChildByPath('Node')!;
expect(node).not.toBeNull();
expect(node.worldScale).toBeCloseToVec3(v3(2, 1, 1));
});

0 comments on commit 767f44a

Please sign in to comment.