From 5ba11b5ad53ce8feccba2c2b916569237fef6bb5 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 30 Sep 2011 01:39:17 +0900 Subject: [PATCH] move pymeshio directory --- .gitignore | 1 + MANIFEST.in | 1 + examples/pymeshviewer.py | 1 + .../pymeshio => pymeshio}/__init__.py | 0 .../pymeshio/mmd.py => pymeshio/common.py | 475 +++++++++------------ pymeshio/compatibility.py | 81 ++++ .../pymeshio => pymeshio}/englishmap.py | 0 {blender25-meshio/pymeshio => pymeshio}/mqo.py | 0 {blender25-meshio/pymeshio => pymeshio}/pmd.py | 3 +- pymeshio/pmx.py | 12 + {blender25-meshio/pymeshio => pymeshio}/vmd.py | 0 {blender25-meshio/pymeshio => pymeshio}/vpd.py | 0 setup.py | 17 +- 13 files changed, 307 insertions(+), 284 deletions(-) rename {blender25-meshio/pymeshio => pymeshio}/__init__.py (100%) rename blender25-meshio/pymeshio/mmd.py => pymeshio/common.py (73%) create mode 100644 pymeshio/compatibility.py rename {blender25-meshio/pymeshio => pymeshio}/englishmap.py (100%) rename {blender25-meshio/pymeshio => pymeshio}/mqo.py (100%) rename {blender25-meshio/pymeshio => pymeshio}/pmd.py (99%) create mode 100644 pymeshio/pmx.py rename {blender25-meshio/pymeshio => pymeshio}/vmd.py (100%) rename {blender25-meshio/pymeshio => pymeshio}/vpd.py (100%) diff --git a/.gitignore b/.gitignore index 3687164..ecb6cb4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ build dist pymeshio.egg-info *.pyc +__pycache__/* diff --git a/MANIFEST.in b/MANIFEST.in index e82e56e..ea08a5e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include blender25-meshio/*.py include examples/*.py +include README.* diff --git a/examples/pymeshviewer.py b/examples/pymeshviewer.py index 6aa79ac..29e7f48 100644 --- a/examples/pymeshviewer.py +++ b/examples/pymeshviewer.py @@ -42,6 +42,7 @@ class Frame(tkinter.Frame): ('poloygon model files', '*.mqo;*.pmd'), ], initialdir=self.current) + self.current=os.path.dirname(path) self.load(path) def load(self, path): diff --git a/blender25-meshio/pymeshio/__init__.py b/pymeshio/__init__.py similarity index 100% rename from blender25-meshio/pymeshio/__init__.py rename to pymeshio/__init__.py diff --git a/blender25-meshio/pymeshio/mmd.py b/pymeshio/common.py similarity index 73% rename from blender25-meshio/pymeshio/mmd.py rename to pymeshio/common.py index cc9ea33..2f2fd6e 100644 --- a/blender25-meshio/pymeshio/mmd.py +++ b/pymeshio/common.py @@ -1,279 +1,196 @@ -#!/usr/bin/python -# coding: utf-8 -""" -utitlities for pmd and vmd loading. - -- python2 and python3 compatibility. -- common structures. - -""" -import sys -import codecs -import os.path -import struct -import math -import re -from decimal import * - -ENCODING='cp932' - -""" -utility functions for python2 and python3 compatibility. -""" -if sys.version_info[0]>=3: - xrange=range - -if sys.version_info[0]<3: - def truncate_zero(src): - """ - drop after 0x00 - """ - assert(type(src)==bytes) - pos = src.find(b"\x00") - if pos >= 0: - return src[:pos] - else: - return src -else: - def truncate_zero(src): - """ - drop after 0x00 - """ - assert(type(src)==bytes) - pos = src.find(b"\x00") - if pos >= 0: - return src[:pos].decode('cp932') - else: - return src.decode('cp932') - - -if sys.version_info[0]<3: - def to_str(src): - """ - str or unicode to str - """ - t=type(src) - if t==unicode: - return src.encode('cp932') - elif t==str: - return src - else: - raise "INVALID str: %s" % t - - def from_str(src): - """ - do nothing - """ - return src - -else: - def to_str(src): - """ - bytes or str to str - """ - t=type(src) - if t==str: - return src - elif t==bytes: - return src.decode('cp932') - else: - raise "INVALID str: %s" % t - - def from_str(src): - """ - str to bytes - """ - return src.encode('cp932') - - -""" -utility functions. -""" -def radian_to_degree(x): - return x/math.pi * 180.0 - - -""" -common structures. -""" -class Vector2(object): - """ - 2D coordinate for uv value - """ - __slots__=['x', 'y'] - def __init__(self, x=0, y=0): - self.x=x - self.y=y - - def __str__(self): - return "<%f %f>" % (self.x, self.y) - - def __getitem__(self, key): - if key==0: - return self.x - elif key==1: - return self.y - else: - assert(False) - - def to_tuple(self): - return (self.x, self.y) - - -class Vector3(object): - """ - 3D coordinate for vertex position, normal direction - """ - __slots__=['x', 'y', 'z'] - def __init__(self, x=0, y=0, z=0): - self.x=x - self.y=y - self.z=z - - def __str__(self): - return "<%f %f %f>" % (self.x, self.y, self.z) - - def __getitem__(self, key): - if key==0: - return self.x - elif key==1: - return self.y - elif key==2: - return self.z - else: - assert(False) - - def to_tuple(self): - return (self.x, self.y, self.z) - - def __add__(l, r): - return Vector3(l.x+r.x, l.y+r.y, l.z+r.z) - - -class Quaternion(object): - """ - rotation representation in vmd motion - """ - __slots__=['x', 'y', 'z', 'w'] - def __init__(self, x=0, y=0, z=0, w=1): - self.x=x - self.y=y - self.z=z - self.w=w - - def __str__(self): - return "<%f %f %f %f>" % (self.x, self.y, self.z, self.w) - - def __mul__(self, rhs): - u=numpy.array([self.x, self.y, self.z], 'f') - v=numpy.array([rhs.x, rhs.y, rhs.z], 'f') - xyz=self.w*v+rhs.w*u+numpy.cross(u, v) - q=Quaternion(xyz[0], xyz[1], xyz[2], self.w*rhs.w-numpy.dot(u, v)) - return q - - def dot(self, rhs): - return self.x*rhs.x+self.y*rhs.y+self.z*rhs.z+self.w*rhs.w - - def getMatrix(self): - sqX=self.x*self.x - sqY=self.y*self.y - sqZ=self.z*self.z - xy=self.x*self.y - xz=self.x*self.z - yz=self.y*self.z - wx=self.w*self.x - wy=self.w*self.y - wz=self.w*self.z - return numpy.array([ - # 1 - [1-2*sqY-2*sqZ, 2*xy+2*wz, 2*xz-2*wy, 0], - # 2 - [2*xy-2*wz, 1-2*sqX-2*sqZ, 2*yz+2*wx, 0], - # 3 - [2*xz+2*wy, 2*yz-2*wx, 1-2*sqX-2*sqY, 0], - # 4 - [0, 0, 0, 1]], - 'f') - - def getRHMatrix(self): - x=-self.x - y=-self.y - z=self.z - w=self.w - sqX=x*x - sqY=y*y - sqZ=z*z - xy=x*y - xz=x*z - yz=y*z - wx=w*x - wy=w*y - wz=w*z - return numpy.array([ - # 1 - [1-2*sqY-2*sqZ, 2*xy+2*wz, 2*xz-2*wy, 0], - # 2 - [2*xy-2*wz, 1-2*sqX-2*sqZ, 2*yz+2*wx, 0], - # 3 - [2*xz+2*wy, 2*yz-2*wx, 1-2*sqX-2*sqY, 0], - # 4 - [0, 0, 0, 1]], - 'f') - - def getRollPitchYaw(self): - m=self.getMatrix() - - roll = math.atan2(m[0, 1], m[1, 1]) - pitch = math.asin(-m[2, 1]) - yaw = math.atan2(m[2, 0], m[2, 2]) - - if math.fabs(math.cos(pitch)) < 1.0e-6: - roll += m[0, 1] > math.pi if 0.0 else -math.pi - yaw += m[2, 0] > math.pi if 0.0 else -math.pi - - return roll, pitch, yaw - - def getSqNorm(self): - return self.x*self.x+self.y*self.y+self.z*self.z+self.w*self.w - - def getNormalized(self): - f=1.0/self.getSqNorm() - q=Quaternion(self.x*f, self.y*f, self.z*f, self.w*f) - return q - - def getRightHanded(self): - "swap y and z axis" - return Quaternion(-self.x, -self.z, -self.y, self.w) - - @staticmethod - def createFromAxisAngle(axis, rad): - q=Quaternion() - half_rad=rad/2.0 - c=math.cos(half_rad) - s=math.sin(half_rad) - return Quaternion(axis[0]*s, axis[1]*s, axis[2]*s, c) - - -class RGBA(object): - """ - material color - """ - __slots__=['r', 'g', 'b', 'a'] - def __init__(self, r=0, g=0, b=0, a=1): - self.r=r - self.g=g - self.b=b - self.a=a - - def __getitem__(self, key): - if key==0: - return self.r - elif key==1: - return self.g - elif key==2: - return self.b - elif key==3: - return self.a - else: - assert(False) - +# coding: utf-8 +""" +common utilities. +""" +import math + +def radian_to_degree(x): + """darian to deglee""" + + return x/math.pi * 180.0 + + +""" +common structures. +""" +class Vector2(object): + """ + 2D coordinate for uv value + """ + __slots__=['x', 'y'] + def __init__(self, x=0, y=0): + self.x=x + self.y=y + + def __str__(self): + return "<%f %f>" % (self.x, self.y) + + def __getitem__(self, key): + if key==0: + return self.x + elif key==1: + return self.y + else: + assert(False) + + def to_tuple(self): + return (self.x, self.y) + + +class Vector3(object): + """ + 3D coordinate for vertex position, normal direction + """ + __slots__=['x', 'y', 'z'] + def __init__(self, x=0, y=0, z=0): + self.x=x + self.y=y + self.z=z + + def __str__(self): + return "<%f %f %f>" % (self.x, self.y, self.z) + + def __getitem__(self, key): + if key==0: + return self.x + elif key==1: + return self.y + elif key==2: + return self.z + else: + assert(False) + + def to_tuple(self): + return (self.x, self.y, self.z) + + def __add__(l, r): + return Vector3(l.x+r.x, l.y+r.y, l.z+r.z) + + +class Quaternion(object): + """ + rotation representation in vmd motion + """ + __slots__=['x', 'y', 'z', 'w'] + def __init__(self, x=0, y=0, z=0, w=1): + self.x=x + self.y=y + self.z=z + self.w=w + + def __str__(self): + return "<%f %f %f %f>" % (self.x, self.y, self.z, self.w) + + def __mul__(self, rhs): + u=numpy.array([self.x, self.y, self.z], 'f') + v=numpy.array([rhs.x, rhs.y, rhs.z], 'f') + xyz=self.w*v+rhs.w*u+numpy.cross(u, v) + q=Quaternion(xyz[0], xyz[1], xyz[2], self.w*rhs.w-numpy.dot(u, v)) + return q + + def dot(self, rhs): + return self.x*rhs.x+self.y*rhs.y+self.z*rhs.z+self.w*rhs.w + + def getMatrix(self): + sqX=self.x*self.x + sqY=self.y*self.y + sqZ=self.z*self.z + xy=self.x*self.y + xz=self.x*self.z + yz=self.y*self.z + wx=self.w*self.x + wy=self.w*self.y + wz=self.w*self.z + return numpy.array([ + # 1 + [1-2*sqY-2*sqZ, 2*xy+2*wz, 2*xz-2*wy, 0], + # 2 + [2*xy-2*wz, 1-2*sqX-2*sqZ, 2*yz+2*wx, 0], + # 3 + [2*xz+2*wy, 2*yz-2*wx, 1-2*sqX-2*sqY, 0], + # 4 + [0, 0, 0, 1]], + 'f') + + def getRHMatrix(self): + x=-self.x + y=-self.y + z=self.z + w=self.w + sqX=x*x + sqY=y*y + sqZ=z*z + xy=x*y + xz=x*z + yz=y*z + wx=w*x + wy=w*y + wz=w*z + return numpy.array([ + # 1 + [1-2*sqY-2*sqZ, 2*xy+2*wz, 2*xz-2*wy, 0], + # 2 + [2*xy-2*wz, 1-2*sqX-2*sqZ, 2*yz+2*wx, 0], + # 3 + [2*xz+2*wy, 2*yz-2*wx, 1-2*sqX-2*sqY, 0], + # 4 + [0, 0, 0, 1]], + 'f') + + def getRollPitchYaw(self): + m=self.getMatrix() + + roll = math.atan2(m[0, 1], m[1, 1]) + pitch = math.asin(-m[2, 1]) + yaw = math.atan2(m[2, 0], m[2, 2]) + + if math.fabs(math.cos(pitch)) < 1.0e-6: + roll += m[0, 1] > math.pi if 0.0 else -math.pi + yaw += m[2, 0] > math.pi if 0.0 else -math.pi + + return roll, pitch, yaw + + def getSqNorm(self): + return self.x*self.x+self.y*self.y+self.z*self.z+self.w*self.w + + def getNormalized(self): + f=1.0/self.getSqNorm() + q=Quaternion(self.x*f, self.y*f, self.z*f, self.w*f) + return q + + def getRightHanded(self): + "swap y and z axis" + return Quaternion(-self.x, -self.z, -self.y, self.w) + + @staticmethod + def createFromAxisAngle(axis, rad): + q=Quaternion() + half_rad=rad/2.0 + c=math.cos(half_rad) + s=math.sin(half_rad) + return Quaternion(axis[0]*s, axis[1]*s, axis[2]*s, c) + + +class RGBA(object): + """ + material color + """ + __slots__=['r', 'g', 'b', 'a'] + def __init__(self, r=0, g=0, b=0, a=1): + self.r=r + self.g=g + self.b=b + self.a=a + + def __getitem__(self, key): + if key==0: + return self.r + elif key==1: + return self.g + elif key==2: + return self.b + elif key==3: + return self.a + else: + assert(False) + diff --git a/pymeshio/compatibility.py b/pymeshio/compatibility.py new file mode 100644 index 0000000..ab8da34 --- /dev/null +++ b/pymeshio/compatibility.py @@ -0,0 +1,81 @@ +#!/usr/bin/python +# coding: utf-8 +""" +utitlities for pmd and vmd loading. + +- python2 and python3 compatibility. + +""" +import sys +import os.path + + +""" +utility functions for python2 and python3 compatibility. +""" +if sys.version_info[0]>=3: + xrange=range + +if sys.version_info[0]<3: + def truncate_zero(src): + """ + drop after 0x00 + """ + assert(type(src)==bytes) + pos = src.find(b"\x00") + if pos >= 0: + return src[:pos] + else: + return src +else: + def truncate_zero(src): + """ + drop after 0x00 + """ + assert(type(src)==bytes) + pos = src.find(b"\x00") + if pos >= 0: + return src[:pos].decode('cp932') + else: + return src.decode('cp932') + + +if sys.version_info[0]<3: + def to_str(src): + """ + str or unicode to str + """ + t=type(src) + if t==unicode: + return src.encode('cp932') + elif t==str: + return src + else: + raise "INVALID str: %s" % t + + def from_str(src): + """ + do nothing + """ + return src + +else: + def to_str(src): + """ + bytes or str to str + """ + t=type(src) + if t==str: + return src + elif t==bytes: + return src.decode('cp932') + else: + raise "INVALID str: %s" % t + + def from_str(src): + """ + str to bytes + """ + return src.encode('cp932') + + diff --git a/blender25-meshio/pymeshio/englishmap.py b/pymeshio/englishmap.py similarity index 100% rename from blender25-meshio/pymeshio/englishmap.py rename to pymeshio/englishmap.py diff --git a/blender25-meshio/pymeshio/mqo.py b/pymeshio/mqo.py similarity index 100% rename from blender25-meshio/pymeshio/mqo.py rename to pymeshio/mqo.py diff --git a/blender25-meshio/pymeshio/pmd.py b/pymeshio/pmd.py similarity index 99% rename from blender25-meshio/pymeshio/pmd.py rename to pymeshio/pmd.py index befe484..713bd38 100644 --- a/blender25-meshio/pymeshio/pmd.py +++ b/pymeshio/pmd.py @@ -6,7 +6,8 @@ http://blog.goo.ne.jp/torisu_tetosuki/e/209ad341d3ece2b1b4df24abf619d6e4 import os import sys import struct -from .mmd import * +from .common import * +from .compatibility import * class Vertex(object): diff --git a/pymeshio/pmx.py b/pymeshio/pmx.py new file mode 100644 index 0000000..e4b9ba5 --- /dev/null +++ b/pymeshio/pmx.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python +# coding: utf-8 +""" +pmx file io library. + +pmx file format: + PMDEditor's Lib/PMX仕様/PMX仕様.txt +""" +__author__="ousttrue" +__license__="zlib" +__versioon__="0.0.1" + diff --git a/blender25-meshio/pymeshio/vmd.py b/pymeshio/vmd.py similarity index 100% rename from blender25-meshio/pymeshio/vmd.py rename to pymeshio/vmd.py diff --git a/blender25-meshio/pymeshio/vpd.py b/pymeshio/vpd.py similarity index 100% rename from blender25-meshio/pymeshio/vpd.py rename to pymeshio/vpd.py diff --git a/setup.py b/setup.py index 4337df7..508fdb1 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,10 @@ from setuptools import setup import sys +import os +import shutil name='pymeshio' -version='1.9.2' +version='1.9.3' short_description='pure python 3d model io library' long_description='''\ `pymeshio` is a package for 3d model io. @@ -46,6 +48,13 @@ classifiers=[ 'Topic :: Multimedia :: Graphics :: 3D Modeling', ] +# copy pymeshio dir for blender25 plugin +PYMESHIO_DIR_IN_BLENDER='blender25-meshio/pymeshio' +if os.path.exists(PYMESHIO_DIR_IN_BLENDER): + shutil.rmtree(PYMESHIO_DIR_IN_BLENDER) +print("copy pymeshio to blender-25") +shutil.copytree('pymeshio', PYMESHIO_DIR_IN_BLENDER) + setup( name=name, version=version, @@ -57,9 +66,9 @@ setup( author_email='ousttrue@gmail.com', url='http://meshio.sourceforge.jp/', license='zlib', - package_dir={ - 'pymeshio': 'blender25-meshio/pymeshio' - }, + #package_dir={ + # 'pymeshio': 'blender25-meshio/pymeshio' + # }, packages=['pymeshio'], test_suite='nose.collector', tests_require=['Nose'], -- 2.11.0