Пример #1
0
def getHairs(ob, mod, psys , hair_name):
    
    steps = psys.settings.draw_step
    steps = 2 ** steps + 1
    width = psys.settings.particle_size / 10.0
    num_parents = len(psys.particles)
    num_children = len(psys.child_particles)    
    
    act_hair = [] 
    indent = 0
    space = "        "
    
    
    act_hair.append("%s %s %s" % (space * indent , "object", "{"))
    indent += 1
    
    materials = ob.data.materials[:]
    material_names = [m.name if m else 'None' for m in materials]
    
    num_of_shaders = len(material_names)
    if  num_of_shaders > 1:
        act_hair.append("%s %s %s" % (space * indent , "shaders", num_of_shaders))
        indent += 1
        for each_shdr in material_names:
            act_hair.append("%s %s %s" % (space * indent , "", each_shdr))
        indent -= 1
    else:
        act_hair.append("%s %s %s" % (space * indent , "shader", material_names[0])) 
    
    act_hair.append("%s %s %s" % (space * indent , "type", "hair"))
    act_hair.append("%s %s %s" % (space * indent , "name", hair_name))
    act_hair.append("%s %s %s" % (space * indent , "segments", steps - 1))
    act_hair.append("%s %s %s" % (space * indent , "width", "%+0.5f" % width))
    
    points = 3 * steps * (num_parents + num_children)
    act_hair.append("%s %s %s" % (space * indent , "points", points))  
        
    tmpfile = efutil.temp_file(hair_name + ".sc")
    outfile = open(tmpfile, 'w')
    for lines in act_hair :
        outfile.write("\n%s" % lines)
    
    indent += 1
    for pindex in range(0, num_parents + num_children):
        # sunflowLog("particle " + str(pindex))
        lines = ''
        for step in range(0, steps):
            co = psys.co_hair(ob, mod, pindex, step)
            # sunflowLog("step " + str(step) + ": " + str(co))
            lines += "%+0.4f  %+0.4f  %+0.4f   " % (co.x , co.y , co.z)
        outfile.write("\n%s" % lines)

    outfile.write("\n}")
    outfile.close()    
    dictionary = {}
    dictionary['path'] = tmpfile
    dictionary['parent'] , dictionary['psys'] = hair_name.split('.hair.')
    dictionary['showemitter'] = psys.settings.use_render_emitter
    return { 'hair' : dictionary }
Пример #2
0
def getHairs(ob, mod, psys, hair_name):

    steps = psys.settings.draw_step
    steps = 2 ** steps + 1
    width = psys.settings.particle_size / 10.0
    num_parents = len(psys.particles)
    num_children = len(psys.child_particles)

    act_hair = []
    indent = 0
    space = "        "

    act_hair.append("%s %s %s" % (space * indent, "object", "{"))
    indent += 1

    materials = ob.data.materials[:]
    material_names = [m.name if m else "None" for m in materials]

    num_of_shaders = len(material_names)
    if num_of_shaders > 1:
        act_hair.append("%s %s %s" % (space * indent, "shaders", num_of_shaders))
        indent += 1
        for each_shdr in material_names:
            act_hair.append("%s %s %s" % (space * indent, "", each_shdr))
        indent -= 1
    else:
        act_hair.append("%s %s %s" % (space * indent, "shader", material_names[0]))

    act_hair.append("%s %s %s" % (space * indent, "type", "hair"))
    act_hair.append("%s %s %s" % (space * indent, "name", hair_name))
    act_hair.append("%s %s %s" % (space * indent, "segments", steps - 1))
    act_hair.append("%s %s %s" % (space * indent, "width", "%+0.5f" % width))

    points = 3 * steps * (num_parents + num_children)
    act_hair.append("%s %s %s" % (space * indent, "points", points))

    tmpfile = efutil.temp_file(hair_name + ".sc")
    outfile = open(tmpfile, "w")
    for lines in act_hair:
        outfile.write("\n%s" % lines)

    indent += 1
    for pindex in range(0, num_parents + num_children):
        # sunflowLog("particle " + str(pindex))
        lines = ""
        for step in range(0, steps):
            co = psys.co_hair(ob, mod, pindex, step)
            # sunflowLog("step " + str(step) + ": " + str(co))
            lines += "%+0.4f  %+0.4f  %+0.4f   " % (co.x, co.y, co.z)
        outfile.write("\n%s" % lines)

    outfile.write("\n}")
    outfile.close()
    dictionary = {}
    dictionary["path"] = tmpfile
    dictionary["parent"], dictionary["psys"] = hair_name.split(".hair.")
    dictionary["showemitter"] = psys.settings.use_render_emitter
    return {"hair": dictionary}
Пример #3
0
def save_object_data(Object_name="", Object_data={}):    
    
    if 'vertices' in Object_data.keys() and Object_data['vertices'] != [] :
        number_of_vertices = len(Object_data['vertices'])
    else:
        # sunflowLog("Object has no vertices")
        return ''
    
    if 'faces' in Object_data.keys() and Object_data['faces'] != [] :
        number_of_faces = len(Object_data['faces'])
    else:
        # sunflowLog("Object has no faces")
        return ''
    
    if  'normal' in Object_data.keys() and Object_data['normal'] != [] :
        if len(Object_data['normal']) != number_of_faces :
            sunflowLog("Number of normal vector and faces don't match")
            return ''
        normal_type = 'facevarying'
    else:
        # sunflowLog("Object has no normal vector")
        normal_type = 'none'
    
    if 'uv' in Object_data.keys()  and Object_data['uv'] != [] :
        if len(Object_data['uv']) != number_of_faces :
            sunflowLog("Number of uv's and faces don't match")
            return ''
        uv_type = 'facevarying'
    else:
        # sunflowLog("Object has no uv's defined")
        uv_type = 'none'
    
    if 'matindex' in Object_data.keys()  and Object_data['matindex'] != [] :
        if len(Object_data['matindex']) != number_of_faces :
            sunflowLog("Number of matindex's and faces don't match")
            return ''
        matindex_type = 'face_shaders'
    else:
        # sunflowLog("Object has no face shaders's defined")
        matindex_type = ''
        
    
