PhysicsMain.h
1 /************************************************************
2 * (C) Voxel Farm Inc. 2015
3 */
4 
5 #pragma once
6 
7 #include "CellData.h"
8 #include "ExternalMutex.h"
9 #include "FastQuadrics.h"
10 #include "MaterialLibrary.h"
11 #include "PhysicsData.h"
12 #include "PhysicsMaterials.h"
13 #include "PinkNoise.h"
14 #include "StampMesh.h"
15 #include "UnionFind.h"
16 #include "Vector.h"
17 #include "VoxelFarmConfig.h"
18 #include "VoxelLayer.h"
19 
20 namespace VoxelFarm
21 {
22  namespace Physics
23  {
24  // physics event handler
26  {
27  public:
29  virtual CCellData* createCellData() = 0;
30 
31  virtual void processCell(CCellData* cellData) = 0;
32 
33  // pipes dead fragment mesh ids to the engine for VBO cleanup
34  virtual void notifyCellsDestroyed(TSet<CCellData*>* deadCells) = 0;
35 
36  // pipes modified cells to the engine to be re-contoured
37  virtual void notifyCellsToProcess(TSet<CellId>* changedCells) = 0;
38 
39  // notifies the engine to add fragments
40  virtual void notifyFragmentsPending() = 0;
41  };
42 
45  {
46  public:
47  CFragmentSource(const CFastQuadrics* mesh, const double worldPos[3]);
48  int getSolidCount() { return 1; }
49  MaterialId getSolidMaterial(int solid) { return 0; }
50  int getFaceCount(int solid) { return mesh->faceCount; }
51  void getFace(int solid, int index, Algebra::Vector& v0, Algebra::Vector& v1, Algebra::Vector& v2);
52  private:
53  const CFastQuadrics* mesh;
54  double worldPos[3];
55  };
56 
58  void discoverFragmentMeshes(
59  const TSet<CellId>* scene, // in :: a list of active cells
60  const TMap<CellId, CCellData*>* cellCache, // in :: a pointer to the cellData objects for the active cells (must contain mesh information!)
61  ExternalMutex::Mutex* cacheLock, // in :: a pointer to a mutex which protects the above since, in general, it may be modified by multiple threads
62  const int sourceLOD, // in :: the desired LOD to be analyzed
63  TVector<CFastQuadrics*>* fragments // out :: a container for the output meshes
64  );
65 
67  void contourNoiseBuffer(
68  const int sourceLOD, // in :: lod at which the buffer was created
69  const CVoxelBuffer* nVoxBuffer, // in :: noise voxel buffer
70  TVector<CCellData*>* cells, // out :: cellData objects (mesh stage)
71  IPhysicsEvents* events
72  );
73 
75  void processFragmentMesh(
76  CCellData* cellData, // in :: cell mesh | out :: cell vbos
77  CMaterialLibrary* materialLibrary, // in :: material library
78  VoxelFarm::CCellData::ThreadContext* tc, // in :: thread context
79  VoxelFarm::LODStats stats, // out :: stats
80  double origin[3], // out :: cell origin
81  double meshMin[3], // out :: cell min bounds
82  double meshRange[3], // out :: cell range
83  IPhysicsEvents* events,
84  const bool useCOM = false, // in :: use center of mass origin
85  const CPhysicsMaterialLibrary* physicsML = NULL // in :: physics material library (if using CoM)
86  );
87 
89  void deleteFragmentVoxels(
90  CBlockData* blockData, // out :: a pointer to the user blockdata (or similar) so that any static voxels may be overwritten
91  const double worldPos[3], // in :: the world position used to compute the mesh/voxel overlap
92  const int sourceLOD, // in :: the LOD at which to process the deletion (must match that of discoverFragmentMeshes!)
93  CMaterialLibrary* materialLibrary, // in :: the material library used to read material class
94  const TVector<CFastQuadrics*>* fragments, // in :: the list of fragment meshes for which to delete voxels
95  TVector<CMassInfo*>* massInfo, // out :: mass properties of removed voxels for each fragment
96  TSet<CellId>* changedCells // out :: a list of cells which have been modified (and require re-processing by the engine)
97  );
98 
100  void generateNoiseBrush(
101  CNoiseBrush* noiseBrush // out :: brush buffer
102  );
103 
106  bool fragmentSimplification(
107  CFastQuadrics* mesh, // in :: fragment mesh
108  const int faceCount, // in :: maximum collider face count
109  CFastQuadrics* collider, // out :: reduced collision mesh
110  int gridDim = 6 // in :: grid dimension
111  );
112  };
113 };
Contains all classes and functions for the VoxelFarm engine.
Contains all materials available in the system.
int getFaceCount(int solid)
Returns the number of faces in a solid.
Definition: PhysicsMain.h:50
A 3D Vector.
Definition: Vector.h:34
A default implementation of IBlockData that also acts as a VoxelLayer.
Definition: BlockData.h:182
It allows to access to the faces and materials of a list of solids.
Definition: StampMesh.h:31
int faceCount
Number of faces in the mesh.
Definition: FastQuadrics.h:56
void getFace(int solid, int index, Algebra::Vector &v0, Algebra::Vector &v1, Algebra::Vector &v2)
Get the vertices of a face of a solid.
Stores the information for a Cell that has already been converted to a polygonal mesh.
Definition: CellData.h:107
StatTracker LODStats[LEVELS][STAT_NULL]
Used to track stats across all LOD.
Definition: VoxelLayer.h:530
MaterialId getSolidMaterial(int solid)
Returns the material of a solid.
Definition: PhysicsMain.h:49
int getSolidCount()
Returns the number of solids.
Definition: PhysicsMain.h:48
converts a physics fragment mesh into a MeshStampSource to be applied by the stampMesh algorithm duri...
Definition: PhysicsMain.h:44
An efficient mesh representation that features Quadratic Error function simplification using a Multip...
Definition: FastQuadrics.h:44
virtual CCellData * createCellData()=0
creates a CellData object with (unique) CellId id to hold a fragment mesh