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

Code before:
                    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,
                )
            else:
                gs.raise_exception(f"Unsupported morph: {self.morph}.")

            self.instantiate(*eu.split_all_surface_tets(verts, elems))

    def _add_to_solver(self, in_backward=False):
        from genesis.engine.materials.FEM.cloth import Cloth as ClothMaterial

        is_cloth = isinstance(self.material, ClothMaterial)

        if not in_backward:
            self._step_global_added = self._sim.cur_step_global
            gs.logger.info(
                f"Entity {self.uid} added. class: {self.__class__.__name__}, morph: {self.morph.__class__.__name__}, size: ({self.n_elements}, {self.n_vertices}), material: {self.material}."
            )

        # Convert to appropriate numpy array types
        verts_numpy = tensor_to_array(self.init_positions, dtype=gs.np_float)

        if is_cloth:
            # Cloth: add only vertices and surfaces for rendering (no physics computation)
            gs.logger.info(
                f"Entity {self.uid} is cloth - adding to FEM solver for rendering only (physics managed by IPC)"
            )

Review comment (suggestion):
Just return UVS systematically and update all places where this function is being called. Use `, _ = [...]` to assign to new unused return value.

Code after:
                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(
                    file=self._morph.file,
                    pos=self._morph.pos,
                    scale=self._morph.scale,
                    tet_cfg=self.tet_cfg,
                )
            else:
                gs.raise_exception(f"Unsupported morph: {self.morph}.")

            self.instantiate(*eu.split_all_surface_tets(verts, elems))

    def _add_to_solver(self, in_backward=False):
        from genesis.engine.materials.FEM.cloth import Cloth as ClothMaterial

        is_cloth = isinstance(self.material, ClothMaterial)

        if not in_backward:
            self._step_global_added = self._sim.cur_step_global
            gs.logger.info(
                f"Entity {self.uid} added. class: {self.__class__.__name__}, morph: {self.morph.__class__.__name__}, size: ({self.n_elements}, {self.n_vertices}), material: {self.material}."
            )

        # Convert to appropriate numpy array types
        verts_numpy = tensor_to_array(self.init_positions, dtype=gs.np_float)
        uvs_np = self._uvs if self._uvs is not None else np.zeros((0, 2), dtype=gs.np_float)