scripted/footPrintNode.py

scripted/footPrintNode.py
1 #-
2 # ==========================================================================
3 # Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors. All
4 # rights reserved.
5 #
6 # The coded instructions, statements, computer programs, and/or related
7 # material (collectively the "Data") in these files contain unpublished
8 # information proprietary to Autodesk, Inc. ("Autodesk") and/or its
9 # licensors, which is protected by U.S. and Canadian federal copyright
10 # law and by international treaties.
11 #
12 # The Data is provided for use exclusively by You. You have the right
13 # to use, modify, and incorporate this Data into other products for
14 # purposes authorized by the Autodesk software license agreement,
15 # without fee.
16 #
17 # The copyright notices in the Software and this entire statement,
18 # including the above license grant, this restriction and the
19 # following disclaimer, must be included in all copies of the
20 # Software, in whole or in part, and all derivative works of
21 # the Software, unless such copies or derivative works are solely
22 # in the form of machine-executable object code generated by a
23 # source language processor.
24 #
25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
26 # AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED
27 # WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF
28 # NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
29 # PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR
30 # TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS
31 # BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
32 # DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK
33 # AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY
34 # OR PROBABILITY OF SUCH DAMAGES.
35 #
36 # ==========================================================================
37 #+
38 
39 import maya.OpenMaya as OpenMaya
40 import maya.OpenMayaMPx as OpenMayaMPx
41 import maya.OpenMayaRender as OpenMayaRender
42 import maya.OpenMayaUI as OpenMayaUI
43 
44 import math
45 import sys
46 
47 kPluginNodeTypeName = "spFootPrintNode"
48 
49 footPrintNodeId = OpenMaya.MTypeId(0x87010)
50 glRenderer = OpenMayaRender.MHardwareRenderer.theRenderer()
51 glFT = glRenderer.glFunctionTable()
52 
53 sole = ( [ 0.00, 0.0, -0.70 ],
54 [ 0.04, 0.0, -0.69 ],
55 [ 0.09, 0.0, -0.65 ],
56 [ 0.13, 0.0, -0.61 ],
57 [ 0.16, 0.0, -0.54 ],
58 [ 0.17, 0.0, -0.46 ],
59 [ 0.17, 0.0, -0.35 ],
60 [ 0.16, 0.0, -0.25 ],
61 [ 0.15, 0.0, -0.14 ],
62 [ 0.13, 0.0, 0.00 ],
63 [ 0.00, 0.0, 0.00 ],
64 [ -0.13, 0.0, 0.00 ],
65 [ -0.15, 0.0, -0.14 ],
66 [ -0.16, 0.0, -0.25 ],
67 [ -0.17, 0.0, -0.35 ],
68 [ -0.17, 0.0, -0.46 ],
69 [ -0.16, 0.0, -0.54 ],
70 [ -0.13, 0.0, -0.61 ],
71 [ -0.09, 0.0, -0.65 ],
72 [ -0.04, 0.0, -0.69 ],
73 [ -0.00, 0.0, -0.70 ] )
74 
75 heel = ( [ 0.00, 0.0, 0.06 ],
76 [ 0.13, 0.0, 0.06 ],
77 [ 0.14, 0.0, 0.15 ],
78 [ 0.14, 0.0, 0.21 ],
79 [ 0.13, 0.0, 0.25 ],
80 [ 0.11, 0.0, 0.28 ],
81 [ 0.09, 0.0, 0.29 ],
82 [ 0.04, 0.0, 0.30 ],
83 [ 0.00, 0.0, 0.30 ],
84 [ -0.04, 0.0, 0.30 ],
85 [ -0.09, 0.0, 0.29 ],
86 [ -0.11, 0.0, 0.28 ],
87 [ -0.13, 0.0, 0.25 ],
88 [ -0.14, 0.0, 0.21 ],
89 [ -0.14, 0.0, 0.15 ],
90 [ -0.13, 0.0, 0.06 ],
91 [ -0.00, 0.0, 0.06 ] )
92 
93 class footPrintNode(OpenMayaMPx.MPxLocatorNode):
94  size = OpenMaya.MObject()
95 
96  def __init__(self):
97  OpenMayaMPx.MPxLocatorNode.__init__(self)
98 
99  def compute(self, plug, dataBlock):
100  return OpenMaya.kUnknownParameter
101 
102  def draw(self, view, path, style, status):
103  thisNode = self.thisMObject()
104 
105  plug = OpenMaya.MPlug(thisNode, self.size)
106 
107  sizeVal = plug.asMDistance()
108 
109  multiplier = sizeVal.asCentimeters()
110 
111  view.beginGL()
112 
113  if style == OpenMayaUI.M3dView.kFlatShaded or style == OpenMayaUI.M3dView.kGouraudShaded:
114  glFT.glPushAttrib(OpenMayaRender.MGL_CURRENT_BIT)
115 
116  if status == OpenMayaUI.M3dView.kActive:
117  view.setDrawColor( 13, OpenMayaUI.M3dView.kActiveColors )
118  else:
119  view.setDrawColor( 13, OpenMayaUI.M3dView.kDormantColors )
120 
121  last = len(sole) - 1
122  glFT.glBegin( OpenMayaRender.MGL_TRIANGLE_FAN )
123  for i in range(last):
124  glFT.glVertex3f(sole[i][0]*multiplier, sole[i][1]*multiplier, sole[i][2]*multiplier)
125  glFT.glEnd()
126 
127  last = len(heel) - 1
128  glFT.glBegin( OpenMayaRender.MGL_TRIANGLE_FAN )
129  for i in range(last):
130  glFT.glVertex3f(heel[i][0]*multiplier, heel[i][1]*multiplier, heel[i][2]*multiplier)
131  glFT.glEnd()
132 
133  glFT.glPopAttrib()
134 
135  glFT.glBegin(OpenMayaRender.MGL_LINES)
136 
137  last = len(sole) - 1
138  for i in range(last):
139  glFT.glVertex3f( sole[i][0]*multiplier, sole[i][1]*multiplier, sole[i][2]*multiplier )
140  glFT.glVertex3f( sole[i+1][0]*multiplier, sole[i+1][1]*multiplier, sole[i+1][2]*multiplier )
141 
142  last = len(heel) - 1
143  for i in range(last):
144  glFT.glVertex3f( heel[i][0]*multiplier, heel[i][1]*multiplier, heel[i][2]*multiplier )
145  glFT.glVertex3f( heel[i+1][0]*multiplier, heel[i+1][1]*multiplier, heel[i+1][2]*multiplier )
146 
147  glFT.glEnd()
148 
149  view.endGL()
150 
151  def isBounded(self):
152  return True
153 
154  def boundingBox(self):
155  thisNode = self.thisMObject()
156  plug = OpenMaya.MPlug(thisNode, self.size)
157 
158  sizeVal = plug.asMDistance()
159 
160  multiplier = sizeVal.asCentimeters()
161 
162  corner1 = OpenMaya.MPoint(-0.17, 0.0, -0.7)
163  corner2 = OpenMaya.MPoint(0.17, 0.0, 0.3)
164 
165  corner1 = corner1 * multiplier
166  corner2 = corner2 * multiplier
167 
168  bbox = OpenMaya.MBoundingBox( corner1, corner2 )
169  return bbox
170 
171 
172 # creator
173 def nodeCreator():
174  return OpenMayaMPx.asMPxPtr( footPrintNode() )
175 
176 # initializer
177 def nodeInitializer():
178  unitFn = OpenMaya.MFnUnitAttribute()
179  footPrintNode.size = unitFn.create("size", "in", OpenMaya.MFnUnitAttribute.kDistance)
180  unitFn.setDefault(1.0)
181  footPrintNode.addAttribute( footPrintNode.size )
182 
183 # initialize the script plug-in
184 def initializePlugin(mobject):
185  mplugin = OpenMayaMPx.MFnPlugin(mobject)
186  try:
187  mplugin.registerNode( kPluginNodeTypeName, footPrintNodeId, nodeCreator, nodeInitializer, OpenMayaMPx.MPxNode.kLocatorNode )
188  except:
189  sys.stderr.write( "Failed to register node: %s" % kPluginNodeTypeName )
190  raise
191 
192 # uninitialize the script plug-in
193 def uninitializePlugin(mobject):
194  mplugin = OpenMayaMPx.MFnPlugin(mobject)
195  try:
196  mplugin.deregisterNode( footPrintNodeId )
197  except:
198  sys.stderr.write( "Failed to deregister node: %s" % kPluginNodeTypeName )
199  raise
200