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 setMatrix(self, matrix): """Set the transformation matrix.""" m = coin.SbMatrix(matrix.A11, matrix.A12, matrix.A13, matrix.A14, matrix.A21, matrix.A22, matrix.A23, matrix.A24, matrix.A31, matrix.A32, matrix.A33, matrix.A34, matrix.A41, matrix.A42, matrix.A43, matrix.A44) self.trans.setMatrix(m)
def transform_points(self, points, node=None, refresh=True): """ Transform selected points by the transformation matrix """ #store the view state matrix if a valid node is passed. #subsequent calls with null node will re-use the last valid node matrix refresh = refresh and node is not None _matrix = self.get_matrix(node, refresh=refresh) if not _matrix: return [] #list of coin vectors requires conversion to tuples if isinstance(points[0], coin.SbVec3f): points = [_v.getValue() for _v in points] else: try: points = [SmartTuple(_v)._multiply for _v in points] except: print(""" ViewState().transform_points(): Unable to convert points to tuple """) return #append fourth point to each coordinate _pts = [_v + (1.0, ) for _v in points] _s = 0 _result = [] #iterate the list, processing it in sets of four coordinates at a time while _s < len(_pts): _mat_pts = _pts[_s:_s + 4] _last_point = len(_mat_pts) #pad the list if less than four points for _i in range(len(_mat_pts), 4): _mat_pts.append((0.0, 0.0, 0.0, 1.0)) #convert and transform _mat = coin.SbMatrix(_mat_pts) for _v in _mat.multRight(_matrix).getValue()[:_last_point]: _result.append(tuple(_v)) _s += 4 return _result
def transform_points(self, points, node=None, refresh=True): """ Transform selected points by the transformation matrix """ #store the view state matrix if a valid node is passed. #subsequent calls with null node will re-use the last valid node matrix refresh = refresh and node is not None _matrix = self.get_matrix(node, refresh=refresh) if not _matrix: return [] #append fourth point to each coordinate _pts = [_v + (1.0, ) for _v in points] _s = 0 _result = [] #iterate the list, processing it in sets of four coordinates at a time while _s < len(_pts): _mat_pts = _pts[_s:_s + 4] _last_point = len(_mat_pts) #pad the list if less than four points for _i in range(len(_mat_pts), 4): _mat_pts.append((0.0, 0.0, 0.0, 1.0)) #convert and transform _mat = coin.SbMatrix(_mat_pts) for _v in _mat.multRight(_matrix).getValue()[:_last_point]: _result.append(tuple(_v)[0:3]) _s += 4 return _result
def setMatrix(self,matrix): m = coin.SbMatrix(matrix.A11,matrix.A12,matrix.A13,matrix.A14, matrix.A21,matrix.A22,matrix.A23,matrix.A24, matrix.A31,matrix.A32,matrix.A33,matrix.A34, matrix.A41,matrix.A42,matrix.A43,matrix.A44) self.trans.setMatrix(m)