25 voxelfile =
"test_Edges.bvox" 27 infile = open(voxelfile,
"r") 35 for ob
in scene.objects:
36 if ob.name !=
"Camera":
37 scene.objects.unlink(ob)
41 tempMat = bpy.data.materials.new(passedName)
43 tempMat.diffuse_color = passedcolor
44 tempMat.diffuse_shader =
'LAMBERT' 45 tempMat.diffuse_intensity = 1.0
46 tempMat.specular_color = (0.9,0.9,0.9)
47 tempMat.specular_shader =
'COOKTORR' 48 tempMat.specular_intensity = 0.5
49 tempMat.use_transparency=
False 53 tempMat.keyframe_insert(data_path=
"diffuse_color", frame=1, index=-1)
57 def def_scene(box_length, res_stand, xres, yres, zres):
63 scene = bpy.context.scene
69 bpy.ops.object.add(type=
"EMPTY",
74 bpy.ops.object.select_pattern(pattern=
"Camera")
75 bpy.context.scene.objects.active = bpy.context.scene.objects[
"Camera"]
76 ob = bpy.data.objects[
"Camera"]
77 bpy.ops.object.constraint_add(type =
"TRACK_TO")
78 target = bpy.data.objects.get(
"Empty",
False)
79 ob.constraints[
"Track To"].target=target
81 ob.constraints[
"Track To"].track_axis =
"TRACK_NEGATIVE_Z" 82 ob.constraints[
"Track To"].up_axis =
"UP_Y" 84 scene.camera.location.x = box_length * x_cam * xres / res_stand
85 scene.camera.location.y = box_length * y_cam * yres / res_stand
86 scene.camera.location.z = box_length * z_cam * zres / res_stand
89 scene.camera.data.angle = 50*(np.pi/180.0)
90 bpy.data.cameras[
"Camera"].ortho_scale = 21.0
93 scene.render.threads_mode =
"FIXED" 94 scene.render.threads = 8
97 bpy.data.worlds[
"World"].horizon_color = (1,1,1)
102 def create_cube(box_length, res_stand, xres, yres, zres, step_size,
103 dens_scale, voxelfile):
104 cube = bpy.ops.mesh.primitive_cube_add(
106 radius = box_length * 0.5)
108 bpy.ops.object.mode_set(mode=
"EDIT")
109 bpy.ops.object.mode_set(mode=
"OBJECT")
110 ob = bpy.context.object
111 ob.scale = ((xres/res_stand, yres/res_stand, zres/res_stand))
115 mat =
create_volume(
"MaterialVolume", xres, yres, zres, step_size,
116 dens_scale, voxelfile)
117 me.materials.append(mat)
122 def create_volume(passedName, xres, yres, zres, step_size, dens_scale,
124 volMat = bpy.data.materials.new(passedName)
125 volMat.type =
"VOLUME" 126 volMat.volume.density = 0.0
127 volMat.volume.step_method =
"CONSTANT" 128 volMat.volume.step_size = step_size
129 volMat.volume.depth_threshold = 0.01
130 volMat.volume.density_scale = dens_scale
131 matTex = volMat.texture_slots.add()
132 voxTex = bpy.data.textures.new(
"VoxelData", type =
"VOXEL_DATA")
133 voxTex.voxel_data.file_format =
"BLENDER_VOXEL" 134 voxTex.use_color_ramp =
True 135 voxTex.color_ramp.color_mode =
"RGB" 136 ramp = voxTex.color_ramp
138 values = [(0.0,(0,0,1,0)), (0.5,(0,0,1,0.3)), (0.75,(1,0,1,0.5)), (1.0, (1,0,0,1))]
140 for n,value
in enumerate(values):
143 ramp.elements.new(pos)
144 elt = ramp.elements[n]
147 voxTex.voxel_data.filepath = voxelfile
148 voxTex.voxel_data.resolution = (xres, yres, zres)
149 matTex.texture = voxTex
150 matTex.use_map_to_bounds =
True 151 matTex.texture_coords =
'ORCO' 152 matTex.use_map_color_diffuse =
True 153 matTex.use_map_emission =
True 154 matTex.emission_factor = 1
155 matTex.emission_color_factor = 1
156 matTex.use_map_density =
True 157 matTex.density_factor = 1
161 cageMat = bpy.data.materials.new(passedName)
162 cageMat.use_shadeless =
True 167 bpy.data.scenes[
'Scene'].render.filepath = filename
168 bpy.ops.render.render( write_still=
True )
172 temp_fiber = bpy.ops.mesh.primitive_cylinder_add(radius = 0.1,
175 ob = bpy.context.active_object
181 me.materials.append(mat)
190 xDim = yDim = zDim = 256
192 create_cube(5, xDim, xDim, yDim, zDim, 0.01, 15, voxelfile)
def create_volume(passedName, xres, yres, zres, step_size, dens_scale, voxelfile)
def createCage(passedName)
def create_new_material(passedName, passedcolor)
def create_cube(box_length, res_stand, xres, yres, zres, step_size, dens_scale, voxelfile)
def def_scene(box_length, res_stand, xres, yres, zres)