mikedh / trimesh

Python library for loading and using triangular meshes.

Home Page:https://trimesh.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scaling is messing up the mesh rendering

raabuchanan opened this issue · comments

Hello, I have trimesh 4.1.3 and I am trying to apply a translation, rotation and scale to three meshes and rendering them together in a scene. Translation and rotation are fine but as soon as I set scale to anything other than 1.0 it messes up the visualization as shown below:

Translation and rotation (no scaling)
Screenshot from 2024-03-01 16-05-13

Translation and rotation and 0.5 equal scaling on every axis
Screenshot from 2024-03-01 16-05-35

code snippet

    def render_scene_from_name(self, scn_name):
        if self.scenes is not None and scn_name in self.scenes:
            print(
                f"Rengering scene: {scn_name} of type: {self.scenes[scn_name]['type']}"
            )
            obj_list = []
            for obj_name, obj_yaml in self.scenes[scn_name]["objects"].items():
                print(f"Rendering object {obj_name}")
                obj_mesh = self.get_object_from_name(obj_name)
                scaling = np.array(
                    [
                        obj_yaml["scale"]["x"],
                        obj_yaml["scale"]["y"],
                        obj_yaml["scale"]["z"],
                    ]
                )

                translation = np.array(
                    [
                        obj_yaml["position"]["x"],
                        obj_yaml["position"]["y"],
                        obj_yaml["position"]["z"],
                    ]
                )

                rotation = trimesh.transformations.euler_from_quaternion(
                    [
                        obj_yaml["orientation"]["w"],
                        obj_yaml["orientation"]["x"],
                        obj_yaml["orientation"]["y"],
                        obj_yaml["orientation"]["z"]
                    ]
                )

                transform = trimesh.transformations.compose_matrix(
                    scale=scaling,
                    shear=None,
                    angles=rotation,
                    translate=translation,
                    perspective=None,
                )

                obj_mesh.apply_transform(transform)
                obj_list.append(obj_mesh)
        else:
            return None

        if len(obj_list) > 0:
            trimesh.Scene([trimesh.creation.axis(axis_length=1), obj_list]).show()

Am I doing something wrong?
Thanks