def _add_rendering(self, mode='osg'): # Set renderer self.app.setAutoStepping(True) self.app.setEnableDebugRenderer(False) self.app.setEnableOSGRenderer(True) file_directory = os.path.dirname(os.path.abspath(__file__)) package_directory = os.path.split(file_directory)[0] gripper_texture = os.path.join(package_directory, TEXTURE_GRIPPER_FILE) # Create scene graph for rendering root = self.app.getSceneRoot() rbs = self.sim.getRigidBodies() for rb in rbs: node = agxOSG.createVisual(rb, root) if rb.getName() == "hollow_cylinder": agxOSG.setDiffuseColor(node, agxRender.Color_SteelBlue()) agxOSG.setShininess(node, 15) elif rb.getName() == "gripper_body": agxOSG.setDiffuseColor(node, agxRender.Color(1.0, 1.0, 1.0, 1.0)) agxOSG.setTexture(node, gripper_texture, False, agxOSG.DIFFUSE_TEXTURE) agxOSG.setShininess(node, 2) elif "dlo" in rb.getName(): # Cable segments agxOSG.setDiffuseColor(node, agxRender.Color(0.0, 1.0, 0.0, 1.0)) else: agxOSG.setDiffuseColor(node, agxRender.Color.Beige()) agxOSG.setAlpha(node, 0.0) # Set rendering options scene_decorator = self.app.getSceneDecorator() scene_decorator.setEnableLogo(False) scene_decorator.setBackgroundColor(agxRender.Color(1.0, 1.0, 1.0, 1.0))
def add_color(geomerty): waterNode = agxOSG.createVisual(geomerty, demoutils.root()) color = agxRender.Color.DeepSkyBlue() alpha = 0.4 agxOSG.setDiffuseColor(waterNode, color) agxOSG.setAmbientColor(waterNode, agx.Vec4f(1)) agxOSG.setShininess(waterNode, 120) agxOSG.setAlpha(waterNode, alpha)
def create_water_visual(geo, root): node = agxOSG.createVisual(geo, root) diffuse_color = agxRender.Color(0.0, 0.75, 1.0, 1) ambient_color = agxRender.Color(1, 1, 1, 1) specular_color = agxRender.Color(1, 1, 1, 1) agxOSG.setDiffuseColor(node, diffuse_color) agxOSG.setAmbientColor(node, ambient_color) agxOSG.setSpecularColor(node, specular_color) agxOSG.setShininess(node, 120) agxOSG.setAlpha(node, 0.5) return node
def create_visual(obj, diffuse_color: Color = None, ambient_color: Color = None, shininess=None, alpha: float = None): node = agxOSG.createVisual(obj, root()) if diffuse_color is not None: agxOSG.setDiffuseColor(node, diffuse_color) if ambient_color is not None: agxOSG.setAmbientColor(node, ambient_color) if shininess is not None: agxOSG.setShininess(node, shininess) if alpha is not None: agxOSG.setAlpha(node, alpha) return node
def addGround(MiroSystem, size_x, size_y, size_z, pos, heightmap, texture='test.jpg', scale=[4,3], Collide=True, Fixed=True, rotX=0, rotY=0, rotZ=0, rotOrder=['x','y','z'], rotAngle=0, rotAxis=[1,0,0], rotDegrees=True, mass=False, density=1000, dynamic=False, color=[0.5, 0.5, 0.5]): agxSim = agxPython.getContext().environment.getSimulation() agxApp = agxPython.getContext().environment.getApplication() agxRoot = agxPython.getContext().environment.getSceneRoot() # Create the ground ground_material = agx.Material("Ground") # Create the height field from a heightmap hf = agxCollide.HeightField.createFromFile("textures/"+heightmap, size_x, size_z, 0, size_y) ground_geometry = agxCollide.Geometry(hf) ground = agx.RigidBody(ground_geometry) ground.setPosition(agxVecify(pos)) ground.setMotionControl(agx.RigidBody.STATIC) node = agxOSG.createVisual( ground, agxRoot ) agxOSG.setShininess(node, 5) # Add a visual texture. agxOSG.setTexture(node, "textures/"+texture, True, agxOSG.DIFFUSE_TEXTURE, 100, 100) agxSim.add(ground)
def __init__(self, ground: agxCollide.Geometry, rov, depth): """ Args: ground: rov: depth: """ super().__init__() self.setMask(ContactEventListener.CONTACT) b = agxCollide.Box(.1, .1, depth) self.beam = Geometry(b) # print(self.beam.getShapes(),self.beam) self.beam.setPosition(0, 0, -depth) self.beam.setSensor(True) self.setFilter(GeometryFilter(self.beam, ground)) color = agxRender.Color.IndianRed() node = agxOSG.createVisual(self.beam, demoutils.root()) agxOSG.setDiffuseColor(node, color) agxOSG.setAmbientColor(node, agx.Vec4f(1)) agxOSG.setShininess(node, 120) agxOSG.setAlpha(node, 0.6) self.ground = ground.getShape().asHeightField()
def __init__(self): hf = agxCollide.HeightField.createFromFile("assets/textures/dirtRoad128.png", 6, 6, -0.5, 0.5) terrain = agxModel.Terrain(hf) snakeapp.add(terrain) self.material = agx.Material("GroundMaterial") terrain_data = terrain.getDataInterface() # type: agxModel.TerrainDataInterface terrain_data.setMaxCompressionMultiplier(32) particle_adhesion = 0 deformity = 100 angle_of_repose = math.pi * 0.2 material_index = 0 terrain_data.add(self.material, material_index, particle_adhesion, deformity, angle_of_repose) range_for_youngs_modulus = agx.RangeReal(10000, 20000) terrain_renderer = agxOSG.TerrainRenderer(terrain, range_for_youngs_modulus, snakeapp.root()) snakeapp.add(terrain_renderer) terrain_visual = terrain_renderer.getTerrainNode() agxOSG.setDiffuseColor(terrain_visual, Color(0.7, 0.7, 0.8, 1)) agxOSG.setSpecularColor(terrain_visual, Color(0.4, 0.4, 0.4, 1)) agxOSG.setShininess(terrain_visual, 128)