33#include <NDEVR/Model.h>
34#if NDEVR_MODEL_TILE_CONTAINER
35#include <NDEVR/Geometry.h>
36#include <NDEVR/AngleDefinitions.h>
37#include <NDEVR/MatrixFunctions.h>
38#include <NDEVR/Scene.h>
67 Buffer<Model> old_model_pool;
68 Buffer<Model> new_models_added;
69 Matrix<fltp08> source_transform = Matrix<fltp08>(1.0);
70 Matrix<fltp08> model_to_tile_transform = Matrix<fltp08>(1.0);
71 LineSegment<3, fltp08> placement_segment;
72 bool use_heading =
true;
73 bool use_inclination =
true;
74 bool scale_to_fit =
false;
75 bool per_vertex_placement =
false;
87 static Model IndexChild(TileOptions& options)
90 if (options.old_model_pool.size() > 0)
92 child = options.old_model_pool.last();
94 options.new_models_added.add(child);
95 if (child.get<NDPO::library_id>() != options.model_to_tile.get<NDPO::library_id>())
96 child.copyFrom(options.model_to_tile,
false);
97 options.model_to_tile = child;
98 options.old_model_pool.removeLast();
102 child = options.parent.createChild();
103 child.copyFrom(options.model_to_tile,
false);
104 options.model_to_tile = child;
105 options.new_models_added.add(child);
118 static void TileAlongGeo(
const Geometry& linework, TileOptions& options)
120 if (linework.getGeometryType() == GeometryType::e_linework)
123 Buffer<Polyline<3, fltp08>> polylines = linework.polylines<3,
fltp08>(PrimitiveProperty::Outline, VertexProperty::Position);
125 for (uint04 i = 0; i < polylines.size(); i++)
127 polylines[i].simplify();
128 TileModelAlongLine(polylines[i], options);
147 else if (linework.getGeometryType() == GeometryType::e_points)
149 Buffer<Vertex<3, fltp08>> vertices = linework.vertices<Vertex<3, fltp08>>(VertexProperty::Position);
150 const Matrix<fltp08> dest_transform = options.model_to_tile_transform;
151 const Matrix<fltp08> parent_transform = options.parent.getCompleteTransform().invert();
152 for (uint04 i = 0; i < vertices.size(); i++)
156 Model child = IndexChild(options);
157 Matrix<fltp08> mat = Matrix<fltp08>::OffsetMatrix(options.source_transform * vertices[i]);
158 mat = parent_transform * mat * dest_transform;
159 child.set<NDPO::transform>(mat);
174 static void TileModelAlongLine(
const Polyline<3, fltp08>& extrude_path, TileOptions& options)
176 fltp08 distance = options.placement_segment.ray()[X];
177 Polyline<3, fltp08> broken_poly = options.source_transform * extrude_path;
178 if (!options.per_vertex_placement)
180 broken_poly = broken_poly.breakIntoSegmentsByDistance(distance);
181 if (options.scale_to_fit)
182 distance = 0.9999999 * broken_poly.length<
fltp08>() / cast<fltp08>(cast<sint04>(broken_poly.length<fltp08>() / distance));
184 if (broken_poly.segmentCount() == 0)
189 Matrix<fltp08> dest_transform = options.model_to_tile_transform;
191 const Matrix<fltp08> parent_transform = options.parent.getCompleteTransform().invert();
192 for (uint04 i = 0; i < broken_poly.vertexCount(); i++)
194 Model child = IndexChild(options);
195 Matrix<fltp08> mat = Matrix<fltp08>::OffsetMatrix(broken_poly.vertex(i));
196 uint04 segment_index =
getMin(broken_poly.segmentCount() - 1, i);
197 if(options.use_heading)
198 mat = mat.rotate(AngleDefinitions::Heading<sint04>(broken_poly.segment(segment_index).ray()), Vector<3, fltp08>(0, 0, 1));
199 if(options.use_inclination)
200 mat = mat.rotate(-AngleDefinitions::Inclination<sint04>(broken_poly.segment(segment_index).ray()), Vector<3, fltp08>(0, 1, 0));
201 if (options.scale_to_fit)
203 auto bounds = dest_transform * child.getBounds();
204 mat = mat.scale({ distance / bounds.span(X), 1.0, 1.0 });
206 mat = parent_transform * mat * dest_transform;
207 child.update<NDPO::transform>(mat);
The primary namespace for the NDEVR SDK.
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid.