3#include "Scene/RayPick.h"
4#include "Scene/GetBounds.h"
5#include "Resources/DataFetcherManager.h"
6#include "Resources/Resources.h"
7#include "Systems/ComponentSystem.h"
9#include "PotreeComponent.h"
12#include "Rendering/Common.h"
13#include "Rendering/VertexFormat.h"
14#include "Resources/MeshStreamsLayout.h"
16#include "Foundation/Collections/Pool.h"
17#include "Foundation/Collections/SmallVector.h"
18#include "Foundation/Memory/MemoryBuffer.h"
29 struct PotreeRenderer;
32 enum struct PotreeState {
40 enum struct PotreeeType
55 enum struct PotreeEnconding
62 enum struct PotreeAttributes {
63 POSITION_CARTESIAN = 0,
76 enum struct PotreeVertexLayout {
80 POSITION_COLOR_NORMAL,
82 POSITION_COLOR_INTENSITY,
83 POSITION_NORMAL_INTENSITY,
84 POSITION_COLOR_NORMAL_INTENSITY,
85 POSITION_CLASSIFICATION,
86 POSITION_COLOR_CLASSIFICATION,
87 POSITION_NORMAL_CLASSIFICATION,
88 POSITION_COLOR_NORMAL_CLASSIFICATION,
89 POSITION_INTENSITY_CLASSIFICATION,
90 POSITION_COLOR_INTENSITY_CLASSIFICATION,
91 POSITION_NORMAL_INTENSITY_CLASSIFICATION,
92 POSITION_COLOR_NORMAL_INTENSITY_CLASSIFICATION,
97 unsigned positionOffset;
99 unsigned normalOffset;
100 unsigned intensityOffset;
101 unsigned classOffset;
103 std::vector<Cogs::VertexElement> elements;
111 uint64_t byteOffset = 0;
112 uint64_t byteCount = 0;
126 glm::vec3 tbmin, tbmax;
128 uint32_t hierarchyNumPoints = 0;
129 uint32_t pointCount = 0;
131 uint16_t texOffset =
static_cast<uint16_t
>(~0u);
136 uint8_t scaleFactor = 100;
139 enum struct Kind : uint8_t
143 } kind = Kind::RegularNode;
144 enum struct State : uint8_t
150 } state = State::None;
151 enum struct Flags : uint8_t
155 } flags = Flags::None;
156 DataFetcherManager::FetchId fetch_id = DataFetcherManager::NoFetchId;
158 inline bool isRootNode()
const;
159 bool isActive()
const {
return unsigned(flags) & unsigned(Flags::Active); }
160 void setActive() { flags = Flags(
unsigned(flags) |
unsigned(Flags::Active)); }
161 void setInactive() { flags = Flags(
unsigned(flags) & ~
unsigned(Flags::Active)); }
163 void appendDescendSteps(std::string& path)
const;
170 ENABLE_ENUM_FLAGS(PotreeCell::Flags);
179 } state = State::None;
180 DataFetcherManager::FetchId fetch_id = DataFetcherManager::NoFetchId;
187 uint32_t subtreeId = 0;
198 bool PotreeCell::isRootNode()
const {
return l == 0 && owningSubtree->containingCell ==
nullptr; }
203 float priority = 0.f;
214 std::string suffix =
".bin";
218 size_t clipPlaneCount = 0;
234 glm::dvec3 positionInEntityFrame;
235 glm::vec3 currentPositionInEntityFrame;
237 glm::vec3 toBBoxShift;
238 glm::vec3 fullBBoxSize;
239 float fullBBoxDiagonal;
241 glm::vec3 fullBBoxMin;
242 glm::vec3 fullBBoxMax;
244 glm::vec3 tightBBoxMin;
245 glm::vec3 tightBBoxMax;
256 glm::dvec3 bbmin, bbmax;
261 glm::dvec3 tbmin = glm::vec3(0.f);
262 glm::dvec3 tbmax = glm::vec3(0.f);
266 glm::vec3 scale = glm::vec3(1.f);
269 glm::dvec3 offset = glm::vec3(0.f);
277 float levelScale = 1.f;
281 PotreeEnconding encoding = PotreeEnconding::Default;
282 uint32_t firstChunkSize = 0;
283 uint32_t hierarchyStepSize = 0;
284 uint32_t hierarchyDepth = 0;
288 float modelSpaceRadius = 1.f;
289 float tolerance = std::numeric_limits<float>::infinity();
290 float rootTolerance = std::numeric_limits<float>::infinity();
292 unsigned versionMajor = 0;
293 unsigned versionMinor = 0;
295 bool hasColor =
false;
296 bool hasNormal =
false;
297 bool hasIntensity =
false;
298 bool hasClassification =
false;
300 bool supportPicking =
true;
302 PotreeState state = PotreeState::Uninitialized;
303 DataFetcherManager::FetchId fetch_id = DataFetcherManager::NoFetchId;
304 PotreeVertexLayout layout = PotreeVertexLayout::COUNT;
306 MeshStreamsLayout streamsLayout;
311 Memory::TypedBuffer<glm::u8vec4> octtreeTextureData;
313 uint32_t instanceId = 0;
316 glm::mat4 worldFromOcttreeFrame;
319 List<PotreeSubtree, offsetof(PotreeSubtree, member)> subtrees;
322 List<PotreeCell, offsetof(PotreeCell, activeNode)> activeCells;
324 Memory::MemoryBuffer tmpVertexData;
325 Memory::TypedBuffer<PotreeCell*> tmpCellPointers;
327 static constexpr size_t occupancyGridDim = 32;
328 std::vector<uint8_t> occupancyTmpData;
330 Collections::Pool<PotreeCell> cellStore;
331 Collections::Pool<PotreeSubtree> subtreeStore;
334 MaterialInstanceHandle instance;
340 MaterialInstanceHandle instance;
356 glm::dvec3 boundsMin = glm::dvec3(std::numeric_limits<double>::max());
357 glm::dvec3 boundsMax = glm::dvec3(-std::numeric_limits<double>::max());
364 std::unique_ptr<PotreeData> poData;
368 glm::vec4 pointControl[2];
373 glm::vec4 boxControl[3];
382 size_t pointCount = 0;
384 size_t nonEmptyCells = 0;
385 glm::vec3 lo = glm::vec3(std::numeric_limits<float>::max());
386 glm::vec3 hi = glm::vec3(-std::numeric_limits<float>::max());
395 } state = State::Success;
405 PotreeEnconding encoding;
407 glm::vec3 fullBBoxMin;
408 glm::vec3 fullBBoxSize;
419 const glm::vec2& normPosition,
425 std::vector<RayPicking::RayPickHit>& hits)
override;
428 const glm::vec3& startPos,
429 const glm::quat& rot,
435 std::vector<RayPicking::RayPickHit>& hits)
override;
444 void getBounds(
Context* context, Cogs::Geometry::BoundingBox& bounds)
override;
490 unsigned requestsInFlight = 0;
491 bool materialLoaded =
false;
Container for components, providing composition of dynamic entities.
Context * context
Pointer to the Context instance the system lives in.
void update()
Updates the system state to that of the current frame.
void preUpdate()
Run the pre-update method of the system.
Component system with parallel data per component stored in a pool similar to how the components them...
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Interface for modules implementing custom picking.
void getBounds(Context *context, Cogs::Geometry::BoundingBox &bounds) override
Expand bounds including bounds of all entities in this system in world coordinates.
Base allocator implementation.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
@ Success
Resource activated successfully.
PicksReturned
* Options for returning picking hits.
PickingFlags
Options for COGS picking.
@ None
No debug node outlines.
@ Ready
All 6 baselayers are fully loaded, instance will begin rendering.
@ None
Just use scale and offset as is.
uint16_t VariableKey
Used to lookup material properties.
ComponentIndex SizeType
Type used to track the size of pools.
Handle to a Component instance.
Component for Point Cloud Display.
uint32_t requestsInFlight
Number of outstanding data fetch requests.
std::vector< PotreeNodeHeapItem > lodHeap
heap used while calculating lod levels
float val
Current dpi-scaled and min-max clamped point-size.
float min
Current dpi-scaled minimum point-size.
float max
Current dpi-scaled maximum point-size.
static constexpr size_t MaxClipPlanes
Max available in shader.
std::string jsonPath
URL to metadata file.
PotreeNotification potreeNotificationState
Current notification state for this PoTree Component.
std::string octreeDir
1.x only: subdir with data
std::string rootPath
URL to folder containing metadata file.
bool pickRay(Context *, const glm::vec3 &startPos, const glm::quat &rot, float rayLength, float radius, PickingFlags pickingFlags, PicksReturned returnFlag, const RayPicking::RayPickFilter &filter, std::vector< RayPicking::RayPickHit > &hits) override
Do a ray pick from a position and orientation in world space and return all hits.
bool pickCamera(Context *context, const CameraComponent &camera, const glm::vec2 &normPosition, float, float radius, PickingFlags pickingFlags, PicksReturned returnFlag, const RayPicking::RayPickFilter &filter, std::vector< RayPicking::RayPickHit > &hits) override
Do a ray pick from a normalized screen space position in the camera direction and return all hits.
ComponentHandle createComponent() override
static void startFetch(Context *context, const PotreeComponent *poComp, PotreeData *poData)
Update Component request count and notify client when starting data fetch.
void destroyComponent(ComponentHandle component) override
void cleanup(Context *context) override
Provided for custom cleanup logic in derived systems.
void initialize(Context *context) override
Initialize the system.
static void endFetch(Context *context, const PotreeComponent *poComp, PotreeData *poData)
Abstract base class storing data read from a file.