def build_axis(self): np = self._number_of_points n = 1 + 2 * np ds = coin.SoDrawStyle() ds.lineWidth = 2 self.sep3.addChild(ds) self.mat1 = coin.SoMaterial() #bind1 = coin.SoMaterialBinding() #bind1.value = coin.SoMaterialBinding.PER_PART ax = coin.SoIndexedLineSet() ax.coordIndex.setValue(0) ax.coordIndex.setValues(0, 3, [n * np, n * (np + 1) - 1, -1]) #self.sep3.addChild(bind1) self.sep3.addChild(self.mat1) self.sep3.addChild(ax) self.mat2 = coin.SoMaterial() #bind2 = coin.SoMaterialBinding() #bind2.value = coin.SoMaterialBinding.PER_PART ax2 = coin.SoIndexedLineSet() ax2.coordIndex.setValue(0) ax2.coordIndex.setValues(0, 3, [np, n * (n - 1) + np, -1]) #self.sep3.addChild(bind2) self.sep3.addChild(self.mat2) self.sep3.addChild(ax2)
def attach(self, obj): #debug("Comb : ViewProviderComb.attach ") self.oldx = 0 self.oldy = 0 self.wireframe = coin.SoGroup() self.combColor = coin.SoBaseColor() self.curveColor = coin.SoBaseColor() self.combColor.rgb = (obj.CombColor[0], obj.CombColor[1], obj.CombColor[2]) self.curveColor.rgb = (obj.CurveColor[0], obj.CurveColor[1], obj.CurveColor[2]) self.points = coin.SoCoordinate3() self.combLines = coin.SoIndexedLineSet() self.curveLines = coin.SoIndexedLineSet() self.wireframe.addChild(self.points) self.wireframe.addChild(self.combColor) self.wireframe.addChild(self.combLines) self.wireframe.addChild(self.curveColor) self.wireframe.addChild(self.curveLines) #self.selectionNode = coin.SoType.fromName("SoFCSelection").createInstance() #self.selectionNode.documentName.setValue(FreeCAD.ActiveDocument.Name) #self.selectionNode.objectName.setValue(obj.Object.Name) # here obj is the ViewObject, we need its associated App Object #self.selectionNode.subElementName.setValue("Comb") #self.selectionNode.addChild(self.curveLines) #self.wireframe.addChild(self.selectionNode) obj.addDisplayMode(self.wireframe, "Wireframe")
def __init__(self, mlist): self.colorRed = coin.SoBaseColor() self.colorRed.rgb = (1, 0, 0) self.colorGreen = coin.SoBaseColor() self.colorGreen.rgb = (0, 1, 0) self.colorBlue = coin.SoBaseColor() self.colorBlue.rgb = (0, 0, 1) self.colorYellow = coin.SoBaseColor() self.colorYellow.rgb = (1, 1, 0) self.colorPurple = coin.SoBaseColor() self.colorPurple.rgb = (1, 0, 1) self.colorCyan = coin.SoBaseColor() self.colorCyan.rgb = (0, 1, 1) self.colorWhite = coin.SoBaseColor() self.colorWhite.rgb = (1, 1, 1) self.colorBlack = coin.SoBaseColor() self.colorBlack.rgb = (0, 0, 0) self.Ulen = len(mlist) self.Vlen = len(mlist[0]) self.pts = [] for row in mlist: for pt in row: self.pts.append(pt.points[0]) num = [] for u in range(self.Ulen): for v in range(self.Vlen): num.append(u * self.Vlen + v) num.append(-1) num2 = [] for v in range(self.Vlen): for u in range(self.Ulen): num2.append(u * self.Vlen + v) num2.append(-1) print(str(num)) print(str(num2)) self.gridSep = coin.SoSeparator() #self.coords = coin.SoCoordinate3() #self.coords.point.setValues(0,len(self.pts),self.pts) self.Line = coin.SoIndexedLineSet() self.Line.coordIndex.setValues(0, len(num), num) self.Node = coin.SoSeparator() #self.Node.addChild(self.coords) self.Node.addChild(self.colorBlue) self.Node.addChild(self.Line) self.Line2 = coin.SoIndexedLineSet() self.Line2.coordIndex.setValues(0, len(num2), num2) self.Node2 = coin.SoSeparator() #self.Node2.addChild(self.coords) self.Node2.addChild(self.colorPurple) self.Node2.addChild(self.Line2) self.gridSep.addChild(self.Node) self.gridSep.addChild(self.Node2)
def __init__(self, color = (0.,0.,0.), lineWidth = 1.0): super(polygonNode, self).__init__() self.lines = coin.SoIndexedLineSet() self.addChild(self.lines) self.color = color self.lineWidth = lineWidth self._numVertices = []
def mesh_sep(vertices, polygons, color=(1,1,0), draw_lines=False): _vertices = vertices _polygons = [] _lines = [] for i in polygons: _polygons += i _lines += i _lines.append(i[0]) _polygons.append(-1) _lines.append(-1) sep = coin.SoSeparator() vertex_property = coin.SoVertexProperty() face_set = coin.SoIndexedFaceSet() shape_hint = coin.SoShapeHints() shape_hint.vertexOrdering = coin.SoShapeHints.COUNTERCLOCKWISE shape_hint.creaseAngle = coin.M_PI / 3 face_mat = coin.SoMaterial() face_mat.diffuseColor = color vertex_property.vertex.setValues(0, len(_vertices), _vertices) face_set.coordIndex.setValues(0, len(_polygons), list(_polygons)) vertex_property.materialBinding = coin.SoMaterialBinding.PER_VERTEX_INDEXED sep += shape_hint, vertex_property, face_mat, face_set if draw_lines: line_set = coin.SoIndexedLineSet() line_set.coordIndex.setValues(0, len(_lines), list(_lines)) line_mat = coin.SoMaterial() line_mat.diffuseColor = (.0, .0, .0) sep += line_mat, line_set return sep
def build_lines(self): np = self._number_of_points n = 1 + 2 * np self.line_mat1 = coin.SoMaterial() ol = list() #[(0.2,0.2,0.2)] + [(0.6,0.6,0.6)] * 9 bind1 = coin.SoMaterialBinding() bind1.value = coin.SoMaterialBinding.PER_PART l1 = coin.SoIndexedLineSet() l1.coordIndex.setValue(0) ind = list() for i in range(2 * self._number_of_points + 1): if not i == self._number_of_points: ind.append((i * n)) ind.append(((i + 1) * n) - 1) ind.append(-1) if (i % 10) == 0: ol.append((0.2, 0.2, 0.2)) else: ol.append((0.4, 0.4, 0.4)) #print(ind) self.line_mat1.diffuseColor.setValues(0, len(ol), ol) l1.coordIndex.setValues(0, len(ind), ind) l2 = coin.SoIndexedLineSet() l2.coordIndex.setValue(0) ind2 = list() for i in range(2 * self._number_of_points + 1): if not i == self._number_of_points: ind2.append(i) ind2.append(i + (n - 1) * n) ind2.append(-1) #if (i % 10) == 0: #ol.append((0.2,0.2,0.2)) #else: #ol.append((0.4,0.4,0.4)) #print(ind) #self.line_mat1.diffuseColor.setValues(0, len(ol), ol ) l2.coordIndex.setValues(0, len(ind2), ind2) self.sep2.addChild(bind1) self.sep2.addChild(self.line_mat1) self.sep2.addChild(l1) self.sep2.addChild(l2)
def attach(self,vobj): self.Object = vobj.Object self.clip = None from pivy import coin self.sep = coin.SoGroup() self.mat = coin.SoMaterial() self.sep.addChild(self.mat) self.dst = coin.SoDrawStyle() self.sep.addChild(self.dst) self.lco = coin.SoCoordinate3() self.sep.addChild(self.lco) lin = coin.SoType.fromName("SoBrepEdgeSet").createInstance() lin.coordIndex.setValues([0,1,-1,2,3,-1,4,5,-1]) self.sep.addChild(lin) self.bbox = coin.SoSwitch() self.bbox.whichChild = -1 bboxsep = coin.SoSeparator() self.bbox.addChild(bboxsep) drawstyle = coin.SoDrawStyle() drawstyle.style = coin.SoDrawStyle.LINES drawstyle.lineWidth = 3 drawstyle.linePattern = 0x0f0f # 0xaa bboxsep.addChild(drawstyle) self.bbco = coin.SoCoordinate3() bboxsep.addChild(self.bbco) lin = coin.SoIndexedLineSet() lin.coordIndex.setValues([0,1,2,3,0,-1,4,5,6,7,4,-1,0,4,-1,1,5,-1,2,6,-1,3,7,-1]) bboxsep.addChild(lin) self.sep.addChild(self.bbox) self.tra = coin.SoTransform() self.tra.rotation.setValue(FreeCAD.Rotation(0,0,90).Q) self.sep.addChild(self.tra) self.fon = coin.SoFont() self.sep.addChild(self.fon) self.txt = coin.SoAsciiText() self.txt.justification = coin.SoText2.LEFT self.txt.string.setValue("level") self.sep.addChild(self.txt) vobj.addDisplayMode(self.sep,"Default") self.onChanged(vobj,"ShapeColor") self.onChanged(vobj,"FontName") self.onChanged(vobj,"ShowLevel") self.onChanged(vobj,"FontSize") self.onChanged(vobj,"AutogroupBox") self.setProperties(vobj) return
def attach(self, obj): '''Setup the scene sub-graph of the view provider, this method is mandatory''' self.shaded = coin.SoGroup() self.wireframe = coin.SoGroup() self.scale = coin.SoScale() self.color = coin.SoBaseColor() self.data=coin.SoCoordinate3() self.face=coin.SoIndexedLineSet() self.shaded.addChild(self.scale) self.shaded.addChild(self.color) self.shaded.addChild(self.data) self.shaded.addChild(self.face) obj.addDisplayMode(self.shaded,"Shaded"); style=coin.SoDrawStyle() style.style = coin.SoDrawStyle.LINES self.wireframe.addChild(style) self.wireframe.addChild(self.scale) self.wireframe.addChild(self.color) self.wireframe.addChild(self.data) self.wireframe.addChild(self.face) obj.addDisplayMode(self.wireframe,"Wireframe"); self.onChanged(obj,"Color")
def __init__(self, spGrp): CoinTemplate.__init__(self, spGrp) self.__lines = coin.SoIndexedLineSet() spGrp.addChild(self.__lines) self.style({'style': coin.SoDrawStyle.LINES})
def __init__(self, color = (0.,0.,0.), lineWidth = 1.0): super(sensorPolyNode, self).__init__() self.lines = coin.SoIndexedLineSet() self.addChild(self.lines) self.color = color self.lineWidth = lineWidth
def __init__(self): super(gridNode, self).__init__() self.vec = coin.SoTransformVec3f() #self.vec.matrix.connectFrom(cam.orientation) self.vec.vector = coin.SbVec3f(0, 0, -1) self.calc = coin.SoCalculator() self.calc.A.connectFrom(self.vec.direction) self.calc.expression.set1Value(0, "ta=0.5") # maxviz self.calc.expression.set1Value(1, "tb=20.0") # factor self.calc.expression.set1Value(2, "tA=vec3f(1,0,0)") # plane normal self.calc.expression.set1Value(3, "tc=dot(A,tA)") self.calc.expression.set1Value(4, "td=fabs(tc)") self.calc.expression.set1Value(5, "oa=1.0-ta*pow(td,tb)") self.calc.expression.set1Value(6, "oA=vec3f(oa,0,0)") self.scaleEngine = coin.SoCalculator() #self.scaleEngine.a.connectFrom(cam.height) self.scaleEngine.expression.set1Value(0, "ta=floor(log10(a/10))") self.scaleEngine.expression.set1Value(1, "tb=pow(10,ta)") self.scaleEngine.expression.set1Value(2, "oA=vec3f(tb,tb,tb)") self.scaleEngine.expression.set1Value(3, "oa=0.01*a/tb") self.calc2 = coin.SoCalculator() self.calc2.a.connectFrom(self.scaleEngine.oa) self.calc2.b.connectFrom(self.calc.oa) self.calc2.expression.set1Value(0, "ta=pow(a,0.3)") self.calc2.expression.set1Value(1, "oa=(b>ta)?b:ta") self.material1 = coin.SoMaterial() self.material2 = coin.SoMaterial() self.material3 = coin.SoMaterial() self.material4 = coin.SoMaterial() self.coord = coin.SoCoordinate3() self.coord2 = coin.SoCoordinate3() self.line1 = coin.SoIndexedLineSet() self.line2 = coin.SoIndexedLineSet() self.lineSet = coin.SoIndexedLineSet() self.lineSet2 = coin.SoIndexedLineSet() self.miniscale = coin.SoScale() self.miniscale.scaleFactor = coin.SbVec3f(0.1, 0.1, 0.1) self.mainscale = coin.SoScale() self.mainscale.scaleFactor.connectFrom(self.scaleEngine.oA) self.addChild(self.mainscale) self.addChild(self.coord) self.addChild(self.material1) self.addChild(self.line1) self.addChild(self.material2) self.addChild(self.line2) self.addChild(self.material3) self.addChild(self.lineSet) self.addChild(self.miniscale) self.addChild(self.material4) self.addChild(self.coord2) self.addChild(self.lineSet2) self._vector1 = coin.SbVec3f(1, 0, 0) self._vector2 = coin.SbVec3f(0, 1, 0) self.normal = self._vector1.cross(self._vector2) self._mainDim = 100 self._subDim = 10 self._maxviz = 1.0 self._factor = 1.0 self._numGridLines = 4 self.material1.diffuseColor = coin.SbColor(1, 0, 0) self.material2.diffuseColor = coin.SbColor(0, 1, 0) self.material3.diffuseColor = coin.SbColor(0.5, 0.5, 0.5) self.material4.diffuseColor = coin.SbColor(0.5, 0.5, 0.5) self.material3.transparency.connectFrom(self.calc.oa) self.material4.transparency.connectFrom(self.calc2.oa)