Applying a Common Material to Multiple Objects

When creating objects through programming, generating multiple objects results in the creation of individual materials and looks for each object. I would like these to share a common material, but I’m unsure how to achieve this. (For example, generating three spheres but wanting them to have the same color and physical properties.) Below are the screenshot and program code for this process. Additionally, I plan to enable these created objects to interact with each other in the future.

from omni.isaac.examples.base_sample import BaseSample
from omni.isaac.core.objects import DynamicSphere, DynamicCuboid
from omni.isaac.dynamic_control import _dynamic_control
import numpy as np

class HelloWorld(BaseSample):
    def __init__(self) -> None:
        super().__init__()

    def setup_scene(self):
        world = self.get_world()
        world.scene.add_default_ground_plane()

        # 球体のロード
        self.pedestrian1 = world.scene.add(
            DynamicSphere(prim_path="/World/Pedestrian1",
                          name="pedestrian1",
                          position=np.array([0, 0, 0.5]),
                          scale=np.array([0.04, 0.04, 0.04]),
                          color=np.array([1.0, 0, 0]),
                          mass=0.05))
        self.pedestrian2 = world.scene.add(
            DynamicSphere(prim_path="/World/Pedestrian2",
                          name="pedestrian2",
                          position=np.array([0, 0.5, 0.5]),
                          scale=np.array([0.04, 0.04, 0.04]),
                          color=np.array([1.0, 0, 0]),
                          mass=0.05))
        self.pedestrian3 = world.scene.add(
            DynamicSphere(prim_path="/World/Pedestrian3",
                          name="pedestrian3",
                          position=np.array([0, 0.7, 0.5]),
                          scale=np.array([0.04, 0.04, 0.04]),
                          color=np.array([1.0, 0, 0]),
                          mass=0.05))
        
        # 立方体のロード
        self.cube = world.scene.add(
            DynamicCuboid(prim_path="/World/Cube",
                          name="cube",
                          position=np.array([1.5, 0, 0.5]),
                          scale=np.array([0.1, 0.1, 0.1]), 
                          color=np.array([0, 1.0, 0]), 
                          mass=0.5))
        self.cube2 = world.scene.add(
            DynamicCuboid(prim_path="/World/Cube2",
                          name="cube2",
                          position=np.array([0, -1, 0.5]),
                          scale=np.array([0.1, 0.1, 0.1]),
                          color=np.array([0, 1.0, 0]),
                          mass=0.5))
        
    async def setup_post_load(self):
        self._world = self.get_world()
        self._dc = _dynamic_control.acquire_dynamic_control_interface()

        self.pedestrian1_handle = self._dc.get_rigid_body("/World/Pedestrian1")
        self.pedestrian2_handle = self._dc.get_rigid_body("/World/Pedestrian2")
        self.pedestrian3_handle = self._dc.get_rigid_body("/World/Pedestrian3")
        self.cube1_handle = self._dc.get_rigid_body("/World/Cube")
        self.cube2_handle = self._dc.get_rigid_body("/World/Cube2")

        self._world.add_physics_callback("send_actions", self.send_actions)

    def send_actions(self, step_size):
        # 歩行者と障害物の位置を取得
        pedestrian1_pos = np.array(self._dc.get_rigid_body_pose(self.pedestrian1_handle).p)
        pedestrian2_pos = np.array(self._dc.get_rigid_body_pose(self.pedestrian2_handle).p)
        pedestrian3_pos = np.array(self._dc.get_rigid_body_pose(self.pedestrian3_handle).p)
        cube1_pos = np.array(self._dc.get_rigid_body_pose(self.cube1_handle).p)
        cube2_pos = np.array(self._dc.get_rigid_body_pose(self.cube2_handle).p)

Hi @Atsushisaku - Have you referred to this section of document?
https://docs.omniverse.nvidia.com/isaacsim/latest/how_to_guides/environment_setup.html#usd-how-tos

Thank you for your reply.
I resolved the issue using Isaac Cloner.
https://docs.omniverse.nvidia.com/py/isaacsim/source/extensions/omni.isaac.cloner/docs/index.html?highlight=duplication

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.