-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassThroughNode.cpp
More file actions
184 lines (143 loc) · 4.53 KB
/
passThroughNode.cpp
File metadata and controls
184 lines (143 loc) · 4.53 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
//-
// ==========================================================================
// Copyright 1995,2006,2008 Autodesk, Inc. All rights reserved.
//
// Use of this software is subject to the terms of the Autodesk
// license agreement provided at the time of installation or download,
// or which otherwise accompanies this software in either electronic
// or hard copy form.
// ==========================================================================
//+
////////////////////////////////////////////////////////////////////////
// DESCRIPTION:
//
// Produces the dependency graph node "passthrough".
//
// Setup scene
/*
import maya.cmds as mc
passthrough_node = mc.createNode('passthrough')
color_in_node = mc.createNode('colorConstant')
color_out_node = mc.createNode('colorConstant')
mc.connectAttr(f'{color_in_node}.outColor', f'{passthrough_node}.palette[0].color0', force=True)
mc.connectAttr(f'{passthrough_node}.palette[0].color0', f'{color_out_node}.inColor', force=True)
*/
////////////////////////////////////////////////////////////////////////
#include <maya/MPxNode.h>
#include <maya/MString.h>
#include <maya/MTypeId.h>
#include <maya/MPlug.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MFnCompoundAttribute.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnPlugin.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
//#include <string>
#include <maya/MIOStream.h>
class passthrough : public MPxNode
{
public:
passthrough() {};
~passthrough() override {};
MStatus compute( const MPlug& plug, MDataBlock& data ) override;
static void* creator();
static MStatus initialize();
static MTypeId id;
static MObject aTouchColor0;
static MObject aColor1;
static MObject aColor2;
static MObject aAlpha;
static MObject aPalette;
MStatus setDependentsDirty(const MPlug& plugBeingDirtied, MPlugArray& affectedPlugs);
};
MTypeId passthrough::id( 0x80013 );
MObject passthrough::aTouchColor0 = {};
MObject passthrough::aColor1 = {};
MObject passthrough::aColor2 = {};
MObject passthrough::aAlpha = {};
MObject passthrough::aPalette = {};
void* passthrough::creator()
{
return new passthrough;
}
#define MAKE_IO(attr) \
CHECK_MSTATUS(attr.setKeyable(true)); \
CHECK_MSTATUS(attr.setStorable(true)); \
CHECK_MSTATUS(attr.setReadable(true)); \
CHECK_MSTATUS(attr.setWritable(true));
MStatus passthrough::initialize()
{
MFnNumericAttribute numericFn;
MFnTypedAttribute typedFn;
MFnCompoundAttribute compoundFn;
MStatus stat;
aTouchColor0 = numericFn.createColor("color0", "c0");
MAKE_IO(numericFn);
CHECK_MSTATUS(numericFn.setDefault(.0, .25, .75)); // Blue
aColor1 = numericFn.createColor("color1", "c1");
MAKE_IO(numericFn);
CHECK_MSTATUS(numericFn.setDefault(.75, .03, .0)); // Red
aColor2 = numericFn.createColor("color2", "c2");
MAKE_IO(numericFn);
CHECK_MSTATUS(numericFn.setDefault(.9, .9, .0)); // Yellow
aAlpha = numericFn.create("alpha", "alph", MFnNumericData::kFloat, .50f);
numericFn.setMin(0.0f);
numericFn.setMax(1.0f);
MAKE_IO(numericFn);
aPalette = compoundFn.create("palette", "palette");
MAKE_IO(compoundFn);
compoundFn.setArray(true);
compoundFn.addChild(aTouchColor0);
compoundFn.addChild(aColor1);
compoundFn.addChild(aColor2);
compoundFn.addChild(aAlpha);
compoundFn.setUsesArrayDataBuilder(true);
addAttribute(aPalette);
return MS::kSuccess;
}
MStatus passthrough::compute( const MPlug& plug, MDataBlock& block )
{
MStatus stat;
// naughty case, call getValue to force eval
if (plug.isCompound()) {
//MGlobal::displayInfo("Palette compute");
//MGlobal::displayInfo(plug.name());
plug.isDefaultValue(true);
}
// eval error case, call inputValue to force eval
/*
if (plug.attribute() == aPalette) {
MDataHandle inputValue = block.inputValue(aPalette);
MArrayDataHandle adh = block.inputArrayValue(aPalette);
}
*/
return MS::kSuccess;
}
MStatus passthrough::setDependentsDirty(const MPlug& plugBeingDirtied, MPlugArray& affectedPlugs) {
// Stub for dirty
return MS::kSuccess;
}
MStatus initializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj, PLUGIN_COMPANY, "3.0", "Any");
status = plugin.registerNode( "passthrough", passthrough::id,
passthrough::creator, passthrough::initialize );
if (!status) {
status.perror("registerNode");
return status;
}
return status;
}
MStatus uninitializePlugin( MObject obj)
{
MStatus status;
MFnPlugin plugin( obj );
status = plugin.deregisterNode( passthrough::id );
if (!status) {
status.perror("deregisterNode");
return status;
}
return status;
}