//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ #include #include #include #include #include #include #include #include #include #include #include // // DESCRIPTION: /////////////////////////////////////////////////////// class DispNode : public MPxNode { public: DispNode(); virtual ~DispNode(); virtual MStatus compute( const MPlug&, MDataBlock& ); virtual void postConstructor(); static void * creator(); static MStatus initialize(); static MTypeId id; private: static MObject aColor; static MObject aInputValue; static MObject aOutColor; static MObject aOutTransparency; static MObject aOutDisplacement; }; MTypeId DispNode::id( 0x81011 ); MObject DispNode::aColor; MObject DispNode::aInputValue; MObject DispNode::aOutColor; MObject DispNode::aOutTransparency; MObject DispNode::aOutDisplacement; void DispNode::postConstructor( ) { setMPSafe(true); } // // DESCRIPTION: /////////////////////////////////////////////////////// DispNode::DispNode() { } // // DESCRIPTION: /////////////////////////////////////////////////////// DispNode::~DispNode() { } // // DESCRIPTION: /////////////////////////////////////////////////////// void* DispNode::creator() { return new DispNode(); } // // DESCRIPTION: /////////////////////////////////////////////////////// MStatus DispNode::initialize() { MFnNumericAttribute nAttr; // Inputs aColor = nAttr.createColor( "color", "c" ); CHECK_MSTATUS(nAttr.setKeyable(true)); CHECK_MSTATUS(nAttr.setStorable(true)); CHECK_MSTATUS(nAttr.setDefault(1.0f, 1.0f, 1.0f)); aInputValue = nAttr.create( "factor", "f", MFnNumericData::kFloat); CHECK_MSTATUS(nAttr.setKeyable(true)); CHECK_MSTATUS(nAttr.setStorable(true)); CHECK_MSTATUS(nAttr.setDefault(1.0f)); // Outputs aOutColor = nAttr.createColor( "outColor", "oc" ); CHECK_MSTATUS(nAttr.setStorable(false)); CHECK_MSTATUS(nAttr.setHidden(false)); CHECK_MSTATUS(nAttr.setReadable(true)); CHECK_MSTATUS(nAttr.setWritable(false)); aOutTransparency = nAttr.createColor( "outTransparency", "ot" ); CHECK_MSTATUS(nAttr.setStorable(false)); CHECK_MSTATUS(nAttr.setHidden(false)); CHECK_MSTATUS(nAttr.setReadable(true)); CHECK_MSTATUS(nAttr.setWritable(false)); aOutDisplacement = nAttr.create( "displacement", "od", MFnNumericData::kFloat); CHECK_MSTATUS(nAttr.setStorable(false)); CHECK_MSTATUS(nAttr.setHidden(false)); CHECK_MSTATUS(nAttr.setReadable(true)); CHECK_MSTATUS(nAttr.setWritable(false)); CHECK_MSTATUS(addAttribute(aColor)); CHECK_MSTATUS(addAttribute(aInputValue)); CHECK_MSTATUS(addAttribute(aOutColor)); CHECK_MSTATUS(addAttribute(aOutTransparency)); CHECK_MSTATUS(addAttribute(aOutDisplacement)); CHECK_MSTATUS(attributeAffects (aColor, aOutColor)); CHECK_MSTATUS(attributeAffects (aColor, aOutDisplacement)); return MS::kSuccess; } // // DESCRIPTION: /////////////////////////////////////////////////////// MStatus DispNode::compute( const MPlug& plug, MDataBlock& block ) { if ((plug == aOutColor) || (plug.parent() == aOutColor) || (plug == aOutDisplacement)) { MFloatVector resultColor(0.0,0.0,0.0); MFloatVector& InputColor = block.inputValue( aColor ).asFloatVector(); float MultValue = block.inputValue( aInputValue ).asFloat(); resultColor = InputColor; float scalar = resultColor[0] + resultColor[1] + resultColor[2]; if (scalar != 0.0) { scalar /= 3.0; scalar *= MultValue; } // set ouput color attribute MDataHandle outColorHandle = block.outputValue( aOutColor ); MFloatVector& outColor = outColorHandle.asFloatVector(); outColor = resultColor; outColorHandle.setClean(); MDataHandle outDispHandle = block.outputValue( aOutDisplacement ); float& outDisp = outDispHandle.asFloat(); outDisp = scalar; outDispHandle.setClean( ); } else if ((plug == aOutTransparency) || (plug.parent() == aOutTransparency)) { // set output transparency to be opaque MFloatVector transparency(0.0,0.0,0.0); MDataHandle outTransHandle = block.outputValue( aOutTransparency ); MFloatVector& outTrans = outTransHandle.asFloatVector(); outTrans = transparency; outTransHandle.setClean( ); } else return MS::kUnknownParameter; return MS::kSuccess; } // // DESCRIPTION: /////////////////////////////////////////////////////// MStatus initializePlugin( MObject obj ) { const MString UserClassify( "shader/displacement" ); MFnPlugin plugin( obj, "Alias", "4.5", "Any"); CHECK_MSTATUS( plugin.registerNode( "dispNodeExample", DispNode::id, DispNode::creator, DispNode::initialize, MPxNode::kDependNode, &UserClassify ) ); return MS::kSuccess; } // // DESCRIPTION: /////////////////////////////////////////////////////// MStatus uninitializePlugin( MObject obj ) { MFnPlugin plugin( obj ); CHECK_MSTATUS( plugin.deregisterNode( DispNode::id ) ); return MS::kSuccess; }