Repository: Genesis-Embodied-AI/Genesis
File: genesis/engine/entities/fem_entity.py (Python)

Code before:
        ------
        Exception
            If the morph type is unsupported.
        """
        from genesis.engine.materials.FEM.cloth import Cloth as ClothMaterial

        is_cloth = isinstance(self.material, ClothMaterial)
        self._uvs = None

        if is_cloth:
            # Cloth: load surface mesh directly (no tetrahedralization)
            if isinstance(self.morph, gs.options.morphs.Mesh):
                import trimesh

                mesh = trimesh.load_mesh(self._morph.file)
                verts = mesh.vertices * self._morph.scale + np.array(self._morph.pos)
                faces = mesh.faces
                # For cloth, we store faces as "elements" (treating them as surface elements)
                self.instantiate(verts, faces)

                # Load UVs from mesh (1:1 mapping for cloth)
                try:
                    uvs = mesh.visual.uv.copy()
                    self._uvs = uvs.astype(gs.np_float)
                except AttributeError:
                    self._uvs = None
            else:
                gs.raise_exception(f"Cloth material only supports Mesh morph. Got: {self.morph}.")
        else:
            # Regular FEM: tetrahedralize mesh
            if isinstance(self.morph, gs.options.morphs.Sphere):
                verts, elems = eu.sphere_to_elements(
                    pos=self._morph.pos,
                    radius=self._morph.radius,
                    tet_cfg=self.tet_cfg,
                )
            elif isinstance(self.morph, gs.options.morphs.Box):
                verts, elems = eu.box_to_elements(
                    pos=self._morph.pos,
                    size=self._morph.size,
                    tet_cfg=self.tet_cfg,
                )
            elif isinstance(self.morph, gs.options.morphs.Cylinder):
                verts, elems = eu.cylinder_to_elements()
            elif isinstance(self.morph, gs.options.morphs.Mesh):
                verts, elems, self._uvs = eu.mesh_to_elements(
                    file=self._morph.file,
                    pos=self._morph.pos,
                    scale=self._morph.scale,
                    tet_cfg=self.tet_cfg,
                    return_uvs=True,

Review comment (suggestion):
Could you add a comment to explain which attribute may not exist exactly, in which scenario it would be the case (and why this scenario must be supported if not obvious), and why just ignoring UV is the right approach if not obvious.

Code after:
        ------
        Exception
            If the morph type is unsupported.
        """
        from genesis.engine.materials.FEM.cloth import Cloth as ClothMaterial

        is_cloth = isinstance(self.material, ClothMaterial)
        self._uvs = None

        if is_cloth:
            # Cloth: load surface mesh directly (no tetrahedralization)
            if isinstance(self.morph, gs.options.morphs.Mesh):
                import trimesh

                mesh = trimesh.load_mesh(self._morph.file)
                verts = mesh.vertices * self._morph.scale + np.array(self._morph.pos)
                faces = mesh.faces
                # For cloth, we store faces as "elements" (treating them as surface elements)
                self.instantiate(verts, faces)

                # Load UVs from mesh (1:1 mapping for cloth).
                # UVs are not always available in 3D file, in case they are missing we set the entity UVs to None when UVs are None,
                # the solver will use 0 UVs for rendering. A mesh with 0 UVs means that no tangent directions can be recomputed,
                # thus texture mapping and anisotropic surfaces will not work properly.
                self._uvs = None
                if isinstance(mesh.visual, trimesh.visual.texture.TextureVisuals) and mesh.visual.uv is not None:
                    self._uvs = mesh.visual.uv.astype(gs.np_float, copy=False)
            else:
                gs.raise_exception(f"Cloth material only supports Mesh morph. Got: {self.morph}.")
        else:
            # Regular FEM: tetrahedralize mesh
            if isinstance(self.morph, gs.options.morphs.Sphere):
                verts, elems = eu.sphere_to_elements(
                    pos=self._morph.pos,
                    radius=self._morph.radius,
                    tet_cfg=self.tet_cfg,
                )
            elif isinstance(self.morph, gs.options.morphs.Box):
                verts, elems = eu.box_to_elements(
                    pos=self._morph.pos,
                    size=self._morph.size,
                    tet_cfg=self.tet_cfg,
                )
            elif isinstance(self.morph, gs.options.morphs.Cylinder):
                verts, elems = eu.cylinder_to_elements()
            elif isinstance(self.morph, gs.options.morphs.Mesh):
                # We don't need to proces UVs here because the tetrahedralization process append new vertices
                # and faces at the end of the vertex list, thus the original UVs are preserved at the beginning.
                # We can't generate UVs for newly created internal vertices as it doesn't make sense but they're
                # not used for rendering so it's fine.
                verts, elems, self._uvs = eu.mesh_to_elements(