My Project
MetaWorldFragment.h
1 #pragma once
2 #include <vector>
3 #include "MetaObject.h"
4 #include "DataGrid.h"
5 #include "ShapeAABB.h"
6 
7 namespace ParaEngine
8 {
9  class IsoSurfaceRenderable;
10  class IsoSurfaceBuilder;
11  class MetaObject;
12 
18  {
19  public:
20  typedef std::vector<MetaWorldFragment*> WfList;
21  typedef std::vector<MetaWorldFragment*>::iterator WfIter;
22  typedef std::vector<MetaWorldFragment*>::const_iterator WfConstIter;
23 
24 
26  MetaWorldFragment(const Vector3 &position, int ylevel = 0);
27  virtual ~MetaWorldFragment();
28 
30  void addMetaObject(MetaObjectPtr mo);
32  void update(IsoSurfaceBuilder *builder);
33  int getNumMetaObjects() {return (int)mObjs.size();} const
34  CShapeAABB getAABB() {return mAabb;} const
35  Vector3 getPosition() {return mPosition;} const
36  bool empty() {return mObjs.empty();}
37  static float getScale() {return mGridScale;}
38  static float getSize() {return mSize;}
39  static void setScale(float s) {mGridScale = s;}
40  static void setSize(float s) {mSize = s;}
41 
42  IsoSurfaceRenderable * getIsoSurface() {return mSurf;}
43  int getYLevel() { return mYLevel; }
44 
45  static void setMaterialName(const std::string &name) {mMaterialName = name;}
46  static const std::string &getMaterialName() {return mMaterialName;}
47 
51  bool IsNeedUpdate(){ return m_bNeedUpdate; }
52 
53  void SetNeedUpdate(bool bNeedUpdate = true){ m_bNeedUpdate = bNeedUpdate; }
54  protected:
55  void addToWfList(MetaWorldFragment* wf);
56 
57  protected:
58  IsoSurfaceRenderable *mSurf;
59 
60  Vector3 mPosition;
61  CShapeAABB mAabb;
62  static float mGridScale;
63  static float mSize;
64  // Child meta objects in this world fragment. Vector of potentially overlapping MetaObjects children.
65  std::vector<MetaObjectPtr> mObjs;
67  std::vector<MetaWorldFragment*> mAdjacentFragments;
68 
73  int mYLevel;
74 
77 
78  // TODO: use TextureEntity share ptr here.
79  static std::string mMaterialName;
80  };
81 
82  typedef asset_ptr<MetaWorldFragment> MetaWorldFragmentPtr;
83 }
Renderable object for the dynamically generated IsoSurface or voxel mesh.
Definition: IsoSurfaceRenderable.h:15
A MetaWorldFragment is the basic building block of the world.
Definition: MetaWorldFragment.h:17
Base class for a reference counted asset.
Definition: PERef.h:55
different physics engine has different winding order.
Definition: EventBinding.h:32
MetaWorldFragment(const Vector3 &position, int ylevel=0)
Creates new MetaWorldFragment, it will only create IsoSuface and grid on demand.
Definition: MetaWorldFragment.cpp:29
int mYLevel
position in y, counted in tile-sizes.
Definition: MetaWorldFragment.h:73
bool IsNeedUpdate()
it will only update when needed by draw function call.
Definition: MetaWorldFragment.h:51
std::vector< MetaWorldFragment * > mAdjacentFragments
TODO: currently no merging is supported for adjacent fragments.
Definition: MetaWorldFragment.h:67
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
building triangles from 3d grid data.
Definition: IsoSurfaceBuilder.h:11
AABB-related code.
Definition: ShapeAABB.h:11
void addMetaObject(MetaObjectPtr mo)
Adds MetaObject to mObjs, and to mMoDataGrid.
Definition: MetaWorldFragment.cpp:41
bool m_bNeedUpdate
whether the grid is modified and needs update in the next draw call.
Definition: MetaWorldFragment.h:76
void update(IsoSurfaceBuilder *builder)
Updates IsoSurface.
Definition: MetaWorldFragment.cpp:50