apply transform to mesh file frame

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Pablo Delgado
Posts: 24
Joined: Tue Feb 11, 2020 3:39 pm

apply transform to mesh file frame

Post by Pablo Delgado » Mon Feb 21, 2022 11:34 am

Hello,

I would like to know if someone can help me to figure out how to apply a transformation to the mesh file that I am importing to a body in a xml file. I want this because the location of the body frame for the part is not in the right place for the geometry file. I already know what is the transform that I need to apply, but I do not know how or where in the model. I already went through the user's guide for the model (https://simtk-confluence.stanford.edu:8 ... Sim+Models), however I do not know how to use the line "<input_transform></input_transform>". attached is a picture of the xml file of the model and the part that I am trying to add.

Code: Select all

				<Body name="Link0">
					<!--The geometry used to display the axes of this Frame.-->
					<FrameGeometry name="frame_geometry">
						<!--Path to a Component that satisfies the Socket 'frame' of type Frame.-->
						<socket_frame>..</socket_frame>
						<!--Scale factors in X, Y, Z directions respectively.-->
						<scale_factors>0.20000000000000001 0.20000000000000001 0.20000000000000001</scale_factors>
					</FrameGeometry>
					<!--List of geometry attached to this Frame. Note, the geometry are treated as fixed to the frame and they share the transform of the frame when visualized-->
					<attached_geometry>
						<Mesh name="exo_base_link">
							<!--Path to a Component that satisfies the Socket 'frame' of type Frame.-->
							<socket_frame>..</socket_frame>
							<input_transform></input_transform>							<!--Scale factors in X, Y, Z directions respectively.-->
							<scale_factors>0.001 0.001 0.001</scale_factors>
							<!--Default appearance attributes for this Geometry-->
							<Appearance>
								<!--The opacity used to display the geometry between 0:transparent, 1:opaque.-->
								<opacity>1</opacity>
								<!--The color, (red, green, blue), [0, 1], used to display the geometry. -->
								<color>0 0 1</color>
							</Appearance>
							<!--Name of geometry file.-->
							<mesh_file>LINK0.stl</mesh_file>
						</Mesh>
					</attached_geometry>
					<!--Set of wrap objects fixed to this body that GeometryPaths can wrap over.This property used to be a member of Body but was moved up with the introduction of Frames.-->
					<WrapObjectSet name="wrapobjectset">
						<objects />
						<groups />
					</WrapObjectSet>
					<!--The mass of the body (kg)-->
					<mass>0.15599999999999997</mass>
					<!--The location (Vec3) of the mass center in the body frame.-->
					<mass_center>0 0 0</mass_center>
					<!--The elements of the inertia tensor (Vec6) as [Ixx Iyy Izz Ixy Ixz Iyz] measured about the mass_center and not the body origin.-->
					<inertia>0 0 0 0 0 0</inertia>
				</Body>

Attachments
body frame.PNG
body frame.PNG (67.15 KiB) Viewed 518 times

Tags:

User avatar
Katie Blessinger
Posts: 14
Joined: Mon Sep 13, 2021 11:21 am

Re: apply transform to mesh file frame

Post by Katie Blessinger » Wed Feb 23, 2022 9:53 am

Hi! I also have an issue/question about using input_transform--if you figure it out, would you be able to share?

Thanks!
Katie

User avatar
Pablo Delgado
Posts: 24
Joined: Tue Feb 11, 2020 3:39 pm

Re: apply transform to mesh file frame

Post by Pablo Delgado » Wed Feb 23, 2022 1:18 pm

blessinger.1 wrote:
Wed Feb 23, 2022 9:53 am
Hi! I also have an issue/question about using input_transform--if you figure it out, would you be able to share?

Thanks!
Katie
Hello Katie,
Of course, however, I have not figured out how to use it yet. In the mean time, what I did was to open the files in a CAD software and from there change the orientation and location of the stl-files.

User avatar
Ana de Sousa
Posts: 58
Joined: Thu Apr 07, 2016 4:21 pm

Re: apply transform to mesh file frame

Post by Ana de Sousa » Fri Nov 03, 2023 7:29 am

Hello there!

Even though this post is a bit old, I wanted to share a solution I recently came up with for this issue.

Mesh geometry, which represents only the visual aspect of objects, cannot be rotated directly in OpenSim. However, you can work around this limitation by creating a Frame related to your Body (a PhysicalOffsetFrame), adjusting its translation and orientation, attaching your Mesh to this Frame, and then adding the Frame to your Body. Here's a simple function that achieves this:

This function finds the body based on the body name, then it creates

Code: Select all

def add_body_frame(model, body_name, mesh_path, translation, rotation):
    body = model.updBodySet().get(body_name)
    offset_name = body_name + "_offset"
    
    frame = osim.PhysicalOffsetFrame(offset_name, body, osim.Transform())
    frame.set_translation(translation)
    frame.set_orientation(rotation)

    mesh= osim.Mesh(mesh_path)
    mesh.setColor(osim.Vec3(0.5, 0.5, 1.0))
    mesh.set_scale_factors(osim.Vec3(1.0))
    
    model.addComponent(frame)
    frame.attachGeometry(mesh)
    model.finalizeConnections()
To use this function, simply call it like this:

Code: Select all

add_body_frame(model, "crank", gear_obj_path, osim.Vec3(0., 0., 0.), osim.Vec3(0.0, -0.5*np.pi, 0.0))
This approach allows you to attach and position mesh geometry as desired. Hope this helps!

POST REPLY