|
|
"Mr" <nomail@nomail> wrote:
>
> Honestly, I could with no problem export 2 million + hair,only parsing is a
> little long but it works, so I don't see why we should modify the scene
> structure, this is user decision, not something the program should do imho.
development:
If hair direct, it is better to write down them as a cone
#declare Hair = cone {<0,0,0>,0.01,<1,0,0>,0.01}
Parsing takes not enough time
If hair curling, it is better to write down them as sphere_sweep
Parsing takes a lot of time - Your only option
And, as I understood, you can't paint the ends of black hair in white color
And, at you everything is good!
class ExportHair(Operator):
bl_idname = "ob.exporthair"
bl_label = "Add hair"
def execute(self, context):
import bmesh
import mathutils
from math import pi
scene=context.scene
ob=context.object
global_matrix = mathutils.Matrix.Rotation(-pi / 2.0, 4, 'X')
matrix=global_matrix*ob.matrix_world
for pSys in ob.particle_systems:
for mod in ob.modifiers:
if mod.type == 'PARTICLE_SYSTEM':
if mod.particle_system.settings.type == 'HAIR' and
mod.particle_system.name==pSys.name:
modPovName=string_strip_hyphen(bpy.path.clean_name(mod.particle_system.name))
numberHairs = (len(mod.particle_system.particles) +
len(mod.particle_system.child_particles))
file=open("%s/%s.inc"%(scene.pov.scene_path,modPovName),'w')
file.write("#declare Array%s = array[%s]
{\n"%(modPovName,len(mod.particle_system.child_particles)))
steps=mod.particle_system.settings.draw_step
steps=(2**steps)+1
radiusRoot =
mod.particle_system.settings.pov.thickness_root
radiusTip =
mod.particle_system.settings.pov.thickness_tip
for i in
range(len(mod.particle_system.particles),numberHairs):
if mod.particle_system.settings.pov.hair_type ==
"CONE":
coRoot = pSys.co_hair(ob,i,0)
coTip = pSys.co_hair(ob,i,steps-1)
file.write("cone{\n")
centerRoot = "<%.4g,%.4g,%.4g>"%(coRoot[:])
file.write("%s,
%.4g,\n"%(centerRoot,radiusRoot))
centerTip = "<%.4g,%.4g,%.4g>"%(coTip[:])
file.write("%s, %.4g},\n"%(centerTip,radiusTip))
if mod.particle_system.settings.pov.hair_type ==
"SPLINE":
file.write("spline { cubic_spline\n")
numPtAll=steps+4
co = pSys.co_hair(ob,i,0)
file.write("0/%s
<%.4g,%.4g,%.4g>\n"%(numPtAll,co[0],co[1],co[2]))
file.write("1/%s
<%.4g,%.4g,%.4g>\n"%(numPtAll,co[0],co[1],co[2]))
for p in range(0,steps):
co = pSys.co_hair(ob,i,p)
file.write("%s/%s
<%.4g,%.4g,%.4g>\n"%(p+2,numPtAll,co[0],co[1],co[2]))
file.write("%s/%s
<%.4g,%.4g,%.4g>\n"%(numPtAll-2,numPtAll,co[0],co[1],co[2]))
file.write("%s/%s
<%.4g,%.4g,%.4g>\n"%(numPtAll-1,numPtAll,co[0],co[1],co[2]))
file.write("},\n")
file.write("}\n")
file.write("#declare ArrayColors%s = array[%s]
{\n"%(modPovName,len(mod.particle_system.child_particles)))
tex =
ob.active_material.active_texture.pov.tex_images_data
image=bpy.data.images[tex]
image_width = image.size[0]
image_height = image.size[1]
image_pixels = image.pixels[:]
for i in range(0,len(mod.particle_system.particles)):
uv_co = pSys.uv_on_emitter(mod, pSys.particles[i],
i, 0)
x_co = round(uv_co[0] * (image_width - 1))
y_co = round(uv_co[1] * (image_height - 1))
pixelnumber = (image_width * y_co) + x_co
r = image_pixels[pixelnumber*4]
g = image_pixels[pixelnumber*4+1]
b = image_pixels[pixelnumber*4+2]
col = (r,g,b)
file.write("rgb <%.4g,%.4g,%.4g>\n"%(r,g,b))
file.write("}\n")
if mod.particle_system.settings.pov.hair_type ==
"SPLINE":
file.write("#declare Segment%s =\n"%modPovName)
file.write("sphere {0,%.4g}\n\n"%radiusRoot)
file.write("#declare HairStep = 1;\n")
file.write("#declare Hairs%s =\n"%modPovName)
file.write("union {\n")
file.write(" #declare I = 0;\n")
file.write(" #while (I <
%s)\n"%len(mod.particle_system.child_particles))
file.write(" union {\n")
file.write(" #declare ctr = 0;\n")
file.write(" #declare col = 0;\n")
file.write(" #while (ctr < 1)\n")
file.write(" object { Segment%s
texture{pigment{rgb col}}\n"%modPovName)
file.write(" translate
Array%s[I](ctr)}\n"%modPovName)
file.write(" #declare ctr = ctr +
0.0025;\n")
file.write(" #if (ctr > 0.5)\n")
file.write(" #declare col = col +
0.0025;\n")
file.write(" #end\n")
file.write(" #if (ctr > 0.6)\n")
file.write(" #declare col = 1;\n")
file.write(" #end\n")
file.write(" #end }\n")
file.write("#declare I = I + HairStep ;\n")
file.write("#end }\n")
file.close()
if mod.particle_system.settings.pov.hair_type == "CONE":
file.write("#declare HairStep = 1;\n")
file.write("#declare Hairs%s =\n"%modPovName)
file.write("union {\n")
file.write(" #declare I = 0;\n")
file.write(" #while (I <
%s)\n"%len(mod.particle_system.child_particles))
file.write(" object { Array%s[I]
texture{pigment{ArrayColors%s[I]}}}\n"%(modPovName,modPovName))
file.write("#declare I = I + HairStep ;\n")
file.write("#end }\n")
file.close()
return {'FINISHED'}
> but I will also try to add your texture evaluation code
> for hair if you agree.
You only speak, but, anything you do.
Post a reply to this message
|
|