creating a colorSet within a node

74 views
Skip to first unread message

mePt

unread,
Nov 27, 2008, 12:41:28 AM11/27/08
to python_inside_maya
hi all,

so i'm having an issue while trying to create a new node via maya/
python api that takes an input of a mesh and an out of a mesh (i.e. a
simple through-put)...while in the node, it creates a new colorSet on
the mesh. what could i be doing wrong with creating the colorSet?

thanx!

#----------------------------------------------------------

# get in
inMeshHnd = dataBlock.inputValue( myNode.inputGeometry ) # takes a
mesh input
inMeshData = inMeshHnd.asMesh()

# get out
outMeshHnd = dataBlock.outputValue( myNode.outputGeometry ) # has a
mesh output

# copy in to out
meshDataFn = OpenMaya.MFnMeshData()
newMeshData = meshDataFn.create()
inMeshFn = OpenMaya.MFnMesh( inMeshData )
inMeshFn.copy( inMeshData, newMeshData )

# create colorSet on mesh
colorSetNameString = "myNewColorSet"
inMeshFn.createColorSetWithName( colorSetNameString )


# output
outMeshHnd.setMObject( newMeshData )

mePt

unread,
Nov 27, 2008, 1:05:22 AM11/27/08
to python_inside_maya
to help out, here's an empty shell node (as above--and really does
nothing, but pretty much just copied from the docs). this failes on
the creation of the correct MFnMesh for the colorSet....

##########################


import math, sys

import maya.OpenMaya as OpenMaya
import maya.OpenMayaAnim as OpenMayaAnim
import maya.OpenMayaMPx as OpenMayaMPx

kPluginNodeTypeName = "spTestNode"

testNodeId = OpenMaya.MTypeId(0x00129) # random bad number

#==================================================
# Node definition
class testNode(OpenMayaMPx.MPxNode):
# class variables
inputGeometry = OpenMaya.MObject()
outputGeometry = OpenMaya.MObject()


#==================================================
# constructor
def __init__(self):
OpenMayaMPx.MPxNode.__init__(self)


#==================================================
# compute
def compute ( self, plug, dataBlock ):
if plug == self.outputGeometry:
self.doCalculation( plug, dataBlock )
dataBlock.setClean(plug)
else:
return OpenMaya.kUnknownParameter


#==================================================
# doCalculation
def doCalculation( self, plug, dataBlock ):
inMeshHnd = dataBlock.inputValue( testNode.inputGeometry )
inMeshData = inMeshHnd.asMesh()

outMeshHnd = dataBlock.outputValue( testNode.outputGeometry )


meshDataFn = OpenMaya.MFnMeshData()
newMeshData = meshDataFn.create()
inMeshFn = OpenMaya.MFnMesh( inMeshData )
inMeshFn.copy( inMeshData, newMeshData )


colorSetNameString = "myNewColorSet"
inMeshFn.createColorSetWithName( colorSetNameString )

outMeshHnd.setMObject( newMeshData )


#==================================================
# creator
def nodeCreator():
return OpenMayaMPx.asMPxPtr( testNode() )

#==================================================
# initializer
def nodeInitializer():
tAttr = OpenMaya.MFnTypedAttribute()

#----------------------------------------------
# DEFINE ATTRS

testNode.inputGeometry = tAttr.create( "inputGeometry", "in",
OpenMaya.MFnData.kMesh )

testNode.outputGeometry = tAttr.create( "outputGeometry", "out",
OpenMaya.MFnData.kMesh )
tAttr.setStorable( False )


#-----------------------------------------
# ADD ATTRS

try:
testNode.addAttribute( testNode.outputGeometry )
except:
sys.stderr.write( "Failed to create %s of %s node\n" %
('outputGeometry', kPluginNodeTypeName ) )

try:
testNode.addAttribute( testNode.inputGeometry )
testNode.attributeAffects( testNode.inputGeometry,
testNode.outputGeometry )
except:
sys.stderr.write( "Failed to create %s of %s node\n" %
('inputGeometry', kPluginNodeTypeName ) )


#==================================================
# initialize the script plug-in
def initializePlugin(mobject):
mplugin = OpenMayaMPx.MFnPlugin(mobject, "us", "0.0.1", "Any")
try:
mplugin.registerNode( kPluginNodeTypeName, testNodeId, nodeCreator,
nodeInitializer )
except:
sys.stderr.write( "Failed to register node: %s\n" %
kPluginNodeTypeName )

# uninitialize the script plug-in
def uninitializePlugin(mobject):
mplugin = OpenMayaMPx.MFnPlugin( mobject )
try:
mplugin.deregisterNode( testNodeId )
except:
sys.stderr.write( "Failed to unregister node: %s\n" %
kPluginNodeTypeName )


##########################

and here's some MEL to create the node:

//file -f -new;
//unloadPlugin spTestNode;

file -f -new;

loadPlugin "<yourPathHere>/spTestNode.py";

file -f -new;

string $s[] = `polySphere`;
string $tm = `createNode spTestNode`;

connectAttr -f polySphere1.output spTestNode1.inputGeometry;
connectAttr -f spTestNode1.outputGeometry pSphereShape1.inMesh;

mePt

unread,
Nov 28, 2008, 2:30:04 AM11/28/08
to python_inside_maya
not ideal, but may have a workaround, seems that i can't get the
meshShape from the node as i was thinking (without a nasty cycle) and
use the createColorSet call as initially intended, but if i use
setFaceColor it creates a default colorSet. this actually isn't the
ideal and won't help me if i wanted to generate multiples, but it's a
start, and may be the only current working solution unless someone can
point me in another direction.

?


Reply all
Reply to author
Forward
0 new messages