Python API 2.0 Reference
python/api1/py1FootPrintNode.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 ########################################################################
40 # DESCRIPTION:
41 #
42 # Produces the dependency graph node "spFootPrint".
43 #
44 # This example demonstrates how to create a user-defined locator.
45 # A locator is a DAG object that is drawn in the 3D views, but that does
46 # not render. This example plug-in defines a new locator node that draws
47 # a foot print. The foot print can be selected and moved using the regular
48 # manipulators.
49 #
50 # To use this plug-in, execute the footPrintNode.py script to create a foot print locator.
51 #
52 ########################################################################
53 
54 from builtins import range
55 import maya.OpenMaya as OpenMaya
56 import maya.OpenMayaMPx as OpenMayaMPx
57 import maya.OpenMayaRender as OpenMayaRender
58 import maya.OpenMayaUI as OpenMayaUI
59 
60 import math
61 import sys
62 
63 kPluginNodeTypeName = "spFootPrintNode"
64 
65 footPrintNodeId = OpenMaya.MTypeId(0x00080057)
66 glRenderer = OpenMayaRender.MHardwareRenderer.theRenderer()
67 glFT = glRenderer.glFunctionTable()
68 
69 sole = ( [ 0.00, 0.0, -0.70 ],
70 [ 0.04, 0.0, -0.69 ],
71 [ 0.09, 0.0, -0.65 ],
72 [ 0.13, 0.0, -0.61 ],
73 [ 0.16, 0.0, -0.54 ],
74 [ 0.17, 0.0, -0.46 ],
75 [ 0.17, 0.0, -0.35 ],
76 [ 0.16, 0.0, -0.25 ],
77 [ 0.15, 0.0, -0.14 ],
78 [ 0.13, 0.0, 0.00 ],
79 [ 0.00, 0.0, 0.00 ],
80 [ -0.13, 0.0, 0.00 ],
81 [ -0.15, 0.0, -0.14 ],
82 [ -0.16, 0.0, -0.25 ],
83 [ -0.17, 0.0, -0.35 ],
84 [ -0.17, 0.0, -0.46 ],
85 [ -0.16, 0.0, -0.54 ],
86 [ -0.13, 0.0, -0.61 ],
87 [ -0.09, 0.0, -0.65 ],
88 [ -0.04, 0.0, -0.69 ],
89 [ -0.00, 0.0, -0.70 ] )
90 
91 heel = ( [ 0.00, 0.0, 0.06 ],
92 [ 0.13, 0.0, 0.06 ],
93 [ 0.14, 0.0, 0.15 ],
94 [ 0.14, 0.0, 0.21 ],
95 [ 0.13, 0.0, 0.25 ],
96 [ 0.11, 0.0, 0.28 ],
97 [ 0.09, 0.0, 0.29 ],
98 [ 0.04, 0.0, 0.30 ],
99 [ 0.00, 0.0, 0.30 ],
100 [ -0.04, 0.0, 0.30 ],
101 [ -0.09, 0.0, 0.29 ],
102 [ -0.11, 0.0, 0.28 ],
103 [ -0.13, 0.0, 0.25 ],
104 [ -0.14, 0.0, 0.21 ],
105 [ -0.14, 0.0, 0.15 ],
106 [ -0.13, 0.0, 0.06 ],
107 [ -0.00, 0.0, 0.06 ] )
108 
109 class footPrintNode(OpenMayaMPx.MPxLocatorNode):
110  size = OpenMaya.MObject()
111 
112  def __init__(self):
113  OpenMayaMPx.MPxLocatorNode.__init__(self)
114 
115  def compute(self, plug, dataBlock):
116  return OpenMaya.kUnknownParameter
117 
118  def draw(self, view, path, style, status):
119  thisNode = self.thisMObject()
120 
121  plug = OpenMaya.MPlug(thisNode, self.size)
122 
123  sizeVal = plug.asMDistance()
124 
125  multiplier = sizeVal.asCentimeters()
126 
127  view.beginGL()
128 
129  if style == OpenMayaUI.M3dView.kFlatShaded or style == OpenMayaUI.M3dView.kGouraudShaded:
130  glFT.glPushAttrib(OpenMayaRender.MGL_CURRENT_BIT)
131 
132  if status == OpenMayaUI.M3dView.kActive:
133  view.setDrawColor( 13, OpenMayaUI.M3dView.kActiveColors )
134  else:
135  view.setDrawColor( 13, OpenMayaUI.M3dView.kDormantColors )
136 
137  last = len(sole) - 1
138  glFT.glBegin( OpenMayaRender.MGL_TRIANGLE_FAN )
139  for i in range(last):
140  glFT.glVertex3f(sole[i][0]*multiplier, sole[i][1]*multiplier, sole[i][2]*multiplier)
141  glFT.glEnd()
142 
143  last = len(heel) - 1
144  glFT.glBegin( OpenMayaRender.MGL_TRIANGLE_FAN )
145  for i in range(last):
146  glFT.glVertex3f(heel[i][0]*multiplier, heel[i][1]*multiplier, heel[i][2]*multiplier)
147  glFT.glEnd()
148 
149  glFT.glPopAttrib()
150 
151  glFT.glBegin(OpenMayaRender.MGL_LINES)
152 
153  last = len(sole) - 1
154  for i in range(last):
155  glFT.glVertex3f( sole[i][0]*multiplier, sole[i][1]*multiplier, sole[i][2]*multiplier )
156  glFT.glVertex3f( sole[i+1][0]*multiplier, sole[i+1][1]*multiplier, sole[i+1][2]*multiplier )
157 
158  last = len(heel) - 1
159  for i in range(last):
160  glFT.glVertex3f( heel[i][0]*multiplier, heel[i][1]*multiplier, heel[i][2]*multiplier )
161  glFT.glVertex3f( heel[i+1][0]*multiplier, heel[i+1][1]*multiplier, heel[i+1][2]*multiplier )
162 
163  glFT.glEnd()
164 
165  view.endGL()
166 
167  def isBounded(self):
168  return True
169 
170  def boundingBox(self):
171  thisNode = self.thisMObject()
172  plug = OpenMaya.MPlug(thisNode, self.size)
173 
174  sizeVal = plug.asMDistance()
175 
176  multiplier = sizeVal.asCentimeters()
177 
178  corner1 = OpenMaya.MPoint(-0.17, 0.0, -0.7)
179  corner2 = OpenMaya.MPoint(0.17, 0.0, 0.3)
180 
181  corner1 = corner1 * multiplier
182  corner2 = corner2 * multiplier
183 
184  bbox = OpenMaya.MBoundingBox( corner1, corner2 )
185  return bbox
186 
187 
188 # creator
189 def nodeCreator():
190  return OpenMayaMPx.asMPxPtr( footPrintNode() )
191 
192 # initializer
193 def nodeInitializer():
194  unitFn = OpenMaya.MFnUnitAttribute()
195  footPrintNode.size = unitFn.create("size", "in", OpenMaya.MFnUnitAttribute.kDistance)
196  unitFn.setDefault(1.0)
197  footPrintNode.addAttribute( footPrintNode.size )
198 
199 # initialize the script plug-in
200 def initializePlugin(mobject):
201  mplugin = OpenMayaMPx.MFnPlugin(mobject)
202  try:
203  mplugin.registerNode( kPluginNodeTypeName, footPrintNodeId, nodeCreator, nodeInitializer, OpenMayaMPx.MPxNode.kLocatorNode )
204  except:
205  sys.stderr.write( "Failed to register node: %s" % kPluginNodeTypeName )
206  raise
207 
208 # uninitialize the script plug-in
209 def uninitializePlugin(mobject):
210  mplugin = OpenMayaMPx.MFnPlugin(mobject)
211  try:
212  mplugin.deregisterNode( footPrintNodeId )
213  except:
214  sys.stderr.write( "Failed to deregister node: %s" % kPluginNodeTypeName )
215  raise
216