Local transformations for Mitsuba shapes in XML #1637
-
I wish to rotate a shape, but the rotations are around the world origin, while I need the rotations around the object's centre. In the transformation toolbox page in the docs, I do see a way to convert to/from the local frame. However, if I wish to automate the rotations to simulate different room scene configurations, I'd need to get the shape's coordinates, convert it to the local frame, apply the rotations I want, convert it back to the world frame and then apply it to the xml. Is there any way to do it natively in XML? I'd also be open to ideas that simply make this to-and-fro mapping less convoluted. Thanks ! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Hi @mohanamisra As far as I know, there isn't a built-in operation for this in XML. If you only want to edit the XML, I guess your only choice is to parse the world transform, then edit the XML to apply the inverse transform,, apply your rotation, and then apply the world transform again. |
Beta Was this translation helpful? Give feedback.
-
I finally got it working, and the solution is relatively simple with the correct methods, order of operations and so on. Here's the code for finding out the centre of the shape: mirror_shape = mi.load_dict({
'type': 'ply',
'filename': '/<your file path>/Mirror.ply',
'face_normals': True
})
# Get the bounding box of the shape
bbox = mirror_shape.bbox()
# Get the centre
center = bbox.center() And then in XML you simply do the following: <transform name="to_world">
<translate value="-2.17873, -1.79809, -0"/> # THE NEGATIVES OF YOUR CENTRE COORDINATES. MOVES TO ORIGIN
<rotate value="1, 0, 0" angle="60"/> # EXAMPLE ROTATIONS
<rotate value="0, 1, 0" angle="120"/>
<rotate value="0, 0, 1" angle="30"/>
<translate value="2.17873, 1.79809, 0"/> # MOVE IT BACK TO THE ORIGINAL OBJECT CENTRE.
</transform> To automate it, I'll probably use an XML parsing/editing solution like @njroussel mentioned. |
Beta Was this translation helpful? Give feedback.
I finally got it working, and the solution is relatively simple with the correct methods, order of operations and so on.
Here's the code for finding out the centre of the shape:
And then in XML you simply do the following: