//- // ========================================================================== // 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. // // ========================================================================== //+ // Description // The torusField node implements an attraction-and-repel field. // // The field repels all objects between itself and repelDistance attribute // and attracts objects greater than attractDistance attribute from itself. // This will eventually result in the objects clustering // in a torus shape around the field. // #include #include #include #include #include #include #include #if defined(OSMac_MachO_) #include #else #include #endif #define McheckErr(stat, msg) \ if ( MS::kSuccess != stat ) \ { \ cerr << msg; \ return MS::kFailure; \ } class torusField: public MPxFieldNode { public: torusField() {}; virtual ~torusField() {}; static void *creator(); static MStatus initialize(); // will compute output force. // virtual MStatus compute( const MPlug& plug, MDataBlock& block ); virtual void draw ( M3dView & view, const MDagPath & path, M3dView::DisplayStyle style, M3dView:: DisplayStatus ); /// virtual MStatus getForceAtPoint(const MVectorArray& point, const MVectorArray& velocity, const MDoubleArray& mass, MVectorArray& force, double deltaTime); /// virtual MStatus iconSizeAndOrigin( GLuint& width, GLuint& height, GLuint& xbo, GLuint& ybo ); /// virtual MStatus iconBitmap(GLubyte* bitmap); // // attributes. // // minimum distance from field at which repel is applied // static MObject aMinDistance; // min distance from field at which the force attracts // static MObject aAttractDistance; // max distance from field at which the force repels. // static MObject aRepelDistance; // drag exerted on the attractRepel force. // static MObject aDrag; // amplitude/magnitude of the swarm force. // static MObject aSwarmAmplitude; // frequency of the swarm force. // static MObject aSwarmFrequency; // phase of the swarm force. // static MObject aSwarmPhase; // Other data members // static MTypeId id; private: // methods to compute output force. // void applyNoMaxDist( MDataBlock& block, const MVectorArray &points, const MVectorArray &velocities, const MDoubleArray &masses, MVectorArray &outputForce ); void applyMaxDist( MDataBlock& block, const MVectorArray &points, const MVectorArray &velocities, const MDoubleArray &masses, MVectorArray &outputForce ); void ownerPosition( MDataBlock& block, MVectorArray &vArray ); MStatus getWorldPosition( MVector &vector ); MStatus getWorldPosition( MDataBlock& block, MVector &vector ); void noiseFunction( double *inputNoise, double *out ); // methods to get attribute value. // double magnitudeValue( MDataBlock& block ); double attenuationValue( MDataBlock& block ); double maxDistanceValue( MDataBlock& block ); bool useMaxDistanceValue( MDataBlock& block ); bool applyPerVertexValue( MDataBlock& block ); // methods to get attribute value of local attributes. // double minDistanceValue( MDataBlock& block ); double attractDistanceValue( MDataBlock& block ); double repelDistanceValue( MDataBlock& block ); double dragValue( MDataBlock& block ); double swarmAmplitudeValue( MDataBlock& block ); double swarmFrequencyValue( MDataBlock& block ); double swarmPhaseValue( MDataBlock& block ); MStatus ownerCentroidValue( MDataBlock& block, MVector &vector ); }; // inlines // inline double torusField::magnitudeValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( mMagnitude, &status ); double value = 0.0; if( status == MS::kSuccess ) value = hValue.asDouble(); return( value ); } inline double torusField::attenuationValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( mAttenuation, &status ); double value = 0.0; if( status == MS::kSuccess ) value = hValue.asDouble(); return( value ); } inline double torusField::maxDistanceValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( mMaxDistance, &status ); double value = 0.0; if( status == MS::kSuccess ) value = hValue.asDouble(); return( value ); } inline bool torusField::useMaxDistanceValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( mUseMaxDistance, &status ); bool value = false; if( status == MS::kSuccess ) value = hValue.asBool(); return( value ); } inline bool torusField::applyPerVertexValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( mApplyPerVertex, &status ); bool value = false; if( status == MS::kSuccess ) value = hValue.asBool(); return( value ); } inline double torusField::minDistanceValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( aMinDistance, &status ); double value = 0.0; if( status == MS::kSuccess ) value = hValue.asDouble(); return( value ); } inline double torusField::attractDistanceValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( aAttractDistance, &status ); double value = 0.0; if( status == MS::kSuccess ) value = hValue.asDouble(); return( value ); } inline double torusField::repelDistanceValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( aRepelDistance, &status ); double value = 0.0; if( status == MS::kSuccess ) value = hValue.asDouble(); return( value ); } inline double torusField::dragValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( aDrag, &status ); double value = 0.0; if( status == MS::kSuccess ) value = hValue.asDouble(); return( value ); } inline double torusField::swarmAmplitudeValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( aSwarmAmplitude, &status ); double value = 0.0; if( status == MS::kSuccess ) value = hValue.asDouble(); return( value ); } inline double torusField::swarmFrequencyValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( aSwarmFrequency, &status ); double value = 0.0; if( status == MS::kSuccess ) value = hValue.asDouble(); return( value ); } inline double torusField::swarmPhaseValue( MDataBlock& block ) { MStatus status; MDataHandle hValue = block.inputValue( aSwarmPhase, &status ); double value = 0.0; if( status == MS::kSuccess ) value = hValue.asDouble(); return( value ); } inline MStatus torusField::ownerCentroidValue(MDataBlock& block,MVector &vector) { MStatus status; MDataHandle hValueX = block.inputValue( mOwnerCentroidX, &status ); MDataHandle hValueY = block.inputValue( mOwnerCentroidY, &status ); MDataHandle hValueZ = block.inputValue( mOwnerCentroidZ, &status ); if( status == MS::kSuccess ) { vector[0] = hValueX.asDouble(); vector[1] = hValueY.asDouble(); vector[2] = hValueZ.asDouble(); } return( status ); }