Back to the Shapespark home page

Moving and rotating

Hello, everyone,
I may have addressed this topic before. It’s more of a basic understanding question.

I have an existing scene that I have as a bundle.

I would like to program new features for our customers, such as moving objects.

This works quite well so far, I can move objects on the axes and animate them via tween.

I still have problems with the rotation of objects. When I rotate individual objects, they always rotate around the global origin of the scene. This is most likely due to the local position of the object I guess. For test purposes, we placed an object exactly on the zero point and the rotation worked as expected.

Is there a way to change the pivot point of the object? Maybe you have to move the vertices for this?

I know the topic is not easy, but I would like to know more about the possibilities.

I have taken the following steps so far.

  1. I took the geometry of an object from the scene and created a new Object3D from it and added it to the scene.

  2. I transferred the world matrix of the newly created object to the actual object. If the newly generated object is moved or rotated, the actual object in the scene also moves.

Right approach or rather wrong?

Shapespark geometry stores absolute positions, not position relative to some object center, this is why if you rotate an object, it will rotate around [0,0,0].

What you try to accomplish goes well above what APIs were designed for, I’m not 100% sure if it is doable. We can try to help but you would need to share code for what you have so far.

The way we handle rotation of objects is that we build a matrix that encodes 3 operations:

  • translates the object position, so the object’s bounding box center is at the origin.
  • rotates the object
  • translates the object position back to it’s original location.
1 Like

Ok, that is interesting.
I just tried those 3 steps, but I kinda failed.
Do you have a quick example how I could do this with the API?
Just imagine we have a node, maybe a simple cube mesh. Let’s say ist has a position of Vector3(5,10,2).
That would be really helpfull.