0

I dont know who needs to see this, just wanted to share a solution for a problem I encountered recently. I hope it helps someone.

Lets say you have an object House and inside that House you have another object Chair in a very specific spot. you scale the House's Size by 2, making it bigger. The Chair then is not at the same spot inside the House because the House's size is different. you need to move the chair to that very specific spot without doing it manually.

EDIT Moved the solution to an answer

4
  • Typically, you'd want to check the "Answer your own question - Q&A style! button when creating the question. Then, you would write your own answer, instead of posting the solution in the question itself. I would recommend moving the solution to an answer. Commented Jun 9, 2022 at 18:27
  • 1
    Thanks. I moved the solution to an answer Commented Jun 9, 2022 at 19:55
  • Sounds like you’re not using the scene graph properly. Commented Jun 11, 2022 at 21:25
  • Of course making Chair a child of House, or scaling the parent would solve this. This is obviously for a case where you cant have that hierarchy. Commented Jun 13, 2022 at 15:18

1 Answer 1

1

this is the formula you would use: ( (Chair.position * House.scaleFactor) - (House.position * (House.scaleFactor - 1)) )

In Threejs code it would look something like this:

const scaleFactor = 2;
house.scale.setScalar(scaleFactor);
chair.position.set(
                    (chair.position.x * scaleFactor) - (house.position.x * (scaleFactor - 1)),
                    (chair.position.y * scaleFactor) - (house.position.y * (scaleFactor - 1)),
                    (chair.position.z * scaleFactor) - (house.position.z * (scaleFactor - 1))
                );
Sign up to request clarification or add additional context in comments.

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.