simulation.py
def _addObjects(self): # {{{0
    "Add all configured objects to the world"
    scs = [EmptyPlaneScenario()]
    wantWalls = self.getArg("walls")
    wantBricks1 = self.getArg("bricks") or self.getArg("b1")
    wantBricks2 = self.getArg("b2")
    wantBricks3 = self.getArg("b3")
    wantProjectile = self.getArg("projectile")
    wantPit = self.getArg("pit")
    wantBunny = self.getArg("bunny")
    wantUrdfs = self.getArg("urdfs")
    wantRand = self.getArg("rand")
    wantChain = self.getArg("chain")
    if wantWalls:
      scs.append(BoxedScenario())
    if wantPit:
      kws = {}
      kws["objShape"] = self.getArg("projShape", ProjectileScenario.SHAPE_SPHERE, int)
      scs.append(BallpitScenario(rand=wantRand, **kws))
    if wantBricks1:
      scs.append(BrickTower1Scenario(rand=wantRand))
    if wantBricks2:
      scs.append(BrickTower2Scenario(rand=wantRand))
    if wantBricks3:
      scs.append(BrickTower3Scenario(rand=wantRand))
    if wantProjectile:
      kws = {}
      kws["projShape"] = self.getArg("projShape", ProjectileScenario.SHAPE_SPHERE, int)
      kws["projSize"] = self.getArg("projSize", self.objectRadius(), float)
      kws["velCoeff"] = self.getArg("projSpeed", 20, float)
      kws["projMass"] = self.getArg("projMass", 100, float)
      kws["projTargetX"] = self.getArg("projTargetX", 0, float)
      kws["projTargetY"] = self.getArg("projTargetY", 0, float)
      kws["projTargetZ"] = self.getArg("projTargetZ", 0, float)
      scs.append(ProjectileScenario(rand=wantRand, **kws))
    if wantBunny:
      kws = {}
      kws["bunnyZ"] = self.getArg("bunnyZ", 20, float)
      kws["bunnySize"] = self.getArg("bunnySize", 10, float)
      kws["bunnyMass"] = self.getArg("bunnyMass", self.objectMass() * 10, float)
      kws["margin"] = self.getArg("margin", 0.5, float)
      scs.append(BunnyScenario(**kws))
    if wantUrdfs:
      scs.append(RandomUrdfScenario())
    if wantChain:
      scs.append(ChainScenario())

    # Add all of the objects from all of the scenarios configured
    for sc in scs:
      if self.getArg("bouncy"):
        sc.set("bouncy", True)
      if self.getArg("frictionless"):
        sc.set("frictionless", True)
      logger.debug("Setting up scenario {!r}".format(sc))
      for b in sc.setup(self):
        self._bodies.add(b)

    # Handle --urdf argument: add URDF at a random position between (-0.5, 0.5)
    for path in self.getArg("urdf", (), tuple):
      pos = randomVec()
      logger.debug("Adding URDF {} at {}".format(path, pos))
      self.loadURDF(path, basePosition=pos)

    # Handle --sb argument: add soft bodies
    for spec in self.getArg("softBodies", (), tuple):
      parts = spec.split(":")
      path = parts[0]
      scale = float(parts[1]) if len(parts) > 1 else 1
      margin = float(parts[2]) if len(parts) > 2 else 1
      pos = V3()
      orn = p.getQuaternionFromEuler((0, math.pi/2, 0))
      logger.debug("Adding soft body {} at {}".format(path, pos))
      self.loadSoftBody(path, pos=pos, scale=scale, mass=100, orn=orn, margin=margin)

    # Handle --rb argument: add rigid bodies
    for spec in self.getArg("rigidBodies", (), tuple):
      parts = spec.split(":")
      path = parts[0]
      scale = float(parts[1]) if len(parts) > 1 else 1
      logger.debug("Creating collision {}, scale={}".format(path, scale))
      coll = self.createCollision(p.GEOM_MESH, fileName=path, meshScale=scale)
      kws = {
        "baseMass": 100,
        "baseCollisionShapeIndex": coll,
        "baseVisualShapeIndex": -1,
        "basePosition": V3()
      }
      logger.debug("Creating multibody {}".format(kws))
      self.createMultiBody(**kws)

    nb, ns = len(self._bodies), len(scs)
    logger.debug("Added {} bodies from {} scenarios".format(nb, ns))

    # Add non-body items
    if self.getArg("axes") or self._debug:
      self._addAxes()
    if self.getArg("grid"):
      self._addGrid()
