triobj.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:        triobj.h
00012 // DESCRIPTION: Defines Triangle Mesh Object
00013 // AUTHOR:      Dan Silva
00014 // HISTORY:     created 9 September 1994
00015 //**************************************************************************/
00016 
00017 #pragma once
00018 
00019 #include "meshlib.h"
00020 #include "snap.h"
00021 #include "maxtess.h"
00022 #include "object.h"
00023 
00024 #define TRI_MULTI_PROCESSING TRUE
00025 
00026 extern CoreExport Class_ID triObjectClassID;
00027 
00028 #pragma warning(push)
00029 #pragma warning(disable:4239)
00030 
00061 class TriObject: public GeomObject {
00062     protected:
00063         Interval geomValid;
00064         Interval topoValid;
00065         Interval texmapValid;
00066         Interval selectValid;
00067         Interval vcolorValid;
00068         Interval gfxdataValid;
00069         ChannelMask validBits; // for the remaining constant channels
00070         CoreExport void CopyValidity(TriObject *fromOb, ChannelMask channels);
00071 #if TRI_MULTI_PROCESSING
00072         static int      refCount;
00073         static HANDLE   defThread;
00074         static HANDLE   defMutex;
00075         static HANDLE   defStartEvent;
00076         static HANDLE   defEndEvent;
00077         friend DWORD WINAPI defFunc(LPVOID ptr);
00078 #endif  
00079         //  inherited virtual methods for Reference-management
00080         CoreExport RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget, PartID& partID, RefMessage message );
00081     public:
00082         Mesh  mesh;
00083         TessApprox mDispApprox;
00084         bool mSubDivideDisplacement;
00085         bool mDisableDisplacement;
00086         bool mSplitMesh;
00087 
00088         CoreExport TriObject();
00089         CoreExport ~TriObject();
00090 
00091         //  inherited virtual methods:
00092 
00093         // display functions from BaseObject
00094         CoreExport virtual bool RequiresSupportForLegacyDisplayMode() const;
00095         CoreExport virtual bool UpdateDisplay(
00096             unsigned long renderItemCategories, 
00097             const MaxSDK::Graphics::MaterialRequiredStreams& materialRequiredStreams, 
00098             TimeValue t);
00099 
00100         // from InterfaceServer
00101         CoreExport virtual BaseInterface* GetInterface(Interface_ID iid);
00102 
00103         //from animatable
00104         CoreExport void* GetInterface(ULONG id);
00105         CoreExport void ReleaseInterface(ULONG id,void *i);
00106 
00107         // From BaseObject
00108         CoreExport int HitTest(TimeValue t, INode* inode, int type, int crossing, int flags, IPoint2 *p, ViewExp *vpt);
00109         CoreExport int Display(TimeValue t, INode* inode, ViewExp *vpt, int flags);
00110         CoreExport void Snap(TimeValue t, INode* inode, SnapInfo *snap, IPoint2 *p, ViewExp *vpt);
00111         CoreExport CreateMouseCallBack* GetCreateMouseCallBack();
00112         CoreExport RefTargetHandle Clone(RemapDir& remap);
00113         
00114         // From Object           
00115         CoreExport ObjectState Eval(TimeValue time);
00116         CoreExport Interval ObjectValidity(TimeValue t);
00117         CoreExport BOOL HasUVW();
00118         CoreExport BOOL HasUVW (int mapChannel);
00119 
00120         // get and set the validity interval for the nth channel
00121         CoreExport Interval ChannelValidity(TimeValue t, int nchan);
00122         CoreExport void SetChannelValidity(int i, Interval v);
00123         CoreExport void InvalidateChannels(ChannelMask channels);
00124 
00125         // Convert-to-type validity
00126         CoreExport Interval ConvertValidity(TimeValue t);
00127 
00128         // Deformable object procs  
00129         int IsDeformable() { return 1; }  
00130         int NumPoints() { return mesh.getNumVerts(); }
00131         Point3 GetPoint(int i) { return mesh.getVert(i); }
00132         void SetPoint(int i, const Point3& p) { mesh.setVert(i,p); }
00133 
00134         CoreExport BOOL IsPointSelected (int i);
00135         CoreExport float PointSelection (int i);
00136 
00137         // Mappable object procs
00138         int IsMappable() { return 1; }
00139         int NumMapChannels () { return MAX_MESHMAPS; }
00140         int NumMapsUsed () { return mesh.getNumMaps(); }
00141         void ApplyUVWMap(int type, float utile, float vtile, float wtile,
00142             int uflip, int vflip, int wflip, int cap,const Matrix3 &tm,int channel=1) {
00143                 mesh.ApplyUVWMap(type,utile,vtile,wtile,uflip,vflip,wflip,cap,tm,channel); }
00144                 
00145         CoreExport BOOL PolygonCount(TimeValue t, int& numFaces, int& numVerts);
00146         void PointsWereChanged(){ mesh.InvalidateGeomCache(); }
00147         CoreExport void GetDeformBBox(TimeValue t, Box3& box, Matrix3 *tm=NULL,BOOL useSel=FALSE );
00148         CoreExport void Deform(Deformer *defProc, int useSel);
00149 
00150         CoreExport int CanConvertToType(Class_ID obtype);
00151         CoreExport Object* ConvertToType(TimeValue t, Class_ID obtype);
00152         CoreExport void FreeChannels(ChannelMask chan);
00153         CoreExport Object *MakeShallowCopy(ChannelMask channels);
00154         CoreExport void ShallowCopy(Object* fromOb, ChannelMask channels);
00155         CoreExport void NewAndCopyChannels(ChannelMask channels);
00156 
00157         CoreExport DWORD GetSubselState();
00158         CoreExport void SetSubSelState(DWORD s);
00159 
00160         CoreExport BOOL CheckObjectIntegrity();
00161 
00162         // From GeomObject
00163         CoreExport int IntersectRay(TimeValue t, Ray& ray, float& at, Point3& norm);
00164         CoreExport ObjectHandle CreateTriObjRep(TimeValue t);  // for rendering, also for deformation       
00165         CoreExport void GetWorldBoundBox(TimeValue t, INode *inode, ViewExp* vpt, Box3& box );
00166         CoreExport void GetLocalBoundBox(TimeValue t, INode *inode, ViewExp* vpt, Box3& box );
00167         CoreExport Mesh* GetRenderMesh(TimeValue t, INode *inode, View &view,  BOOL& needDelete);
00168         
00169         // for displacement mapping
00170         CoreExport BOOL CanDoDisplacementMapping();
00174         CoreExport TessApprox& DisplacmentApprox() { return mDispApprox; }
00179         CoreExport bool& DoSubdivisionDisplacment() { return mSubDivideDisplacement; }
00183         CoreExport bool& SplitMeshForDisplacement() { return mSplitMesh; }
00188         CoreExport void SetDisplacmentApproxToPreset(int preset);
00195         CoreExport void DisableDisplacementMapping(BOOL disable);
00196 
00197         CoreExport void TopologyChanged();
00198 
00203         Mesh& GetMesh() { return mesh; }
00204 
00205         // Animatable methods
00206 
00207         CoreExport void DeleteThis();
00208         void FreeCaches() {mesh.InvalidateGeomCache(); }
00209         Class_ID ClassID() { return Class_ID(TRIOBJ_CLASS_ID,0); }
00210         void GetClassName(MSTR& s) { s = MSTR(_M("TriObject")); }
00211         void NotifyMe(Animatable* subAnim, int message) { UNUSED_PARAM(subAnim); UNUSED_PARAM(message);}
00212         int IsKeyable() { return 0;}
00213         int Update(TimeValue t) { UNUSED_PARAM(t); return 0; }
00214         //BOOL BypassTreeView() { return TRUE; }
00215         // This is the name that will appear in the history browser.
00216         MCHAR *GetObjectName() { return _M("Mesh"); }
00217 
00218         CoreExport void RescaleWorldUnits(float f);
00219 
00220         // IO
00221         CoreExport IOResult Save(ISave *isave);
00222         CoreExport IOResult Load(ILoad *iload);
00223 
00224         // TriObject-specific methods
00226 
00229         CoreExport void ReduceDisplayCaches();
00230         
00237         CoreExport bool NeedGWCacheRebuilt(GraphicsWindow *gw, Material *ma, int numMat);
00238 
00246         CoreExport void BuildGWCache(GraphicsWindow *gw, Material *ma, int numMat,BOOL threaded);
00247     };
00248 
00249 #pragma warning(pop)
00250 
00251 CoreExport void SetDisplacmentPreset(int preset, TessApprox approx);
00252 
00253 // Regular TriObject
00256 CoreExport ClassDesc* GetTriObjDescriptor();
00257 
00258 // A new decsriptor can be registered to replace the default
00259 // tri object descriptor. This new descriptor will then
00260 // be used to create tri objects.
00261 
00268 CoreExport void RegisterEditTriObjDesc(ClassDesc* desc);
00271 CoreExport ClassDesc* GetEditTriObjDesc(); // Returns default of none have been registered
00272 
00273 // Use this instead of new TriObject. It will use the registered descriptor
00274 // if one is registered, otherwise you'll get a default tri-object.
00278 CoreExport TriObject *CreateNewTriObject();
00279 
00280 #include "XTCObject.h"
00281 
00282 const Class_ID kTriObjNormalXTCID = Class_ID(0x730a33d7, 0x27246c55);
00283 
00284 // The purpose of this class is to remove specified Mesh normals
00285 // after modifiers which would invalidate them.
00286 class TriObjectNormalXTC : public XTCObject
00287 {
00288 public:
00289     TriObjectNormalXTC () { }
00290 
00291     Class_ID ExtensionID () { return kTriObjNormalXTCID; }
00292     CoreExport XTCObject *Clone();
00293 
00294     ChannelMask DependsOn () { return PART_TOPO|PART_GEOM; }
00295     ChannelMask ChannelsChanged () { return 0; }
00296 
00297     CoreExport void PreChanChangedNotify (TimeValue t, ModContext &mc, ObjectState *os,
00298         INode *node, Modifier *mod, bool bEndOfPipeline);
00299     CoreExport void PostChanChangedNotify (TimeValue t, ModContext &mc, ObjectState *os,
00300         INode *node, Modifier *mod, bool bEndOfPipeline);
00301     
00302     CoreExport void DeleteThis ();
00303 };
00304 
00305