1 #!/usr/bin/env python
\r
7 import opengl.material
\r
8 import opengl.texture
\r
9 import opengl.vertexarray
\r
15 io=pymeshio.pmd.IO()
\r
16 if not io.read(path):
\r
18 print(time.time()-t, "sec")
\r
20 basedir=os.path.dirname(path)
\r
21 indexedVertexArray=opengl.vertexarray.IndexedVertexArray()
\r
22 for v in io.vertices:
\r
23 # left-handed y-up to right-handed y-up
\r
24 indexedVertexArray.addVertex(
\r
25 (v.pos[0], v.pos[1], -v.pos[2], 1),
\r
26 (v.normal[0], v.normal[1], -v.normal[2]),
\r
27 (v.uv[0], v.uv[1]),
\r
29 v.bone0, v.bone1, v.weight0)
\r
35 for i in io.indices:
\r
38 for i, m in enumerate(io.materials):
\r
40 material=opengl.material.MQOMaterial()
\r
47 texturefile=m.texture.decode('cp932')
\r
49 texturepath=os.path.join(basedir, texturefile)
\r
50 if not texturepath in textureMap:
\r
51 texture=opengl.texture.Texture(texturepath)
\r
52 textureMap[texturepath]=texture
\r
53 material.texture=textureMap[texturepath]
\r
54 indices=indexedVertexArray.addMaterial(material)
\r
55 indices+=[next(indexGen) for n in range(m.vertex_count)]
\r
56 indexedVertexArray.optimize()
\r
57 return indexedVertexArray
\r