simpobj.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: SimpObj.h
00004 
00005     DESCRIPTION:  A base class for procedural objects that fit into
00006                   a standard form.
00007 
00008     CREATED BY: Rolf Berteig
00009 
00010     HISTORY: created 10/10/95
00011 
00012  *> Copyright (c) 1994, All Rights Reserved.
00013  **********************************************************************/
00014 
00015 #pragma once
00016 
00017 #include "object.h"
00018 #include "particle.h"
00019 
00052 #pragma warning(push)
00053 #pragma warning(disable:4100)
00054 class SimpleObject : public GeomObject {
00055     public:
00056         IParamBlock* pblock;
00057         Mesh mesh;
00058         Interval ivalid;
00059 
00060         BOOL suspendSnap;   // If TRUE, no snapping will occur
00061         
00062         static SimpleObject* editOb;
00063 
00064         CoreExport SimpleObject();
00065         CoreExport ~SimpleObject();
00066         
00067         CoreExport void UpdateMesh(TimeValue t);                
00068         CoreExport void GetBBox(TimeValue t, Matrix3& tm, Box3& box );      
00069         void MeshInvalid() {ivalid.SetEmpty();}
00070 
00071         // display functions from BaseObject
00072         CoreExport virtual bool RequiresSupportForLegacyDisplayMode() const;
00073         CoreExport virtual bool UpdateDisplay(
00074             unsigned long renderItemCategories, 
00075             const MaxSDK::Graphics::MaterialRequiredStreams& materialRequiredStreams, 
00076             TimeValue t);
00077 
00078         // From BaseObject
00079         CoreExport void BeginEditParams( IObjParam  *ip, ULONG flags,Animatable *prev);
00080         CoreExport void EndEditParams( IObjParam *ip, ULONG flags,Animatable *next);
00081         CoreExport int HitTest(TimeValue t, INode* inode, int type, int crossing, int flags, IPoint2 *p, ViewExp *vpt);
00082         CoreExport void Snap(TimeValue t, INode* inode, SnapInfo *snap, IPoint2 *p, ViewExp *vpt);
00083         CoreExport int Display(TimeValue t, INode* inode, ViewExp *vpt, int flags);     
00084         CoreExport IParamArray *GetParamBlock();
00085         CoreExport int GetParamBlockIndex(int id);
00086 
00087         // From Object
00088         CoreExport ObjectState Eval(TimeValue time);
00089         void InitNodeName(MSTR& s) {s = GetObjectName();}
00090         CoreExport Interval ObjectValidity(TimeValue t);
00091         CoreExport int CanConvertToType(Class_ID obtype);
00092         CoreExport Object* ConvertToType(TimeValue t, Class_ID obtype);     
00093         CoreExport BOOL PolygonCount(TimeValue t, int& numFaces, int& numVerts);
00094 
00095         // From GeomObject
00096         CoreExport int IntersectRay(TimeValue t, Ray& ray, float& at, Point3& norm);        
00097         CoreExport void GetWorldBoundBox(TimeValue t, INode* inode, ViewExp* vpt, Box3& box );
00098         CoreExport void GetLocalBoundBox(TimeValue t, INode* inode, ViewExp* vpt, Box3& box );
00099         CoreExport void GetDeformBBox(TimeValue t, Box3& box, Matrix3 *tm, BOOL useSel );
00100         CoreExport Mesh* GetRenderMesh(TimeValue t, INode *inode, View &view, BOOL& needDelete);
00101 
00102         // Animatable methods
00103         CoreExport void FreeCaches();       
00104         void GetClassName(MSTR& s) {s = GetObjectName();}       
00105         int NumSubs() { return 1; }  
00106         Animatable* SubAnim(int i) { return (Animatable*)pblock; }
00107         CoreExport MSTR SubAnimName(int i);
00108 
00109         // from InterfaceServer
00110         CoreExport virtual BaseInterface* GetInterface(Interface_ID iid);
00111         CoreExport void* GetInterface(ULONG id);
00112 
00113         // From ref
00114         int NumRefs() {return 1;}
00115         RefTargetHandle GetReference(int i) {return (RefTargetHandle)pblock;}
00116     protected:
00117         virtual void SetReference(int i, RefTargetHandle rtarg) {pblock=(IParamBlock*)rtarg;}       
00118     public:
00119         CoreExport RefResult NotifyRefChanged(Interval changeInt,RefTargetHandle hTarget, 
00120            PartID& partID, RefMessage message);
00121         
00122 
00123         // --- These must be implemented by the derived class ----------------
00130         virtual void BuildMesh(TimeValue t)=0;
00143         virtual BOOL OKtoDisplay(TimeValue t) {return TRUE;}
00173         virtual void InvalidateUI() {}
00185         virtual ParamDimension* GetParameterDim(int pbIndex) {return defaultDim;}
00193         virtual MSTR GetParameterName(int pbIndex) {return MSTR(_M("Parameter"));}      
00194     };
00195 
00196 // ParamBlock2 version added JBW 9/11/98
00197 
00198 class IParamBlock2;
00212 class SimpleObject2 : public SimpleObject
00213 {
00214 public:
00215     IParamBlock2* pblock2;
00216     SimpleObject2() { pblock2 = NULL; }
00217     // From ref
00218     RefTargetHandle GetReference(int i) {return (RefTargetHandle)pblock;}
00219 protected:
00220     virtual void SetReference(int i, RefTargetHandle rtarg)
00221     {
00222         pblock2 = (IParamBlock2*)rtarg; 
00223         SimpleObject::SetReference(i, rtarg);
00224     }
00225 };
00226 
00247 class SimpleWSMObject : public WSMObject {
00248     public:
00249         IParamBlock *pblock;
00250         Mesh mesh;
00251         Interval ivalid;
00252         
00253         static SimpleWSMObject *editOb;
00254 
00255         CoreExport SimpleWSMObject();
00256         CoreExport ~SimpleWSMObject();
00257         
00258         CoreExport void UpdateMesh(TimeValue t);                
00259         CoreExport void GetBBox(TimeValue t, Matrix3& tm, Box3& box );      
00260         void MeshInvalid() {ivalid.SetEmpty();}
00261         
00262         // From BaseObject
00263         CoreExport void BeginEditParams( IObjParam  *ip, ULONG flags,Animatable *prev);
00264         CoreExport void EndEditParams( IObjParam *ip, ULONG flags,Animatable *next);
00265         CoreExport int HitTest(TimeValue t, INode* inode, int type, int crossing, int flags, IPoint2 *p, ViewExp *vpt);
00266         CoreExport void Snap(TimeValue t, INode* inode, SnapInfo *snap, IPoint2 *p, ViewExp *vpt);
00267         CoreExport int Display(TimeValue t, INode* inode, ViewExp *vpt, int flags);     
00268         CoreExport IParamArray *GetParamBlock();
00269         CoreExport int GetParamBlockIndex(int id);
00270 
00271         // From Object
00272         int DoOwnSelectHilite() {return TRUE;}
00273         CoreExport ObjectState Eval(TimeValue time);
00274         void InitNodeName(MSTR& s) {s = GetObjectName();}
00275         CoreExport Interval ObjectValidity(TimeValue t);        
00276         CoreExport void GetWorldBoundBox(TimeValue t, INode* inode, ViewExp* vpt, Box3& box );
00277         CoreExport void GetLocalBoundBox(TimeValue t, INode* inode, ViewExp* vpt, Box3& box );
00278         CoreExport void GetDeformBBox(TimeValue t, Box3& box, Matrix3 *tm, BOOL useSel );
00279         int IsRenderable() {return FALSE;}
00280 
00281         // Animatable methods
00282         CoreExport void FreeCaches();       
00283         void GetClassName(MSTR& s) {s = GetObjectName();}       
00284         int NumSubs() { return 1; }  
00285         Animatable* SubAnim(int i) { return (Animatable*)pblock; }
00286         CoreExport MSTR SubAnimName(int i);
00287 
00288         // From ref
00289         int NumRefs() {return 1;}
00290         RefTargetHandle GetReference(int i) {return (RefTargetHandle)pblock;}
00291 protected:
00292         virtual void SetReference(int i, RefTargetHandle rtarg) {pblock=(IParamBlock*)rtarg;}       
00293 public:
00294         CoreExport RefResult NotifyRefChanged(Interval changeInt,RefTargetHandle hTarget, 
00295            PartID& partID, RefMessage message);
00296         
00297 
00298         // --- These must be implemented by the derived class ----------------
00304         virtual void BuildMesh(TimeValue t)=0;
00317         virtual BOOL OKtoDisplay(TimeValue t) {return TRUE;}
00342         virtual void InvalidateUI() {}
00354         virtual ParamDimension *GetParameterDim(int pbIndex) {return defaultDim;}
00362         virtual MSTR GetParameterName(int pbIndex) {return MSTR(_M("Parameter"));}      
00363     };
00364 
00365 class SimpleWSMObject2 : public SimpleWSMObject
00366 {
00367 public:
00368     IParamBlock2* pblock2;
00369     SimpleWSMObject2() { pblock2 = NULL; }
00370     // From ref, upcast
00371     RefTargetHandle GetReference(int i) {return (RefTargetHandle)pblock;}
00372 protected:
00373     virtual void SetReference(int i, RefTargetHandle rtarg)
00374     {
00375         pblock2 = (IParamBlock2*)rtarg; 
00376         SimpleWSMObject::SetReference(i, rtarg);
00377     }
00378 };
00379 
00380 class SimpleMod;
00381 class IParamMap;
00382 
00383 // Make a WSM out of an OSM
00384 class SimpleOSMToWSMObject : public SimpleWSMObject {
00385     public:
00386         SimpleMod *mod;
00387         static IParamMap *pmapParam;
00388 
00390         CoreExport SimpleOSMToWSMObject();
00395         CoreExport SimpleOSMToWSMObject(SimpleMod *m);
00396 
00397         int NumRefs() {return 2;}
00398         CoreExport RefTargetHandle GetReference(int i);
00399 protected:
00400         CoreExport virtual void SetReference(int i, RefTargetHandle rtarg);
00401 public:
00402         CoreExport IOResult Load(ILoad *iload);
00403 
00404         int NumSubs() {return 2;}  
00405         CoreExport Animatable* SubAnim(int i);
00406         CoreExport MSTR SubAnimName(int i);
00407 
00408         CoreExport void BuildMesh(TimeValue t);
00409         CoreExport Modifier *CreateWSMMod(INode *node);
00410 
00411         CoreExport CreateMouseCallBack* GetCreateMouseCallBack();
00412         CoreExport void BeginEditParams( IObjParam  *ip, ULONG flags,Animatable *prev);
00413         CoreExport void EndEditParams( IObjParam *ip, ULONG flags,Animatable *next);
00414 
00415         CoreExport ParamDimension *GetParameterDim(int pbIndex) {return stdWorldDim;}
00416         CoreExport MSTR GetParameterName(int pbIndex);
00417 
00422         CoreExport Deformer &GetDecayDeformer(TimeValue t,Deformer &mdef,Point3 origin,Interval &iv);
00423 
00424         CoreExport SimpleOSMToWSMObject* SimpleOSMToWSMClone(SimpleOSMToWSMObject *from,RemapDir& remap);
00425 
00426         CoreExport void InvalidateUI();
00427     };
00428 
00429 #define PB_OSMTOWSM_LENGTH  0
00430 #define PB_OSMTOWSM_WIDTH   1
00431 #define PB_OSMTOWSM_HEIGHT  2
00432 #define PB_OSMTOWSM_DECAY   3
00433 
00434 
00476 class SimpleParticle : public ParticleObject {
00477     public:
00478         IParamBlock *pblock;
00479         ParticleSys parts;
00480         TimeValue tvalid;
00481         BOOL valid;
00482         Tab<ForceField*> fields;        
00483         Tab<CollisionObject*> cobjs;
00484         Mesh mesh;
00485         Interval mvalid;
00486         MetaParticle metap;
00487         
00488         CoreExport static SimpleParticle *editOb;
00489         CoreExport static IObjParam *ip;
00490 
00494         CoreExport SimpleParticle();
00495         CoreExport ~SimpleParticle();
00496                 
00497         CoreExport void Update(TimeValue t,INode *node=NULL);
00498         CoreExport void UpdateMesh(TimeValue t);
00499         CoreExport void GetBBox(TimeValue t, Matrix3& tm, Box3& box);       
00500         void MeshInvalid() {mvalid.SetEmpty();}
00501         void ParticleInvalid() {valid=FALSE;}
00502 
00503         // From BaseObject
00504         CoreExport void BeginEditParams( IObjParam  *ip, ULONG flags,Animatable *prev);
00505         CoreExport void EndEditParams( IObjParam *ip, ULONG flags,Animatable *next);
00506         CoreExport int HitTest(TimeValue t, INode* inode, int type, int crossing, int flags, IPoint2 *p, ViewExp *vpt);     
00507         CoreExport int Display(TimeValue t, INode* inode, ViewExp *vpt, int flags);     
00508         CoreExport IParamArray *GetParamBlock();
00509         CoreExport int GetParamBlockIndex(int id);
00510 
00511         // From Object
00512         int DoOwnSelectHilite() {return TRUE;}
00513         CoreExport ObjectState Eval(TimeValue time);
00514         void InitNodeName(MSTR& s) {s = GetObjectName();}
00515         CoreExport Interval ObjectValidity(TimeValue t);
00516         CoreExport int CanConvertToType(Class_ID obtype);
00517         CoreExport Object* ConvertToType(TimeValue t, Class_ID obtype);     
00518         CoreExport Object *MakeShallowCopy(ChannelMask channels);
00519         void WSStateInvalidate() {valid = FALSE;}
00520         BOOL IsWorldSpaceObject() {return TRUE;}
00521 
00522         // From GeomObject              
00523         CoreExport void GetWorldBoundBox(TimeValue t, INode* inode, ViewExp* vpt, Box3& box );
00524         CoreExport void GetLocalBoundBox(TimeValue t, INode* inode, ViewExp* vpt, Box3& box );
00525         CoreExport void GetDeformBBox(TimeValue t, Box3& box, Matrix3 *tm, BOOL useSel );
00526 
00527         // From ParticleObject
00528         CoreExport void ApplyForceField(ForceField *ff);
00529         CoreExport BOOL ApplyCollisionObject(CollisionObject *co);
00530         CoreExport TimeValue ParticleAge(TimeValue t, int i);       
00541         CoreExport void SetParticlePosition(TimeValue t, int i, Point3 pos);
00553         CoreExport void SetParticleVelocity(TimeValue t, int i, Point3 vel);
00564         CoreExport void SetParticleAge(TimeValue t, int i, TimeValue age);
00565 
00566         // Animatable methods       
00567         void GetClassName(MSTR& s) {s = GetObjectName();}       
00568         int NumSubs() {return 1;}  
00569         // upcast pointer
00570         Animatable* SubAnim(int i) { return (Animatable*)pblock; }
00571         CoreExport MSTR SubAnimName(int i);
00572 
00573         using ParticleObject::GetInterface;
00574         CoreExport void* GetInterface(ULONG id);
00575 
00576         // From ref
00577         int NumRefs() {return 1;}
00578         RefTargetHandle GetReference(int i) {return (RefTargetHandle)pblock;}
00579 protected:
00580         virtual void SetReference(int i, RefTargetHandle rtarg) {pblock=(IParamBlock*)rtarg;}       
00581 public:
00582         CoreExport RefResult NotifyRefChanged(Interval changeInt,RefTargetHandle hTarget, 
00583            PartID& partID, RefMessage message);
00584         
00585 
00586         // --- These must be implemented by the derived class ----------------
00601         virtual void UpdateParticles(TimeValue t,INode *node)=0;
00609         virtual void BuildEmitter(TimeValue t, Mesh& amesh)=0;
00617         virtual Interval GetValidity(TimeValue t)=0;
00624         virtual MarkerType GetMarkerType() {return POINT_MRKR;}
00636         virtual BOOL OKtoDisplay(TimeValue t) {return TRUE;}
00644         virtual BOOL EmitterVisible() {return TRUE;}
00669         virtual void InvalidateUI() {}
00681         virtual ParamDimension *GetParameterDim(int pbIndex) {return defaultDim;}
00689         virtual MSTR GetParameterName(int pbIndex) {return MSTR(_M("Parameter"));}      
00690     };
00691 #pragma warning(pop)
00692 
00697 class GenBoxObject: public SimpleObject {   
00698     public:
00721     virtual void SetParams(float width, float height, float length, int wsegs=1,int lsegs=1, 
00722         int hsegs=1, BOOL genUV=TRUE)=0; 
00723     };
00724 
00730 class GenCylinder: public SimpleObject {    
00731     public:
00761     virtual void SetParams(float rad, float height, int segs, int sides, int capsegs=1, BOOL smooth=TRUE, 
00762         BOOL genUV=TRUE, BOOL sliceOn= FALSE, float slice1 = 0.0f, float slice2 = 0.0f)=0;
00763     };
00764 
00770 class GenSphere: public SimpleObject {  
00771     public:
00802     virtual void SetParams(float rad, int segs, BOOL smooth=TRUE, BOOL genUV=TRUE,
00803          float hemi=0.0f, BOOL squash=FALSE, BOOL recenter=FALSE)=0;
00804     };
00805 
00806