-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
fix: attach detach #749
fix: attach detach #749
Conversation
✅ Deploy Preview for tresjs-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work @andretchen0 thanks for solving this 🙏🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, it took me a while to review the full code changes
I love the attention to detail in your unit tests. No issues here
I also ran through the playground suites as well for more of a hands on verification and everything looks good.
Approved!
closes #496
Context
This PR deals with "attached objects", e.g., materials, geometries.
These objects can't be
add()
ed via THREE'sObject3D.add(value)
. Instead, they are "attached" as values as insomeObject[someField] = value
.Compared to
add()
ing, "attach"ing requires extra implementation steps and logic in order to support Vue's declarative paradigm transparently for users.This PR is another in a series to prepare for a rework of Tres'
<primitive />
. Issue: #701Playground
http://localhost:5173/advanced/material-array
Problem
Fields with attached objects don't revert back their original values when unmounted. As a result, an unmounted material will continue to affect its parent.
Solution
When attaching, save the previous value to a variable and restore it when detaching.
Problem
The current implementation of
:attach
doesn't allow for array indices. This means e.g., it's not possible to attach multiple materials, even though THREE allows this. #496Solution
Add "attach" logic to traverse arrays.
Problem
:attach
is a prop but isn't reactive, as users might expect.Solution
Implement reactivity for
:attach
.Problem
:attach
prop value can't be a "pierced prop", i.e., it can only replace values directly on the parent –parent[field]
. It can't be used to "drill down" intoparent[object][field]
.Solution
Implement "pierced" logic for
:attach
– seeresolve
insrc/utils/index.ts
and tests insrc/utils/index.test.ts
.Refactor
THREE does not define the attach field. Tres defines it. Most Tres data is stored in
object.__tres
.attach
is stored directly onobject
asobject.attach
.Refactor and store
:attach
value inobject.__tres.attach
.Refactor
Move
src/utils/nodeOpsUtils.ts
tosrc/utils/index.ts
.