test.py 2.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# set ID [mol new]

graphics $ID delete all

class MayaObj():
    def __init__(self, maya_lines):
        self.name, self.parent_name = MayaObj._parse_first_maya_line( maya_lines[0] )

    def _parse_first_maya_line(l):
        ## createNode vHelix -n "helix_1";
        name = parent = None
        vals = l.split()
        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


b = MayaObj( lines )


class MayaHelix(MayaObj):
    def __init__(self, maya_lines):
        MayaObj.__init__(self, maya_lines)
        self.bases = []

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 = []

        linesBuffer.append(line)    


        if line[1] == "vHelix"




while {[gets $ch line] >= 0} {
    set args [lassign [split $line] cmd obj]
    if {$cmd == "createNode"} {
	if {$obj == "HelixBase" && $drawBase} {
	    set drawBase 1
	    # set v [vecscale 10 [getNextVector $ch]] 
	    set v [coordtrans $R [vecscale 10 [getNextVector $ch]]]
	    # set v [coordtrans [transmult [trans_from_offset [vecscale 10 [getNextVector $ch]] $R ] {0 0 0}]]
	    graphics $ID sphere $v radius 2
	} elseif {$obj == "vHelix"} {
	    set drawBase 1
	    # createNode vHelix -n "helix_1";
	    # setAttr ".t" -type "double3" -16.9433 11.8494 25.2659 ;
	    # setAttr ".r" -type "double3" 42.338094401101131 222.16004220698011 5.8192508587610412 ;
	    # setAttr ".dh" yes;
		
	    set v [vecscale 10 [getNextVector $ch]] 
	    # set r [vecscale [expr {90.0/acos(0)}] [getNextVector $ch]]
	    set r [getNextVector $ch]
	    set R [eulerToRot $r]	    
	    set R [transmult [trans_from_offset $v] $R ]

	    # if {$helixCount == 2} {
	    # 	break
	    # } else {
	    # 	incr helixCount
	    # }
	}
    }    
}