-
Notifications
You must be signed in to change notification settings - Fork 0
/
cColorDeformer.py
94 lines (76 loc) · 2.91 KB
/
cColorDeformer.py
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
# import math
import sys
# import maya.mel as mel
import maya.OpenMaya as OpenMaya
import maya.OpenMayaMPx as OpenMayaMPx
# import maya.OpenMayaAnim as OpenMayaAnim
kPluginNodeTypeName = "cColorDeformer"
kPluginNodeId = OpenMaya.MTypeId(0x96427)
class cColorDeformer(OpenMayaMPx.MPxDeformerNode):
'''
Color Collsion Deformer.
Inherits OpenMaya.MPxDeformerNode
'''
def __init__(self):
'''
Initializer.
'''
OpenMayaMPx.MPxDeformerNode.__init__(self)
def deform(self, dataBlock, geoIterator, matrix, geometryIndex):
'''
Compute function for the node. Calculates all dat maths.
@param dataBlock - Datablock that holds all data.
@param geoIterator - Current geoIterator that is affected.
@param matrix - Current matrix that is affected.
@param geometryIndex - Current geometry index that is affected.
'''
input = OpenMayaMPx.cvar.MPxDeformerNode_input
# 1. Attach a handle to input Array Attribute.
dataHandleInputArray = dataBlock.outputArrayValue(input)
# 2. Jump to particular element
dataHandleInputArray.jumpToElement(geometryIndex)
# 3. Attach a handle to specific data block
dataHandleInputElement = dataHandleInputArray.outputValue()
# 4. Reach to the child - inputGeom
inputGeom = OpenMayaMPx.cvar.MPxDeformerNode_inputGeom
dataHandleInputGeom = dataHandleInputElement.child(inputGeom)
inMesh = dataHandleInputGeom.asMesh()
#Envelope
envelope = OpenMayaMPx.cvar.MPxDeformerNode_envelope
dataHandleEnvelope = dataBlock.inputValue(envelope)
envelopeValue = dataHandleEnvelope.asFloat()
def nodeCreator():
return OpenMayaMPx.asMPxPtr(cColorDeformer())
def nodeInitializer():
'''
Initializes attributes for the node.
'''
outputGeom = OpenMayaMPx.cvar.MPxDeformerNode_outputGeom
def initializePlugin(mObject):
'''
Initializes the plugin in maya.
@param - mObject that maya uses to make the node.
'''
mplugin = OpenMayaMPx.MFnPlugin(mObject)
try:
mplugin.registerNode(kPluginNodeTypeName,
kPluginNodeId,
nodeCreator,
nodeInitializer,
OpenMayaMPx.MPxNode.kDeformerNode)
sys.stderr.write("Registered node: %s\n" % kPluginNodeTypeName)
except:
sys.stderr.write("Failed to register node: %s\n" % kPluginNodeTypeName)
raise
def uninitializePlugin(mObject):
'''
Uninitializes our plugin in maya.
@param - mObject that maya uses to make the node.
'''
mplugin = OpenMayaMPx.MFnPlugin(mObject)
try:
mplugin.deregisterNode(kPluginNodeId)
sys.stderr.write("Deregistered node: %s\n" % kPluginNodeTypeName)
except:
sys.stderr.write("Failed to register node: %s\n" % kPluginNodeTypeName)
raise