Add all configured objects to the world
Add all configured objects to the world
Add all configured objects to the world
def _addObjects(self): 
    scs = [EmptyPlaneScenario()]
    wantWalls = self.getArg("walls")
    wantBricks1 = self.getArg("bricks") or self.getArg("b1")
    wantBricks2 = self.getArg("b2")
    wantBricks3 = self.getArg("b3")
    wantProjectile = self.getArg("projectile")
    wantPit = self.getArg("pit")
    wantBunny = self.getArg("bunny")
    wantUrdfs = self.getArg("urdfs")
    wantRand = self.getArg("rand")
    wantChain = self.getArg("chain")
    if wantWalls:
      scs.append(BoxedScenario())
    if wantPit:
      kws = {}
      kws["objShape"] = self.getArg("projShape", ProjectileScenario.SHAPE_SPHERE, int)
      scs.append(BallpitScenario(rand=wantRand, **kws))
    if wantBricks1:
      scs.append(BrickTower1Scenario(rand=wantRand))
    if wantBricks2:
      scs.append(BrickTower2Scenario(rand=wantRand))
    if wantBricks3:
      scs.append(BrickTower3Scenario(rand=wantRand))
    if wantProjectile:
      kws = {}
      kws["projShape"] = self.getArg("projShape", ProjectileScenario.SHAPE_SPHERE, int)
      kws["projSize"] = self.getArg("projSize", self.objectRadius(), float)
      kws["velCoeff"] = self.getArg("projSpeed", 20, float)
      kws["projMass"] = self.getArg("projMass", 100, float)
      kws["projTargetX"] = self.getArg("projTargetX", 0, float)
      kws["projTargetY"] = self.getArg("projTargetY", 0, float)
      kws["projTargetZ"] = self.getArg("projTargetZ", 0, float)
      scs.append(ProjectileScenario(rand=wantRand, **kws))
    if wantBunny:
      kws = {}
      kws["bunnyZ"] = self.getArg("bunnyZ", 20, float)
      kws["bunnySize"] = self.getArg("bunnySize", 10, float)
      kws["bunnyMass"] = self.getArg("bunnyMass", self.objectMass() * 10, float)
      kws["margin"] = self.getArg("margin", 0.5, float)
      scs.append(BunnyScenario(**kws))
    if wantUrdfs:
      scs.append(RandomUrdfScenario())
    if wantChain:
      scs.append(ChainScenario())
    for sc in scs:
      if self.getArg("bouncy"):
        sc.set("bouncy", True)
      if self.getArg("frictionless"):
        sc.set("frictionless", True)
      logger.debug("Setting up scenario {!r}".format(sc))
      for b in sc.setup(self):
        self._bodies.add(b)
    for path in self.getArg("urdf", (), tuple):
      pos = randomVec()
      logger.debug("Adding URDF {} at {}".format(path, pos))
      self.loadURDF(path, basePosition=pos)
    for spec in self.getArg("softBodies", (), tuple):
      parts = spec.split(":")
      path = parts[0]
      scale = float(parts[1]) if len(parts) > 1 else 1
      margin = float(parts[2]) if len(parts) > 2 else 1
      pos = V3()
      orn = p.getQuaternionFromEuler((0, math.pi/2, 0))
      logger.debug("Adding soft body {} at {}".format(path, pos))
      self.loadSoftBody(path, pos=pos, scale=scale, mass=100, orn=orn, margin=margin)
    for spec in self.getArg("rigidBodies", (), tuple):
      parts = spec.split(":")
      path = parts[0]
      scale = float(parts[1]) if len(parts) > 1 else 1
      logger.debug("Creating collision {}, scale={}".format(path, scale))
      coll = self.createCollision(p.GEOM_MESH, fileName=path, meshScale=scale)
      kws = {
        "baseMass": 100,
        "baseCollisionShapeIndex": coll,
        "baseVisualShapeIndex": -1,
        "basePosition": V3()
      }
      logger.debug("Creating multibody {}".format(kws))
      self.createMultiBody(**kws)
    nb, ns = len(self._bodies), len(scs)
    logger.debug("Added {} bodies from {} scenarios".format(nb, ns))
    if self.getArg("axes") or self._debug:
      self._addAxes()
    if self.getArg("grid"):
      self._addGrid()
