polyobj.h

Go to the documentation of this file.
00001 //**************************************************************************/
00002 // Copyright (c) 1998-2006 Autodesk, Inc.
00003 // All rights reserved.
00004 // 
00005 // These coded instructions, statements, and computer programs contain
00006 // unpublished proprietary information written by Autodesk, Inc., and are
00007 // protected by Federal copyright law. They may not be disclosed to third
00008 // parties or copied or duplicated in any form, in whole or in part, without
00009 // the prior written consent of Autodesk, Inc.
00010 //**************************************************************************/
00011 // FILE:        polyobj.h
00012 // DESCRIPTION: Defines Polygon Mesh Object
00013 // AUTHOR:      Steve Anderson
00014 // HISTORY:     created June 1998
00015 //**************************************************************************/
00016 
00017 #pragma once
00018 
00019 #include "meshlib.h"
00020 #include "mnmath.h"
00021 #include "snap.h"
00022 #include "object.h"
00023 #include "maxtess.h"
00024 
00025 #ifdef POLY_LIB_EXPORTING
00026 #define PolyLibExport __declspec( dllexport )
00027 #else
00028 #define PolyLibExport __declspec( dllimport )
00029 #endif
00030 
00031 #define POLY_MULTI_PROCESSING TRUE
00032 
00033 extern PolyLibExport Class_ID polyObjectClassID;
00034 
00035 #pragma warning(push)
00036 #pragma warning(disable:4239 4100)
00037 
00081 class PolyObject: public GeomObject {
00082 private:
00083     // Displacement approximation stuff:
00084     TessApprox mDispApprox;
00085     bool mSubDivideDisplacement;
00086     bool mDisableDisplacement;
00087     bool mSplitMesh;
00088 
00089 protected:
00090     Interval geomValid;
00091     Interval topoValid;
00092     Interval texmapValid;
00093     Interval selectValid;
00094     Interval vcolorValid;
00095     DWORD validBits; // for the remaining constant channels
00096     PolyLibExport void CopyValidity(PolyObject *fromOb, ChannelMask channels);
00097     //  inherited virtual methods for Reference-management
00098     PolyLibExport RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, PartID& partID, RefMessage message );
00099 public:
00100     MNMesh mm;
00101 
00102     PolyLibExport PolyObject();
00103     PolyLibExport ~PolyObject();
00104 
00105     //  inherited virtual methods:
00106 
00107     // display functions from BaseObject
00108     PolyLibExport virtual bool RequiresSupportForLegacyDisplayMode() const;
00109     PolyLibExport virtual bool UpdateDisplay(
00110         unsigned long renderItemCategories, 
00111         const MaxSDK::Graphics::MaterialRequiredStreams& materialRequiredStreams, 
00112         TimeValue t);
00113 
00114     // From BaseObject
00115     PolyLibExport int HitTest(TimeValue t, INode* inode, int type, int crossing, int flags, IPoint2 *p, ViewExp *vpt);
00116     PolyLibExport int Display(TimeValue t, INode* inode, ViewExp *vpt, int flags);
00117     PolyLibExport void Snap(TimeValue t, INode* inode, SnapInfo *snap, IPoint2 *p, ViewExp *vpt);
00118     PolyLibExport CreateMouseCallBack* GetCreateMouseCallBack() { return NULL; }
00119     
00120     PolyLibExport RefTargetHandle Clone(RemapDir& remap);
00121     
00122 
00123     // From Object           
00124     PolyLibExport ObjectState Eval(TimeValue time);
00125     PolyLibExport Interval ObjectValidity(TimeValue t);
00126     PolyLibExport BOOL HasUVW();
00127     PolyLibExport BOOL HasUVW(int mapChannel);
00128     PolyLibExport Object *CollapseObject();
00129     // get and set the validity interval for the nth channel
00130     PolyLibExport Interval ChannelValidity (TimeValue t, int nchan);
00131     PolyLibExport Interval PartValidity (DWORD partIDs);
00132     PolyLibExport void SetChannelValidity (int i, Interval v);
00133     PolyLibExport void SetPartValidity (DWORD partIDs, Interval v);
00134     PolyLibExport void InvalidateChannels (ChannelMask channels);
00135 
00136     // Convert-to-type validity
00137     PolyLibExport Interval ConvertValidity(TimeValue t);
00138 
00139     // Deformable object procs  
00140     int IsDeformable() { return 1; }  
00141     PolyLibExport int NumPoints();
00142     PolyLibExport Point3 GetPoint(int i);
00143     PolyLibExport void SetPoint(int i, const Point3& p);
00144     PolyLibExport void PointsWereChanged();
00145     PolyLibExport void Deform (Deformer *defProc, int useSel=0);
00146 
00147 // The following members have been added
00148 // in 3ds max 4.2.  If your plugin utilizes this new
00149 // mechanism, be sure that your clients are aware that they
00150 // must run your plugin with 3ds max version 4.2 or higher.
00155     BOOL IsPointSelected (int i) {
00156         if ((i<0) || (i>=mm.numv)) return false;
00157         return mm.v[i].FlagMatch (MN_DEAD|MN_SEL, MN_SEL);
00158     }
00164     float PointSelection (int i) {
00165         if ((i<0) || (i>=mm.numv)) return 0.0f;
00166         if (mm.v[i].GetFlag (MN_DEAD)) return 0.0f;
00167         if (mm.v[i].GetFlag (MN_SEL)) return 1.0f;
00168         float *vssel = mm.getVSelectionWeights();
00169         if (vssel) return vssel[i];
00170         else return 0.0f;
00171     }
00172 
00186     BOOL PolygonCount(TimeValue t, int& numFaces, int& numVerts) {
00187         numFaces = 0;
00188         numVerts = 0;
00189         for (int i=0; i<mm.numf; i++) if (!mm.f[i].GetFlag (MN_DEAD)) numFaces++;
00190         for (int i=0; i<mm.numv; i++) if (!mm.v[i].GetFlag (MN_DEAD)) numVerts++;
00191         return TRUE;
00192     }
00193 
00194     // Mappable object procs
00195     int IsMappable() { return 1; }
00196     int NumMapChannels () { return MAX_MESHMAPS; }
00197     int NumMapsUsed () { return mm.numm; }
00198     PolyLibExport void ApplyUVWMap(int type, float utile, float vtile, float wtile,
00199         int uflip, int vflip, int wflip, int cap,const Matrix3 &tm,int channel=1);
00200 
00201     PolyLibExport void GetDeformBBox(TimeValue t, Box3& box, Matrix3 *tm=NULL,BOOL useSel=FALSE );
00202 
00203     PolyLibExport int CanConvertToType(Class_ID obtype);
00204     PolyLibExport Object* ConvertToType(TimeValue t, Class_ID obtype);
00205     PolyLibExport void FreeChannels(ChannelMask chan);
00206     PolyLibExport Object *MakeShallowCopy(ChannelMask channels);
00207     PolyLibExport void ShallowCopy(Object* fromOb, ChannelMask channels);
00208     PolyLibExport void NewAndCopyChannels(ChannelMask channels);
00209 
00213     PolyLibExport DWORD GetSubselState();
00220     PolyLibExport void SetSubSelState(DWORD s);
00221 
00224     PolyLibExport BOOL CheckObjectIntegrity();
00225 
00226     // From GeomObject
00227     PolyLibExport int IntersectRay(TimeValue t, Ray& ray, float& at, Point3& norm);
00228     PolyLibExport ObjectHandle CreateTriObjRep(TimeValue t);  // obselete, do not use!!!  (Returns NULL.)
00229     PolyLibExport void GetWorldBoundBox(TimeValue t, INode *inode, ViewExp* vpt, Box3& box );
00230     PolyLibExport void GetLocalBoundBox(TimeValue t, INode *inode, ViewExp* vpt, Box3& box );
00231     PolyLibExport Mesh* GetRenderMesh(TimeValue t, INode *inode, View &view,  BOOL& needDelete);
00232 
00233     PolyLibExport void TopologyChanged();
00234 
00236     MNMesh& GetMesh() { return mm; }
00237 
00238     // Animatable methods
00239 
00240     PolyLibExport void DeleteThis();
00241     void FreeCaches() {mm.InvalidateGeomCache(); mm.InvalidateTopoCache(false); }
00242     Class_ID ClassID() { return Class_ID(POLYOBJ_CLASS_ID,0); }
00243     void GetClassName(MSTR& s) { s = MSTR(_M("PolyMeshObject")); }
00244     void NotifyMe(Animatable* subAnim, int message) { UNUSED_PARAM(subAnim); UNUSED_PARAM(message);}
00245     int IsKeyable() { return 0;}
00246     int Update(TimeValue t) { UNUSED_PARAM(t); return 0; }
00247     //BOOL BypassTreeView() { return TRUE; }
00248     // This is the name that will appear in the history browser.
00249     MCHAR *GetObjectName() { return _M("PolyMesh"); }
00250     PolyLibExport void RescaleWorldUnits(float f);
00251 
00252     // IO
00253     PolyLibExport IOResult Save(ISave *isave);
00254     PolyLibExport IOResult Load(ILoad *iload);
00255 
00256     // Displacement mapping parameter access.
00257     // (PolyObjects don't do displacement mapping directly, but they
00258     // pass their settings on to TriObjects.)
00262     PolyLibExport BOOL CanDoDisplacementMapping();
00268     PolyLibExport void SetDisplacementApproxToPreset(int preset);
00269 
00270     // Accessor methods:
00276     void SetDisplacementDisable (bool disable) { mDisableDisplacement = disable; }
00282     void SetDisplacementParameters (TessApprox & params) { mDispApprox = params; }
00287     void SetDisplacementSplit (bool split) { mSplitMesh = split; }
00292     void SetDisplacement (bool displace) { mSubDivideDisplacement = displace; }
00293 
00296     bool GetDisplacementDisable () const { return mDisableDisplacement; }
00299     TessApprox GetDisplacementParameters () const { return mDispApprox; }
00302     bool GetDisplacementSplit () const { return mSplitMesh; }
00304     bool GetDisplacement () const { return mSubDivideDisplacement; }
00305 
00310     TessApprox &DispParams() { return mDispApprox; }
00311 
00313 
00316     PolyLibExport void ReduceDisplayCaches();
00317 
00324     PolyLibExport bool NeedGWCacheRebuilt(GraphicsWindow *gw, Material *ma, int numMat);
00325     
00333     PolyLibExport void BuildGWCache(GraphicsWindow *gw, Material *ma, int numMat,BOOL threaded);    
00334 
00335 
00336 };
00337 
00338 #pragma warning(pop)
00339 
00340 // Regular PolyObject
00342 PolyLibExport ClassDesc* GetPolyObjDescriptor();
00343 
00344 // A new descriptor can be registered to replace the default
00345 // tri object descriptor. This new descriptor will then
00346 // be used to create tri objects.
00347 
00356 PolyLibExport void RegisterEditPolyObjDesc(ClassDesc* desc);
00358 PolyLibExport ClassDesc* GetEditPolyObjDesc(); // Returns default of none have been registered
00359 
00360 // Use this instead of new PolyObject. It will use the registered descriptor
00361 // if one is registered, otherwise you'll get a default poly-object.
00364 PolyLibExport PolyObject *CreateEditablePolyObject();
00365 
00366 // Inter-object conversions:
00367 PolyLibExport void ConvertPolyToPatch (MNMesh & from, PatchMesh & to, DWORD flags=0);
00368 PolyLibExport void ConvertPatchToPoly (PatchMesh & from, MNMesh & to, DWORD flags=0);
00369