Пример #1
0
    def display_shape(self, shape, rgb=None, transparency=None, material=None):
        """
        Display a shape.
        :param OCC.Core.TopoDS.TopoDS_Shape shape: The shape.
        :param rgb: The RGB color (r, g, b).
        :type rgb: collections.Sequence(float) or OCC.Core.Quantity.Quantity_Color
        :param float transparency: The transparency (0 to 1).
        :param OCC.Core.Graphic3d.Graphic3d_NameOfMaterial material: The material.
        :return: The AIS_Shape created for the part.
        :rtype: OCC.Core.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)

        if material is not None:
            ma = Graphic3d_MaterialAspect(material)
            ais_shape.SetMaterial(ma)

        self._my_context.Display(ais_shape, True)
        return ais_shape
Пример #2
0
 def _styleAis(self, ais, styleName, styleValue):
     if styleName == 'color':
         r, g, b = styleValue
         color = Quantity_Color(r, g, b, Quantity_TOC_RGB)
         ais.SetColor(color)
         if isinstance(ais, AIS_Trihedron):
             ais.SetArrowColor(color)
             ais.SetTextColor(color)
     elif styleName == 'tran':
         ais.SetTransparency(styleValue)
     elif styleName == 'material':
         aspect = Graphic3d_MaterialAspect(MATERIAL_TYPES.index(styleValue))
         ais.SetMaterial(aspect)
     elif styleName == 'lineType':
         lineType = LINE_TYPES.index(styleValue)
         ais.Attributes().WireAspect().SetTypeOfLine(lineType)
         ais.Attributes().LineAspect().SetTypeOfLine(lineType)
     elif styleName == 'lineWidth':
         ais.Attributes().LineAspect().SetWidth(styleValue)
         ais.Attributes().WireAspect().SetWidth(styleValue)
     if isinstance(ais, AIS_Point):
         if styleName == 'pointType':
             ais.SetMarker(POINT_TYPES.index(styleValue))
         if styleName == 'pointSize':
             ais.Attributes().PointAspect().SetScale(styleValue)
Пример #3
0
 def renderShapeObj(self, shape, transforms, styleName):
     color, transparency, materialName = self.getStyle(styleName)
     trsf = gp_Trsf()
     for tr in transforms:
         trsf *= tr.getTrsf()
     shape =  BRepBuilderAPI_Transform(shape, trsf).Shape()
     ais = AIS_Shape(shape)
     r,g,b = color
     aisColor =  Quantity_Color(r/256, g/256, b/256, Quantity_TypeOfColor(Quantity_TypeOfColor.Quantity_TOC_RGB))
     ais.SetColor(aisColor)
     ais.SetTransparency(transparency/100)
     aspect = Graphic3d_MaterialAspect(getMaterialNameConst(materialName))
     ais.SetMaterial(aspect)
     self.display.Context.Display(ais, False)
Пример #4
0
 def _renderShapeObj(self, aShape):
     shapeTr = BRepBuilderAPI_Transform(aShape,
                                        self.aMove.getTrsf()).Shape()
     ais = AIS_Shape(shapeTr)
     r, g, b = self.aStyle.getNormedColor()
     aisColor = Quantity_Color(
         r, g, b,
         Quantity_TypeOfColor(Quantity_TypeOfColor.Quantity_TOC_RGB))
     ais.SetColor(aisColor)
     ais.SetTransparency(self.aStyle.getNormedTransparency())
     aspect = Graphic3d_MaterialAspect(
         MATERIAL_CONSTS[self.aStyle.getMaterial()])
     ais.SetMaterial(aspect)
     self.display.Context.Display(ais, False)
Пример #5
0
 def stylingNativeObj(self, obj, styleName, styleValue):
     if obj == None:
         return
     if isinstance(obj, NativeStubText):
         if styleName == 'visible':
             if styleValue > 0.5:
                 if self.isInit:
                     obj.struct = self.display.DisplayMessage(
                         obj.position, obj.text, obj.textHeight,
                         obj.textColor, False)
                     obj.visible = 1
         elif styleName == 'textColor':
             obj.textColor = styleValue
         elif styleName == 'textHeight':
             obj.textHeight = styleValue
     if isinstance(obj, AIS_InteractiveObject):
         if styleName == 'color':
             r, g, b = styleValue
             color = Quantity_Color(r, g, b, Quantity_TOC_RGB)
             obj.SetColor(color)
             if isinstance(obj, AIS_Trihedron):
                 obj.SetArrowColor(color)
                 obj.SetTextColor(color)
         elif styleName == 'transparensy':
             obj.SetTransparency(styleValue)
         elif styleName == 'material':
             aspect = Graphic3d_MaterialAspect(
                 MATERIAL_TYPES.index(styleValue))
             obj.SetMaterial(aspect)
         elif styleName == 'lineType':
             lineType = LINE_TYPES.index(styleValue)
             obj.Attributes().WireAspect().SetTypeOfLine(lineType)
             obj.Attributes().LineAspect().SetTypeOfLine(lineType)
         elif styleName == 'lineWidth':
             obj.Attributes().LineAspect().SetWidth(styleValue)
             obj.Attributes().WireAspect().SetWidth(styleValue)
         elif styleName == 'visible':
             if self.isInit:
                 if styleValue > 0.5:
                     self.display.Context.Display(obj, False)
                 else:
                     self.display.Context.Erase(obj, False)
         if isinstance(obj, AIS_Point):
             if styleName == 'pointType':
                 obj.SetMarker(POINT_TYPES.index(styleValue))
             if styleName == 'pointSize':
                 obj.Attributes().PointAspect().SetScale(styleValue)
Пример #6
0
    def DisplayShape(self,
                     shapes,
                     material=None,
                     texture=None,
                     color=None,
                     transparency=None,
                     update=False):
        """ display one or a set of displayable objects
        """
        ais_shapes = []  # the list of all displayed shapes

        if issubclass(shapes.__class__, gp_Pnt):
            # if a gp_Pnt is passed, first convert to vertex
            vertex = BRepBuilderAPI_MakeVertex(shapes)
            shapes = [vertex.Shape()]
        elif isinstance(shapes, gp_Pnt2d):
            vertex = BRepBuilderAPI_MakeVertex(
                gp_Pnt(shapes.X(), shapes.Y(), 0))
            shapes = [vertex.Shape()]
        elif isinstance(shapes, Geom_Surface):
            bounds = True
            toldegen = 1e-6
            face = BRepBuilderAPI_MakeFace()
            face.Init(shapes, bounds, toldegen)
            face.Build()
            shapes = [face.Shape()]
        elif isinstance(shapes, Geom_Curve):
            edge = BRepBuilderAPI_MakeEdge(shapes)
            shapes = [edge.Shape()]
        elif isinstance(shapes, Geom2d_Curve):
            edge2d = BRepBuilderAPI_MakeEdge2d(shapes)
            shapes = [edge2d.Shape()]
        # if only one shapes, create a list with a single shape
        if not isinstance(shapes, list):
            shapes = [shapes]
        # build AIS_Shapes list
        for shape in shapes:
            if material or texture:
                if texture:
                    shape_to_display = AIS_TexturedShape(shape)
                    filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties(
                    )
                    shape_to_display.SetTextureFileName(
                        TCollection_AsciiString(filename))
                    shape_to_display.SetTextureMapOn()
                    shape_to_display.SetTextureScale(True, toScaleU, toScaleV)
                    shape_to_display.SetTextureRepeat(True, toRepeatU,
                                                      toRepeatV)
                    shape_to_display.SetTextureOrigin(True, originU, originV)
                    shape_to_display.SetDisplayMode(3)
                elif material:
                    shape_to_display = AIS_Shape(shape)
                    shape_to_display.SetMaterial(
                        Graphic3d_MaterialAspect(material))
            else:
                # TODO: can we use .Set to attach all TopoDS_Shapes
                # to this AIS_Shape instance?
                shape_to_display = AIS_Shape(shape)

            ais_shapes.append(shape_to_display)

        # if not SOLO:
        #     # computing graphic properties is expensive
        #     # if an iterable is found, so cluster all TopoDS_Shape under
        #     # an AIS_MultipleConnectedInteractive
        #     #shape_to_display = AIS_MultipleConnectedInteractive()
        #     for ais_shp in ais_shapes:
        #         # TODO : following line crashes with oce-0.18
        #         # why ? fix ?
        #         #shape_to_display.Connect(i)
        #         self.Context.Display(ais_shp, False)
        # set the graphic properties
        if material is None:
            #The default material is too shiny to show the object
            #color well, so I set it to something less reflective
            for shape_to_display in ais_shapes:
                shape_to_display.SetMaterial(
                    Graphic3d_MaterialAspect(Graphic3d_NOM_NEON_GNC))
        if color:
            if isinstance(color, str):
                color = get_color_from_name(color)
            elif isinstance(color, int):
                color = Quantity_Color(color)
            for shp in ais_shapes:
                self.Context.SetColor(shp, color, False)
        if transparency:
            for shape_to_display in ais_shapes:
                shape_to_display.SetTransparency(transparency)
        # display the shapes
        for shape_to_display in ais_shapes:
            self.Context.Display(shape_to_display, False)
        if update:
            # especially this call takes up a lot of time...
            self.FitAll()
            self.Repaint()

        return ais_shapes
Пример #7
0
        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()
display.Viewer.AddLight(ambient_light)
# directional light
dir_light = V3d_DirectionalLight(gp_Dir(0, 0, 1),
                                 Quantity_Color(Quantity_NOC_WHITE))
display.Viewer.AddLight(dir_light)
# light
spot_light = V3d_SpotLight(gp_Pnt(-100, -100, 100), V3d_XnegYnegZpos,
                           Quantity_Color(Quantity_NOC_WHITE))
## display the spotlight in rasterized mode
display.Viewer.AddLight(spot_light)

# first create the material for the bottle
pbr_mat_1 = Graphic3d_PBRMaterial()
pbr_mat_1.SetMetallic(0.8)
pbr_mat_1.SetRoughness(0.5)
alu_pbr_aspect = Graphic3d_MaterialAspect(Graphic3d_NOM_ALUMINIUM)
alu_pbr_aspect.SetPBRMaterial(pbr_mat_1)
alu_pbr_aspect.SetBSDF(Graphic3d_BSDF().CreateMetallicRoughness(pbr_mat_1))

# then the glass
pbr_mat_2 = Graphic3d_PBRMaterial()
glass_pbr_aspect = Graphic3d_MaterialAspect(Graphic3d_NOM_PLASTIC)
glass_pbr_aspect.SetPBRMaterial(pbr_mat_2)
# the BSDF glass
weights = Graphic3d_Vec3(0.5, 6., 1.)
absorption_color = Graphic3d_Vec3(0.8, 0.8, 0.8)
absorption_coef = 0.6
refraction_index = 2.2
glass_pbr_aspect.SetBSDF(Graphic3d_BSDF().CreateGlass(weights,
                                                      absorption_color,
                                                      absorption_coef,