NDEVR
API Documentation
DesignObjectBase.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: DesignObjectBase
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/TableColumnBuffer.h>
35#include <NDEVR/Table.h>
36#include <NDEVR/Pointer.h>
37#include <NDEVR/Bounds.h>
38#include <NDEVR/Set.h>
39#include <NDEVR/RandomColorGenerator.h>
40namespace NDEVR
41{
42 class JSONNode;
43 template<uint01 t_dims, class t_type>
44 class RTree;
45 typedef AlocatingAlignedBuffer<JSONNode, 0> JSONBuffer;
56 NDEVR_DESIGN_T_API template class NDEVR_DESIGN_API StringStream<PrimitiveProperty>;
61 {
63 , Normal = 1
64 , Tangent = 2
65 , BiTangent = 3
66 , Color = 4
67 , Texture = 5
68 , BitFlag = 6
69 , Bones = 7
71 , Region = 9
73 , Invalid = 255
74 };
75 NDEVR_DESIGN_T_API template class NDEVR_DESIGN_API StringStream<VertexProperty>;
89
95 {
97 , e_is_hidden = 0x02
98 , e_is_locked = 0x04
99 , e_is_deleted = 0x08
101 };
102
116
126 NDEVR_DESIGN_T_API template class NDEVR_DESIGN_API StringStream<WindingMode>;
137 NDEVR_DESIGN_T_API template class NDEVR_DESIGN_API StringStream<NormalMode>;
154 NDEVR_DESIGN_T_API template class NDEVR_DESIGN_API StringStream<PrimitiveMode>;
169 NDEVR_DESIGN_T_API template class NDEVR_DESIGN_API StringStream<UVType>;
170 class WLock;
178 {
179 public:
185 NDEVR_DESIGN_API DesignObjectBase(bool is_app_owned);
190
191 // --- Tables ---
198#if NDEVR_SUPPORTS_BONES
199 Table bone_table;
200 uint04 bone_index = Constant<uint04>::Invalid;
201 uint04 bone_child_index = Constant<uint04>::Invalid;
202#endif
204
205 // --- Design Object Columns ---
206
208 ColumnT<uint04> model_index;
209 ColumnT<uint04> material_index;
210 ColumnT<uint04> geometry_index;
211 ColumnT<uint04> effect_index;
212
213 // --- High Efficiency Accessors ---
214 ColumnT<UUID> guid;
215 ColumnT<Time> modified_time;
216 ColumnT<Time> asc_modified_time;
217 ColumnT<Time> desc_modified_time;
218 ColumnT<String> name;
219 ColumnT<uint01> design_type;
220 ColumnT<Matrix<fltp08>> transform;
222 ColumnT<bool> spacial_visible;
223 ColumnT<bool> tree_visible;
224 ColumnT<bool> is_deleted;
225
226 // --- Material Columns ---
233
234 // --- Geometry Table Columns ---
236 ColumnT<Buffer<uint04>> geometry_parent;
240 ColumnT<uint04> primitive_index_column;
241 ColumnT<uint04> primitive_fan_column;
242 ColumnT<uint01> primitive_flag_column;
243
244 ColumnT<uint04> index_mode_offset_column;
245 ColumnT<uint04> index_mode_size_column;
246
247 ColumnT<uint04> index_fan_offset_column;
248 ColumnT<uint04> index_fan_size_column;
249
250
252 ColumnT<uint04> vertex_offset_column;
253 ColumnT<uint04> vertex_count_column;
255
259
260
261 // --- Vertex Table Columns ---
263
264
265 // --- Model Columns ---
267 ColumnT<uint04> model_geometry_index;
268 ColumnT<Buffer<uint04>> effect_child_index;
269 ColumnT<Buffer<uint04>> local_child_location;
270 ColumnT<Buffer<uint04>> external_child_location;
271 ColumnT<uint04> parent_location;
272 ColumnT<uint04> layer_location;
273
274
275 ColumnT<String> model_type;
276 ColumnT<Bounds<3, fltp08>> visible_box;
277 ColumnT<Bounds<3, fltp08>> global_bounds;
278 ColumnT<Bounds<3, fltp08>> global_selection_bounds;
279 ColumnT<Matrix<fltp08>> complete_transform;
280 ColumnT<uint08> child_base_ptr;
281 ColumnT<uint08> parent_base_ptr;
282 ColumnT<uint04> inherited_flags;
283 ColumnT<uint04> personal_inherited_flags;
284 ColumnT<uint08> material_base_ptr;
285 ColumnT<uint08> geometry_base_ptr;
286 ColumnT<uint04> material_child_index;
287
288 // --- Effect Columns ---
290 ColumnT<Buffer<uint04>> effect_targets;
291 ColumnT<Buffer<uint08>> effect_extern_targets;
292
293
294 JSONBuffer cached_meta_data;
295 ColumnT<Buffer<uint04>>* neighbor_index_location = nullptr;
296 ColumnT<Buffer<uint04>>* face_to_edge_column = nullptr;
297 ColumnT<Buffer<uint04>>* edge_to_face_column = nullptr;
298 public:
320 const Dictionary<UUID, DynamicPointer<RTree<3, fltp04>>>& trees() const { return m_r_trees; }
326 void setRTree(UUID id, const DynamicPointer<RTree<3, fltp04>>& tree);
337 bool hasRTree(UUID id) const;
342 void addTable(Table* table);
347 void removeTable(const StringView& label);
353 Table* table(const StringView& label);
358 const Dictionary<UUID, Table*>& tables() { return m_tables; };
359 public:
364 Set<DesignObjectBase*>& referencedBases() { return m_referenced_bases; };
374 bool isApplicationOwned() const;
390 NDEVR_DESIGN_API void finishMapFromFile(BinaryFileTableInfo& info);
395 NDEVR_DESIGN_API void fetchDataColumns(Buffer<TableColumn*>& columns);
400 NDEVR_DESIGN_API void mapToFile(BinaryFileTableInfo& file) const;
405 NDEVR_DESIGN_API void mapFromFile(BinaryFileTableInfo& file);
411 NDEVR_DESIGN_API void mapTreeToFile(BinaryFileTableInfo& file, int mode) const;
421 const RandomColorGenerator& randomColorGenerator() const { return m_color_generator; }
425 NDEVR_DESIGN_API void readMetaDataFromColumn();
429 NDEVR_DESIGN_API void writeMetaDataToColumn();
430#ifdef _DEBUG
431 public:
432 const void* lock_ptr_check = nullptr;
433#endif
434 protected:
471 private:
472 Dictionary<UUID, Table*> m_tables;
473 Dictionary<String, Table*> m_custom_tables;
474
476 Set<DesignObjectBase*> m_referenced_bases;
478 RandomColorGenerator m_color_generator;
479 bool m_is_app_owned = false;
480 };
481}
A bitset that stores 8 bits (elements with only two possible values: 0 or 1, true or false,...
Definition BitFlag.hpp:55
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
The core Color class in the NDEVR API.
Definition Color.h:42
Provides a constant, unmodifiable pointer that has shared ownership of a dynamically allocated object...
Definition Pointer.hpp:276
Table vertex_table
Table storing per-vertex data (position, normal, color, etc.).
const Dictionary< UUID, Table * > & tables()
Returns a reference to the dictionary of all custom tables keyed by UUID.
void createEffectTable()
Creates and configures the effect table and its columns.
ColumnT< uint04 > vertex_reserved_count_column
Column storing the number of reserved (allocated) vertices.
ColumnT< Time > asc_modified_time
Column storing the ascending-order modification timestamp.
void addTable(Table *table)
Adds a custom table to this base, making it accessible by its label.
ColumnT< uint08 > geometry_base_ptr
Column storing a pointer or handle to the geometry DesignObjectBase.
DesignObjectBase(bool is_app_owned)
Constructs a DesignObjectBase and initializes all internal tables and columns.
ColumnT< uint04 > material_index
Column storing the material table index for each design object.
void createModelTable()
Creates and configures the model hierarchy table and its columns.
Vector< 16, TableColumn * > vertex_property_column
Array of pointers to vertex property columns, indexed by VertexProperty.
ColumnT< uint04 > index_fan_size_column
Column storing the size of the fan index buffer region.
ColumnT< uint04 > index_mode_offset_column
Column storing the offset into the index mode buffer.
Vector< 11, TableColumn * > effect_properties
Array of pointers to all effect property columns.
ColumnT< Buffer< uint04 > > effect_child_index
Column storing child effect indices for each model.
DynamicPointer< RTree< 3, fltp04 > > getRTree(UUID id)
Retrieves a mutable pointer to the R-tree associated with the given UUID.
ColumnT< String > name
Column storing the display name for each design object.
void mapTreesFromFile(BinaryFileTableInfo &file)
Deserializes R-tree spatial index data from a binary file.
Dictionary< String, DesignObjectBase * > & ownedBases()
Returns a reference to the dictionary of DesignObjectBase instances owned by this base.
void mapTreeToFile(BinaryFileTableInfo &file, int mode) const
Serializes R-tree spatial index data to a binary file.
void removeTable(const StringView &label)
Removes a custom table identified by its label.
Table geometry_table
Table storing geometry metadata (vertex ranges, primitive modes).
Vector< 8, ColumnT< uint04 > * > primitive_property_offset_column
Primitive property offset columns into the index table.
Vector< 16, TableColumn * > vertex_mode_column
Vertex mode columns describing how each vertex property is stored per geometry.
Vector< 8, ColumnT< uint04 > * > primitive_property_size_column
Primitive property size columns (number of indices).
Vector< 10, TableColumn * > uv_intensity
UV intensity value columns, one per UVType.
bool hasRTree(UUID id) const
Checks whether an R-tree exists for the given UUID.
ColumnT< uint04 > primitive_fan_column
Column storing the triangle fan index offset.
void removeRTree(UUID id)
Removes the R-tree associated with the given UUID.
ConstPointer< RTree< 3, fltp04 > > getRTree(UUID id) const
Retrieves a read-only pointer to the R-tree associated with the given UUID.
ColumnT< uint04 > vertex_offset_column
Column storing the starting vertex offset in the vertex table.
void createMaterialTable()
Creates and configures the material table and its columns.
~DesignObjectBase()
Destroys the DesignObjectBase and releases all owned resources.
JSONBuffer cached_meta_data
Buffer storing cached JSON metadata for design objects.
Set< DesignObjectBase * > & referencedBases()
Returns a reference to the set of externally referenced DesignObjectBase instances.
ColumnT< uint01 > design_type
Column storing the design object type identifier.
ColumnT< Buffer< uint04 > > * edge_to_face_column
Optional column mapping edges to their adjacent face indices.
ColumnT< uint04 > solid_vertex_reserved_count_column
Column storing the number of reserved solid-fill vertices.
ColumnT< uint04 > vertex_count_column
Column storing the number of active vertices.
void setRTree(UUID id, const DynamicPointer< RTree< 3, fltp04 > > &tree)
Sets or replaces the R-tree for the given UUID.
ColumnT< uint04 > index_mode_size_column
Column storing the size of the index mode buffer region.
ColumnT< Bounds< 3, fltp08 > > visible_box
Column storing the visible bounding box for culling.
void setupStaticTables()
Configures static (non-row-dependent) table properties and metadata.
ColumnT< Time > desc_modified_time
Column storing the descending-order modification timestamp.
Table effect_table
Table storing effect definitions (animations, constraints, etc.).
ColumnT< uint01 > primitive_flag_column
Column storing per-primitive bit flags.
ColumnT< uint04 > model_geometry_index
Column storing the geometry index associated with each model.
void mapFromFile(BinaryFileTableInfo &file)
Deserializes all table data from a binary file.
ColumnT< uint08 > parent_base_ptr
Column storing a pointer or handle to the parent DesignObjectBase.
ColumnT< UUID > guid
Column storing the globally unique identifier for each design object.
ColumnT< uint08 > child_base_ptr
Column storing a pointer or handle to the child DesignObjectBase.
ColumnT< Bounds< 3, fltp08 > > global_bounds
Column storing the world-space axis-aligned bounding box.
ColumnT< Buffer< uint08 > > effect_extern_targets
Column storing external target references for each effect.
ColumnT< uint04 > effect_index
Column storing the effect table index for each design object.
void createTables()
Creates and initializes all internal tables (property, material, geometry, model, effect).
void setDefaultValues()
Sets default values for all columns across all tables.
const Dictionary< UUID, DynamicPointer< RTree< 3, fltp04 > > > & trees() const
Returns a const reference to the dictionary of all R-trees keyed by UUID.
ColumnT< uint04 > index_fan_offset_column
Column storing the offset into the fan index buffer.
ColumnT< uint04 > layer_location
Column storing the layer index that this model belongs to.
ColumnT< String > model_type
Column storing the model type string identifier.
Table property_table
Table storing design object properties (name, transform, type, etc.).
ColumnT< Buffer< uint04 > > * neighbor_index_location
Optional column storing neighbor vertex indices for adjacency queries.
ColumnT< Bounds< 3, fltp08 > > global_selection_bounds
Column storing the world-space selection bounding box.
void fetchDataColumns(Buffer< TableColumn * > &columns)
Populates the given buffer with pointers to all active data columns across all tables.
ColumnT< Matrix< fltp08 > > complete_transform
Column storing the fully composed world-space transform matrix.
WLock lockRTrees()
Acquires a write lock on all R-trees in this base.
ColumnT< Time > modified_time
Column storing the last modification timestamp.
Vector< 8, TableColumn * > primitive_property_mode_column
Primitive property mode columns, one per PrimitiveProperty.
void addReference(DesignObjectBase *base)
Adds an external reference to another DesignObjectBase.
ColumnT< uint04 > solid_vertex_offset_column
Column storing the starting offset for solid-fill vertices.
Vector< 10, TableColumn * > uv_color
UV color columns, one per UVType.
ColumnT< Buffer< uint04 > > local_child_location
Column storing local child model indices in the hierarchy.
ColumnT< Buffer< uint04 > > effect_targets
Column storing target design object indices for each effect.
ColumnT< bool > is_deleted
Column indicating whether the object has been soft-deleted.
DesignObjectBase * base(const StringView &base)
Retrieves an owned or referenced DesignObjectBase by its string key.
ColumnT< bool > tree_visible
Column indicating whether the object is visible in the scene tree.
Vector< 10, TableColumn * > uv_image_file
UV image file path columns, one per UVType.
ColumnT< Buffer< uint04 > > geometry_parent
Column storing parent geometry indices for geometry grouping.
void readMetaDataFromColumn()
Reads JSON metadata from the metadata column into the cached_meta_data buffer.
bool isApplicationOwned() const
Checks whether this base is owned by the application.
ColumnT< uint04 > geometry_index
Column storing the geometry table index for each design object.
ColumnT< uint04 > model_index
Column storing the model table index for each design object.
Table model_table
Table storing model hierarchy data (parent/child, bounds, transforms).
Table material_table
Table storing material definitions (textures, colors, shading).
void linkTables()
Links all tables together by establishing cross-table column references.
void createPropertyTable()
Creates and configures the design object property table and its columns.
Vector< 10, TableColumn * > uv_layer
UV layer index columns, one per UVType.
void mapToFile(BinaryFileTableInfo &file) const
Serializes all table data to a binary file.
Table primitive_index_table
Table storing primitive index buffers (triangles, lines, etc.).
const RandomColorGenerator & randomColorGenerator() const
Returns a const reference to the random color generator used for assigning colors.
Vector< 18, TableColumn * > model_properties
Array of pointers to all model property columns.
TableVectorType< 6, fltp08 > bounding_box
Column storing the axis-aligned bounding box (min XYZ, max XYZ).
ColumnT< uint04 > material_child_index
Column storing the material index assigned to child models.
ColumnT< Matrix< fltp08 > > transform
Column storing the local transformation matrix.
ColumnT< Buffer< uint04 > > * face_to_edge_column
Optional column mapping faces to their edge indices.
Vector< 28, TableColumn * > material_properties
Array of pointers to all material property columns.
void finishMapFromFile(BinaryFileTableInfo &info)
Completes the mapping process after reading table data from a binary file.
ColumnT< uint04 > primitive_index_column
Column storing the primitive index buffer offset.
Vector< 21, TableColumn * > geometry_properties
Array of pointers to all geometry property columns.
ColumnT< uint04 > inherited_flags
Column storing flags inherited from ancestors (visibility, lock, etc.).
ColumnT< uint04 > solid_vertex_count_column
Column storing the number of active solid-fill vertices.
ColumnT< uint04 > personal_inherited_flags
Column storing flags set on this model that propagate to children.
ColumnT< uint08 > material_base_ptr
Column storing a pointer or handle to the material DesignObjectBase.
Table * table(const StringView &label)
Retrieves a custom table by its label.
Vector< 38, TableColumn * > design_properties
Array of pointers to all design property columns, indexed by property enum.
ColumnT< Buffer< uint04 > > external_child_location
Column storing external child model references.
void writeMetaDataToColumn()
Writes cached JSON metadata from the cached_meta_data buffer back to the metadata column.
ColumnT< bool > spacial_visible
Column indicating whether the object is visible in the 3D viewport.
void createGeometryTable()
Creates and configures the geometry table and its columns.
ColumnT< uint04 > parent_location
Column storing the parent model index in the hierarchy.
Vector< 10, TableColumn * > uv_mode
UV mapping mode columns, one per UVType.
A hash-based key-value store, useful for quick associative lookups.
Definition Dictionary.h:64
Provides a modifiable pointer that has shared ownership of a dynamically allocated object.
Definition Pointer.hpp:356
JavaScript Object Notation or JSON is an open - standard file format that uses human - readable text ...
Definition JSONParser.h:149
Generates random colors based on configurable hue and luminosity settings.
Container that stores unique elements in no particular order, and which allow for fast retrieval or i...
Definition Set.h:59
The core String View class for the NDEVR API.
Definition StringView.h:58
A TableColumnBuffer that also has some number of defined rows stored in a Vector object Allows for vi...
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
Used to lock a particular variable for writing.
Definition RWLock.h:272
The primary namespace for the NDEVR SDK.
NormalMode
Describes how surface normals are computed or stored for a Geometry object.
@ e_vertex_smooth_normals
Normals are smoothed per-vertex.
@ e_smooth_normals
Normals are interpolated smoothly across faces.
@ e_hard_normals
Each face uses a single flat normal (hard edges).
@ e_no_normals
No normals are provided.
VertexProperty
Per-vertex data channels that can be stored in the vertex table to be used by Geometry.
@ Position
XYZ position of the vertex.
@ Tangent
Tangent vector for normal mapping.
@ Normal
Surface normal vector at the vertex.
@ Texture
Texture UV coordinates.
@ PreSmoothedPosition
Original vertex position before smoothing was applied.
@ Vertex_Property_Size
The number of vertex property types. Used for sizing arrays.
@ BiTangent
Bitangent vector for normal mapping.
@ Bones
Bone indices and weights for skeletal animation.
@ Region
Region identifier for vertex grouping.
PrimitiveMode
Used with Geometry to describe how vertices and indices are used to form shapes.
@ e_grid
Indices define a regular grid topology.
@ e_no_index
No index buffer is used; vertices are not indexed.
@ e_triangle_strip
Indices define a triangle strip.
@ e_lines
Each pair of indices defines a line segment.
@ e_polyline
Indices define a connected polyline.
@ e_triangle
Each triplet of indices defines a triangle.
@ e_index_mode_size
The number of primitive modes. Used for sizing arrays.
@ e_block_model
Indices define a volumetric block model.
@ e_triangle_fan
Indices define a triangle fan around a central vertex.
@ e_point
Each index references a single point.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
GeometryType
Describes the high-level geometric topology of a Geometry object.
@ e_points
Point cloud or discrete points.
@ e_geometry_type_size
The number of geometry types. Used for sizing arrays.
@ e_block_models
Volumetric block model grids.
@ e_grids
Regular grid structures (e.g., terrain heightmaps).
@ e_linework
Lines or polylines.
@ e_convex_polygons
Convex polygon meshes.
@ e_concave_polygons
Concave polygon meshes.
@ e_triangles
Triangle meshes.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
@ file
The source file path associated with this object.
PrimitiveProperty
Describes which rendering property a primitive index buffer corresponds to.
@ Outline
Line-based outline rendering of primitives.
@ Index_Property_Size
The number of primitive property types. Used for sizing arrays.
@ Solid
Solid filled rendering of primitives.
@ Vertices
Vertex highlighting and point drawing.
WindingMode
Describes the vertex winding order used to determine front-facing direction of polygons.
@ e_clockwise_winding
Vertices wind clockwise when viewed from the front.
@ e_counterclockwise_winding
Vertices wind counterclockwise when viewed from the front.
@ e_no_winding
No winding order is defined.
@ e_indeterminate_winding
Winding order is mixed or unknown.
VertexFlags
Bit flags that can be set on individual vertices to control selection, visibility,...
@ e_is_smooth
Vertex should use smooth shading.
@ e_is_locked
Vertex is locked and cannot be edited.
@ e_is_filtered
Vertex is excluded by a filter.
@ e_is_closure_location
Vertex marks a closure point (e.g., closing a polygon loop).
@ e_is_selected
Vertex is currently selected.
@ e_is_hidden
Vertex is hidden from display.
UVType
Channels that describe how an object should interact with light.
@ e_KA
Ambient texture/color channel.
@ e_displace
Displacement map channel for surface deformation.
@ e_emmisive
Emissive (self-illumination) map channel.
@ e_KS
Specular texture/color channel.
@ e_KD
Diffuse texture/color channel.
@ e_uv_size
The number of UV types. Used for sizing arrays.
@ e_reflect
Reflection map channel.
@ e_normal
Normal map channel for per-pixel lighting.
PrimitiveBitFlags
Bit flags that can be set on individual primitives (triangles, lines, etc.) to control their selectio...
@ e_is_deleted
Primitive has been marked for deletion.
@ e_is_closure_primitive
Primitive represents a closure element (e.g., closing face).
Extended file table information for reading and writing NDV binary files.