From 03f0cebe03446729de338d4676f6e9ee434d72aa Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 3 Oct 2011 00:18:18 +0900 Subject: [PATCH] fix import_mqo.py --- blender25-meshio/import_mqo.py | 49 +++++++++++++++-------------------------- examples/mqobuilder.py | 2 +- pymeshio/mqo/__init__.py | 17 +++++++------- pymeshio/mqo/reader.py | 11 +++++---- test/mqo_test.pyc | Bin 699 -> 0 bytes test/pmd_test.pyc | Bin 2556 -> 0 bytes 6 files changed, 32 insertions(+), 47 deletions(-) delete mode 100644 test/mqo_test.pyc delete mode 100644 test/pmd_test.pyc diff --git a/blender25-meshio/import_mqo.py b/blender25-meshio/import_mqo.py index 264ca2f..692dc47 100644 --- a/blender25-meshio/import_mqo.py +++ b/blender25-meshio/import_mqo.py @@ -29,6 +29,7 @@ This script imports a mqo into Blender for editing. 2.3 20101228: update for Blender2.55. 2.4 20110429: update for Blender2.57b. 2.6 20110918: update for Blender2.59. +2.7 20111002: update for pymeshio-2.1.0 ''' bl_addon_info = { @@ -46,14 +47,7 @@ bl_addon_info = { import os import sys - -try: - # C extension - from .meshio import mqo - print('use meshio C module') -except ImportError: - # full python - from .pymeshio import mqo +from .pymeshio.mqo import reader # for 2.5 import bpy @@ -62,7 +56,7 @@ import bpy from . import bl25 as bl def createMqoMaterial(m): - material = bpy.data.materials.new(m.getName()) + material = bpy.data.materials.new(m.name.decode("cp932")) # shader if m.shader==1: material.diffuse_shader='FRESNEL' @@ -81,13 +75,6 @@ def createMqoMaterial(m): def has_mikoto(mqo): - #for o in mqo.objects: - # if o.getName().startswith('bone'): - # return True - # if o.getName().startswith('sdef'): - # return True - # if o.getName().startswith('anchor'): - # return True return False @@ -104,8 +91,8 @@ def __createMaterials(mqo, directory): material=createMqoMaterial(m) materials.append(material) # texture - texture_name=m.getTexture() - if texture_name!='': + texture_name=m.tex.decode("cp932") + if texture_name!=b'': if texture_name in textureMap: texture=textureMap[texture_name] else: @@ -141,7 +128,7 @@ def __createObjects(mqo, root, materials, imageMap, scale): stack=[root] objects=[] for o in mqo.objects: - mesh, mesh_object=bl.mesh.create(o.getName()) + mesh, mesh_object=bl.mesh.create(o.name.decode("cp932")) # add hierarchy stack_depth=len(stack)-1 @@ -152,11 +139,12 @@ def __createObjects(mqo, root, materials, imageMap, scale): bl.object.makeParent(stack[-1], mesh_object) stack.append(mesh_object) - if o.getName().startswith('sdef'): + obj_name=o.name.decode("cp932") + if obj_name.startswith('sdef'): objects.append(mesh_object) - elif o.getName().startswith('anchor'): + elif obj_name.startswith('anchor'): bl.object.setLayerMask(mesh_object, [0, 1]) - elif o.getName().startswith('bone'): + elif obj_name.startswith('bone'): bl.object.setLayerMask(mesh_object, [0, 1]) # geometry @@ -596,28 +584,27 @@ def create_bone_weight(scene, mqo, armature_object, objects): def _execute(filepath='', scale=0.1): - # parse file - io=mqo.IO() - if not io.read(filepath): + # read mqo model + model=reader.read_from_file(filepath) + if not model: bl.message("fail to load %s" % filepath) return # create materials - materials, imageMap=__createMaterials(io, os.path.dirname(filepath)) + materials, imageMap=__createMaterials(model, os.path.dirname(filepath)) if len(materials)==0: materials.append(bl.material.create('default')) # create objects root=bl.object.createEmpty(os.path.basename(filepath)) - objects=__createObjects(io, root, materials, imageMap, scale) + objects=__createObjects(model, root, materials, imageMap, scale) - if has_mikoto(io): + if has_mikoto(model): # create mikoto bone - armature_object=create_armature(io) + armature_object=create_armature(model) if armature_object: root.makeParent([armature_object]) # create bone weight - create_bone_weight(io, armature_object, objects) - + create_bone_weight(model, armature_object, objects) diff --git a/examples/mqobuilder.py b/examples/mqobuilder.py index cc9ec7d..cc20b66 100644 --- a/examples/mqobuilder.py +++ b/examples/mqobuilder.py @@ -3,7 +3,7 @@ import time import os -import pymeshio.mqo +import pymeshio.mqo.reader import opengl.material import opengl.texture import opengl.vertexarraymap diff --git a/pymeshio/mqo/__init__.py b/pymeshio/mqo/__init__.py index dd9af9d..77c6328 100644 --- a/pymeshio/mqo/__init__.py +++ b/pymeshio/mqo/__init__.py @@ -7,9 +7,8 @@ http://www.metaseq.net/metaseq/format.html import os import sys import math -import pymeshio.common -import pymeshio.mqo.reader import warnings +from .. import common """ @@ -37,13 +36,13 @@ class Material(object): def __init__(self, name): self.name=name self.shader=3 - self.color=pymeshio.common.RGBA(0.5, 0.5, 0.5, 1.0) + self.color=common.RGBA(0.5, 0.5, 0.5, 1.0) self.diffuse=1.0 self.ambient=0.0 self.emit=0.0 self.specular=0.0 self.power=5.0 - self.tex="" + self.tex=b"" def getName(self): return self.name def getTexture(self): return self.tex @@ -63,7 +62,7 @@ class Material(object): if key==b"shader": self.shader=int(param) elif key==b"col": - self.color=pymeshio.common.RGBA(*[float(e) for e in param.split()]) + self.color=common.RGBA(*[float(e) for e in param.split()]) elif key==b"dif": self.diffuse=float(param) elif key==b"amb": @@ -143,7 +142,7 @@ class Obj(object): def getName(self): return self.name def addVertex(self, x, y, z): - self.vertices.append(pymeshio.common.Vector3(x, y, z)) + self.vertices.append(common.Vector3(x, y, z)) def addFace(self, face): if face.index_count==2: @@ -175,7 +174,7 @@ class Face(object): raise ValueError("invalid vertex count: %d" % index_count) self.material_index=0 self.col=[] - self.uv=[pymeshio.common.Vector2(0, 0)]*4 + self.uv=[common.Vector2(0, 0)]*4 self.index_count=index_count offset=0 while True: @@ -195,7 +194,7 @@ class Face(object): uv_list=[float(e) for e in params] self.uv=[] for i in range(0, len(uv_list), 2): - self.uv.append(pymeshio.common.Vector2(uv_list[i], uv_list[i+1])) + self.uv.append(common.Vector2(uv_list[i], uv_list[i+1])) elif key==b"COL": for n in params: d=int(n) @@ -217,7 +216,7 @@ class Face(object): offset=rightParenthesis+2 def getIndex(self, i): return self.indices[i] - def getUV(self, i): return self.uv[i] if i(t{2MS=@( z;D6~I-dNcdam8NGKF^yOzp>-{VgGM)H_m7~BK*H%@kf{(pQ4Irs#+X9!7)u^%Hioy z9@8ztx)T38=^(dwz!>uzKxf#lU1oScTc4Xz{l|vm6sQ>M5Q|F~PgE)@BPwI^9lB9; z_0QR*ORzm!M#Kl?cjy|D6#3oY-;-dWeza87QvH^iw-iC4oI5Uhu!YD-Udi#hFsn^% zcu`m{5m4$S#+g}eoPWKAdhTqk=S5{g%IUA4`up+8k?(>(wYjPM9+1{qHDlH~DCWm+A8u|6N&I|pLs{y kTak<64Nv6JCzASK>q`ZTw9n{&U70U(A3^ItVaC1q5qj{T3jhEB diff --git a/test/pmd_test.pyc b/test/pmd_test.pyc deleted file mode 100644 index 237a34bd38b7f171ea873828fbd256eeabbc7346..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2556 zcmb_e-)kII6uz^YY_i*=wMo+$EOEgiD`+eUK3GI-HmMD`X_zKL!oo1wxtq*pc4nP> zr*$!XNLI8Jp?#&DQ-UNP!qF#0h1F|uOxP_7f*@j2m~=)@1;If!xc zNc=!|{3)RanbAq2)1=Q~L57m}4sa#`hK~Rv32^2J za5e!(jsT+xa5e$>T#TVR^U(n2?xV>atu)@Anq;WtZbbPjwpNiZqbbBL1YWZg?BDyT z-TI;3`n=tG!1GRf`{|!M-*jinUzg#; z!)v*S4rwl;6Q6j0X}2D?w;yGZwY|07-g?m9deYwdYVXmVBn~g9*Y5s!d+*M-&y9N( z`HDfK8M~{Ax3M$#?6vvUAZ0fMVdI4q7^gkn@Zr#IpZM%bmUe zIr(iF6Www}-TLIh&AgT$>j>K75+nCZnqH>q4Vqq}X?V~Og;7|#A5(IHHDw{;$>14E z+X1zc9n-3YLEWmlp5!G9r5Wq;+y}Gz1aMnH8uaW(k?rvT;qB@y5X-7~KrM??O22|a zu*CRwU25Vh{WZ^3>lQmm@G3#QE`6;@G7>QH5kC(gk*2!2kWN-f*LT<^;?*Fm+Zs0z zy9)vzViZ?{2?3FzYkP``t_D65(4u+}Hr5sI2FJm5Rs+ZFK()a2wJMNgnRF0&Wt}>D zEE-8=BE7Vz;6wOBaav=<7&Fe{lj$8c294aoa}54bjQGQ9N-|5ODbngMFde8VIvPtU zd3s1qYZ-xxLF=HHBu)_8RL9d2;wIELj?9W$PHd*dCgc^0`<(SqSg0hv-{LGiEY}0H zU=sq4HLN4?_X{<{B*EumQ#%8n8%LYAJTqD*sFIm3<6 zMIX5nZ1Ra%llr>tMbe~_@>gx#FDlJyR5j`3^AQgs-Dx_SIC(5x%u#OYBGbXOjBlez z4W-770po1yyupl^sKuupmx5MV7S2-SNy{?%h@FGaBu>wGvGxDIhD{_B)B#1c&7`vF z?0A6*Q)N_BnRz^!S>(H#w!v33kp=o+ByQd?;<~*P9g+B#Kkg5AmGdqlXVF%YsT|wJ XIQ2Vm`QD}CDN?He)VuRZXVU)w)P8H* -- 2.11.0