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

feat: add globalPosition getter/setter to Transform #1032

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

leanmendoza
Copy link
Contributor

@leanmendoza leanmendoza commented Nov 9, 2024

This is a PoC to have

// getter
console.log(Transform.get(entity).globalPosition)
// and setter
Transform.getMutable(entity).globalPosition = Vector3.create(8, 1, 8)

Notes:

  • So far it doesn't support AvatarAttach

Also, this research is to have a test for performance and if it's a viable option to implement further in more components (like the ones with oneOf and make their interactions seamless)

Transform is like a very fetched components, the most representative scene to compare the performance (measured with OpCode count executed) is the cubes scene where:

  • OpCode increases from 998k to 1017k ~ +1.9%
  • Memory Total Usage increases from 869.52k bytes to 881.48k bytes ~ +1.3%

These metrics doesn't say anything about the property added. Instead, it shows how expensive it is to add the a value patcher to implement custom non-data properties.

This would be very useful to add something like:

  • Transform: .move(), .rotate(), etc
  • Material: .textureSource (getter and setter without going deeper due to the particular $case
  • Animation: .play()
    ... and so on.

This approach takes distance from the pure-ecs one, but it provides quality of life for developers. They should be taken into consideration and evaluate the pro/cons each case.

Copy link

cloudflare-workers-and-pages bot commented Nov 10, 2024

Deploying js-sdk-toolchain with  Cloudflare Pages  Cloudflare Pages

Latest commit: dda9a4f
Status: ✅  Deploy successful!
Preview URL: https://304bc9b2.js-sdk-toolchain.pages.dev
Branch Preview URL: https://feat-add-global-position-to.js-sdk-toolchain.pages.dev

View logs

Copy link
Contributor

github-actions bot commented Nov 10, 2024

Test this pull request

  • The @dcl/sdk package can be tested in scenes by running

    npm install "https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/feat/add-global-position-to-transform/dcl-sdk-7.6.5-11779904879.commit-d186f5a.tgz"
  • To test with npx init

    export SDK_COMMANDS="https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/feat/add-global-position-to-transform/dcl-sdk-commands-7.6.5-11779904879.commit-d186f5a.tgz"
    npx $SDK_COMMANDS init
  • The @dcl/inspector package can be tested by visiting this url

    • Or by installing it via NPM
    npm install "https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/feat/add-global-position-to-transform/@dcl/inspector/dcl-inspector-7.6.5-11779904879.commit-d186f5a.tgz"
  • The /changerealm command to test test in-world

    /changerealm https://sdk-team-cdn.decentraland.org/ipfs/feat/add-global-position-to-transform-e2e
    
  • You can preview this build entering:
    https://playground.decentraland.org/?sdk-branch=feat/add-global-position-to-transform

@leanmendoza leanmendoza changed the title wip feat: add globalPosition getter/setter to Transform Nov 11, 2024
@leanmendoza leanmendoza marked this pull request as ready for review November 11, 2024 14:07

helperArray.length = 0
let currentTransform = null
if (transform.parent !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not going to work for network entities.

We should include some logic here for that, like if the entity is marked as sync, look for the network parentEntity instead of the transform.parent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can take two path for this, as it doesn't work with AvatarAttach nor Billboard neither:
a. We add the disclaimer comment to get noticed when this accessor is approachable or not.
b. We proper implement all the possibilities and get this feature reliable.

In case of a) we can move forward with the current implementation and add the comments

In case of b), my question is, is there any mechanism to get the globalPositon so far? Because what I saw in Utils library, this is not implemented. The current getWorldPosition and getWorldRotation doesn't take into consideration the scale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants