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
00051 class csMeshList : public iMeshList
00052 {
00053 private:
00054 csRefArrayObject<iMeshWrapper> list;
00055
00056 public:
00057 SCF_DECLARE_IBASE;
00058
00060 csMeshList ();
00061 virtual ~csMeshList ();
00062
00064 iMeshWrapper *FindByNameWithChild (const char *Name) const;
00065
00067 virtual void PrepareItem (iMeshWrapper*) { }
00069 virtual void FreeItem (iMeshWrapper*) { }
00070
00071 virtual int GetCount () const { return list.Length () ; }
00072 virtual iMeshWrapper *Get (int n) const { return list.Get (n); }
00073 virtual int Add (iMeshWrapper *obj);
00074 virtual bool Remove (iMeshWrapper *obj);
00075 virtual bool Remove (int n);
00076 virtual void RemoveAll ();
00077 virtual int Find (iMeshWrapper *obj) const;
00078 virtual iMeshWrapper *FindByName (const char *Name) const;
00079 };
00080
00084 class csMeshMeshList : public csMeshList
00085 {
00086 private:
00087 csMeshWrapper* mesh;
00088
00089 public:
00090 csMeshMeshList () : mesh (NULL) { }
00091 virtual ~csMeshMeshList () { RemoveAll (); }
00092 void SetMesh (csMeshWrapper* m) { mesh = m; }
00093 virtual void PrepareItem (iMeshWrapper* item);
00094 virtual void FreeItem (iMeshWrapper* item);
00095 };
00096
00100 class csMeshFactoryList : public iMeshFactoryList
00101 {
00102 private:
00103 csRefArrayObject<iMeshFactoryWrapper> list;
00104
00105 public:
00106 SCF_DECLARE_IBASE;
00107
00109 csMeshFactoryList ();
00110 virtual ~csMeshFactoryList () { RemoveAll (); }
00111 virtual void PrepareItem (iMeshFactoryWrapper*) { }
00112 virtual void FreeItem (iMeshFactoryWrapper*) { }
00113
00114 virtual int GetCount () const { return list.Length (); }
00115 virtual iMeshFactoryWrapper *Get (int n) const { return list.Get (n); }
00116 virtual int Add (iMeshFactoryWrapper *obj);
00117 virtual bool Remove (iMeshFactoryWrapper *obj);
00118 virtual bool Remove (int n);
00119 virtual void RemoveAll ();
00120 virtual int Find (iMeshFactoryWrapper *obj) const;
00121 virtual iMeshFactoryWrapper *FindByName (const char *Name) const;
00122 };
00123
00127 class csMeshFactoryFactoryList : public csMeshFactoryList
00128 {
00129 private:
00130 csMeshFactoryWrapper* meshfact;
00131
00132 public:
00133 csMeshFactoryFactoryList () : meshfact (NULL) {}
00134 virtual ~csMeshFactoryFactoryList () { RemoveAll (); }
00135 void SetMeshFactory (csMeshFactoryWrapper* m) { meshfact = m; }
00136 virtual void PrepareItem (iMeshFactoryWrapper* item);
00137 virtual void FreeItem (iMeshFactoryWrapper* item);
00138 };
00139
00140 SCF_VERSION (csMeshWrapper, 0, 0, 1);
00141
00145 class csMeshWrapper : public csObject
00146 {
00147 friend class csMovable;
00148 friend class csMovableSectorList;
00149
00150 protected:
00152 iMeshWrapper *Parent;
00153
00159 csBox3 wor_bbox;
00161 long wor_bbox_movablenr;
00162
00164 int defered_num_lights;
00165
00167 int defered_lighting_flags;
00168
00169 #ifdef CS_USE_NEW_RENDERER
00170
00171 bool draw_test;
00173 bool in_light;
00175 bool cast_hardware_shadow;
00177 bool draw_after_fancy_stuff;
00178 #endif
00179
00186 csTicks last_anim_time;
00187
00191 uint32 visnr;
00192
00196 csMovable movable;
00197
00204 long render_priority;
00205
00207 void GetFullBBox (csBox3& box);
00208
00210 void UpdateDeferedLighting (const csBox3& box);
00211
00212 private:
00214 csRef<iMeshObject> meshobj;
00216 csRef<iLightingInfo> light_info;
00218 csRef<iShadowReceiver> shadow_receiver;
00219
00221 csMeshMeshList children;
00222
00227 csRefArray<iMeshDrawCallback> draw_cb_vector;
00228
00230 iMeshFactoryWrapper* factory;
00231
00233 csZBufMode zbufMode;
00234
00236 bool imposter_active;
00237
00239 csRef<iSharedVariable> min_imposter_distance;
00240
00242 csRef<iSharedVariable> imposter_rotation_tolerance;
00243
00244 csImposterMesh *imposter_mesh;
00245
00246 public:
00248 csFlags flags;
00250 csFlags culler_flags;
00251
00252 protected:
00254 void MoveToSector (csSector* s);
00255
00257 void RemoveFromSectors ();
00258
00266 void UpdateMove ();
00267
00272 void DrawInt (iRenderView* rview);
00273
00278 virtual ~csMeshWrapper ();
00279
00280 public:
00282 csMeshWrapper (iMeshWrapper* theParent, iMeshObject* meshobj);
00284 csMeshWrapper (iMeshWrapper* theParent);
00285
00287 void SetParentContainer (iMeshWrapper* newParent) { Parent = newParent; }
00289 iMeshWrapper* GetParentContainer () const { return Parent; }
00290
00292 void SetFactory (iMeshFactoryWrapper* factory)
00293 {
00294 csMeshWrapper::factory = factory;
00295 }
00297 iMeshFactoryWrapper* GetFactory () const
00298 {
00299 return factory;
00300 }
00301
00303 void SetMeshObject (iMeshObject* meshobj);
00305 iMeshObject* GetMeshObject () const { return meshobj; }
00306
00308 void SetZBufMode (csZBufMode mode) { zbufMode = mode; }
00310 csZBufMode GetZBufMode () const { return zbufMode; }
00311
00320 void SetDrawCallback (iMeshDrawCallback* cb)
00321 {
00322 draw_cb_vector.Push (cb);
00323 }
00324
00325 void RemoveDrawCallback (iMeshDrawCallback* cb)
00326 {
00327 int idx = draw_cb_vector.Find (cb);
00328 if (idx != -1)
00329 draw_cb_vector.Delete (idx);
00330 }
00331
00332 virtual int GetDrawCallbackCount () const
00333 {
00334 return draw_cb_vector.Length ();
00335 }
00336
00337 iMeshDrawCallback* GetDrawCallback (int idx) const
00338 {
00339 return draw_cb_vector.Get (idx);
00340 }
00341
00343 void SetVisibilityNumber (uint32 vis)
00344 {
00345 visnr = vis;
00346 if (Parent)
00347 {
00348 ((csMeshWrapper::MeshWrapper*)Parent)->scfParent
00349 ->SetVisibilityNumber (vis);
00350 }
00351 }
00352
00354 uint32 GetVisibilityNumber () const { return visnr; }
00355
00360 void UpdateLighting (iLight** lights, int num_lights);
00361
00367 void DeferUpdateLighting (int flags, int num_lights);
00368
00374 void Draw (iRenderView* rview);
00375
00376 #ifdef CS_USE_NEW_RENDERER
00377
00381 csRenderMesh *GetRenderMesh (iRenderView* rview);
00383 void DrawShadow (iRenderView* rview, iLight* light);
00385 void DrawLight (iRenderView* rview, iLight* light);
00387 void CastHardwareShadow (bool castShadow);
00389 void SetDrawAfterShadow (bool drawAfter);
00391 bool GetDrawAfterShadow ();
00392 #endif
00393
00401 csMovable& GetMovable () { return movable; }
00402
00415 void PlaceMesh ();
00416
00421 int HitBeamBBox (const csVector3& start, const csVector3& end,
00422 csVector3& isect, float* pr);
00427 bool HitBeamOutline (const csVector3& start, const csVector3& end,
00428 csVector3& isect, float* pr);
00433 bool HitBeamObject (const csVector3& start, const csVector3& end,
00434 csVector3& isect, float* pr);
00439 bool HitBeam (const csVector3& start, const csVector3& end,
00440 csVector3& isect, float* pr);
00441
00443 const csMeshMeshList& GetChildren () const { return children; }
00444
00446 void GetRadius (csVector3& rad, csVector3& cent) const;
00447
00457 void HardTransform (const csReversibleTransform& t);
00458
00464 void GetWorldBoundingBox (csBox3& cbox);
00465
00471 void GetTransformedBoundingBox (const csReversibleTransform& trans,
00472 csBox3& cbox);
00473
00479 float GetScreenBoundingBox (const iCamera *camera, csBox2& sbox,
00480 csBox3& cbox);
00481
00483 void SetRenderPriority (long rp);
00485 long GetRenderPriority () const
00486 {
00487 return render_priority;
00488 }
00489
00490
00491
00493 void SetImposterActive(bool flag,iObjectRegistry *objreg);
00494
00499 bool GetImposterActive() const
00500 { return imposter_active; }
00501
00508 void SetMinDistance(iSharedVariable* dist)
00509 { min_imposter_distance = dist; }
00510
00518 void SetRotationTolerance(iSharedVariable* angle)
00519 { imposter_rotation_tolerance = angle; }
00520
00526 void CreateImposter(csReversibleTransform& )
00527 { }
00528
00532 bool DrawImposter (iRenderView *rview);
00533
00535 bool WouldUseImposter(csReversibleTransform& )
00536 { return false; }
00537
00539 bool CheckImposterRelevant (iRenderView *rview);
00540
00546 void DrawIntFull (iRenderView* rview);
00547
00548
00549 SCF_DECLARE_IBASE_EXT (csObject);
00550
00551
00552 struct MeshWrapper : public iMeshWrapper
00553 {
00554 SCF_DECLARE_EMBEDDED_IBASE (csMeshWrapper);
00555 virtual csMeshWrapper* GetPrivateObject ()
00556 {
00557 return (csMeshWrapper*)scfParent;
00558 }
00559 virtual iObject *QueryObject ()
00560 {
00561 return scfParent;
00562 }
00563 virtual iMeshObject* GetMeshObject () const
00564 {
00565 return scfParent->GetMeshObject ();
00566 }
00567 virtual void SetMeshObject (iMeshObject* m)
00568 {
00569 scfParent->SetMeshObject (m);
00570 }
00571 virtual iLightingInfo* GetLightingInfo () const
00572 {
00573 return scfParent->light_info;
00574 }
00575 virtual iShadowReceiver* GetShadowReceiver () const
00576 {
00577 return scfParent->shadow_receiver;
00578 }
00579 virtual iMeshFactoryWrapper* GetFactory () const
00580 {
00581 return scfParent->GetFactory ();
00582 }
00583 virtual void SetFactory (iMeshFactoryWrapper* m)
00584 {
00585 scfParent->SetFactory (m);
00586 }
00587 virtual void DeferUpdateLighting (int flags, int num_lights)
00588 {
00589 scfParent->DeferUpdateLighting (flags, num_lights);
00590 }
00591 virtual void UpdateLighting (iLight** lights, int num_lights)
00592 {
00593 scfParent->UpdateLighting (lights, num_lights);
00594 }
00595 virtual iMovable* GetMovable () const
00596 {
00597 return &(scfParent->movable.scfiMovable);
00598 }
00599 virtual void PlaceMesh ()
00600 {
00601 scfParent->PlaceMesh ();
00602 }
00603 virtual int HitBeamBBox (const csVector3& start, const csVector3& end,
00604 csVector3& isect, float* pr)
00605 {
00606 return scfParent->HitBeamBBox (start, end, isect, pr);
00607 }
00608 virtual bool HitBeamOutline (const csVector3& start, const csVector3& end,
00609 csVector3& isect, float* pr)
00610 {
00611 return scfParent->HitBeamOutline (start, end, isect, pr);
00612 }
00613 virtual bool HitBeamObject (const csVector3& start, const csVector3& end,
00614 csVector3& isect, float* pr)
00615 {
00616 return scfParent->HitBeamObject (start, end, isect, pr);
00617 }
00618 virtual bool HitBeam (const csVector3& start, const csVector3& end,
00619 csVector3& isect, float* pr)
00620 {
00621 return scfParent->HitBeam (start, end, isect, pr);
00622 }
00623 virtual void SetDrawCallback (iMeshDrawCallback* cb)
00624 {
00625 scfParent->SetDrawCallback (cb);
00626 }
00627 virtual void RemoveDrawCallback (iMeshDrawCallback* cb)
00628 {
00629 scfParent->RemoveDrawCallback (cb);
00630 }
00631 virtual int GetDrawCallbackCount () const
00632 {
00633 return scfParent->GetDrawCallbackCount ();
00634 }
00635 virtual iMeshDrawCallback* GetDrawCallback (int idx) const
00636 {
00637 return scfParent->GetDrawCallback (idx);
00638 }
00639 virtual void SetRenderPriority (long rp)
00640 {
00641 scfParent->SetRenderPriority (rp);
00642 }
00643 virtual long GetRenderPriority () const
00644 {
00645 return scfParent->GetRenderPriority ();
00646 }
00647 virtual csFlags& GetFlags ()
00648 {
00649 return scfParent->flags;
00650 }
00651 virtual void SetZBufMode (csZBufMode mode)
00652 {
00653 scfParent->SetZBufMode (mode);
00654 }
00655 virtual csZBufMode GetZBufMode () const
00656 {
00657 return scfParent->GetZBufMode ();
00658 }
00659 virtual void HardTransform (const csReversibleTransform& t)
00660 {
00661 scfParent->HardTransform (t);
00662 }
00663 virtual void GetWorldBoundingBox (csBox3& cbox)
00664 {
00665 scfParent->GetWorldBoundingBox (cbox);
00666 }
00667 virtual void GetTransformedBoundingBox (const csReversibleTransform& trans,
00668 csBox3& cbox)
00669 {
00670 scfParent->GetTransformedBoundingBox (trans, cbox);
00671 }
00672 virtual float GetScreenBoundingBox (iCamera* camera, csBox2& sbox,
00673 csBox3& cbox);
00674 virtual iMeshList* GetChildren ()
00675 {
00676 return &scfParent->children;
00677 }
00678 virtual iMeshWrapper* GetParentContainer ()
00679 {
00680 return scfParent->GetParentContainer ();
00681 }
00682 virtual void SetParentContainer (iMeshWrapper* p)
00683 {
00684 scfParent->SetParentContainer (p);
00685 }
00686 virtual void GetRadius (csVector3& rad, csVector3 ¢) const
00687 {
00688 scfParent->GetRadius (rad,cent);
00689 }
00690 virtual void Draw (iRenderView* rview)
00691 {
00692 scfParent->Draw (rview);
00693 }
00694 #ifdef CS_USE_NEW_RENDERER
00695 virtual csRenderMesh *GetRenderMesh (iRenderView* rview)
00696 {
00697 return scfParent->GetRenderMesh (rview);
00698 }
00699 virtual void DrawShadow (iRenderView* rview, iLight* light)
00700 {
00701 scfParent->DrawShadow (rview, light);
00702 }
00703 virtual void DrawLight (iRenderView* rview, iLight* light)
00704 {
00705 scfParent->DrawLight (rview, light);
00706 }
00707 virtual void CastHardwareShadow (bool castShadow)
00708 {
00709 scfParent->CastHardwareShadow (castShadow);
00710 }
00711 virtual void SetDrawAfterShadow (bool drawAfter)
00712 {
00713 scfParent->SetDrawAfterShadow (drawAfter);
00714 }
00715 virtual bool GetDrawAfterShadow ()
00716 {
00717 return scfParent->GetDrawAfterShadow ();
00718 }
00719 #endif
00720 } scfiMeshWrapper;
00721 friend struct MeshWrapper;
00722
00723
00724 struct VisObject : public iVisibilityObject
00725 {
00726 SCF_DECLARE_EMBEDDED_IBASE (csMeshWrapper);
00727 virtual iMovable* GetMovable () const
00728 {
00729 return &(scfParent->movable.scfiMovable);
00730 }
00731 virtual iMeshWrapper* GetMeshWrapper () const
00732 {
00733 return &(scfParent->scfiMeshWrapper);
00734 }
00735 virtual void SetVisibilityNumber (uint32 vis)
00736 {
00737 scfParent->SetVisibilityNumber (vis);
00738 }
00739 virtual uint32 GetVisibilityNumber () const
00740 {
00741 return scfParent->GetVisibilityNumber ();
00742 }
00743 virtual iObjectModel* GetObjectModel ()
00744 {
00745 return scfParent->meshobj->GetObjectModel ();
00746 }
00747 virtual csFlags& GetCullerFlags ()
00748 {
00749 return scfParent->culler_flags;
00750 }
00751 } scfiVisibilityObject;
00752 friend struct VisObject;
00753
00754
00755 struct MeshImposter : public iImposter
00756 {
00757 SCF_DECLARE_EMBEDDED_IBASE (csMeshWrapper);
00758 virtual void SetImposterActive(bool flag,iObjectRegistry *objreg)
00759 { scfParent->SetImposterActive(flag,objreg); }
00760 virtual bool GetImposterActive() const
00761 { return scfParent->GetImposterActive(); }
00762 virtual void SetMinDistance(iSharedVariable* dist)
00763 { scfParent->SetMinDistance(dist); }
00764 virtual void SetRotationTolerance(iSharedVariable* angle)
00765 { scfParent->SetRotationTolerance(angle); }
00766 virtual void CreateImposter(csReversibleTransform& pov)
00767 { scfParent->CreateImposter(pov); }
00768 virtual bool WouldUseImposter(csReversibleTransform& pov) const
00769 { return scfParent->WouldUseImposter(pov); }
00770 } scfiImposter;
00771 };
00772
00773 SCF_VERSION (csMeshFactoryWrapper, 0, 0, 3);
00774
00778 class csMeshFactoryWrapper : public csObject
00779 {
00780 private:
00782 csRef<iMeshObjectFactory> meshFact;
00783
00785 iMeshFactoryWrapper* parent;
00786
00788 csReversibleTransform transform;
00789
00791 csMeshFactoryFactoryList children;
00792
00793 private:
00795 virtual ~csMeshFactoryWrapper ();
00796
00797 public:
00799 csMeshFactoryWrapper (iMeshObjectFactory* meshFact);
00801 csMeshFactoryWrapper ();
00802
00804 void SetMeshObjectFactory (iMeshObjectFactory* meshFact);
00805
00807 iMeshObjectFactory* GetMeshObjectFactory () const
00808 {
00809 return meshFact;
00810 }
00811
00815 iMeshWrapper* NewMeshObject ();
00816
00826 void HardTransform (const csReversibleTransform& t);
00827
00829 void PrepareChild (iMeshFactoryWrapper* child);
00831 void UnprepareChild (iMeshFactoryWrapper* child);
00832
00836 csReversibleTransform& GetTransform () { return transform; }
00837
00841 void SetTransform (const csReversibleTransform& tr) { transform = tr; }
00842
00843 SCF_DECLARE_IBASE_EXT (csObject);
00844
00845
00846 struct MeshFactoryWrapper : public iMeshFactoryWrapper
00847 {
00848 SCF_DECLARE_EMBEDDED_IBASE (csMeshFactoryWrapper);
00849 virtual iMeshObjectFactory* GetMeshObjectFactory () const
00850 { return scfParent->GetMeshObjectFactory (); }
00851 virtual void SetMeshObjectFactory (iMeshObjectFactory* fact)
00852 { scfParent->SetMeshObjectFactory (fact); }
00853 virtual iObject *QueryObject ()
00854 { return scfParent; }
00855 virtual void HardTransform (const csReversibleTransform& t)
00856 { scfParent->HardTransform (t); }
00857 virtual iMeshWrapper* CreateMeshWrapper ()
00858 { return scfParent->NewMeshObject (); }
00859 virtual iMeshFactoryWrapper* GetParentContainer () const
00860 { return scfParent->parent; }
00861 virtual void SetParentContainer (iMeshFactoryWrapper *p)
00862 { scfParent->parent = p; }
00863 virtual iMeshFactoryList* GetChildren ()
00864 { return &scfParent->children; }
00865 virtual csReversibleTransform& GetTransform ()
00866 { return scfParent->GetTransform (); }
00867 virtual void SetTransform (const csReversibleTransform& tr)
00868 { scfParent->SetTransform (tr); }
00869 } scfiMeshFactoryWrapper;
00870 friend struct MeshFactoryWrapper;
00871 };
00872
00873 #endif // __CS_MESHOBJ_H__