Commit 0ac00139 authored by cmaffeo2's avatar cmaffeo2
Browse files

Updated test.py a bit

parent 360e6ff4
# set ID [mol new]
graphics $ID delete all
import numpy as np
import sys
from coords import rotationAboutAxis
class MayaObj():
def __init__(self, maya_lines):
......@@ -15,54 +15,106 @@ class MayaObj():
if vals[i] == "-p": parent = vals[i+1]
return name,parent
b = MayaObj( lines )
class MayaHelix(MayaObj):
def __init__(self, maya_lines):
MayaObj.__init__(self, maya_lines)
self.bases = []
self.position = None
self.orientation = None
self._parse_maya_lines(maya_lines)
def _parse_maya_lines(self, maya_lines):
"""
createNode vHelix -n "helix_30";
setAttr ".t" -type "double3" 9.24809 21.4638 -12.465 ;
setAttr ".r" -type "double3" 28.99971393816978 2.2177410772603801 87.637950315471372 ;
setAttr ".dh" yes;
"""
for l in maya_lines:
vals = l.split()
if vals[0] == "setAttr":
if vals[1] == '".t"':
self.position = np.array([float(a) for a in vals[4:7]])
elif vals[1] == '".r"':
# self.eulerAngles = np.array([float(a) for a in vals[4:7]]) # defined here
ax,ay,az = [float(a) for a in vals[4:7]]
Rx = rotationAboutAxis( [1,0,0], ax, normalizeAxis=False )
Ry = rotationAboutAxis( [0,1,0], ay, normalizeAxis=False )
Rz = rotationAboutAxis( [0,0,1], az, normalizeAxis=False )
self.orientation = Rx.dot(Ry.dot(Rz)) # TODO: check
rotXYZ = np.array()
for i in range(len(vals)):
if vals[i] == "-n": name = vals[i+1]
if vals[i] == "-p": parent = vals[i+1]
return name,parent
helices = []
bases = []
# set ch [open /home/cmaffeo2/Downloads/ball.ma]
# proc getNextVector {ch} {
# gets $ch line
# set line [split $line]
# lrange $line 5 7
# }
# proc eulerToRot {euler} {
# lassign $euler x y z
# transmult [transaxis z $z] [transaxis y $y] [transaxis x $x]
# }
with open("/home/cmaffeo2/Downloads/bunny.ma") as fh:
linesBuffer = []
for line in fh:
if line[0] == "createNode":
## Create a new object
if len(linesBuffer) > 0:
objType = linesBuffer[0].split()[1]
if objType == "vHelix":
helices.append( MayaHelix( linesBuffer ) )
elif objType == "HelixBase":
bases.append = MayaBase( linesBuffer )
elif objType == "aimConstraint":
bases.append = MayaBase( linesBuffer )
linesBuffer = []
def print_xyz(self,file_handle = sys.stdout):
for b in self.bases:
position = b.position.dot( self.orientation ) + self.position # TODO: double check
print("%s %f %f %f\n" % (b.name[0], position[0], position[1], position[2]))
linesBuffer.append(line)
class MayaBase(MayaObj):
...
if line[1] == "vHelix"
class MayaAimConstraint(MayaObj):
...
# set ch [open /home/cmaffeo2/Downloads/ball.ma]
def parse_maya_file(maya_file):
helices = dict()
bases = []
aimConstraints = []
## Parse through .ma file
with open(maya_file) as fh:
linesBuffer = []
for line in fh:
if line[0] == "createNode":
## Create a new object
if len(linesBuffer) > 0:
objType = linesBuffer[0].split()[1]
if objType == "vHelix":
h = MayaHelix( linesBuffer ) )
helices[h.name] = h
elif objType == "HelixBase":
bases.append( MayaBase( linesBuffer ) )
elif objType == "aimConstraint":
aimConstraints.append( MayaAimConstraint( linesBuffer ) )
## Clear lines buffer
linesBuffer = []
## Extend lines buffer
linesBuffer.append(line)
## Crawl through bases, attach to parent helix
for b in bases:
helix_name = b.parent
helices[helix_name].bases.append(b)
return helices
if __name__ == "main":
helices = parse_maya_file("/home/cmaffeo2/Downloads/bunny.ma")
...
""" TCL CODE
proc getNextVector {ch} {
gets $ch line
set line [split $line]
lrange $line 5 7
}
proc eulerToRot {euler} {
lassign $euler x y z
transmult [transaxis z $z] [transaxis y $y] [transaxis x $x]
}
while {[gets $ch line] >= 0} {
set args [lassign [split $line] cmd obj]
......@@ -94,4 +146,4 @@ while {[gets $ch line] >= 0} {
}
}
}
"""
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment