Cogs.Core
SparseBuildOctree.h
1#pragma once
2
3#include "Base.h"
4#include "Context.h"
5
6#include "Resources/Resources.h"
7#include "Services/PropertiesManager.h"
8
9#include "Foundation/Geometry/BoundingBox.hpp"
10
11#include <vector>
12
13namespace Cogs::Core::SparseOctree
14{
17 {
19 float tolerance = 0;
20 float remesh = -1.f;
21 float remeshGridSpacing = 1.f / 8.f;
24 float remeshSimplification = 0.1f;
25 float featureAngle = 0.7f;
26 float cullDiameter = -1.f;
27 float cullGeometry = -1.f;
28 float cullLeaf = -1.f;
29 float simplificationFactor = -1.f;
31 bool isLoaded = false;
32 };
33
36 {
37 uint32_t parameterization = 0;
38 float reductionError = 0;
39 float cullingThreshold = 0;
40 float threshold = -1;
41 };
42
43 struct EntityRef
44 {
45 uint32_t index = (uint32_t)-1;
46 uint32_t parent = (uint32_t)-1;
47
48 MeshHandle mesh;
50 uint32_t startIndex = 0;
51 uint32_t vertexCount = (uint32_t)-1;
52
53 Geometry::BoundingBox box;
54 glm::vec3 span;
55 float maxDim = 0;
56 bool skip = false;
57 };
58
59 struct SceneInfo
60 {
61 ModelHandle model;
62
63 Geometry::BoundingBox bounds;
64
65 std::vector<EntityRef> entities;
66
67 uint32_t geometries = 0;
68 //uint32_t leaves = 0;
69
70 float maxGeometrySize = 0;
71 };
72
73 // Mesh reference - mesh stored into a model file.
74 struct MeshRef
75 {
76 std::string fileName;
77 uint32_t part = (uint32_t)-1;
78 Cogs::Geometry::BoundingBox bbox;
79 };
80
81 // Mesh record - mesh not yet packed into a model file.
82 struct MeshRec
83 {
84 MeshHandle mesh;
85 Cogs::Geometry::BoundingBox bbox;
86 };
87
88 struct Cell
89 {
90 uint32_t x = 0;
91 uint32_t y = 0;
92 uint32_t z = 0;
93
94 Geometry::BoundingBox bbox;
95
96 std::vector<uint32_t> touches;
97
98 std::vector<MeshRef> meshRefs;
99 std::vector<MeshRec> meshRecs;
100
101 uint32_t vertexCount = 0;
102 uint32_t sizeEstimate = 0;
103
104 MeshHandle mesh;
105 };
106
107 typedef size_t CellMapKey;
108 typedef size_t CellIndex;
109 struct Grid
110 {
111
112 // Number of cells along each direction
113 glm::uvec3 dimensions;
114 glm::vec3 origin;
115 glm::vec3 cellSize;
116
117 CellMapKey cellMapKey(const size_t i, const size_t j, const size_t k) const {
118 assert(i < dimensions.x && j < dimensions.y && k < dimensions.z);
119 return ((k * dimensions.y) + j) * dimensions.x + i;
120 }
121
122 std::unordered_map<CellMapKey, CellIndex> cellMap;
123
124 // FIXME: Do something more clever with pages
125 std::vector<Cell> cellStore;
126
127 };
128
129 enum struct LevelReducer
130 {
131 RationalReducerVertexCount,
132 MeshOptimizerVertexCount,
133 MeshOptimizerSloppyVertexCount
134 };
135
137 {
142
143 std::string layer;
144 std::string source;
145 std::string name;
146 std::string absolute;
147 std::string directory;
148 std::string layerDirectory;
149 std::string filesDirectory;
150 std::string assetFileNameStem;
151 std::string layerAndName;
152 std::string skipPattern;
153
154 std::string keepList;
155
156 LevelReducer levelReducer = LevelReducer::RationalReducerVertexCount;
157
158 bool discardOutliers = false;
159 bool outputOutliers = false;
160 bool colorizeLevels = false;
161 bool embedMeshBounds = true;
162 bool statistics = false;
163
164
168 uint32_t maxSubtreeSize = 0; // FIXME: Disabled for now as AssetSystem appear to load all lods for sub-assets or something, needs to be fixed before this can be used.
169
175
180
185
186 int outlierMinVertexCount = 10'000;
187 float outlierMaxVolume = 1.0f;
188 float outlierMinVertexDensity = 10'000'000;
189
190 int dropReductionLevelThreshold = 4;
191 int dropReductionThreshold = 1000;
192 int minReductionThreshold = 500;
193
194 float edgeLengthWeight = 1.0f;
195
196 glm::vec3 minBounds;
197 glm::vec3 maxBounds;
198 bool useMinBounds = false;
199 bool useMaxBounds = false;
200
201 bool isEmpty = false;
202
203 bool useCompression = false;
204 bool prettyPrint = false;
205 int compressionLevel = 0;
206
207
218
225 std::string taskFilter;
226
229 std::string filter_rootIncludes;
230 std::string filter_rootPattern;
231 std::string filter_attributeName;
232 std::string filter_attributeValue;
233 std::vector<std::string> filter_excludeNodes;
234 };
235
236 struct Octree
237 {
238 Context * context;
239
240 OctreeInfo info;
241
242 uint32_t numLevels = 0;
243 float minCellSize = 1.0f;
244
246 std::vector<Parameterization> sources;
247
248 std::vector<SceneInfo> scenes; // One scene per level.
249 std::vector<LevelInput> inputs; // Specifies input to the level.
250 std::vector<Grid> grids; // Dimension and store for cell for each level.
251 };
252
253 void distributeGeometryWithIds(Octree & octree, PropertyStore& properties, const size_t level);
254
255 uint32_t clipTriangle(float* V_dst, float *N_dst, float *T_dst, const float (&clipBox)[6], const float *V_in, const float * N_in, const float *T_in);
256 uint32_t clipTriangle(float* V_dst, float *N_dst, const float(&clipBox)[6], const float *V_in, const float * N_in);
257}
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Definition: Context.h:83
std::vector< uint32_t > touches
Entity index of parts that touches the cell.
uint32_t sizeEstimate
Estimated filesize of cell geometry, used to determine if geometry of multiple cells should be packed...
std::vector< MeshRef > meshRefs
Meshes written to disc.
Geometry::BoundingBox bbox
Initially the full bounds of the cell, but shrinked to bounds of geometry after cell has been populat...
std::vector< MeshRec > meshRecs
Meshes not yet written to disc.
uint32_t parameterization
Specifies which of the parameterizations to use as input.
float reductionError
Target reduction percentage for per-cell rational reducer run, set to zero to disable.
float cullingThreshold
Cull all objects smaller than this value. This culls against the size of the shape of an entity.
float threshold
What error value to write in the asset file for this level, negative values imply just use level * 10...
std::string fileName
File name of cogsbin file with processed geometry.
uint32_t part
Part index of this cell's geometry in cogsbin file with processed geometry, -1 means that the entire ...
std::string filter_rootEndsWith
Individual Task: filter settings - for compatibility.
bool embedMeshBounds
Add mesh bounds where appropriate.
bool colorizeLevels
Add material to output colorized dependent on lod level, intended as a debug tool.
std::string keepList
("rvm.tagSimplify.keepList")
bool statistics
Calculate statistics for resulting hierarchy.
std::vector< Parameterization > sources
int remeshVolumeBlur
("rvm.tessellate.remeshVolumeBlur") The number of blur iterations to run on the volumetric scalar fie...
float simplificationFactor
("rvm.tessellate.simplificationFactor") If greater than zero, simplify non-parametric shapes within s...
float remeshSimplification
("rvm.tessellate.remeshSimplification") The simplification tolerance to use after remesh surface extr...
float cullLeaf
("rvm.tessellate.cullLeafThreshold") Cull leaves in the hierarchy where the combined geometry is smal...
float cullGeometry
("rvm.tessellate.cullGeometryThreshold") Cull geometries smaller than this value. Value is relative t...
float tolerance
("rvm.tessellate.tolerance") Tolerance used by rvmparser tessellator, in world space units.
bool isLoaded
Set to true when parameterization has been loaded.
float cullDiameter
("rvm.tessellate.cullDiameter") Cull round shapes with a diameter less than this value....
int simplificationMode
("rvm.tessellate.simplificationMode") Specifies which algorithm to use when simplifying.
float featureAngle
("rvm.tessellate.featureAngle") Minimum angle in radians between normals of two abutting triangles be...
int remeshTriSoupBlur
("rvm.tessellate.remeshTriSoupBlur") The number of blur iterations on 2D rasterized triangle soup bef...
float remeshGridSpacing
("rvm.tessellate.remeshGridSpacing") Specifies the remesh grid spacing relative to tolerance.
ModelHandle model
The imported model.
float remesh
("rvm.tessellate.remesh") Shapes with bbox cross-section diameter less than this value gets remeshed....
uint32_t geometries
The number of non-culled geometries in the scene.
float maxGeometrySize
Largest bounding box side length of an object in the scene.