Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.x/y/z are back. #18228

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 77 additions & 1 deletion cocos/scene-graph/node.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export const Node: typeof JsbNode = jsb.Node;
export type Node = JsbNode;
cclegacy.Node = Node;

const NodeCls: any = Node;
const tempVec3 = new Vec3();

const NodeCls: any = Node;

NodeCls.reserveContentsForAllSyncablePrefabTag = reserveContentsForAllSyncablePrefabTag;

Expand Down Expand Up @@ -860,6 +861,39 @@ Object.defineProperty(nodeProto, 'position', {
},
});

Object.defineProperty(nodeProto, 'x', {
configurable: true,
enumerable: true,
get(): number {
return this._lpos.x;
},
set(v: number) {
this.setPosition(v, this._lpos.y, this._lpos.z);
},
});

Object.defineProperty(nodeProto, 'y', {
configurable: true,
enumerable: true,
get(): number {
return this._lpos.y;
},
set(v: number) {
this.setPosition(this._lpos.x, v, this._lpos.z);
},
});

Object.defineProperty(nodeProto, 'z', {
configurable: true,
enumerable: true,
get(): number {
return this._lpos.z;
},
set(v: number) {
this.setPosition(this._lpos.x, this._lpos.y, v);
},
});

Object.defineProperty(nodeProto, 'rotation', {
configurable: true,
enumerable: true,
Expand Down Expand Up @@ -893,6 +927,48 @@ Object.defineProperty(nodeProto, 'worldPosition', {
},
});

Object.defineProperty(nodeProto, 'worldPositionX', {
configurable: true,
enumerable: true,
get(): number {
this.getWorldPosition(tempVec3);
return tempVec3.x;
},
set(v: number) {
this.getWorldPosition(tempVec3);
tempVec3.x = v;
this.setWorldPosition(tempVec3);
},
});

Object.defineProperty(nodeProto, 'worldPositionY', {
configurable: true,
enumerable: true,
get(): number {
this.getWorldPosition(tempVec3);
return tempVec3.y;
},
set(v: number) {
this.getWorldPosition(tempVec3);
tempVec3.y = v;
this.setWorldPosition(tempVec3);
},
});

Object.defineProperty(nodeProto, 'worldPositionZ', {
configurable: true,
enumerable: true,
get(): number {
this.getWorldPosition(tempVec3);
return tempVec3.z;
},
set(v: number) {
this.getWorldPosition(tempVec3);
tempVec3.z = v;
this.setWorldPosition(tempVec3);
},
});

Object.defineProperty(nodeProto, 'worldRotation', {
configurable: true,
enumerable: true,
Expand Down
99 changes: 99 additions & 0 deletions cocos/scene-graph/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

const idGenerator = new js.IDGenerator('Node');

function getConstructor<T> (typeOrClassName: string | Constructor<T> | AbstractedConstructor<T>): Constructor<T> | AbstractedConstructor<T> | null | undefined {

Check warning on line 58 in cocos/scene-graph/node.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 160. Maximum allowed is 150
if (!typeOrClassName) {
errorID(3804);
return null;
Expand Down Expand Up @@ -295,7 +295,7 @@
return null;
}

protected static _findComponents<T extends Component> (node: Node, constructor: Constructor<T> | AbstractedConstructor<T>, components: Component[]): void {

Check warning on line 298 in cocos/scene-graph/node.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 159. Maximum allowed is 150
const cls = constructor;
const comps = node._components;
// NOTE: internal rtti property
Expand Down Expand Up @@ -1592,6 +1592,54 @@
this.setPosition(val as Vec3);
}

/**
* @en Get x axis value in local coordinate system
* @zh 获取本地 x 轴坐标分量
*/
get x (): number {
return this._lpos.x;
}

/**
* @en Set x axis value in local coordinate system
* @zh 设置本地 x 轴坐标分量
*/
set x (val: number) {
this.setPosition(val, this._lpos.y, this._lpos.z);
}

/**
* @en Get y axis value in local coordinate system
* @zh 获取本地 y 轴坐标分量
*/
get y (): number {
return this._lpos.y;
}

/**
* @en Set y axis value in local coordinate system
* @zh 设置本地 y 轴坐标分量
*/
set y (val: number) {
this.setPosition(this._lpos.x, val, this._lpos.z);
}

/**
* @en Get z axis value in local coordinate system
* @zh 获取本地 z 轴坐标分量
*/
get z (): number {
return this._lpos.z;
}

/**
* @en Set z axis value in local coordinate system
* @zh 设置本地 z 轴坐标分量
*/
set z (val: number) {
this.setPosition(this._lpos.x, this._lpos.y, val);
}

/**
* @en Position in world coordinate system
* @zh 世界坐标系下的坐标
Expand All @@ -1606,6 +1654,57 @@
this.setWorldPosition(val as Vec3);
}

/**
* @en Get x axis value in world coordinate system
* @zh 获取世界坐标 x 轴分量
*/
get worldPositionX (): number {
this.updateWorldTransform();
return this._pos.x;
}

/**
* @en Set x axis value in world coordinate system
* @zh 设置世界坐标 x 轴分量
*/
set worldPositionX (val: number) {
this.setWorldPosition(val, this._pos.y, this._pos.z);
}

/**
* @en Get y axis value in world coordinate system
* @zh 获取世界坐标 y 轴分量
*/
get worldPositionY (): number {
this.updateWorldTransform();
return this._pos.y;
}

/**
* @en Set y axis value in world coordinate system
* @zh 设置世界坐标 y 轴分量
*/
set worldPositionY (val: number) {
this.setWorldPosition(this._pos.x, val, this._pos.z);
}

/**
* @en Get z axis value in world coordinate system
* @zh 获取世界坐标 z 轴分量
*/
get worldPositionZ (): number {
this.updateWorldTransform();
return this._pos.z;
}

/**
* @en Set z axis value in world coordinate system
* @zh 设置世界坐标 z 轴分量
*/
set worldPositionZ (val: number) {
this.setWorldPosition(this._pos.x, this._pos.y, val);
}

/**
* @en Rotation in local coordinate system, represented by a quaternion
* @zh 本地坐标系下的旋转,用四元数表示
Expand Down
Loading