#------------------------------------------------------------------------------ 
    act_obj = []
    indent = 0
    space = "        "
    indent += 1
    
    
    act_obj.append("%s %s %s" % (space * indent , "points", number_of_vertices))
    indent += 1
    for item in Object_data['vertices']:
        vertstring = '  '.join(item)
        act_obj.append("%s %s %s" % (space * indent , "", vertstring))
    indent -= 1
    
    act_obj.append("%s %s %s" % (space * indent , "triangles", number_of_faces))
    indent += 1
    for item in Object_data['faces']:
        facestring = '  '.join(item)
        act_obj.append("%s %s %s" % (space * indent , "", facestring))
    indent -= 1
    

    act_obj.append("%s %s %s" % (space * indent , "normals", normal_type))
    if normal_type == 'none':        
        pass
    else:        
        indent += 1
        for item in Object_data['normal']:
            concat = ' '.join(item)
            act_obj.append("%s %s %s" % (space * indent , "", concat))
        indent -= 1    
    

    act_obj.append("%s %s %s" % (space * indent , "uvs", uv_type))
    if uv_type == 'none':        
        pass
    else:        
        indent += 1
        for item in Object_data['uv']:
            concat = ' '.join(item)
            act_obj.append("%s %s %s" % (space * indent , "", concat))
        indent -= 1


    act_obj.append("%s %s %s" % (space * indent , "", matindex_type))
    if matindex_type == '':        
        pass
    else:        
        indent += 1
        for item in Object_data['matindex']:
            act_obj.append("%s %s %s" % (space * indent , "", item))
        indent -= 1        
    indent -= 1

    tmpfile = efutil.temp_file(Object_name + ".sc")
    outfile = open(tmpfile, 'w')
    for lines in act_obj :
        outfile.write("\n%s" % lines)
    outfile.close()
    return tmpfile
Пример #4
0
def save_object_data(Object_name="", Object_data={}):

    if 'vertices' in Object_data.keys() and Object_data['vertices'] != []:
        number_of_vertices = len(Object_data['vertices'])
    else:
        # print("Object has no vertices")
        return ''

    if 'faces' in Object_data.keys() and Object_data['faces'] != []:
        number_of_faces = len(Object_data['faces'])
    else:
        # print("Object has no faces")
        return ''

    if 'normal' in Object_data.keys() and Object_data['normal'] != []:
        if len(Object_data['normal']) != number_of_faces:
            print("Number of normal vector and faces don't match")
            return ''
        normal_type = 'facevarying'
    else:
        # print("Object has no normal vector")
        normal_type = 'none'

    if 'uv' in Object_data.keys() and Object_data['uv'] != []:
        if len(Object_data['uv']) != number_of_faces:
            print("Number of uv's and faces don't match")
            return ''
        uv_type = 'facevarying'
    else:
        # print("Object has no uv's defined")
        uv_type = 'none'

    if 'matindex' in Object_data.keys() and Object_data['matindex'] != []:
        if len(Object_data['matindex']) != number_of_faces:
            print("Number of matindex's and faces don't match")
            return ''
        matindex_type = 'face_shaders'
    else:
        # print("Object has no face shaders's defined")
        matindex_type = ''

#------------------------------------------------------------------------------
    act_obj = []
    indent = 0
    space = "        "
    indent += 1

    act_obj.append("%s %s %s" % (space * indent, "points", number_of_vertices))
    indent += 1
    for item in Object_data['vertices']:
        vertstring = '  '.join(item)
        act_obj.append("%s %s %s" % (space * indent, "", vertstring))
    indent -= 1

    act_obj.append("%s %s %s" % (space * indent, "triangles", number_of_faces))
    indent += 1
    for item in Object_data['faces']:
        facestring = '  '.join(item)
        act_obj.append("%s %s %s" % (space * indent, "", facestring))
    indent -= 1

    act_obj.append("%s %s %s" % (space * indent, "normals", normal_type))
    if normal_type == 'none':
        pass
    else:
        indent += 1
        for item in Object_data['normal']:
            concat = ' '.join(item)
            act_obj.append("%s %s %s" % (space * indent, "", concat))
        indent -= 1

    act_obj.append("%s %s %s" % (space * indent, "uvs", uv_type))
    if uv_type == 'none':
        pass
    else:
        indent += 1
        for item in Object_data['uv']:
            concat = ' '.join(item)
            act_obj.append("%s %s %s" % (space * indent, "", concat))
        indent -= 1

    act_obj.append("%s %s %s" % (space * indent, "", matindex_type))
    if matindex_type == '':
        pass
    else:
        indent += 1
        for item in Object_data['matindex']:
            act_obj.append("%s %s %s" % (space * indent, "", item))
        indent -= 1
    indent -= 1

    #------------------------------------------------------------------------------

    tmpfile = efutil.temp_file(Object_name + ".sc")
    outfile = open(tmpfile, 'w')
    for lines in act_obj:
        outfile.write("\n%s" % lines)
    outfile.close()
    return tmpfile