Created
January 9, 2017 11:04
-
-
Save lesolorzanov/53d9d5d90995ff06c900797cff6c5bc7 to your computer and use it in GitHub Desktop.
Cubes from voxels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import numpy | |
im=Image.open('C:/Users/Administrator/Documents/Leslie/Uppsala/registered161101/crops/b1-2-0001-1757-1887-White Top Hat.tif') | |
def makeMaterial(name, diffuse, specular, alpha): | |
mat = bpy.data.materials.new(name) | |
mat.diffuse_color = diffuse | |
mat.diffuse_shader = 'LAMBERT' | |
mat.diffuse_intensity = 1.0 | |
mat.specular_color = specular | |
mat.specular_shader = 'COOKTORR' | |
mat.specular_intensity = 0.5 | |
mat.alpha = alpha | |
mat.ambient = 1 | |
return mat | |
def setMaterial(ob, mat): | |
me = ob.data | |
me.materials.append(mat) | |
mats=[] | |
for i in range(100): | |
mats.append(makeMaterial('alpha1', (1,0,0), (0,0,0),i/100.0)) | |
mats.append(makeMaterial('alpha1', (1,0,0), (0,0,0),1)) | |
for mat in mats: | |
mat.use_transparency=True | |
mat.diffuse_color=(1,0,0) | |
def draw(): | |
for i in range(7): | |
im.seek(i) | |
for j in range(63): | |
for k in range(66): | |
num=im.getpixel( (j, k) ) | |
if num >700 : | |
bpy.ops.mesh.primitive_cube_add(location=(j/10.0, k/10.0, i/10.0), radius=0.05) | |
if num > 700 and num<800: | |
setMaterial(bpy.context.object, mats[num-700]) | |
else: | |
setMaterial(bpy.context.object, mats[len(mats)-1]) | |
def draw1(): | |
for i in range(7): | |
im.seek(i) | |
for j in range(63): | |
for k in range(66): | |
num=im.getpixel( (j, k) ) | |
if num > 700: | |
bpy.ops.mesh.primitive_cube_add(location=(j/10.0, k/10.0, i/10.0), radius=0.05) | |
if num > 700 and num <= 750: | |
setMaterial(bpy.context.object, mat1) | |
break | |
if num > 750 and num <= 800: | |
setMaterial(bpy.context.object, mat2) | |
break | |
if num > 800 and num <= 850: | |
setMaterial(bpy.context.object, mat3) | |
break | |
if num > 850 and num <= 900: | |
setMaterial(bpy.context.object, mat5) | |
break | |
if num > 900 and num <= 950: | |
setMaterial(bpy.context.object, mat7) | |
break | |
if num > 950 and num <= 1000: | |
setMaterial(bpy.context.object, mat9) | |
break | |
if num > 1000: | |
setMaterial(bpy.context.object, mat10) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment