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 "csgeom/transfrm.h"
00023 #include "csutil/csobject.h"
00024 #include "csutil/nobjvec.h"
00025 #include "csutil/refarr.h"
00026 #include "csutil/flags.h"
00027 #include "csutil/garray.h"
00028 #include "csengine/movable.h"
00029 #include "imesh/object.h"
00030 #include "imesh/lighting.h"
00031 #include "iengine/mesh.h"
00032 #include "iengine/viscull.h"
00033 #include "iengine/imposter.h"
00034 #include "iengine/shadcast.h"
00035 #include "ivideo/graph3d.h"
00036 #include "csengine/impmesh.h"
00037
00038 struct iMeshWrapper;
00039 struct iRenderView;
00040 struct iMovable;
00041 struct iSharedVariable;
00042 class csMeshWrapper;
00043 class csMeshFactoryWrapper;
00044 class csLight;
00045 class csStaticLODMesh;
00046 class csStaticLODFactoryMesh;
00047
00053 class csMeshList : public iMeshList
00054 {
00055 private:
00056 csRefArrayObject<iMeshWrapper> list;
00057
00058 public:
00059 SCF_DECLARE_IBASE;
00060
00062 csMeshList ();
00063 virtual ~csMeshList ();
00064
00066 iMeshWrapper *FindByNameWithChild (const char *Name) const;
00067
00069 virtual void PrepareItem (iMeshWrapper*) { }
00071 virtual void FreeItem (iMeshWrapper*) { }
00072
00073 virtual int GetCount () const { return list.Length () ; }
00074 virtual iMeshWrapper *Get (int n) const { return list.Get (n); }
00075 virtual int Add (iMeshWrapper *obj);
00076 virtual bool Remove (iMeshWrapper *obj);
00077 virtual bool Remove (int n);
00078 virtual void RemoveAll ();
00079 virtual int Find (iMeshWrapper *obj) const;
00080 virtual iMeshWrapper *FindByName (const char *Name) const;
00081 };
00082
00086 class csMeshMeshList : public csMeshList
00087 {
00088 private:
00089 csMeshWrapper* mesh;
00090
00091 public:
00092 csMeshMeshList () : mesh (0) { }
00093 virtual ~csMeshMeshList () { RemoveAll (); }
00094 void SetMesh (csMeshWrapper* m) { mesh = m; }
00095 virtual void PrepareItem (iMeshWrapper* item);
00096 virtual void FreeItem (iMeshWrapper* item);
00097 };
00098
00102 class csMeshFactoryList : public iMeshFactoryList
00103 {
00104 private:
00105 csRefArrayObject<iMeshFactoryWrapper> list;
00106
00107 public:
00108 SCF_DECLARE_IBASE;
00109
00111 csMeshFactoryList ();
00112 virtual ~csMeshFactoryList () { RemoveAll (); }
00113 virtual void PrepareItem (iMeshFactoryWrapper*) { }
00114 virtual void FreeItem (iMeshFactoryWrapper*) { }
00115
00116 virtual int GetCount () const { return list.Length (); }
00117 virtual iMeshFactoryWrapper *Get (int n) const { return list.Get (n); }
00118 virtual int Add (iMeshFactoryWrapper *obj);
00119 virtual bool Remove (iMeshFactoryWrapper *obj);
00120 virtual bool Remove (int n);
00121 virtual void RemoveAll ();
00122 virtual int Find (iMeshFactoryWrapper *obj) const;
00123 virtual iMeshFactoryWrapper *FindByName (const char *Name) const;
00124 };
00125
00129 class csMeshFactoryFactoryList : public csMeshFactoryList
00130 {
00131 private:
00132 csMeshFactoryWrapper* meshfact;
00133
00134 public:
00135 csMeshFactoryFactoryList () : meshfact (0) {}
00136 virtual ~csMeshFactoryFactoryList () { RemoveAll (); }
00137 void SetMeshFactory (csMeshFactoryWrapper* m) { meshfact = m; }
00138 virtual void PrepareItem (iMeshFactoryWrapper* item);
00139 virtual void FreeItem (iMeshFactoryWrapper* item);
00140 };
00141
00142 SCF_VERSION (csMeshWrapper, 0, 0, 1);
00143
00147 class csMeshWrapper : public csObject
00148 {
00149 friend class csMovable;
00150 friend class csMovableSectorList;
00151
00152 protected:
00154 iMeshWrapper *Parent;
00155
00161 csBox3 wor_bbox;
00163 long wor_bbox_movablenr;
00164
00166 int defered_num_lights;
00167
00169 int defered_lighting_flags;
00170
00172 bool draw_test;
00174 bool in_light;
00176 bool cast_hardware_shadow;
00178 bool draw_after_fancy_stuff;
00179
00186 csTicks last_anim_time;
00187
00191 uint32 visnr;
00192
00196 csMovable movable;
00197
00202 csRef<csStaticLODMesh> static_lod;
00203
00210 long render_priority;
00211
00213 void GetFullBBox (csBox3& box);
00214
00216 void UpdateDeferedLighting (const csBox3& box);
00217
00218 private:
00220 csRef<iMeshObject> meshobj;
00222 csRef<iLightingInfo> light_info;
00224 csRef<iShadowReceiver> shadow_receiver;
00225
00227 csMeshMeshList children;
00228
00233 csRefArray<iMeshDrawCallback> draw_cb_vector;
00234
00236 iMeshFactoryWrapper* factory;
00237
00239 csZBufMode zbufMode;
00240
00242 bool imposter_active;
00243
00245 csRef<iSharedVariable> min_imposter_distance;
00246
00248 csRef<iSharedVariable> imposter_rotation_tolerance;
00249
00250 csImposterMesh *imposter_mesh;
00251
00252 public:
00254 csFlags flags;
00256 csFlags culler_flags;
00257
00258 protected:
00260 void MoveToSector (iSector* s);
00261
00263 void RemoveFromSectors ();
00264
00272 void UpdateMove ();
00273
00278 void DrawInt (iRenderView* rview);
00279
00284 virtual ~csMeshWrapper ();
00285
00286 public:
00288 csMeshWrapper (iMeshWrapper* theParent, iMeshObject* meshobj);
00290 csMeshWrapper (iMeshWrapper* theParent);
00291
00293 void SetParentContainer (iMeshWrapper* newParent) { Parent = newParent; }
00295 iMeshWrapper* GetParentContainer () const { return Parent; }
00296
00298 void SetFactory (iMeshFactoryWrapper* factory)
00299 {
00300 csMeshWrapper::factory = factory;
00301 }
00303 iMeshFactoryWrapper* GetFactory () const
00304 {
00305 return factory;
00306 }
00307
00309 void SetMeshObject (iMeshObject* meshobj);
00311 iMeshObject* GetMeshObject () const { return meshobj; }
00312
00314 void SetZBufMode (csZBufMode mode) { zbufMode = mode; }
00316 csZBufMode GetZBufMode () const { return zbufMode; }
00317
00326 void SetDrawCallback (iMeshDrawCallback* cb)
00327 {
00328 draw_cb_vector.Push (cb);
00329 }
00330
00331 void RemoveDrawCallback (iMeshDrawCallback* cb)
00332 {
00333 draw_cb_vector.Delete (cb);
00334 }
00335
00336 virtual int GetDrawCallbackCount () const
00337 {
00338 return draw_cb_vector.Length ();
00339 }
00340
00341 iMeshDrawCallback* GetDrawCallback (int idx) const
00342 {
00343 return draw_cb_vector.Get (idx);
00344 }
00345
00347 void SetVisibilityNumber (uint32 vis)
00348 {
00349 visnr = vis;
00350 if (Parent)
00351 {
00352 ((csMeshWrapper::MeshWrapper*)Parent)->scfParent
00353 ->SetVisibilityNumber (vis);
00354 }
00355 }
00356
00358 uint32 GetVisibilityNumber () const { return visnr; }
00359
00364 void UpdateLighting (iLight** lights, int num_lights);
00365
00371 void DeferUpdateLighting (int flags, int num_lights);
00372
00378 void Draw (iRenderView* rview);
00379
00380
00381 iLODControl* CreateStaticLOD ();
00382 void DestroyStaticLOD ();
00383 iLODControl* GetStaticLOD ();
00384 void RemoveMeshFromStaticLOD (iMeshWrapper* mesh);
00385 void AddMeshToStaticLOD (int lod, iMeshWrapper* mesh);
00386
00391 csRenderMesh** GetRenderMeshes (int& num);
00393 void DrawShadow (iRenderView* rview, iLight* light);
00395 void DrawLight (iRenderView* rview, iLight* light);
00397 void CastHardwareShadow (bool castShadow);
00399 void SetDrawAfterShadow (bool drawAfter);
00401 bool GetDrawAfterShadow ();
00402
00406 float GetSquaredDistance (iRenderView *rview);
00407
00415 csMovable& GetMovable () { return movable; }
00416
00429 void PlaceMesh ();
00430
00435 int HitBeamBBox (const csVector3& start, const csVector3& end,
00436 csVector3& isect, float* pr);
00441 bool HitBeamOutline (const csVector3& start, const csVector3& end,
00442 csVector3& isect, float* pr);
00447 bool HitBeamObject (const csVector3& start, const csVector3& end,
00448 csVector3& isect, float* pr);
00453 bool HitBeam (const csVector3& start, const csVector3& end,
00454 csVector3& isect, float* pr);
00455
00457 const csMeshMeshList& GetChildren () const { return children; }
00458
00460 void GetRadius (csVector3& rad, csVector3& cent) const;
00461
00471 void HardTransform (const csReversibleTransform& t);
00472
00478 void GetWorldBoundingBox (csBox3& cbox);
00479
00485 void GetTransformedBoundingBox (const csReversibleTransform& trans,
00486 csBox3& cbox);
00487
00493 float GetScreenBoundingBox (const iCamera *camera, csBox2& sbox,
00494 csBox3& cbox);
00495
00497 void SetRenderPriority (long rp);
00499 long GetRenderPriority () const
00500 {
00501 return render_priority;
00502 }
00503
00504
00505
00507 void SetImposterActive(bool flag,iObjectRegistry *objreg);
00508
00513 bool GetImposterActive() const
00514 { return imposter_active; }
00515
00522 void SetMinDistance(iSharedVariable* dist)
00523 { min_imposter_distance = dist; }
00524
00532 void SetRotationTolerance(iSharedVariable* angle)
00533 { imposter_rotation_tolerance = angle; }
00534
00540 void CreateImposter(csReversibleTransform& )
00541 { }
00542
00546 bool DrawImposter (iRenderView *rview);
00547
00549 bool WouldUseImposter(csReversibleTransform& )
00550 { return false; }
00551
00553 bool CheckImposterRelevant (iRenderView *rview);
00554
00560 void DrawIntFull (iRenderView* rview);
00561
00562
00563 SCF_DECLARE_IBASE_EXT (csObject);
00564
00565
00566 struct MeshWrapper : public iMeshWrapper
00567 {
00568 SCF_DECLARE_EMBEDDED_IBASE (csMeshWrapper);
00569 virtual iObject *QueryObject ()
00570 {
00571 return scfParent;
00572 }
00573 virtual iMeshObject* GetMeshObject () const
00574 {
00575 return scfParent->GetMeshObject ();
00576 }
00577 virtual void SetMeshObject (iMeshObject* m)
00578 {
00579 scfParent->SetMeshObject (m);
00580 }
00581 virtual iLightingInfo* GetLightingInfo () const
00582 {
00583 return scfParent->light_info;
00584 }
00585 virtual iShadowReceiver* GetShadowReceiver () const
00586 {
00587 return scfParent->shadow_receiver;
00588 }
00589 virtual uint32 GetVisibilityNumber () const
00590 {
00591 return scfParent->GetVisibilityNumber ();
00592 }
00593 virtual iMeshFactoryWrapper* GetFactory () const
00594 {
00595 return scfParent->GetFactory ();
00596 }
00597 virtual void SetFactory (iMeshFactoryWrapper* m)
00598 {
00599 scfParent->SetFactory (m);
00600 }
00601 virtual void DeferUpdateLighting (int flags, int num_lights)
00602 {
00603 scfParent->DeferUpdateLighting (flags, num_lights);
00604 }
00605 virtual void UpdateLighting (iLight** lights, int num_lights)
00606 {
00607 scfParent->UpdateLighting (lights, num_lights);
00608 }
00609 virtual iMovable* GetMovable () const
00610 {
00611 return &(scfParent->movable.scfiMovable);
00612 }
00613 virtual void PlaceMesh ()
00614 {
00615 scfParent->PlaceMesh ();
00616 }
00617 virtual int HitBeamBBox (const csVector3& start, const csVector3& end,
00618 csVector3& isect, float* pr)
00619 {
00620 return scfParent->HitBeamBBox (start, end, isect, pr);
00621 }
00622 virtual bool HitBeamOutline (const csVector3& start, const csVector3& end,
00623 csVector3& isect, float* pr)
00624 {
00625 return scfParent->HitBeamOutline (start, end, isect, pr);
00626 }
00627 virtual bool HitBeamObject (const csVector3& start, const csVector3& end,
00628 csVector3& isect, float* pr)
00629 {
00630 return scfParent->HitBeamObject (start, end, isect, pr);
00631 }
00632 virtual bool HitBeam (const csVector3& start, const csVector3& end,
00633 csVector3& isect, float* pr)
00634 {
00635 return scfParent->HitBeam (start, end, isect, pr);
00636 }
00637 virtual void SetDrawCallback (iMeshDrawCallback* cb)
00638 {
00639 scfParent->SetDrawCallback (cb);
00640 }
00641 virtual void RemoveDrawCallback (iMeshDrawCallback* cb)
00642 {
00643 scfParent->RemoveDrawCallback (cb);
00644 }
00645 virtual int GetDrawCallbackCount () const
00646 {
00647 return scfParent->GetDrawCallbackCount ();
00648 }
00649 virtual iMeshDrawCallback* GetDrawCallback (int idx) const
00650 {
00651 return scfParent->GetDrawCallback (idx);
00652 }
00653 virtual void SetRenderPriority (long rp)
00654 {
00655 scfParent->SetRenderPriority (rp);
00656 }
00657 virtual long GetRenderPriority () const
00658 {
00659 return scfParent->GetRenderPriority ();
00660 }
00661 virtual csFlags& GetFlags ()
00662 {
00663 return scfParent->flags;
00664 }
00665 virtual void SetZBufMode (csZBufMode mode)
00666 {
00667 scfParent->SetZBufMode (mode);
00668 }
00669 virtual csZBufMode GetZBufMode () const
00670 {
00671 return scfParent->GetZBufMode ();
00672 }
00673 virtual void HardTransform (const csReversibleTransform& t)
00674 {
00675 scfParent->HardTransform (t);
00676 }
00677 virtual void GetWorldBoundingBox (csBox3& cbox)
00678 {
00679 scfParent->GetWorldBoundingBox (cbox);
00680 }
00681 virtual void GetTransformedBoundingBox (const csReversibleTransform& trans,
00682 csBox3& cbox)
00683 {
00684 scfParent->GetTransformedBoundingBox (trans, cbox);
00685 }
00686 virtual float GetScreenBoundingBox (iCamera* camera, csBox2& sbox,
00687 csBox3& cbox);
00688 virtual iMeshList* GetChildren ()
00689 {
00690 return &scfParent->children;
00691 }
00692 virtual iMeshWrapper* GetParentContainer ()
00693 {
00694 return scfParent->GetParentContainer ();
00695 }
00696 virtual void SetParentContainer (iMeshWrapper* p)
00697 {
00698 scfParent->SetParentContainer (p);
00699 }
00700 virtual void GetRadius (csVector3& rad, csVector3 ¢) const
00701 {
00702 scfParent->GetRadius (rad,cent);
00703 }
00704 virtual void Draw (iRenderView* rview)
00705 {
00706 scfParent->Draw (rview);
00707 }
00708 virtual iLODControl* CreateStaticLOD ()
00709 {
00710 return scfParent->CreateStaticLOD ();
00711 }
00712 virtual void DestroyStaticLOD ()
00713 {
00714 scfParent->DestroyStaticLOD ();
00715 }
00716 virtual iLODControl* GetStaticLOD ()
00717 {
00718 return scfParent->GetStaticLOD ();
00719 }
00720 virtual void RemoveMeshFromStaticLOD (iMeshWrapper* mesh)
00721 {
00722 scfParent->RemoveMeshFromStaticLOD (mesh);
00723 }
00724 virtual void AddMeshToStaticLOD (int lod, iMeshWrapper* mesh)
00725 {
00726 scfParent->AddMeshToStaticLOD (lod, mesh);
00727 }
00728 virtual csRenderMesh** GetRenderMeshes (int& num)
00729 {
00730 return scfParent->GetRenderMeshes (num);
00731 }
00732 virtual void DrawShadow (iRenderView* rview, iLight* light)
00733 {
00734 scfParent->DrawShadow (rview, light);
00735 }
00736 virtual void DrawLight (iRenderView* rview, iLight* light)
00737 {
00738 scfParent->DrawLight (rview, light);
00739 }
00740 virtual void CastHardwareShadow (bool castShadow)
00741 {
00742 scfParent->CastHardwareShadow (castShadow);
00743 }
00744 virtual void SetDrawAfterShadow (bool drawAfter)
00745 {
00746 scfParent->SetDrawAfterShadow (drawAfter);
00747 }
00748 virtual bool GetDrawAfterShadow ()
00749 {
00750 return scfParent->GetDrawAfterShadow ();
00751 }
00752 } scfiMeshWrapper;
00753 friend struct MeshWrapper;
00754
00755
00756 struct VisObject : public iVisibilityObject
00757 {
00758 SCF_DECLARE_EMBEDDED_IBASE (csMeshWrapper);
00759 virtual iMovable* GetMovable () const
00760 {
00761 return &(scfParent->movable.scfiMovable);
00762 }
00763 virtual iMeshWrapper* GetMeshWrapper () const
00764 {
00765 return &(scfParent->scfiMeshWrapper);
00766 }
00767 virtual void SetVisibilityNumber (uint32 vis)
00768 {
00769 scfParent->SetVisibilityNumber (vis);
00770 }
00771 virtual uint32 GetVisibilityNumber () const
00772 {
00773 return scfParent->GetVisibilityNumber ();
00774 }
00775 virtual iObjectModel* GetObjectModel ()
00776 {
00777 return scfParent->meshobj->GetObjectModel ();
00778 }
00779 virtual csFlags& GetCullerFlags ()
00780 {
00781 return scfParent->culler_flags;
00782 }
00783 } scfiVisibilityObject;
00784 friend struct VisObject;
00785
00786
00787 struct MeshImposter : public iImposter
00788 {
00789 SCF_DECLARE_EMBEDDED_IBASE (csMeshWrapper);
00790 virtual void SetImposterActive(bool flag,iObjectRegistry *objreg)
00791 { scfParent->SetImposterActive(flag,objreg); }
00792 virtual bool GetImposterActive() const
00793 { return scfParent->GetImposterActive(); }
00794 virtual void SetMinDistance(iSharedVariable* dist)
00795 { scfParent->SetMinDistance(dist); }
00796 virtual void SetRotationTolerance(iSharedVariable* angle)
00797 { scfParent->SetRotationTolerance(angle); }
00798 virtual void CreateImposter(csReversibleTransform& pov)
00799 { scfParent->CreateImposter(pov); }
00800 virtual bool WouldUseImposter(csReversibleTransform& pov) const
00801 { return scfParent->WouldUseImposter(pov); }
00802 } scfiImposter;
00803 };
00804
00805 SCF_VERSION (csMeshFactoryWrapper, 0, 0, 3);
00806
00810 class csMeshFactoryWrapper : public csObject
00811 {
00812 private:
00814 csRef<iMeshObjectFactory> meshFact;
00815
00817 iMeshFactoryWrapper* parent;
00818
00820 csReversibleTransform transform;
00821
00823 csMeshFactoryFactoryList children;
00824
00829 csRef<csStaticLODFactoryMesh> static_lod;
00830
00831 private:
00833 virtual ~csMeshFactoryWrapper ();
00834
00835 public:
00837 csMeshFactoryWrapper (iMeshObjectFactory* meshFact);
00839 csMeshFactoryWrapper ();
00840
00842 void SetMeshObjectFactory (iMeshObjectFactory* meshFact);
00843
00845 iMeshObjectFactory* GetMeshObjectFactory () const
00846 {
00847 return meshFact;
00848 }
00849
00853 iMeshWrapper* NewMeshObject ();
00854
00864 void HardTransform (const csReversibleTransform& t);
00865
00867 void PrepareChild (iMeshFactoryWrapper* child);
00869 void UnprepareChild (iMeshFactoryWrapper* child);
00870
00874 csReversibleTransform& GetTransform () { return transform; }
00875
00879 void SetTransform (const csReversibleTransform& tr) { transform = tr; }
00880
00881
00882 iLODControl* CreateStaticLOD ();
00883 void DestroyStaticLOD ();
00884 iLODControl* GetStaticLOD ();
00885 void SetStaticLOD (float m, float a);
00886 void GetStaticLOD (float& m, float& a) const;
00887 void RemoveFactoryFromStaticLOD (iMeshFactoryWrapper* mesh);
00888 void AddFactoryToStaticLOD (int lod, iMeshFactoryWrapper* mesh);
00889
00890 SCF_DECLARE_IBASE_EXT (csObject);
00891
00892
00893 struct MeshFactoryWrapper : public iMeshFactoryWrapper
00894 {
00895 SCF_DECLARE_EMBEDDED_IBASE (csMeshFactoryWrapper);
00896 virtual iMeshObjectFactory* GetMeshObjectFactory () const
00897 { return scfParent->GetMeshObjectFactory (); }
00898 virtual void SetMeshObjectFactory (iMeshObjectFactory* fact)
00899 { scfParent->SetMeshObjectFactory (fact); }
00900 virtual iObject *QueryObject ()
00901 { return scfParent; }
00902 virtual void HardTransform (const csReversibleTransform& t)
00903 { scfParent->HardTransform (t); }
00904 virtual iMeshWrapper* CreateMeshWrapper ()
00905 { return scfParent->NewMeshObject (); }
00906 virtual iMeshFactoryWrapper* GetParentContainer () const
00907 { return scfParent->parent; }
00908 virtual void SetParentContainer (iMeshFactoryWrapper *p)
00909 { scfParent->parent = p; }
00910 virtual iMeshFactoryList* GetChildren ()
00911 { return &scfParent->children; }
00912 virtual csReversibleTransform& GetTransform ()
00913 { return scfParent->GetTransform (); }
00914 virtual void SetTransform (const csReversibleTransform& tr)
00915 { scfParent->SetTransform (tr); }
00916 virtual iLODControl* CreateStaticLOD ()
00917 {
00918 return scfParent->CreateStaticLOD ();
00919 }
00920 virtual void DestroyStaticLOD ()
00921 {
00922 scfParent->DestroyStaticLOD ();
00923 }
00924 virtual iLODControl* GetStaticLOD ()
00925 {
00926 return scfParent->GetStaticLOD ();
00927 }
00928 virtual void SetStaticLOD (float m, float a)
00929 {
00930 scfParent->SetStaticLOD (m, a);
00931 }
00932 virtual void GetStaticLOD (float& m, float& a) const
00933 {
00934 scfParent->GetStaticLOD (m, a);
00935 }
00936 virtual void RemoveFactoryFromStaticLOD (iMeshFactoryWrapper* fact)
00937 {
00938 scfParent->RemoveFactoryFromStaticLOD (fact);
00939 }
00940 virtual void AddFactoryToStaticLOD (int lod, iMeshFactoryWrapper* fact)
00941 {
00942 scfParent->AddFactoryToStaticLOD (lod, fact);
00943 }
00944 } scfiMeshFactoryWrapper;
00945 friend struct MeshFactoryWrapper;
00946 };
00947
00948 #endif // __CS_MESHOBJ_H__