Python bmesh.new() Examples
The following are 30
code examples of bmesh.new().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bmesh
, or try the search function
.
Example #1
Source File: misc_RENDER_PT_bake.py From Blender-CM3D2-Converter with Apache License 2.0 | 6 votes |
def execute(self, context): ob = context.active_object me = ob.data ob.hide_render = False image_width, image_height = int(self.image_width), int(self.image_height) if self.image_name in context.blend_data.images: img = context.blend_data.images[self.image_name] else: img = context.blend_data.images.new(self.image_name, image_width, image_height, alpha=True) area = common.get_request_area(context, 'IMAGE_EDITOR') common.set_area_space_attr(area, 'image', img) img.generated_color = self.image_color for elem in me.uv_textures.active.data: elem.image = img return {'FINISHED'}
Example #2
Source File: W_Capsule.py From Wonder_Mesh with GNU General Public License v3.0 | 6 votes |
def update_WCapsule_GEO(Wdata): v, e, f = primitive_Capsule_ME(**Wdata["animArgs"]) tmpMesh = bpy.data.meshes.new("TemporaryMesh") tmpMesh.from_pydata(v, e, f) tmpMesh.update() bm = bmesh.new() bm.from_mesh(tmpMesh) for fa in bm.faces: fa.smooth = Wdata.smoothed bm.to_mesh(Wdata.id_data) bm.free() bpy.data.meshes.remove(tmpMesh) Wdata.id_data.update() # getters
Example #3
Source File: DynamicTensionMap.py From Modeling-Cloth with MIT License | 6 votes |
def get_bmesh(ob=None): '''Returns a bmesh. Works either in edit or object mode. ob can be either an object or a mesh.''' obm = bmesh.new() if ob is None: mesh = bpy.context.object.data if 'data' in dir(ob): mesh = ob.data if ob.mode == 'OBJECT': obm.from_mesh(mesh) elif ob.mode == 'EDIT': obm = bmesh.from_edit_mesh(mesh) else: mesh = ob obm.from_mesh(mesh) return obm
Example #4
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def execute(self, context): ob = bpy.context.object bpy.ops.object.mode_set(mode='OBJECT') sel = [i.index for i in ob.data.vertices if i.select] name = ob.name matrix = ob.matrix_world.copy() for v in sel: e = bpy.data.objects.new('modeling_cloth_pin', None) bpy.context.scene.objects.link(e) if ob.active_shape_key is None: closest = matrix * ob.data.vertices[v].co# * matrix else: closest = matrix * ob.active_shape_key.data[v].co# * matrix e.location = closest #* matrix e.show_x_ray = True e.select = True e.empty_draw_size = .1 data[name].pin_list.append(v) data[name].hook_list.append(e) ob.select = False bpy.ops.object.mode_set(mode='EDIT') return {'FINISHED'}
Example #5
Source File: DynamicTensionMap.py From Modeling-Cloth with MIT License | 6 votes |
def material_setup(ob=None): '''Creates a node material for displaying the vertex colors''' if ob is None: ob = bpy.context.object mats = bpy.data.materials tens = mats.new('TensionMap') data[ob.name]['material'] = tens tens.use_nodes = True tens.specular_intensity = 0.1 tens.specular_hardness = 17 tens.use_transparency = True tens.node_tree.nodes.new(type="ShaderNodeGeometry") tens.node_tree.links.new(tens.node_tree.nodes['Geometry'].outputs['Vertex Color'], tens.node_tree.nodes['Material'].inputs[0]) if 'Tension' not in ob.data.vertex_colors: ob.data.vertex_colors.new('Tension') ob.data.materials.append(tens) tens.node_tree.nodes['Geometry'].color_layer = 'Tension' tens.node_tree.nodes['Material'].material = tens
Example #6
Source File: utils.py From leadwerks-blender-exporter with GNU General Public License v3.0 | 6 votes |
def triangulate_mesh(meshable_obj): is_editmode = (meshable_obj.mode == 'EDIT') if is_editmode: bpy.ops.object.editmode_toggle() bm = bmesh.new() mesh = meshable_obj.to_mesh(bpy.context.scene, True, 'PREVIEW') bm.from_mesh(mesh) #bm.from_object(meshable_obj, bpy.context.scene, deform=True, render=False) bmesh.ops.triangulate(bm, faces=bm.faces) bm.to_mesh(mesh) bm.free() mesh.update(calc_tessface=True, calc_edges=True) if is_editmode: bpy.ops.object.editmode_toggle() return mesh
Example #7
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def generate_guide_mesh(): """Makes the arrow that appears when creating pins""" verts = [[0.0, 0.0, 0.0], [-0.01, -0.01, 0.1], [-0.01, 0.01, 0.1], [0.01, -0.01, 0.1], [0.01, 0.01, 0.1], [-0.03, -0.03, 0.1], [-0.03, 0.03, 0.1], [0.03, 0.03, 0.1], [0.03, -0.03, 0.1], [-0.01, -0.01, 0.2], [-0.01, 0.01, 0.2], [0.01, -0.01, 0.2], [0.01, 0.01, 0.2]] edges = [[0, 5], [5, 6], [6, 7], [7, 8], [8, 5], [1, 2], [2, 4], [4, 3], [3, 1], [5, 1], [2, 6], [4, 7], [3, 8], [9, 10], [10, 12], [12, 11], [11, 9], [3, 11], [9, 1], [2, 10], [12, 4], [6, 0], [7, 0], [8, 0]] faces = [[0, 5, 6], [0, 6, 7], [0, 7, 8], [0, 8, 5], [1, 3, 11, 9], [1, 2, 6, 5], [2, 4, 7, 6], [4, 3, 8, 7], [3, 1, 5, 8], [12, 10, 9, 11], [4, 2, 10, 12], [3, 4, 12, 11], [2, 1, 9, 10]] name = 'ModelingClothPinGuide' if 'ModelingClothPinGuide' in bpy.data.objects: mesh_ob = bpy.data.objects['ModelingClothPinGuide'] else: mesh = bpy.data.meshes.new('ModelingClothPinGuide') mesh.from_pydata(verts, edges, faces) mesh.update() mesh_ob = bpy.data.objects.new(name, mesh) bpy.context.scene.objects.link(mesh_ob) mesh_ob.show_x_ray = True return mesh_ob
Example #8
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def create_giude(): """Spawns the guide""" if 'ModelingClothPinGuide' in bpy.data.objects: mesh_ob = bpy.data.objects['ModelingClothPinGuide'] return mesh_ob mesh_ob = generate_guide_mesh() bpy.context.scene.objects.active = mesh_ob bpy.ops.object.material_slot_add() if 'ModelingClothPinGuide' in bpy.data.materials: mat = bpy.data.materials['ModelingClothPinGuide'] else: mat = bpy.data.materials.new(name='ModelingClothPinGuide') mat.use_transparency = True mat.alpha = 0.35 mat.emit = 2 mat.game_settings.alpha_blend = 'ALPHA_ANTIALIASING' mat.diffuse_color = (1, 1, 0) mesh_ob.material_slots[0].material = mat return mesh_ob
Example #9
Source File: gen_objs.py From procedural_objects with MIT License | 6 votes |
def union(o1, o2): # create boolean modifier against o1 that unions o2 bool_modifier = o1.modifiers.new(type='BOOLEAN', name='o2_union') bool_modifier.object = o2 bool_modifier.operation = 'UNION' # create mesh from o1 + modifier mesh = o1.to_mesh(bpy.context.scene, True, 'PREVIEW') # replace o1 mesh with this explicit flattened mesh bm = bmesh.new() bm.from_mesh(mesh) bm.to_mesh(o1.data) bm.free() # drop modifier o1.modifiers.remove(bool_modifier) # update center of mass recalc_com(o1) # remove o2 bpy.context.scene.objects.unlink(o2)
Example #10
Source File: 3dm_snow.py From Blender-Add-ons-3DM-Snow with GNU General Public License v3.0 | 6 votes |
def bmesh_copy_from_object(obj, transform=True, triangulate=True, apply_modifiers=False): assert(obj.type == 'MESH') if apply_modifiers and obj.modifiers: import bpy me = obj.to_mesh(bpy.context.scene, True, 'PREVIEW', calc_tessface=False) bm = bmesh.new(); bm.from_mesh(me); bpy.data.meshes.remove(me) del bpy else: me = obj.data if obj.mode == 'EDIT': bm_orig = bmesh.from_edit_mesh(me); bm = bm_orig.copy() else: bm = bmesh.new(); bm.from_mesh(me) if transform: bm.transform(obj.matrix_world) if triangulate: bmesh.ops.triangulate(bm, faces=bm.faces) return bm
Example #11
Source File: W_Cone.py From Wonder_Mesh with GNU General Public License v3.0 | 6 votes |
def update_WCone_GEO(Wdata): v, e, f = primitive_Cone_ME(**Wdata["animArgs"]) tmpMesh = bpy.data.meshes.new("TemporaryMesh") tmpMesh.from_pydata(v, e, f) tmpMesh.update() bm = bmesh.new() bm.from_mesh(tmpMesh) for fa in bm.faces: fa.smooth = Wdata.smoothed bm.to_mesh(Wdata.id_data) bm.free() bpy.data.meshes.remove(tmpMesh) Wdata.id_data.update() # getters
Example #12
Source File: W_Torus.py From Wonder_Mesh with GNU General Public License v3.0 | 6 votes |
def update_WTorus_GEO(Wdata): v, e, f = primitive_Torus_ME(**Wdata["animArgs"]) tmpMesh = bpy.data.meshes.new("TemporaryMesh") tmpMesh.from_pydata(v, e, f) tmpMesh.update() bm = bmesh.new() bm.from_mesh(tmpMesh) for fa in bm.faces: fa.smooth = Wdata.smoothed bm.to_mesh(Wdata.id_data) bm.free() bpy.data.meshes.remove(tmpMesh) Wdata.id_data.update() # getters
Example #13
Source File: blmol.py From blmol with MIT License | 6 votes |
def _create_new_material(name, color): """Create a new material. Args: name (str): Name for the new material (e.g., 'red') color (tuple): RGB color for the new material (diffuse_color) (e.g., (1, 0, 0, 1)) Returns: The new material. """ mat = bpy.data.materials.new(name) mat.diffuse_color = color mat.roughness = 0.5 mat.specular_color = (1, 1, 1) mat.specular_intensity = 0.2 return mat
Example #14
Source File: W_Tube.py From Wonder_Mesh with GNU General Public License v3.0 | 6 votes |
def UpdateWTube(WData): verts, edges, faces = primitive_Tube(**WData["animArgs"]) tmpMesh = bpy.data.meshes.new("TemporaryMesh") tmpMesh.from_pydata(verts, edges, faces) tmpMesh.update() bm = bmesh.new() bm.from_mesh(tmpMesh) for f in bm.faces: f.smooth = WData.smoothed bm.to_mesh(WData.id_data) bm.free() bpy.data.meshes.remove(tmpMesh) WData.id_data.update() # getters
Example #15
Source File: ModelingCloth28.py From Modeling-Cloth-2_8 with MIT License | 6 votes |
def execute(self, context): ob = bpy.context.active_object bpy.ops.object.mode_set(mode='OBJECT') sel = [i.index for i in ob.data.vertices if i.select] name = ob.name matrix = ob.matrix_world.copy() for v in sel: e = bpy.data.objects.new('modeling_cloth_pin', None) bpy.context.collection.objects.link(e) if ob.active_shape_key is None: closest = matrix @ ob.data.vertices[v].co# * matrix else: closest = matrix * ob.active_shape_key.data[v].co# * matrix e.location = closest #* matrix #e.show_x_ray = True e.select_set(True) #e.empty_draw_size = .1 data[name].pin_list.append(v) data[name].hook_list.append(e) ob.select_set(False) bpy.ops.object.mode_set(mode='EDIT') return {'FINISHED'}
Example #16
Source File: writinganim_2_8.py From writinganimation with GNU General Public License v3.0 | 6 votes |
def createNoncyclicSpline(curveData, srcSpline, forceNoncyclic): spline = curveData.splines.new('BEZIER') spline.bezier_points.add(len(srcSpline.bezier_points)-1) if(forceNoncyclic): spline.use_cyclic_u = False else: spline.use_cyclic_u = srcSpline.use_cyclic_u for i in range(0, len(srcSpline.bezier_points)): DrawableCurve.copyBezierPt(srcSpline.bezier_points[i], spline.bezier_points[i]) if(forceNoncyclic == True and srcSpline.use_cyclic_u == True): spline.bezier_points.add(1) DrawableCurve.copyBezierPt(srcSpline.bezier_points[0], spline.bezier_points[-1]) #static method
Example #17
Source File: writinganim_2_8.py From writinganimation with GNU General Public License v3.0 | 6 votes |
def addCustomWriterKFs(customWriter, empty, startFrame, endFrame, resetLocation): if(resetLocation == True): insertKF(obj = customWriter, dataPath = 'location', frame = (startFrame - 1)) customWriter.location = (0,0,0) insertKF(obj = customWriter, dataPath = 'location', frame = startFrame) insertKF(obj = customWriter, dataPath = 'location', frame = endFrame) const = customWriter.constraints.new(type='CHILD_OF') const.target = empty const.name = NEW_DATA_PREFIX + 'Constraint' const.influence = 0 insertKF(obj = const, dataPath = 'influence', frame = (startFrame - 1)) const.influence = 1 insertKF(obj = const, dataPath = 'influence', frame = startFrame) insertKF(obj = const, dataPath = 'influence', frame = endFrame) const.influence = 0 insertKF(obj = const, dataPath = 'influence', frame = (endFrame + 1))
Example #18
Source File: writinganim_2_8.py From writinganimation with GNU General Public License v3.0 | 6 votes |
def getCurveDCObjs(selObjs, objType, defaultDepth, retain, copyPropObj, \ flatMat, bevelObj, group = None): curveDCObjs = [] idx = 0 #Only for naming the new objects for obj in selObjs: dcObjs = DrawableCurve.getDCObjsForSpline(obj, objType, defaultDepth, idx, group, copyPropObj, flatMat, bevelObj) if(len(dcObjs) == 0 ): continue idx += len(dcObjs) if(retain == 'Copy'): obj.hide_viewport = True obj.hide_render = True curveDCObjs.append(dcObjs) return curveDCObjs
Example #19
Source File: ModelingCloth28.py From Modeling-Cloth-2_8 with MIT License | 6 votes |
def create_giude(): """Spawns the guide""" if 'ModelingClothPinGuide' in bpy.data.objects: mesh_ob = bpy.data.objects['ModelingClothPinGuide'] return mesh_ob mesh_ob = generate_guide_mesh() bpy.context.view_layer.objects.active = mesh_ob bpy.ops.object.material_slot_add() if 'ModelingClothPinGuide' in bpy.data.materials: mat = bpy.data.materials['ModelingClothPinGuide'] else: mat = bpy.data.materials.new(name='ModelingClothPinGuide') #mat.use_transparency = True #mat.alpha = 0.35 #mat.emit = 2 #mat.game_settings.alpha_blend = 'ALPHA_ANTIALIASING' #mat.diffuse_color = (1, 1, 0) #mesh_ob.material_slots[0].material = mat return mesh_ob
Example #20
Source File: writinganim.py From writinganimation with GNU General Public License v3.0 | 6 votes |
def createNoncyclicSpline(curveData, srcSpline, forceNoncyclic): spline = curveData.splines.new('BEZIER') spline.bezier_points.add(len(srcSpline.bezier_points)-1) if(forceNoncyclic): spline.use_cyclic_u = False else: spline.use_cyclic_u = srcSpline.use_cyclic_u for i in range(0, len(srcSpline.bezier_points)): DrawableCurve.copyBezierPt(srcSpline.bezier_points[i], spline.bezier_points[i]) if(forceNoncyclic == True and srcSpline.use_cyclic_u == True): spline.bezier_points.add(1) DrawableCurve.copyBezierPt(srcSpline.bezier_points[0], spline.bezier_points[-1]) #static method
Example #21
Source File: ModelingCloth28.py From Modeling-Cloth-2_8 with MIT License | 6 votes |
def generate_guide_mesh(): """Makes the arrow that appears when creating pins""" verts = [[0.0, 0.0, 0.0], [-0.01, -0.01, 0.1], [-0.01, 0.01, 0.1], [0.01, -0.01, 0.1], [0.01, 0.01, 0.1], [-0.03, -0.03, 0.1], [-0.03, 0.03, 0.1], [0.03, 0.03, 0.1], [0.03, -0.03, 0.1], [-0.01, -0.01, 0.2], [-0.01, 0.01, 0.2], [0.01, -0.01, 0.2], [0.01, 0.01, 0.2]] edges = [[0, 5], [5, 6], [6, 7], [7, 8], [8, 5], [1, 2], [2, 4], [4, 3], [3, 1], [5, 1], [2, 6], [4, 7], [3, 8], [9, 10], [10, 12], [12, 11], [11, 9], [3, 11], [9, 1], [2, 10], [12, 4], [6, 0], [7, 0], [8, 0]] faces = [[0, 5, 6], [0, 6, 7], [0, 7, 8], [0, 8, 5], [1, 3, 11, 9], [1, 2, 6, 5], [2, 4, 7, 6], [4, 3, 8, 7], [3, 1, 5, 8], [12, 10, 9, 11], [4, 2, 10, 12], [3, 4, 12, 11], [2, 1, 9, 10]] name = 'ModelingClothPinGuide' if 'ModelingClothPinGuide' in bpy.data.objects: mesh_ob = bpy.data.objects['ModelingClothPinGuide'] else: mesh = bpy.data.meshes.new('ModelingClothPinGuide') mesh.from_pydata(verts, edges, faces) mesh.update() mesh_ob = bpy.data.objects.new(name, mesh) bpy.context.collection.objects.link(mesh_ob) #mesh_ob.show_x_ray = True return mesh_ob
Example #22
Source File: writinganim.py From writinganimation with GNU General Public License v3.0 | 6 votes |
def addCustomWriterKFs(customWriter, empty, startFrame, endFrame, resetLocation): if(resetLocation == True): insertKF(obj = customWriter, dataPath = 'location', frame = (startFrame - 1)) customWriter.location = (0,0,0) insertKF(obj = customWriter, dataPath = 'location', frame = startFrame) insertKF(obj = customWriter, dataPath = 'location', frame = endFrame) const = customWriter.constraints.new(type='CHILD_OF') const.target = empty const.name = NEW_DATA_PREFIX + 'Constraint' const.influence = 0 insertKF(obj = const, dataPath = 'influence', frame = (startFrame - 1)) const.influence = 1 insertKF(obj = const, dataPath = 'influence', frame = startFrame) insertKF(obj = const, dataPath = 'influence', frame = endFrame) const.influence = 0 insertKF(obj = const, dataPath = 'influence', frame = (endFrame + 1))
Example #23
Source File: writinganim.py From writinganimation with GNU General Public License v3.0 | 6 votes |
def getCurveDCObjs(selObjs, objType, defaultDepth, retain, copyPropObj, group = None): curveDCObjs = [] idx = 0 #Only for naming the new objects for obj in selObjs: dcObjs = DrawableCurve.getDCObjsForSpline(obj, objType, defaultDepth, idx, group, copyPropObj) if(len(dcObjs) == 0 ): continue idx += len(dcObjs) if(retain == 'Copy'): obj.hide = True obj.hide_render = True curveDCObjs.append(dcObjs) return curveDCObjs
Example #24
Source File: dff_importer.py From DragonFF with GNU General Public License v3.0 | 6 votes |
def set_vertex_groups(obj, skin_data): # Allocate vertex groups for i in range(skin_data.num_bones): obj.vertex_groups.new() # vertex_bone_indices stores what 4 bones influence this vertex for i in range(len(skin_data.vertex_bone_indices)): for j in range(len(skin_data.vertex_bone_indices[i])): bone = skin_data.vertex_bone_indices[i][j] weight = skin_data.vertex_bone_weights[i][j] obj.vertex_groups[bone].add([i], weight, 'ADD') #######################################################
Example #25
Source File: dff_importer.py From DragonFF with GNU General Public License v3.0 | 6 votes |
def remove_object_doubles(): self = dff_importer for frame in self.meshes: bm = bmesh.new() bm.from_mesh(self.meshes[frame]) # Mark edges with 1 linked face, sharp for edge in bm.edges: if len(edge.link_loops) == 1: edge.smooth = False bmesh.ops.remove_doubles(bm, verts = bm.verts, dist = 0.00001) # Add an edge split modifier object = self.objects[frame] modifier = object.modifiers.new("EdgeSplit", 'EDGE_SPLIT') modifier.use_edge_angle = False bm.to_mesh(self.meshes[frame]) #######################################################
Example #26
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def triangulate(me, ob=None): """Requires a mesh. Returns an index array for viewing co as triangles""" obm = bmesh.new() obm.from_mesh(me) bmesh.ops.triangulate(obm, faces=obm.faces) #obm.to_mesh(me) count = len(obm.faces) #tri_idx = np.zeros(count * 3, dtype=np.int32) #me.polygons.foreach_get('vertices', tri_idx) tri_idx = np.array([[v.index for v in f.verts] for f in obm.faces]) # Identify bend spring groups. Each edge gets paired with two points on tips of tris around edge # Restricted to edges with two linked faces on a triangulated version of the mesh if ob is not None: link_ed = [e for e in obm.edges if len(e.link_faces) == 2] ob.bend_eidx = np.array([[e.verts[0].index, e.verts[1].index] for e in link_ed]) fv = np.array([[[v.index for v in f.verts] for f in e.link_faces] for e in link_ed]) fv.shape = (fv.shape[0],6) ob.bend_tips = np.array([[idx for idx in fvidx if idx not in e] for e, fvidx in zip(ob.bend_eidx, fv)]) obm.free() return tri_idx#.reshape(count, 3)
Example #27
Source File: col_importer.py From DragonFF with GNU General Public License v3.0 | 6 votes |
def __add_spheres(self, collection, array): for index, entity in enumerate(array): name = collection.name + ".Sphere.%d" % (index) obj = bpy.data.objects.new(name, None) obj.location = entity.center obj.scale = [entity.radius] * 3 if (2, 80, 0) > bpy.app.version: obj.empty_draw_type = 'SPHERE' else: obj.empty_display_type = 'SPHERE' obj.dff.type = 'COL' obj.dff.col_material = entity.surface.material obj.dff.col_flags = entity.surface.flags obj.dff.col_brightness = entity.surface.brightness obj.dff.col_light = entity.surface.light link_object(obj, collection) #######################################################
Example #28
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def create_vertex_groups(groups=['common', 'not_used'], weights=[0.0, 0.0], ob=None): '''Creates vertex groups and sets weights. "groups" is a list of strings for the names of the groups. "weights" is a list of weights corresponding to the strings. Each vertex is assigned a weight for each vertex group to avoid calling vertex weights that are not assigned. If the groups are already present, the previous weights will be preserved. To reset weights delete the created groups''' if ob is None: ob = bpy.context.object vg = ob.vertex_groups for g in range(0, len(groups)): if groups[g] not in vg.keys(): # Don't create groups if there are already there vg.new(groups[g]) vg[groups[g]].add(range(0,len(ob.data.vertices)), weights[g], 'REPLACE') else: vg[groups[g]].add(range(0,len(ob.data.vertices)), 0, 'ADD') # This way we avoid resetting the weights for existing groups.
Example #29
Source File: dff_importer.py From DragonFF with GNU General Public License v3.0 | 5 votes |
def preprocess_atomics(): self = dff_importer atomic_frames = [] to_be_preprocessed = [] #these will be assigned a new frame for index, atomic in enumerate(self.dff.atomic_list): frame = self.dff.frame_list[atomic.frame] # For GTA SA bones, which have the frame of the pedestrian # (incorrectly?) set in the atomic to a bone if frame.bone_data is not None and frame.bone_data.header.id != -1: to_be_preprocessed.append(index) atomic_frames.append(atomic.frame) # Assign every atomic in the list a new (possibly valid) frame for atomic in to_be_preprocessed: for index, frame in enumerate(self.dff.frame_list): # Find an empty frame if (frame.bone_data is None or frame.bone_data.header.id == -1) \ and index not in atomic_frames: _atomic = list(self.dff.atomic_list[atomic]) _atomic[0] = index # _atomic.frame = index self.dff.atomic_list[atomic] = dff.Atomic(*_atomic) break #######################################################
Example #30
Source File: VTKBlender.py From VTKBlender with Apache License 2.0 | 5 votes |
def process_polygon(self, cell, pdata, scalars): # Add a vert at the center of the polygon, # and break into triangles x = 0.0 y = 0.0 z = 0.0 scal = 0.0 N = cell.GetNumberOfPoints() for j in range(N): point = pdata.GetPoint(cell.GetPointId(j)) x = x + point[0] y = y + point[1] z = z + point[2] if (scalars != None): scal = scal + scalars.GetTuple1(j) x = x / N y = y / N z = z / N scal = scal / N newidx = len(self.verts) self.add_vert(x, y, z) if (scalars != None): scolor = [0,0,0] plut.GetColor(scal, scolor) color = map(vtk_to_blender_color, scolor) alpha = int(plut.GetOpacity(scalars.GetTuple1(i))*255) colors.append([color[0], color[1], color[2], alpha]) # Add triangles connecting polynomial sides to new vert for j in range(N): n1 = cell.GetPointId(j) n2 = cell.GetPointId( (j+1) % N ) n3 = newidx self.add_face(n1, n2, n3)