def __init__(self, parent, profile=None): QGLViewer.__init__(self, parent) self.__profile = None self.__position = 0 self.__positionCurve = None self.increment = 0.01 self._axisScaleTolerance = abs(pi / 8.) # (radians) #states self.__oldY = None self.__scalingDirection = None #ranges self.__param_min = 0.0 self.__param_max = 1.0 # --rendering components -- self.factor = [1., 1., 1.] #x, y, z scene scaling factors. self.discretizer = Discretizer() self.renderer = GLRenderer(self.discretizer) self.renderer.renderingMode = GLRenderer.Dynamic # -- addons -- self._addons = [] self.visualSections = VisualCrossSectionsAddOn(self) self.grids = GridAddOn(self) self.userSlices = UserSlicesAddOn(self)
def sc_to_blender (sc) : """Export each shape in the scene as a new object :Parameters: - `sc` (Scene) - the scene to transform :Returns Type: None """ bldsc = Scene.GetCurrent() #fill with shapes t = time.time() d = Discretizer() for ind,shp in enumerate(sc) : if ind % 10 == 0 : print(ind) sys.stdout.flush() ob = shp_to_blender(shp,d) bldsc.link(ob) ob.sel = True print() print('Time :', time.time() - t) #return print("created") bldsc.update(1) Blender.Redraw() return ob
def geometry_to_blender (geom, bld_mesh = None, discretizer = None) : """Create a blender mesh Paint the faces too if needed :Parameters: - `geom` (pgl.Geometry) - the geometry to transform - `bld_mesh` (Mesh) - a mesh in which to append the shape. If None, a blank new one will be created - `discretizer` (Discretizer) - algorithm to triangulate the geometry :Returns Type: Mesh """ #create bld_mesh if bld_mesh is None : if geom.isNamed() : name = geom.name else : name = "pglgeom%d" % geom.getId() bld_mesh = Mesh.New(name) #geometry (mesh) if discretizer is None: d = Discretizer() else: d = discretizer geom.apply(d) geom = d.result #fill mesh pts = array(geom.pointList) nbv = len(bld_mesh.verts) faces = nbv + array(geom.indexList) bld_mesh.verts.extend(pts) nbf = len(bld_mesh.faces) bld_mesh.faces.extend(faces.tolist() ) #set vertex colors if needed mat = None if not geom.isColorListToDefault() : bld_mesh.vertexColors = True #create material to render mesh colors try : mat = Material.Get("default_vtx_mat") except NameError : mat = Material.New("default_vtx_mat") mat.mode += Material.Modes['VCOL_PAINT'] bld_mesh.materials = [mat] #modify color list to duplicate colors per face per vertex if geom.colorPerVertex and geom.isColorIndexListToDefault() : #each vertex has a color for i,inds in enumerate(faces) : face = bld_mesh.faces[nbf + i] for j,v in enumerate(face) : col = face.col[j] pglcol = geom.colorList[geom.indexList[i][j] ] col.r = pglcol.red col.g = pglcol.green col.b = pglcol.blue col.a = pglcol.alpha elif geom.colorPerVertex and not geom.isColorIndexListToDefault() : #each local vertex of each face has a color for i,inds in enumerate(geom.colorIndexList) : face = bld_mesh.faces[nbf + i] for j,v in enumerate(face) : col = face.col[j] pglcol = geom.colorList[inds[j] ] col.r = pglcol.red col.g = pglcol.green col.b = pglcol.blue col.a = pglcol.alpha else : #each face has a color for i,col in enumerate(geom.colorList) : face = bld_mesh.faces[nbf + i] R,G,B,A = col.red,col.green,col.blue,col.alpha for j,v in enumerate(face) : col = face.col[j] col.r = R col.g = G col.b = B col.a = A # #assign # for fid in xrange(nb,len(bld_mesh.faces) ) : # face = bld_mesh.faces[fid] # for i,v in enumerate(face) : # col = face.col[i] # col.r = ambient.red # col.g = ambient.green # col.b = ambient.blue # for vtx in bld_mesh.verts : # vtx.sel = 0 #return return bld_mesh,mat