//- // ========================================================================== // 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. // ========================================================================== //+ // $RCSfile: latticeNoise.h $ $Revision: /main/9 $ #include #include // // Class: latticeNoiseCmd // // Description: // The latticeNoise command creates a new lattice (ffd) deformer. A // latticeNoise node is placed between the deformed lattice shape and the // actual deformer node. This causes the deformed object to wobble as // random continuous noise is added to the pointes of the lattice. // // eg // This causes the currently selected object to be deformed // // latticeNoise; // // This causes the specified geometry to be deformed // // latticeNoise sphereShape1; // class MArgList; class latticeNoiseCmd : public MPxCommand { public: latticeNoiseCmd() {}; virtual ~latticeNoiseCmd() {}; MStatus doIt( const MArgList& args ); static void* creator(); }; // // Class: latticeNoiseNode // // Description: // A "latticeNoise" node adds random noise to lattice geometry over time. // This makes the geometry being deformed by the lattice look like // wobbly jello. // // // Node: latticeNoise // // Attributes: input - input lattice // amplitude - amplitude of the noise // frequency - frequency of the noise // time - the current time // output - the modified lattice // class latticeNoiseNode : public MPxNode { public: latticeNoiseNode() {}; virtual ~latticeNoiseNode() {}; virtual MStatus compute( const MPlug& plug, MDataBlock& data ); static void* creator(); static MStatus initialize(); public: static MObject input; // The input lattice. static MObject amplitude; // The noise amplitude. static MObject frequency; // The noise frequency. static MObject time; // The time. static MObject output; // The output lattice. static MTypeId id; // The IFF type id }; // // Class: noise // // Description: // The noise class is used for generating pseudo-random continuous noise. // The noise values generated are always between 0 and 1. // // The technique used is a simple lattice noise algorithm based upon one // by Ken Perlin. This particular implementation is adapted from // Darwyn Peachey's (Texturing and Modeling: a Procedural Approach, // S. Ebert Editor, 1994). // #define TABLE_SIZE 256 extern const int kTableMask; #define MODPERM(x) permtable[(x)&kTableMask] typedef struct { float x; float y; float z; } pnt; class noise { public: static float atValue( float x ); static float atPoint( float x, float y, float z ); static pnt atPointAndTime( float x, float y, float z, float t ); static void initTable( long seed ); private: static int permtable [256]; static float valueTable1 [256]; static float valueTable2 [256]; static float valueTable3 [256]; static int isInitialized; static float spline( float x, float knot0, float knot1, float knot2, float knot3 ); static float value( int x, int y, int z, float table[] = valueTable1 ); static float value( int x, int y, int z, int t, float table[] = valueTable1 ); static float value( int x, float table[] = valueTable1 ); }; inline float noise::value( int x, int y, int z, int t, float table[] ) { return table[MODPERM( x + MODPERM( y + MODPERM( z + MODPERM( t ) ) ) )]; } inline float noise::value( int x, int y, int z, float table[] ) { return table[MODPERM( x + MODPERM( y + MODPERM( z ) ) )]; } inline float noise::value( int x, float table[] ) { return table[MODPERM( x )]; }