Beispiel #1
0
    newfaces[i] = (cc, cc+1, cc+2, cc+3) 
    cc = cc+4
    
me = bpy.data.meshes.new(meshname+"Mesh")
ob = bpy.data.objects.new(meshname,me)
ob.location = meshlocation   # position object at 3d-cursor
bpy.context.scene.objects.link(ob)                # Link object to scene
# Fill the mesh with verts, edges, faces 
me.from_pydata(vertices.tolist(),[],newfaces.tolist())
me.update(calc_edges=True)    # Update mesh with new data


# materials woop woop!
obj = bpy.data.objects[meshname]
bpy.context.scene.objects.active=obj
for i in range(0,len(colors)):
    mat = makeMaterial(meshname+str(i)+'_'+str(plot_index), 
                       (colors[i][0],colors[i][1],colors[i][2]), 
                       (1,1,1), 1.0, 0.0)
    setMaterial(obj,mat)

fnum = 0
for p in range(0,len(line_pts)-1):
    for i in range(0,nfaces):
        me.polygons[fnum].material_index = colorindex[p]
        fnum += 1
        
## now, do individual mat indecies
#for i in range(0,len(newfaces)):
#    me.polygons[i].material_index = colorindex[i]
Beispiel #2
0
 fname = fname_out + '_' + str(ind)
 me = bpy.data.meshes.new('particleMesh_' + fname)
 ob = bpy.data.objects.new('particle_' + fname, me)
 ob.location = (0, 0, 0)
 bpy.context.scene.objects.link(ob)  # Link object to scene
 coords = [(0, 0, 0)]
 me.from_pydata(coords, [], [])
 ob.location = (0, 0, 0)
 ob = bpy.data.objects['particle_' + fname]  # select right object
 science.deselect_all()
 ob.select = True
 bpy.context.scene.objects.active = ob
 mat = science.makeMaterial(
     'particle_' + str(ind),
     (colors[0][ind], colors[1][ind], colors[2][ind]), (1, 1, 1),
     1.0,
     1.0,
     mat_type='HALO',
     halo_size=halo_size)
 science.setMaterial(ob, mat)
 # add in verts
 bpy.ops.object.mode_set(mode='EDIT')  # toggle to edit mode
 bm = bmesh.from_edit_mesh(ob.data)
 # now, find all verts with this color index (ind)
 # move original vertex to actual location
 bm.verts[0].co = (xcoord[cl[0]] * scale[0][0],
                   ycoord[cl[0]] * scale[0][1],
                   zcoord[cl[0]] * scale[0][2])
 for i in range(1, len(xcoord[cl])):
     bm.verts.new(
         (xcoord[cl[i]] * scale[0][0], ycoord[cl[i]] * scale[0][1],
Beispiel #3
0
if not tubemesh.vertex_colors:
    tubemesh.vertex_colors.new()

color_layer = tubemesh.vertex_colors["Col"]


i=0
for poly in tubemesh.polygons:
    #rgb = [random.random() for ii in range(3)]
    xyz = tubemesh.vertices[0].co
    for idx in poly.loop_indices:
        color_layer.data[i].color = rgb
        i += 1

# set to vertex paint mode to see the result ... don't need to do this once we map vertex paint
#bpy.ops.object.mode_set(mode='VERTEX_PAINT')
# NOTE!!!! YOU WILL HAVE TO HAVE "render" OR "Material" view set!!!

# note, to render this, we have to do:
matName = tube.name + 'c'
color = (1,1,1)
mat = science.makeMaterial(matName, color, (1,1,1), 1.0, 1.0)
mat.use_vertex_color_paint = True
science.setMaterial(tube,mat) # sets everything to material 0 by default


# check out: http://blenderscripting.blogspot.com/2014/02/3d-tube-from-points.html
# for particles check out: http://yt-project.org/doc/analyzing/analysis_modules/particle_trajectories.html#particle-trajectories
# may or maynot be useful: http://blenderscripting.blogspot.com/2013/03/painting-vertex-color-map-using.html, http://blenderartists.org/forum/showthread.php?190693-Setting-Vertex-Color-via-Python, http://www.blender.org/api/blender_python_api_2_63_2/bpy.types.Mesh.html
for area in bpy.context.screen.areas:
    if area.type == 'IMAGE_EDITOR':
        if show_annotations:
            area.spaces.active.image = image2
        else:
            area.spaces.active.image = image
    elif area.type == 'VIEW_3D':  # make sure material/render view is on
        for space in area.spaces:
            if space.type == 'VIEW_3D':
                if (space.viewport_shade !=
                        'RENDERED') and (space.viewport_shade != 'MATERIAL'):
                    space.viewport_shade = 'RENDERED'  # material is too slow

# also, attach to the projection in the blender 3d window
# now, set color
figmat = makeMaterial(image_name, (0, 0, 0), (1, 1, 1), 1.0,
                      0.0)  # no emissivity or transperency for now
setMaterial(bpy.data.objects[image_name], figmat)
# also, make shadeless
bpy.data.materials[image_name].use_shadeless = True

# Create image texture from image
cTex = bpy.data.textures.new(image_name, type='IMAGE')
cTex.image = image
# Add texture slot for color texture
mat = bpy.data.materials[image_name]
mtex = mat.texture_slots.add()
mtex.texture = cTex
#mtex.texture_coords = 'UV'
mtex.texture_coords = 'OBJECT'  # this seems to work better for figures, but certainly needs to be tested
mtex.use_map_color_diffuse = True
mtex.use_map_color_emission = True