def get_matrix(self, node, parent=None, refresh=True): """ Return the matrix for transfomations applied to the passed node node - the Coin3D SoNode with the desired transformation parent - optional - sg root default refresh - if false, retrieves last matrix """ if not parent: parent = self.sg_root if not refresh: if self._matrix: return self._matrix #define the search path _search = coin.SoSearchAction() _search.setNode(node) _search.apply(parent) #get the matrix for the transformation _matrix = coin.SoGetMatrixAction(ViewState().viewport) _matrix.apply(_search.getPath()) self._matrix = coin.SbMatrix(_matrix.getMatrix().getValue()) return self._matrix
def get_transformed_coordinates(self): """ Return the transformed coordinates of the selected nodes based on the transformations applied by the drag tracker """ _coords = self.nodes['selected'].getChild(1) #define the search path if not defined if not self.start_path: _search = coin.SoSearchAction() _search.setNode(_coords) _search.apply(self.nodes['selected']) self.start_path = _search.getPath() #get the matrix for the transformation _matrix = coin.SoGetMatrixAction(self.viewport) _matrix.apply(self.start_path) _xf = _matrix.getMatrix() #create the 4D vectors for the transformation _vecs = [ coin.SbVec4f(_v.getValue() + (1.0,)) \ for _v in _coords.point.getValues() ] #multiply each coordinate by the transformation matrix and return #a list of the transformed coordinates, omitting the fourth value return [_xf.multVecMatrix(_v).getValue()[:3] for _v in _vecs]
def getMatrix(self): r = FreeCADGui.ActiveDocument.ActiveView.getViewer().getSoRenderManager().getViewportRegion() v = coin.SoGetMatrixAction(r) m = self.trans.getMatrix(v) if m: m = m.getValue() return FreeCAD.Matrix(m[0][0],m[0][1],m[0][2],m[0][3], m[1][0],m[1][1],m[1][2],m[1][3], m[2][0],m[2][1],m[2][2],m[2][3], m[3][0],m[3][1],m[3][2],m[3][3]) else: return FreeCAD.Matrix()
def updateTransformedNormal(self): # // First get hold of an SoPath through the scenegraph down to the # // node ("mynode") you want to query about its current world space # // transformation(s). # # SoSearchAction * searchaction = new SoSearchAction; # searchaction->setNode(mynode); # searchaction->apply(myscenegraphroot); # # SoPath * path = searchaction->getPath(); # assert(path != NULL); # # // Then apply the SoGetMatrixAction to get the full transformation # // matrix from world space. # # const SbViewportRegion vpr = myviewer->getViewportRegion(); # SoGetMatrixAction * getmatrixaction = new SoGetMatrixAction(vpr); # getmatrixaction->apply(path); # # SbMatrix transformation = getmatrixaction->getMatrix(); # # // And if you want to access the individual transformation # // components of the matrix: # # SbVec3f translation; # SbRotation rotation; # SbVec3f scalevector; # SbRotation scaleorientation; # # transformation.getTransform(translation, rotation, scalevector, scaleorientation); searchaction = coin.SoSearchAction() searchaction.setNode(self) searchaction.apply( FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()) path = searchaction.getPath() vpr = FreeCADGui.ActiveDocument.ActiveView.getViewer( ).getViewportRegion() getmatrixaction = coin.SoGetMatrixAction(vpr) getmatrixaction.apply(path) transformation = getmatrixaction.getMatrix() self.transformedNormal = transformation.multVecMatrix(self.normal) self.calc.expression.set1Value( 2, "tA=vec3f(%f,%f,%f)" % (self.transformedNormal.getValue()[0], self.transformedNormal.getValue()[1], self.transformedNormal.getValue()[2])) return ()