From f0dd4a35fdbbc81bdc2b4f4339993b7ae7510963 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Tue, 29 Jun 2010 23:49:33 +0900 Subject: [PATCH] pmd_import sphere map. --- swig/blender/pmd_import.py | 83 ++++++++++++++++++++++++++++------------------ swig/setup.py | 2 +- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/swig/blender/pmd_import.py b/swig/blender/pmd_import.py index 4b03500..7332b53 100755 --- a/swig/blender/pmd_import.py +++ b/swig/blender/pmd_import.py @@ -112,6 +112,9 @@ if isBlender24(): elif n.startswith("ankle_"): b.lockYRot=True + def setSphereMap(material, index, blende_type=None): + pass + else: # for 2.5 import bpy @@ -157,6 +160,13 @@ else: #b.ik_dof_y=False pass + def setSphereMap(material, index, blend_type=None): + slot=material.texture_slots[index] + slot.texture_coordinates='REFLECTION' + slot.mapping='SPHERE' + if blend_type: + slot.blend_type=blend_type + ############################################################################### def VtoV(v): @@ -169,10 +179,6 @@ def convert_coord(pos): return (pos.x, pos.z, pos.y) -def convert_uv(uv): - return (uv.x, 1.0 - uv.y) - - def to_radian(degree): return math.pi * degree / 180 @@ -393,17 +399,22 @@ def __import16MaerialAndMesh(meshObject, l, texture_name=m.getTexture() if texture_name!='': - if texture_name in textureMap: - texture=textureMap[texture_name] - else: - try: - texture, image=bl.texture.create( - os.path.join(tex_dir, texture_name)) + for i, t in enumerate(texture_name.split('*')): + if t in textureMap: + texture=textureMap[t] + else: + path=os.path.join(tex_dir, t) + texture, image=bl.texture.create(path) textureMap[texture_name]=texture imageMap[material_index]=image - except: - continue - bl.material.addTexture(material, texture) + bl.material.addTexture(material, texture) + if t.endswith('sph'): + # sphere map + setSphereMap(material, i) + elif t.endswith('spa'): + # sphere map + setSphereMap(material, i, 'ADD') + bl.mesh.addMaterial(mesh, material) index+=1 @@ -554,32 +565,34 @@ def __importMesh(scene, io, tex_dir): if io.indices[i] in shape_key_used_vertices: return True - # shapeキーで使われるマテリアルを記録する - shape_key_materials=set() + material_with_shape=set() + # 各マテリアルの開始頂点インデックスを記録する face_map={} face_count=0 for i, m in enumerate(io.materials): face_map[i]=face_count if isMaterialUsedInShape(face_count, m): - shape_key_materials.add(i) + material_with_shape.add(i) face_count+=m.vertex_count - # list化 - material_order=list(shape_key_materials) + # shapeキーで使われる頂点のあるマテリアル + material_with_shape=list(material_with_shape) + material_with_shape.sort() - # shapeキーに使われていないマテリアルを後ろに追加 + # shapeキーに使われていないマテリアル + material_without_shape=[] for i in range(len(io.materials)): - if not i in material_order: - material_order.append(i) + if not i in material_with_shape: + material_without_shape.append(i) - # マテリアル16個ごとに分割したメッシュを作成する - material_offset=0 - mesh_objects=[] - while material_offset