1

I want to maintain some information with shapes I'm creating. I use an HTML canvas for the texture, so I know I can keep the values in the element attributes arrays of the canvases. I'm wondering though, is there a more straight-forward way of maintaining attributes that works for all Three.js shapes regardless of how they are constructed?

2
  • It would help to know why this was down-voted. Commented Nov 13, 2016 at 5:23
  • I don't know why the question has been downvoted. But, to me, your question is confusing. Are you talking about instances of the three.js Shape class? If so, why not just add the needed property to the instance? Commented Nov 13, 2016 at 10:30

2 Answers 2

3

The advantage (or the problem) with Javascript, is that you can do almost everything with your objects. You can add, or even delete attributes as much as you want any time.

Thus, you can add every property you want to THREE objects by simply giving it a value :

 myThreeObject.myProperty = myValue ;

Be careful though, if you haven't assigned a value to the property, this property does not exist (yet), thus, don't forget to check if the value exist before reading it :

if( "undefined" !== typeof myThreeObject.myProperty )
    // ...
Sign up to request clarification or add additional context in comments.

1 Comment

THREE.Mesh(), for example, has the userData property, intended exactly to store the user's data there.
2

To be clear as to the correct answer, prisoner849 provided it in the comment he made to another response: use the THREE.Mesh.userData property.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.