1 from __future__
import division
84 import maya.OpenMaya
as OpenMaya
85 import maya.OpenMayaMPx
as OpenMayaMPx
87 kPluginNodeTypeName =
"spCircle"
92 class circle(OpenMayaMPx.MPxNode):
102 OpenMayaMPx.MPxNode.__init__(self)
105 def compute(self, plug, data):
107 if (plug == circle.aSOutput
or plug == circle.aCOutput):
109 inputData = data.inputValue(circle.aInput)
110 scaleData = data.inputValue(circle.aScale)
111 framesData = data.inputValue(circle.aFrames)
114 currentFrame = inputData.asFloat()
115 scaleFactor = scaleData.asFloat()
116 framesPerCircle = framesData.asFloat()
117 angle = 6.2831853 * (currentFrame/framesPerCircle)
118 sinResult = math.sin(angle) * scaleFactor
119 cosResult = math.cos(angle) * scaleFactor
122 sinHandle = data.outputValue(circle.aSOutput)
123 cosHandle = data.outputValue(circle.aCOutput)
124 sinHandle.setFloat(sinResult)
125 cosHandle.setFloat(cosResult)
128 return OpenMaya.kUnknownParameter
135 return OpenMayaMPx.asMPxPtr( circle() )
139 def nodeInitializer():
143 circle.aInput = nAttr.create(
"input",
"in", OpenMaya.MFnNumericData.kFloat, 0.0)
144 nAttr.setStorable(
True)
146 circle.aScale = nAttr.create(
"scale",
"sc", OpenMaya.MFnNumericData.kFloat, 10.0)
147 nAttr.setStorable(
True)
149 circle.aFrames = nAttr.create(
"frames",
"fr", OpenMaya.MFnNumericData.kFloat, 48.0)
150 nAttr.setStorable(
True)
153 circle.aSOutput = nAttr.create(
"sineOutput",
"so", OpenMaya.MFnNumericData.kFloat, 0.0)
154 nAttr.setWritable(
False)
155 nAttr.setStorable(
False)
157 circle.aCOutput = nAttr.create(
"cosineOutput",
"co", OpenMaya.MFnNumericData.kFloat, 0.0,)
158 nAttr.setWritable(
False)
159 nAttr.setStorable(
False)
162 circle.addAttribute(circle.aInput)
163 circle.addAttribute(circle.aScale)
164 circle.addAttribute(circle.aFrames)
165 circle.addAttribute(circle.aSOutput)
166 circle.addAttribute(circle.aCOutput)
169 circle.attributeAffects(circle.aInput, circle.aSOutput)
170 circle.attributeAffects(circle.aInput, circle.aCOutput)
171 circle.attributeAffects(circle.aScale, circle.aSOutput)
172 circle.attributeAffects(circle.aScale, circle.aCOutput)
173 circle.attributeAffects(circle.aFrames, circle.aSOutput)
174 circle.attributeAffects(circle.aFrames, circle.aCOutput)
178 def initializePlugin(mobject):
179 mplugin = OpenMayaMPx.MFnPlugin(mobject,
"Autodesk",
"1.0",
"Any")
181 mplugin.registerNode( kPluginNodeTypeName, kPluginNodeId, nodeCreator, nodeInitializer )
183 sys.stderr.write(
"Failed to register node: %s" % kPluginNodeTypeName )
188 def uninitializePlugin(mobject):
189 mplugin = OpenMayaMPx.MFnPlugin(mobject)
191 mplugin.deregisterNode( kPluginNodeId )
193 sys.stderr.write(
"Failed to deregister node: %s" % kPluginNodeTypeName )