Treat the scene node as the native root node (#9072)

This commit is contained in:
GengineJS
2021-07-29 18:30:42 +08:00
committed by GitHub
parent b6491be095
commit 3fbe3a1ea8
5 changed files with 40 additions and 16 deletions
@@ -2,6 +2,7 @@
declare const ns: any;
export const NativeNode = ns.Node;
export const NativeScene = ns.Scene;
export const NativeModel = ns.Model;
export const NativeSkinningModel = ns.SkinningModel;
export const NativeBakedSkinningModel = ns.BakedSkinningModel;
+5 -1
View File
@@ -6,10 +6,14 @@ import { RenderPriority } from '../../pipeline/define';
import { LightType } from './light';
export const NativeNode: Constructor<{
initWithData (data: TypedArray, chunk: Uint32Array): void;
initWithData (data: TypedArray, chunk: Uint32Array, computeNodes: NativeNode[]): void;
setParent(val: NativeNode | null): void;
}> = null!;
export type NativeNode = InstanceType<typeof NativeNode>;
export const NativeScene: Constructor<{
setParent(val: NativeScene | null): void;
}> = null!;
export type NativeScene = InstanceType<typeof NativeScene>;
export const NativeAABB: Constructor<{
initWithData(data: TypedArray): void;
-1
View File
@@ -50,7 +50,6 @@ const DontDestroy = CCObject.Flags.DontDestroy;
const Deactivating = CCObject.Flags.Deactivating;
export const TRANSFORM_ON = 1 << 0;
// const CHILD_ADDED = 'child-added';
// const CHILD_REMOVED = 'child-removed';
+19 -13
View File
@@ -55,8 +55,8 @@ const qt_1 = new Quat();
const m3_1 = new Mat3();
const m3_scaling = new Mat3();
const m4_1 = new Mat4();
const array_a: any[] = [];
const dirtyNodes: any[] = [];
const nativeDirtyNodes: any[] = [];
class BookOfChange {
private _chunks: Uint32Array[] = [];
private _freelists: number[][] = [];
@@ -248,7 +248,7 @@ export class Node extends BaseNode implements CustomSerializable {
this._nativeLayer[0] = this._layer;
this._nativeObj = new NativeNode();
const flagBuffer = new Uint32Array(chunk.buffer, chunk.byteOffset + offset * 4, 1);
this._nativeObj.initWithData(NodePool.getBuffer(this._nodeHandle), flagBuffer);
this._nativeObj.initWithData(NodePool.getBuffer(this._nodeHandle), flagBuffer, nativeDirtyNodes);
} else {
this._pos = new Vec3();
this._rot = new Quat();
@@ -277,7 +277,6 @@ export class Node extends BaseNode implements CustomSerializable {
NodePool.free(this._nodeHandle);
this._nodeHandle = NULL_HANDLE;
}
this._nativeObj = null;
}
bookOfChange.free(this._hasChangedFlagsChunk, this._hasChangedFlagsOffset);
@@ -695,6 +694,13 @@ export class Node extends BaseNode implements CustomSerializable {
this.setWorldRotation(q_a);
}
protected _setDirtyNode (idx: number, currNode: this) {
dirtyNodes[idx] = currNode;
if (JSB) {
nativeDirtyNodes[idx] = currNode.native;
}
}
/**
* @en Invalidate the world transform information
* for this node and all its children recursively
@@ -703,11 +709,10 @@ export class Node extends BaseNode implements CustomSerializable {
*/
public invalidateChildren (dirtyBit: TransformBit) {
const childDirtyBit = dirtyBit | TransformBit.POSITION;
array_a[0] = this;
this._setDirtyNode(0, this);
let i = 0;
while (i >= 0) {
const cur: this = array_a[i--];
const cur: this = dirtyNodes[i--];
const hasChangedFlags = cur.hasChangedFlags;
if (cur.isValid && (cur._dirtyFlags & hasChangedFlags & dirtyBit) !== dirtyBit) {
cur._dirtyFlags |= dirtyBit;
@@ -715,7 +720,7 @@ export class Node extends BaseNode implements CustomSerializable {
cur.hasChangedFlags = hasChangedFlags | dirtyBit;
const children = cur._children;
const len = children.length;
for (let j = 0; j < len; ++j) array_a[++i] = children[j];
for (let j = 0; j < len; ++j) this._setDirtyNode(++i, children[j]);
}
dirtyBit = childDirtyBit;
}
@@ -733,13 +738,13 @@ export class Node extends BaseNode implements CustomSerializable {
let i = 0;
while (cur && cur._dirtyFlags) {
// top level node
array_a[i++] = cur;
this._setDirtyNode(i++, cur);
cur = cur._parent;
}
let child: this; let dirtyBits = 0;
while (i) {
child = array_a[--i];
child = dirtyNodes[--i];
dirtyBits |= child._dirtyFlags;
if (cur) {
if (dirtyBits & TransformBit.POSITION) {
@@ -967,12 +972,12 @@ export class Node extends BaseNode implements CustomSerializable {
let cur = this;
let i = 0;
while (cur._parent) {
array_a[i++] = cur;
this._setDirtyNode(i++, cur);
cur = cur._parent;
}
while (i >= 0) {
Vec3.transformInverseRTS(out, out, cur._lrot, cur._lpos, cur._lscale);
cur = array_a[--i];
cur = dirtyNodes[--i];
}
return out;
}
@@ -1289,7 +1294,8 @@ export class Node extends BaseNode implements CustomSerializable {
Node.ClearFrame++;
} else {
Node.ClearFrame = 0;
array_a.length = 0;
dirtyNodes.length = 0;
nativeDirtyNodes.length = 0;
}
}
}
+15 -1
View File
@@ -29,7 +29,7 @@
*/
import { ccclass, serializable, editable } from 'cc.decorator';
import { EDITOR, TEST } from 'internal:constants';
import { EDITOR, JSB, TEST } from 'internal:constants';
import { CCObject } from '../data/object';
import { Mat4, Quat, Vec3 } from '../math';
import { assert, getError } from '../platform/debug';
@@ -39,6 +39,7 @@ import { legacyCC } from '../global-exports';
import { Component } from '../components/component';
import { SceneGlobals } from './scene-globals';
import { applyTargetOverrides } from '../utils/prefab/utils';
import { NativeScene } from '../renderer/scene/native-scene';
/**
* @en
@@ -97,10 +98,22 @@ export class Scene extends BaseNode {
protected _dirtyFlags = 0;
protected declare _nativeObj: NativeScene | null;
protected _updateScene () {
this._scene = this;
}
get native (): any {
return this._nativeObj;
}
protected _init () {
if (JSB) {
this._nativeObj = new NativeScene();
}
}
constructor (name: string) {
super(name);
this._activeInHierarchy = false;
@@ -108,6 +121,7 @@ export class Scene extends BaseNode {
this._renderScene = legacyCC.director.root.createScene({});
}
this._inited = legacyCC.game ? !legacyCC.game._isCloning : true;
this._init();
}
/**