def _addObjects ( self ) : scs = [ EmptyPlaneScenario ( ) ] wantWalls = self . getArg ( "walls" ) wantBricks1 = self . getArg ( "bricks" ) or self . getArg ( "b1" ) wantBricks2 = self . getArg ( "b2" ) wantBricks3 = self . getArg ( "b3" ) wantProjectile = self . getArg ( "projectile" ) wantPit = self . getArg ( "pit" ) wantBunny = self . getArg ( "bunny" ) wantUrdfs = self . getArg ( "urdfs" ) wantRand = self . getArg ( "rand" ) wantChain = self . getArg ( "chain" ) if wantWalls : scs . append ( BoxedScenario ( ) ) if wantPit : kws = { } kws [ "objShape" ] = self . getArg ( "projShape" , ProjectileScenario . SHAPE_SPHERE , int ) scs . append ( BallpitScenario ( rand = wantRand , ** kws ) ) if wantBricks1 : scs . append ( BrickTower1Scenario ( rand = wantRand ) ) if wantBricks2 : scs . append ( BrickTower2Scenario ( rand = wantRand ) ) if wantBricks3 : scs . append ( BrickTower3Scenario ( rand = wantRand ) ) if wantProjectile : kws = { } kws [ "projShape" ] = self . getArg ( "projShape" , ProjectileScenario . SHAPE_SPHERE , int ) kws [ "projSize" ] = self . getArg ( "projSize" , self . objectRadius ( ) , float ) kws [ "velCoeff" ] = self . getArg ( "projSpeed" , 20 , float ) kws [ "projMass" ] = self . getArg ( "projMass" , 100 , float ) kws [ "projTargetX" ] = self . getArg ( "projTargetX" , 0 , float ) kws [ "projTargetY" ] = self . getArg ( "projTargetY" , 0 , float ) kws [ "projTargetZ" ] = self . getArg ( "projTargetZ" , 0 , float ) scs . append ( ProjectileScenario ( rand = wantRand , ** kws ) ) if wantBunny : kws = { } kws [ "bunnyZ" ] = self . getArg ( "bunnyZ" , 20 , float ) kws [ "bunnySize" ] = self . getArg ( "bunnySize" , 10 , float ) kws [ "bunnyMass" ] = self . getArg ( "bunnyMass" , self . objectMass ( ) * 10 , float ) kws [ "margin" ] = self . getArg ( "margin" , 0.5 , float ) scs . append ( BunnyScenario ( ** kws ) ) if wantUrdfs : scs . append ( RandomUrdfScenario ( ) ) if wantChain : scs . append ( ChainScenario ( ) ) for sc in scs : if self . getArg ( "bouncy" ) : sc . set ( "bouncy" , True ) if self . getArg ( "frictionless" ) : sc . set ( "frictionless" , True ) logger . debug ( "Setting up scenario {!r}" . format ( sc ) ) for b in sc . setup ( self ) : self . _bodies . add ( b ) for path in self . getArg ( "urdf" , ( ) , tuple ) : pos = randomVec ( ) logger . debug ( "Adding URDF {} at {}" . format ( path , pos ) ) self . loadURDF ( path , basePosition = pos ) for spec in self . getArg ( "softBodies" , ( ) , tuple ) : parts = spec . split ( ":" ) path = parts [ 0 ] scale = float ( parts [ 1 ] ) if len ( parts ) > 1 else 1 margin = float ( parts [ 2 ] ) if len ( parts ) > 2 else 1 pos = V3 ( ) orn = p . getQuaternionFromEuler ( ( 0 , math . pi / 2 , 0 ) ) logger . debug ( "Adding soft body {} at {}" . format ( path , pos ) ) self . loadSoftBody ( path , pos = pos , scale = scale , mass = 100 , orn = orn , margin = margin ) for spec in self . getArg ( "rigidBodies" , ( ) , tuple ) : parts = spec . split ( ":" ) path = parts [ 0 ] scale = float ( parts [ 1 ] ) if len ( parts ) > 1 else 1 logger . debug ( "Creating collision {}, scale={}" . format ( path , scale ) ) coll = self . createCollision ( p . GEOM_MESH , fileName = path , meshScale = scale ) kws = { "baseMass" : 100 , "baseCollisionShapeIndex" : coll , "baseVisualShapeIndex" : - 1 , "basePosition" : V3 ( ) } logger . debug ( "Creating multibody {}" . format ( kws ) ) self . createMultiBody ( ** kws ) nb , ns = len ( self . _bodies ) , len ( scs ) logger . debug ( "Added {} bodies from {} scenarios" . format ( nb , ns ) ) if self . getArg ( "axes" ) or self . _debug : self . _addAxes ( ) if self . getArg ( "grid" ) : self . _addGrid ( )
Add all configured objects to the world
Add all configured objects to the world
# {{{0 "Add all configured objects to the world" # Add all of the objects from all of the scenarios configured # Handle --urdf argument: add URDF at a random position between (-0.5, 0.5) # Handle --sb argument: add soft bodies # Handle --rb argument: add rigid bodies # Add non-body items
self