예제 #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]
예제 #2
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
예제 #3
0

# make a material
mat = bpy.data.materials.new(mat_name)
mat.type = 'VOLUME'
mat.volume.density = 0.0 # lower?
mat.volume.density_scale = 1.0 # upper in the slice plot
mat.volume.scattering = 0.5 # look far in
mat.volume.emission = 5.0 # super bright
mat.transparency_method = 'Z_TRANSPARENCY'
# this makes things pretty
mat.use_full_oversampling = True
mat.use_mist = True
mat.volume.step_method = 'CONSTANT' # for pretty too

setMaterial(bpy.data.objects['Cube'], mat)

# Create texture from image sequence
mtex = mat.texture_slots.add()
mat.active_texture_index = 0

# this should work but it doesnt right now...
tex = bpy.data.textures.new(tex_name, type = 'VOXEL_DATA')
mat.active_texture = tex

tex.use_color_ramp = True

tex.voxel_data.file_format = 'BLENDER_VOXEL'
#tex.voxel_data.file_format = 'SMOKE'
#tex.voxel_data.file_format = 'IMAGE_SEQUENCE'
예제 #4
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],
                 zcoord[cl[i]] * scale[0][2]))
        bmesh.update_edit_mesh(ob.data)
        bpy.ops.object.mode_set(mode='OBJECT')
예제 #5
0
def voxelcube(name='Cube000',
              left_edge=[0, 0, 0.],
              right_edge=[1, 1, 1],
              array=[0, 0, 0],
              res=(0, 0, 0)):
    # do this to start from clean slate
    from science import delete_object
    for ob in bpy.data.objects:
        if ob.name == 'Cube':
            delete_object('Cube')
    mat_name = name + 'Mat'
    tex_name = name + 'CubeTex'
    # first create but if it does exist
    flagg = True
    # do we have cube?
    for ob in bpy.data.objects:
        if ob.name == 'Cube':
            flagg = False
    if flagg:
        bpy.ops.mesh.primitive_cube_add(radius=1.0)
        bpy.data.objects['Cube'].name = name
    # put it in the center
    bpy.data.objects[name].location = ((right_edge[0] + left_edge[0]) * 0.5,
                                       (right_edge[1] + left_edge[1]) * 0.5,
                                       (right_edge[2] + left_edge[2]) * 0.5)
    bpy.data.objects[name].scale = ((right_edge[0] - left_edge[0]) * 0.5,
                                    (right_edge[1] - left_edge[1]) * 0.5,
                                    (right_edge[2] - left_edge[2]) * 0.5)
    # make a material
    mat = bpy.data.materials.new(mat_name)
    mat.type = 'VOLUME'
    mat.volume.density = 0.0  # lower?
    mat.volume.density_scale = 1.0  # upper in the slice plot
    mat.volume.scattering = 0.5
    mat.volume.emission = 5.0
    mat.transparency_method = 'Z_TRANSPARENCY'
    mat.use_full_oversampling = True
    mat.use_mist = True
    mat.volume.step_method = 'CONSTANT'
    setMaterial(bpy.data.objects[name], mat)
    # Create texture from image sequence
    mtex = mat.texture_slots.add()
    mat.active_texture_index = 0
    tex = bpy.data.textures.new(tex_name, type='VOXEL_DATA')
    mat.active_texture = tex
    tex.use_color_ramp = True
    tex.voxel_data.file_format = 'BLENDER_VOXEL'
    # now, lets try to re-norm the min and max of the transfer function
    tex.color_ramp.elements[0].color = (0, 0, 0, array.min())
    tex.color_ramp.elements[1].color = (1, 1, 1, array.max())
    print(tex.color_ramp.elements[0].color[:])
    mat.texture_slots[0].texture_coords = 'ORCO'  # generated coords
    mat.texture_slots[0].mapping = 'CUBE'  # map to a cube
    # NO idea
    ts = mat.texture_slots[0]
    ts.use_map_density = True
    ts.density_factor = 1.0
    ts.use_map_emission = True
    ts.emission_factor = 1.0
    ts.use_map_color_emission = True
    ts.emission_color_factor = 1.0
    for i in range(3):
        tex.voxel_data.resolution[i] = res[i]
    vdp = ctypes.cast(bpy.data.textures[tex_name].voxel_data.as_pointer(),
                      ctypes.POINTER(VoxelData))
    arr = (ctypes.c_float * array.size)()
    arr2 = np.ctypeslib.as_array(arr, array.shape)
    arr2[:] = array.flat[:]
    vdp.contents.dataset = ctypes.cast(arr, ctypes.POINTER(ctypes.c_float))
    vdp.contents.ok = 1
    vdp.contents.cachedframe = bpy.context.scene.frame_current
예제 #6
0
        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
mtex.emission_color_factor = 0.5