//- // ========================================================================== // Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files contain unpublished // information proprietary to Autodesk, Inc. ("Autodesk") and/or its // licensors, which is protected by U.S. and Canadian federal copyright // law and by international treaties. // // The Data is provided for use exclusively by You. You have the right // to use, modify, and incorporate this Data into other products for // purposes authorized by the Autodesk software license agreement, // without fee. // // The copyright notices in the Software and this entire statement, // including the above license grant, this restriction and the // following disclaimer, must be included in all copies of the // Software, in whole or in part, and all derivative works of // the Software, unless such copies or derivative works are solely // in the form of machine-executable object code generated by a // source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. // AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED // WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF // NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR // PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR // TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS // BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL, // DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK // AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY // OR PROBABILITY OF SUCH DAMAGES. // // ========================================================================== //+ #include #include #include #include #include #include #include #include #include #include class myComp : public MPxNode { public: myComp(); virtual ~myComp(); virtual MStatus compute( const MPlug&, MDataBlock& ); virtual void postConstructor(); static void * creator(); static MStatus initialize(); // Id tag for use with binary file format static MTypeId id; private: // Input attributes static MObject aForegroundColor; static MObject aBackgroundColor; static MObject aBackColor; static MObject aMask; // Output attributes static MObject aOutColor; static MObject aOutAlpha; }; // Static data MTypeId myComp::id( 0x8100c ); // Attributes MObject myComp::aForegroundColor; MObject myComp::aBackgroundColor; MObject myComp::aBackColor; MObject myComp::aMask; MObject myComp::aOutColor; MObject myComp::aOutAlpha; #define MAKE_INPUT(attr) \ CHECK_MSTATUS( attr.setKeyable(true)); \ CHECK_MSTATUS( attr.setStorable(true)); \ CHECK_MSTATUS( attr.setReadable(true)); \ CHECK_MSTATUS( attr.setWritable(true)); #define MAKE_OUTPUT(attr) \ CHECK_MSTATUS( attr.setKeyable(false)); \ CHECK_MSTATUS( attr.setStorable(false)); \ CHECK_MSTATUS( attr.setReadable(true)); \ CHECK_MSTATUS( attr.setWritable(false)); void myComp::postConstructor( ) { setMPSafe(true); } myComp::myComp() { } myComp::~myComp() { } // creates an instance of the node void * myComp::creator() { return new myComp(); } // initializes attribute information MStatus myComp::initialize() { MFnNumericAttribute nAttr; // Create input attributes aForegroundColor = nAttr.createColor("foreground", "fg"); MAKE_INPUT(nAttr); aBackgroundColor = nAttr.createColor("background", "bg"); MAKE_INPUT(nAttr); CHECK_MSTATUS( nAttr.setDefault(1., 1., 1.)); aBackColor = nAttr.createColor("backColor", "bk"); MAKE_INPUT(nAttr); CHECK_MSTATUS( nAttr.setDefault(1., 1., 1.)); aMask = nAttr.create( "mask", "ms", MFnNumericData::kFloat); CHECK_MSTATUS( nAttr.setMin(0.f)); CHECK_MSTATUS( nAttr.setMax(1.f)); MAKE_INPUT(nAttr); // Create output attributes here aOutColor = nAttr.createColor("outColor", "oc"); MAKE_OUTPUT(nAttr); aOutAlpha = nAttr.create( "outAlpha", "oa", MFnNumericData::kFloat); MAKE_OUTPUT(nAttr); // Add the attributes here CHECK_MSTATUS( addAttribute(aForegroundColor) ); CHECK_MSTATUS( addAttribute(aBackgroundColor) ); CHECK_MSTATUS( addAttribute(aBackColor) ); CHECK_MSTATUS( addAttribute(aMask) ); CHECK_MSTATUS( addAttribute(aOutColor) ); CHECK_MSTATUS( addAttribute(aOutAlpha) ); // all input affect the output color and alpha CHECK_MSTATUS( attributeAffects(aForegroundColor, aOutColor) ); CHECK_MSTATUS( attributeAffects(aForegroundColor, aOutAlpha) ); CHECK_MSTATUS( attributeAffects(aBackgroundColor, aOutColor) ); CHECK_MSTATUS( attributeAffects(aBackgroundColor, aOutAlpha) ); CHECK_MSTATUS( attributeAffects(aBackColor, aOutColor) ); CHECK_MSTATUS( attributeAffects(aBackColor, aOutAlpha) ); CHECK_MSTATUS( attributeAffects(aMask, aOutColor) ); CHECK_MSTATUS( attributeAffects(aMask, aOutAlpha) ); return MS::kSuccess; } // // This function gets called by Maya to evaluate the texture. MStatus myComp::compute(const MPlug& plug, MDataBlock& block) { // outColor or individial R, G, B channel if((plug != aOutColor) && (plug.parent() != aOutColor) && (plug != aOutAlpha)) return MS::kUnknownParameter; MFloatVector resultColor; MFloatVector& fore = block.inputValue( aForegroundColor ).asFloatVector(); MFloatVector& back = block.inputValue( aBackgroundColor ).asFloatVector(); MFloatVector& bclr = block.inputValue( aBackColor ).asFloatVector(); float& alpha = block.inputValue( aMask ).asFloat(); if ( alpha > 0.99999f ) alpha = 1.f; else if ( alpha < 0.00001 ) alpha = 0.f; resultColor = fore + ((bclr - back) * (1.0f - alpha)); // normalize output color if (resultColor[0] < 0.f ) resultColor[0] = 0.f; if (resultColor[1] < 0.f ) resultColor[1] = 0.f; if (resultColor[2] < 0.f ) resultColor[2] = 0.f; if (resultColor[0] > 1.f ) resultColor[0] = 1.f; if (resultColor[1] > 1.f ) resultColor[1] = 1.f; if (resultColor[2] > 1.f ) resultColor[2] = 1.f; // set ouput color attribute MDataHandle outColorHandle = block.outputValue( aOutColor ); MFloatVector& outColor = outColorHandle.asFloatVector(); outColor = resultColor; outColorHandle.setClean(); MDataHandle outAlphaHandle = block.outputValue( aOutAlpha ); float& outAlpha = outAlphaHandle.asFloat(); outAlpha = ( resultColor.x + resultColor.y + resultColor.z ) / 3.0f; outAlphaHandle.setClean(); return MS::kSuccess; } MStatus initializePlugin( MObject obj ) { const MString UserClassify( "utility/color" ); MFnPlugin plugin( obj, PLUGIN_COMPANY, "4.5", "Any"); CHECK_MSTATUS( plugin.registerNode( "composite", myComp::id, &myComp::creator, &myComp::initialize, MPxNode::kDependNode, &UserClassify ) ); return MS::kSuccess; } MStatus uninitializePlugin( MObject obj ) { MFnPlugin plugin( obj ); CHECK_MSTATUS( plugin.deregisterNode( myComp::id ) ); return MS::kSuccess; }