00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_MESHOBJ_H__
00020 #define __CS_MESHOBJ_H__
00021
00022 #include "csutil/refarr.h"
00023 #include "iengine/material.h"
00024 #include "iengine/engine.h"
00025 #include "iengine/mesh.h"
00026 #include "imesh/object.h"
00027 #include "csgeom/objmodel.h"
00028
00030 #define CS_DECLARE_SIMPLE_MESH_FACTORY(name,meshclass) \
00031 class name : public csMeshFactory { \
00032 public: \
00033 name (iEngine *e, iObjectRegistry* reg) : csMeshFactory (e, reg) {} \
00034 virtual csPtr<iMeshObject> NewInstance () \
00035 { return new meshclass (Engine, this); } \
00036 };
00037
00039 #define CS_DECLARE_SIMPLE_MESH_PLUGIN(name,factclass) \
00040 class name : public csMeshType { \
00041 public: \
00042 name (iBase *p) : csMeshType (p) {} \
00043 virtual csPtr<iMeshObjectFactory> NewFactory () \
00044 { return new factclass (Engine, object_reg); } \
00045 };
00046
00060 class csMeshObject : public iMeshObject
00061 {
00062 protected:
00064 csRef<iMeshObjectDrawCallback> VisCallback;
00065
00067 iBase *LogParent;
00068
00070 iEngine *Engine;
00071
00073 void WantToDie ();
00074
00075 public:
00076 SCF_DECLARE_IBASE;
00077
00079 csMeshObject (iEngine *engine);
00080
00082 virtual ~csMeshObject ();
00083
00088 virtual iMeshObjectFactory* GetFactory () const = 0;
00089
00094 virtual bool DrawTest (iRenderView* rview, iMovable* movable);
00095
00096 #ifdef CS_USE_NEW_RENDERER
00097 virtual void EnableShadowCaps () = 0;
00098 virtual void DisableShadowCaps () = 0;
00099 #endif
00100
00105 virtual void UpdateLighting (iLight** lights, int num_lights,
00106 iMovable* movable);
00107
00112 virtual bool Draw (iRenderView* rview, iMovable* movable,
00113 csZBufMode zbufMode) = 0;
00114
00115 #ifdef CS_USE_NEW_RENDERER
00116 virtual bool DrawZ (iRenderView* rview, iMovable* movable,
00117 csZBufMode zbufMode) = 0;
00118
00119 virtual bool DrawShadow (iRenderView* rview, iMovable* movable,
00120 csZBufMode zbufMode, iLight *light) = 0;
00121
00122 virtual bool DrawLight (iRenderView* rview, iMovable* movable,
00123 csZBufMode zbufMode, iLight *light) = 0;
00124 #endif // CS_USE_NEW_RENDERER
00125
00131 virtual void SetVisibleCallback (iMeshObjectDrawCallback* cb);
00132
00137 virtual iMeshObjectDrawCallback* GetVisibleCallback () const;
00138
00143 virtual void NextFrame (csTicks current_time,const csVector3& pos);
00144
00149 virtual void HardTransform (const csReversibleTransform& t);
00150
00155 virtual bool SupportsHardTransform () const;
00156
00161 virtual bool HitBeamOutline (const csVector3& start,
00162 const csVector3& end, csVector3& isect, float* pr);
00163
00168 virtual bool HitBeamObject (const csVector3& start, const csVector3& end,
00169 csVector3& isect, float* pr);
00170
00175 virtual void SetLogicalParent (iBase* logparent);
00176
00181 virtual iBase* GetLogicalParent () const;
00182
00186 virtual iObjectModel* GetObjectModel () { return &scfiObjectModel; }
00187
00192 virtual bool SetColor (const csColor& color);
00193
00198 virtual bool GetColor (csColor& color) const;
00199
00204 virtual bool SetMaterialWrapper (iMaterialWrapper* material);
00205
00210 virtual iMaterialWrapper* GetMaterialWrapper () const;
00211
00216 virtual void GetObjectBoundingBox (csBox3& bbox, int type);
00217
00222 virtual void GetRadius (csVector3& radius, csVector3& center);
00223
00224
00225 struct eiObjectModel : public csObjectModel
00226 {
00227 SCF_DECLARE_EMBEDDED_IBASE (csMeshObject);
00228 virtual void GetObjectBoundingBox (csBox3& bbox, int type)
00229 {
00230 scfParent->GetObjectBoundingBox (bbox, type);
00231 }
00232 virtual void GetRadius (csVector3& radius, csVector3& center)
00233 {
00234 scfParent->GetRadius (radius, center);
00235 }
00236 } scfiObjectModel;
00237 friend struct eiObjectModel;
00238 };
00239
00244 class csMeshFactory : public iMeshObjectFactory
00245 {
00246 protected:
00248 iBase *LogParent;
00249
00251 iEngine *Engine;
00252
00254 iObjectRegistry* object_reg;
00255
00256 public:
00257 SCF_DECLARE_IBASE;
00258
00260 csMeshFactory (iEngine *engine, iObjectRegistry* object_reg);
00261
00263 virtual ~csMeshFactory ();
00264
00269 virtual csPtr<iMeshObject> NewInstance () = 0;
00270
00275 virtual void HardTransform (const csReversibleTransform& t);
00276
00281 virtual bool SupportsHardTransform () const;
00282
00287 virtual void SetLogicalParent (iBase* logparent);
00288
00293 virtual iBase* GetLogicalParent () const;
00294
00298 virtual iObjectModel* GetObjectModel () { return NULL; }
00299
00300 };
00301
00305 class csMeshType : public iMeshObjectType
00306 {
00307 protected:
00309 iEngine *Engine;
00310
00312 iObjectRegistry* object_reg;
00313
00314 public:
00315 SCF_DECLARE_IBASE;
00316
00318 csMeshType (iBase *p);
00319
00321 virtual ~csMeshType ();
00322
00326 bool Initialize (iObjectRegistry* reg);
00327
00332 virtual csPtr<iMeshObjectFactory> NewFactory () = 0;
00333
00337 struct eiComponent : public iComponent
00338 {
00339 SCF_DECLARE_EMBEDDED_IBASE (csMeshType);
00340 virtual bool Initialize (iObjectRegistry* p)
00341 { return scfParent->Initialize (p); }
00342 } scfiComponent;
00343 };
00344
00345 #endif // __CS_MESHOBJ_H__