def material_to_material_aspect(material): """ Convert a material name to a Graphic3d material Parameters ---------- material: declaracad.shape.Material The material definition Returns ------- result: Graphic3d_MaterialAspect or None The material """ if material is None or not material.name: name = 'CHARCOAL' else: name = material.name.upper() if name == 'CUSTOM': if material._data is not None: return material._data a = Graphic3d_MaterialAspect() a.SetTransparency(material.transparency) a.SetShininess(material.shininess) a.SetRefractionIndex(material.refraction_index) if material.color: c, t = color_to_quantity_color(material.color) a.SetColor(c) if material.ambient_color: c, t = color_to_quantity_color(material.ambient_color) a.SetAmbientColor(c) if material.diffuse_color: c, t = color_to_quantity_color(material.diffuse_color) a.SetDiffuseColor(c) if material.specular_color: c, t = color_to_quantity_color(material.specular_color) a.SetSpecularColor(c) if material.emissive_color: c, t = color_to_quantity_color(material.emissive_color) a.SetEmissiveColor(c) material._data = a return a ma = OCC_MATERIAL_CACHE.get(name) if ma is None: material_type = 'Graphic3d_NOM_%s' % name ma = Graphic3d_MaterialAspect(getattr(Graphic3d, material_type)) OCC_MATERIAL_CACHE[name] = ma return ma
def material_to_material_aspect(material): """ Convert a material name to a Graphic3d material Parameters ---------- material: declaracad.shape.Material The material definition Returns ------- result: Graphic3d_MaterialAspect or None The material """ if material.name: material_type = 'Graphic3d_NOM_%s' % material.name.upper() return Graphic3d_MaterialAspect(getattr(Graphic3d, material_type)) a = Graphic3d_MaterialAspect() a.SetTransparency(material.transparency) a.SetShininess(material.shininess) a.SetRefractionIndex(material.refraction_index) if material.color: c, t = color_to_quantity_color(material.color) a.SetColor(c) if material.ambient_color: c, t = color_to_quantity_color(material.ambient_color) a.SetAmbientColor(c) if material.diffuse_color: c, t = color_to_quantity_color(material.diffuse_color) a.SetDiffuseColor(c) if material.specular_color: c, t = color_to_quantity_color(material.specular_color) a.SetSpecularColor(c) if material.emissive_color: c, t = color_to_quantity_color(material.emissive_color) a.SetEmissiveColor(c) return a
def display_shape(self, shape, rgb=None, transparency=None, material=Graphic3d_NOM_DEFAULT): """ Display a shape. :param OCCT.TopoDS.TopoDS_Shape shape: The shape. :param rgb: The RGB color (r, g, b). :type rgb: collections.Sequence[float] or OCCT.Quantity.Quantity_Color :param float transparency: The transparency (0 to 1). :param OCCT.Graphic3d.Graphic3d_NameOfMaterial material: The material. :return: The AIS_Shape created for the part. :rtype: OCCT.AIS.AIS_Shape """ ais_shape = AIS_Shape(shape) if isinstance(rgb, (tuple, list)): r, g, b = rgb if r > 1.: r /= 255. if g > 1.: g /= 255. if b > 1.: b /= 255. color = Quantity_Color(r, g, b, Quantity_TOC_RGB) ais_shape.SetColor(color) elif isinstance(rgb, Quantity_Color): ais_shape.SetColor(rgb) if transparency is not None: ais_shape.SetTransparency(transparency) ma = Graphic3d_MaterialAspect(material) ais_shape.SetMaterial(ma) self.my_context.Display(ais_shape, True) return ais_shape
def TextureRepeat(self, toRepeatU, toRepeatV): self._toRepeatU = toRepeatU self._toRepeatV = toRepeatV def TextureOrigin(self, originU, originV): self._originU = originU self._originV = originV def GetProperties(self): return (self._filename, self._toScaleU, self._toScaleV, self._toRepeatU, self._toRepeatV, self._originU, self._originV) # # First create texture and a material # texture_filename = '../assets/images/ground.bmp' t = Texture(texture_filename) m = Graphic3d_MaterialAspect(Graphic3d_NOM_SILVER) # # Displays a cylinder with a material and a texture # s = BRepPrimAPI_MakeCylinder(60, 200) display.DisplayShape(s.Shape(), material=m, texture=t) # # Display settings # display.View_Iso() display.FitAll() start_display()