Radium Engine  1.5.0
DrawPrimitives.cpp
1 #include <Engine/Data/DrawPrimitives.hpp>
2 
3 #include <Core/Geometry/MeshPrimitives.hpp>
4 #include <Core/Geometry/StandardAttribNames.hpp>
5 #include <Core/Utils/Color.hpp>
6 
7 #include <Engine/Data/Mesh.hpp>
8 #include <Engine/Data/ShaderConfigFactory.hpp>
9 #include <Engine/Rendering/RenderObject.hpp>
10 #include <Engine/Rendering/RenderTechnique.hpp>
11 
12 #include <Core/Containers/MakeShared.hpp>
13 #include <Engine/Data/PlainMaterial.hpp>
14 
15 #include <algorithm>
16 #include <numeric>
17 
18 namespace Ra {
19 
20 using namespace Core;
21 using namespace Core::Geometry;
22 
23 namespace Engine {
24 namespace Data {
25 namespace DrawPrimitives {
26 
27 Rendering::RenderObject* Primitive( Scene::Component* component, const MeshPtr& mesh ) {
28  return Primitive( component, std::dynamic_pointer_cast<Data::AttribArrayDisplayable>( mesh ) );
29 }
30 
31 Rendering::RenderObject* Primitive( Scene::Component* component, const LineMeshPtr& mesh ) {
32  return Primitive( component, std::dynamic_pointer_cast<Data::AttribArrayDisplayable>( mesh ) );
33 }
34 
35 Rendering::RenderObject* Primitive( Scene::Component* component,
36  const AttribArrayDisplayablePtr& mesh ) {
38  auto builder = Rendering::EngineRenderTechniques::getDefaultTechnique( "Plain" );
39  builder.second( rt, false );
40  auto roMaterial = Core::make_shared<PlainMaterial>( "Default material" );
41  roMaterial->m_perVertexColor = mesh->getAttribArrayGeometry().hasAttrib(
42  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ) );
43  rt.setParametersProvider( roMaterial );
44 
45  auto ro = Rendering::RenderObject::createRenderObject(
46  mesh->getName(), component, Rendering::RenderObjectType::Debug, mesh, rt );
47  ro->setMaterial( roMaterial );
48  return ro;
49 }
50 
51 LineMeshPtr Point( const Core::Vector3& point, const Core::Utils::Color& color, Scalar scale ) {
52 
53  Geometry::LineMesh geom;
54  geom.setVertices( { ( point + ( scale * Core::Vector3::UnitX() ) ),
55  ( point - ( scale * Core::Vector3::UnitX() ) ),
56  ( point + ( scale * Core::Vector3::UnitY() ) ),
57  ( point - ( scale * Core::Vector3::UnitY() ) ),
58  ( point + ( scale * Core::Vector3::UnitZ() ) ),
59  ( point - ( scale * Core::Vector3::UnitZ() ) ) } );
60  geom.setIndices( { { 0, 1 }, { 2, 3 }, { 4, 5 } } );
61  geom.addAttrib(
62  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ),
63  Core::Vector4Array { geom.vertices().size(), color } );
64 
65  return make_shared<LineMesh>( "Point Primitive", std::move( geom ) );
66 }
67 
68 LineMeshPtr
69 Line( const Core::Vector3& a, const Core::Vector3& b, const Core::Utils::Color& color ) {
70  Geometry::LineMesh geom;
71  geom.setVertices( { a, b } );
72  geom.setIndices( { { 0, 1 } } );
73  geom.addAttrib(
74  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ),
75  Core::Vector4Array { geom.vertices().size(), color } );
76 
77  return make_shared<LineMesh>( "Line Primitive", std::move( geom ) );
78 }
79 
80 LineMeshPtr
81 Vector( const Core::Vector3& start, const Core::Vector3& v, const Core::Utils::Color& color ) {
82  Core::Vector3 end = start + v;
83  Core::Vector3 a, b;
84  Core::Math::getOrthogonalVectors( v.normalized(), a, b );
85  a.normalize();
86  Scalar l = v.norm();
87 
88  const Scalar arrowFract = 0.1f;
89 
90  Geometry::LineMesh geom;
91  geom.setVertices( { start,
92  end,
93  start + ( ( 1.f - arrowFract ) * v ) + ( ( arrowFract * l ) * a ),
94  start + ( ( 1.f - arrowFract ) * v ) - ( ( arrowFract * l ) * a ) } );
95  geom.setIndices( { { 0, 1 }, { 1, 2 }, { 1, 3 } } );
96  geom.addAttrib(
97  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ),
98  Core::Vector4Array { geom.vertices().size(), color } );
99 
100  return make_shared<LineMesh>( "Vector Primitive", std::move( geom ) );
101 }
102 
103 LineMeshPtr Ray( const Core::Ray& ray, const Core::Utils::Color& color, Scalar len ) {
104  Geometry::LineMesh geom;
105  Core::Vector3 end = ray.pointAt( len );
106  geom.setVertices( { ray.origin(), end } );
107  geom.setIndices( { { 0, 1 } } );
108  geom.addAttrib(
109  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ),
110  Core::Vector4Array { geom.vertices().size(), color } );
111  return make_shared<LineMesh>( "Ray Primitive", std::move( geom ) );
112 }
113 
114 AttribArrayDisplayablePtr Triangle( const Core::Vector3& a,
115  const Core::Vector3& b,
116  const Core::Vector3& c,
117  const Core::Utils::Color& color,
118  bool fill ) {
119  if ( fill ) {
120  Geometry::TriangleMesh geom;
121  geom.setVertices( { a, b, c } );
122  geom.setIndices( { { 0, 1, 2 } } );
123  geom.addAttrib(
124  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ),
125  Core::Vector4Array { geom.vertices().size(), color } );
126  return make_shared<Mesh>( "Triangle Primitive", std::move( geom ) );
127  }
128  else {
129  Geometry::LineMesh geom;
130  geom.setVertices( { a, b, c } );
131  geom.setIndices( { { 0, 1 }, { 1, 2 }, { 2, 0 } } );
132  geom.addAttrib(
133  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ),
134  Core::Vector4Array { geom.vertices().size(), color } );
135  return make_shared<LineMesh>( "Triangle Primitive", std::move( geom ) );
136  }
137 }
138 
140 MeshPtr QuadStrip( const Core::Vector3& a,
141  const Core::Vector3& x,
142  const Core::Vector3& y,
143  uint quads,
144  const Core::Utils::Color& color ) {
145  Core::Vector3Array vertices( quads * 2 + 2 );
146  std::vector<uint> indices( quads * 2 + 2 );
147 
148  Core::Vector3 B = a;
149  vertices[0] = B;
150  vertices[1] = B + x;
151  indices[0] = 0;
152  indices[1] = 1;
153  for ( uint i = 0; i < quads; ++i ) {
154  B += y;
155  vertices[2 * i + 2] = B;
156  vertices[2 * i + 3] = B + x;
157  indices[2 * i + 2] = 2 * i + 2;
158  indices[2 * i + 3] = 2 * i + 3;
159  }
160 
161  Core::Vector4Array colors( vertices.size(), color );
162 
163  MeshPtr mesh( new Mesh( "Quad Strip Primitive", Mesh::RM_TRIANGLE_STRIP ) );
164  mesh->loadGeometry( vertices, indices );
165  mesh->getCoreGeometry().addAttrib(
166  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ), colors );
167  return mesh;
168 }
169 
170 LineMeshPtr Circle( const Core::Vector3& center,
171  const Core::Vector3& normal,
172  Scalar radius,
173  uint segments,
174  const Core::Utils::Color& color ) {
175  CORE_ASSERT( segments >= 2, "Cannot draw a circle with less than 3 points" );
176 
177  Geometry::LineMesh geom;
179  Core::Vector3Array vertices( segments + 1 );
180  Geometry::LineMesh::IndexContainerType indices;
181  indices.resize( segments );
182 
183  Core::Vector3 xPlane, yPlane;
184  Core::Math::getOrthogonalVectors( normal, xPlane, yPlane );
185  xPlane.normalize();
186  yPlane.normalize();
187 
188  Scalar thetaInc( Core::Math::PiMul2 / Scalar( segments ) );
189  Scalar theta( 0.0 );
190  vertices[0] = center + radius * ( std::cos( theta ) * xPlane + std::sin( theta ) * yPlane );
191  theta += thetaInc;
192 
193  for ( uint i = 1; i <= segments; ++i ) {
194  vertices[i] = center + radius * ( std::cos( theta ) * xPlane + std::sin( theta ) * yPlane );
195  indices[i - 1] = { i - 1, i };
196  theta += thetaInc;
197  }
198 
199  geom.setVertices( std::move( vertices ) );
200  geom.setIndices( std::move( indices ) );
201  geom.addAttrib(
202  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ),
203  Core::Vector4Array { geom.vertices().size(), color } );
204 
205  return make_shared<LineMesh>( "Circle Primitive", std::move( geom ) );
206 }
207 
208 LineMeshPtr CircleArc( const Core::Vector3& center,
209  const Core::Vector3& normal,
210  Scalar radius,
211  Scalar angle,
212  uint segments,
213  const Core::Utils::Color& color ) {
214 
215  Geometry::LineMesh geom;
216  Core::Vector3Array vertices( segments + 1 );
217  Geometry::LineMesh::IndexContainerType indices;
218  indices.resize( segments );
219 
220  Core::Vector3 xPlane, yPlane;
221  Core::Math::getOrthogonalVectors( normal, xPlane, yPlane );
222  xPlane.normalize();
223  yPlane.normalize();
224 
225  Scalar thetaInc( 2 * angle / Scalar( segments ) );
226  Scalar theta( 0.0 );
227  vertices[0] = center + radius * ( std::cos( theta ) * xPlane + std::sin( theta ) * yPlane );
228  theta += thetaInc;
229 
230  for ( uint i = 1; i <= segments; ++i ) {
231  vertices[i] = center + radius * ( std::cos( theta ) * xPlane + std::sin( theta ) * yPlane );
232  indices[i - 1] = { i - 1, i };
233 
234  theta += thetaInc;
235  }
236 
237  geom.setVertices( std::move( vertices ) );
238  geom.setIndices( std::move( indices ) );
239  geom.addAttrib(
240  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ),
241  Core::Vector4Array { geom.vertices().size(), color } );
242 
243  return make_shared<LineMesh>( "Arc Circle Primitive", std::move( geom ) );
244 }
245 
246 MeshPtr Sphere( const Core::Vector3& center, Scalar radius, const Core::Utils::Color& color ) {
247  auto geom = makeGeodesicSphere( radius, 4, color );
248  auto handle = geom.getAttribHandle<TriangleMesh::Point>(
249  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_POSITION ) );
250  auto& vertices = geom.getAttrib<TriangleMesh::Point>( handle );
251  auto& data = vertices.getDataWithLock();
252 
253  std::for_each( data.begin(), data.end(), [center]( Core::Vector3& v ) { v += center; } );
254  vertices.unlock();
255 
256  return make_shared<Mesh>( "Sphere Primitive", std::move( geom ) );
257 }
258 
259 MeshPtr ParametricSphere( const Core::Vector3& center,
260  Scalar radius,
261  const Core::Utils::Color& color,
262  bool generateTexCoord ) {
263  auto geom = makeParametricSphere<32, 32>( radius, color, generateTexCoord );
264  auto handle = geom.getAttribHandle<TriangleMesh::Point>(
265  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_POSITION ) );
266  auto& vertices = geom.getAttrib<TriangleMesh::Point>( handle );
267  auto& data = vertices.getDataWithLock();
268 
269  std::for_each( data.begin(), data.end(), [center]( Core::Vector3& v ) { v += center; } );
270  vertices.unlock();
271 
272  return make_shared<Mesh>( "Sphere Primitive", std::move( geom ) );
273 }
274 
275 MeshPtr Capsule( const Core::Vector3& p1,
276  const Core::Vector3& p2,
277  Scalar radius,
278  const Core::Utils::Color& color ) {
279  const Scalar l = ( p2 - p1 ).norm();
280 
281  TriangleMesh geom = makeCapsule( l, radius, 32, color );
282 
283  // Compute the transform so that
284  // (0,0,-l/2) maps to p1 and (0,0,l/2) maps to p2
285 
286  const Core::Vector3 trans = 0.5f * ( p2 + p1 );
287  Core::Quaternion rot =
288  Core::Quaternion::FromTwoVectors( Core::Vector3 { 0, 0, l / 2 }, 0.5f * ( p1 - p2 ) );
289 
290  Core::Transform t = Core::Transform::Identity();
291  t.rotate( rot );
292  t.pretranslate( trans );
293  Matrix3 normalMatrix = t.linear().inverse().transpose();
294 
295  auto vertHandle = geom.getAttribHandle<TriangleMesh::Point>(
296  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::VERTEX_POSITION ) );
297  auto& vertAttrib = geom.getAttrib<TriangleMesh::Point>( vertHandle );
298  auto& vertData = vertAttrib.getDataWithLock();
299  std::for_each( vertData.begin(), vertData.end(), [t]( Core::Vector3& v ) { v = t * v; } );
300  vertAttrib.unlock();
301 
302  auto normalHandle = geom.getAttribHandle<TriangleMesh::Point>(
303  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::VERTEX_NORMAL ) );
304  auto& normalAttrib = geom.getAttrib<TriangleMesh::Point>( normalHandle );
305  auto& normalData = normalAttrib.getDataWithLock();
306  std::for_each( normalData.begin(), normalData.end(), [normalMatrix]( Core::Vector3& n ) {
307  n = normalMatrix * n;
308  } );
309  normalAttrib.unlock();
310 
311  return make_shared<Mesh>( "Capsule Primitive", std::move( geom ) );
312 }
313 
314 MeshPtr Disk( const Core::Vector3& center,
315  const Core::Vector3& normal,
316  Scalar radius,
317  uint segments,
318  const Core::Utils::Color& color ) {
319  CORE_ASSERT( segments > 2, "Cannot draw a circle with less than 3 points" );
320 
321  uint seg = segments + 1;
322  Core::Vector3Array vertices( seg );
323  std::vector<uint> indices( seg + 1 );
324 
325  Core::Vector3 xPlane, yPlane;
326  Core::Math::getOrthogonalVectors( normal, xPlane, yPlane );
327  xPlane.normalize();
328  yPlane.normalize();
329 
330  Scalar thetaInc( Core::Math::PiMul2 / Scalar( segments ) );
331  Scalar theta( 0.0 );
332 
333  vertices[0] = center;
334  indices[0] = 0;
335  for ( uint i = 1; i < seg; ++i ) {
336  vertices[i] = center + radius * ( std::cos( theta ) * xPlane + std::sin( theta ) * yPlane );
337  indices[i] = i;
338 
339  theta += thetaInc;
340  }
341  indices[seg] = 1;
342 
343  Core::Vector4Array colors( vertices.size(), color );
344 
345  MeshPtr mesh( new Mesh( "Disk Primitive", Mesh::RM_TRIANGLE_FAN ) );
346  mesh->loadGeometry( vertices, indices );
347  mesh->getCoreGeometry().addAttrib(
348  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ), colors );
349 
350  return mesh;
351 }
352 
353 LineMeshPtr Normal( const Core::Vector3& point,
354  const Core::Vector3& normal,
355  const Core::Utils::Color& color,
356  Scalar scale ) {
357  // Display an arrow (just like the Vector() function)
358  // plus the normal plane.
359  Core::Vector3 a, b;
360  Core::Vector3 n = normal.normalized();
362 
363  n = scale * n;
364  Core::Vector3 end = point + n;
365  a.normalize();
366  b.normalize();
367 
368  const Scalar arrowFract = 0.1f;
369 
370  Geometry::LineMesh geom;
371 
372  Core::Vector3Array vertices = {
373  point,
374  end,
375  point + ( ( 1.f - arrowFract ) * n ) + ( ( arrowFract * scale ) * a ),
376  point + ( ( 1.f - arrowFract ) * n ) - ( ( arrowFract * scale ) * a ),
377 
378  point + ( scale * a ),
379  point + ( scale * b ),
380  point - ( scale * a ),
381  point - ( scale * b ),
382  };
383 
384  geom.setVertices( vertices );
385  geom.setIndices( { { 0, 1 },
386  { 1, 2 },
387  { 1, 3 },
388  { 4, 5 },
389  { 5, 6 },
390  { 6, 7 },
391  { 7, 4 },
392  { 4, 6 },
393  { 5, 7 } } );
394  geom.addAttrib(
395  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ),
396  Core::Vector4Array { geom.vertices().size(), color } );
397 
398  return make_shared<LineMesh>( "Normal Primitive", std::move( geom ) );
399 }
400 
401 MeshPtr Frame( const Core::Transform& frameFromEntity, Scalar scale ) {
402  // Frame is a bit different from the others
403  // since there are 3 lines of different colors.
404  Core::Vector3 pos = frameFromEntity.translation();
405  Core::Vector3 x = frameFromEntity.linear() * Core::Vector3::UnitX();
406  Core::Vector3 y = frameFromEntity.linear() * Core::Vector3::UnitY();
407  Core::Vector3 z = frameFromEntity.linear() * Core::Vector3::UnitZ();
408 
409  Core::Vector3Array vertices = {
410  pos, pos + scale * x, pos, pos + scale * y, pos, pos + scale * z };
411 
412  Core::Vector4Array colors = {
413  Core::Utils::Color::Red(),
414  Core::Utils::Color::Red(),
415  Core::Utils::Color::Green(),
416  Core::Utils::Color::Green(),
417  Core::Utils::Color::Blue(),
418  Core::Utils::Color::Blue(),
419  };
420 
421  std::vector<uint> indices = { 0, 1, 2, 3, 4, 5 };
422  MeshPtr mesh( new Mesh( "Frame Primitive", Mesh::RM_LINES ) );
423 
424  mesh->loadGeometry( vertices, indices );
425  mesh->getCoreGeometry().addAttrib(
426  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ), colors );
427 
428  return mesh;
429 }
430 
431 MeshPtr Grid( const Core::Vector3& center,
432  const Core::Vector3& x,
433  const Core::Vector3& y,
434  const Core::Utils::Color& color,
435  Scalar cellSize,
436  uint res ) {
437 
438  CORE_ASSERT( res > 1, "Grid has to be at least a 2x2 grid." );
439  Core::Vector3Array vertices;
440  std::vector<uint> indices;
441 
442  const Scalar halfWidth { ( cellSize * res ) / 2.f };
443  const Core::Vector3 deltaPosX { cellSize * x };
444  const Core::Vector3 startPosX { center - halfWidth * x };
445  const Core::Vector3 endPosX { center + halfWidth * x };
446  const Core::Vector3 deltaPosY { cellSize * y };
447  const Core::Vector3 startPosY { center - halfWidth * y };
448  const Core::Vector3 endPosY { center + halfWidth * y };
449  Core::Vector3 currentPosX { startPosX };
450  for ( uint i = 0; i < res + 1; ++i ) {
451  vertices.push_back( startPosY + currentPosX );
452  vertices.push_back( endPosY + currentPosX );
453  indices.push_back( uint( vertices.size() ) - 2 );
454  indices.push_back( uint( vertices.size() ) - 1 );
455  currentPosX += deltaPosX;
456  }
457 
458  Core::Vector3 currentPosY = startPosY;
459  for ( uint i = 0; i < res + 1; ++i ) {
460  vertices.push_back( startPosX + currentPosY );
461  vertices.push_back( endPosX + currentPosY );
462  indices.push_back( uint( vertices.size() ) - 2 );
463  indices.push_back( uint( vertices.size() ) - 1 );
464  currentPosY += deltaPosY;
465  }
466 
467  Core::Vector4Array colors( vertices.size(), color );
468 
469  MeshPtr mesh( new Mesh( "GridPrimitive", Mesh::RM_LINES ) );
470  mesh->loadGeometry( vertices, indices );
471  mesh->getCoreGeometry().addAttrib(
472  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ), colors );
473 
474  return mesh;
475 }
476 
477 MeshPtr AABB( const Core::Aabb& aabb, const Core::Utils::Color& color ) {
478  Core::Vector3Array vertices( 8 );
479 
480  for ( uint i = 0; i < 8; ++i ) {
481  vertices[i] = aabb.corner( static_cast<Core::Aabb::CornerType>( i ) );
482  }
483 
484  std::vector<uint> indices = {
485  0, 1, 1, 3, 3, 2, 2, 0, // Floor
486  0, 4, 1, 5, 2, 6, 3, 7, // Links
487  4, 5, 5, 7, 7, 6, 6, 4, // Ceil
488  };
489 
490  Core::Vector4Array colors( vertices.size(), color );
491 
492  MeshPtr mesh( new Mesh( "AABB Primitive", Mesh::RM_LINES ) );
493  mesh->loadGeometry( vertices, indices );
494  mesh->getCoreGeometry().addAttrib(
495  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ), colors );
496 
497  return mesh;
498 }
499 
500 MeshPtr OBB( const Obb& obb, const Core::Utils::Color& color ) {
501  Core::Vector3Array vertices( 8 );
502 
503  for ( uint i = 0; i < 8; ++i ) {
504  vertices[i] = obb.worldCorner( i );
505  }
506 
507  std::vector<uint> indices = {
508  0, 1, 1, 3, 3, 2, 2, 0, // Floor
509  4, 5, 5, 7, 7, 6, 6, 4, // Ceil
510  0, 4, 1, 5, 2, 6, 3, 7, // Links
511  };
512 
513  Core::Vector4Array colors( vertices.size(), color );
514 
515  MeshPtr mesh( new Mesh( "OBB Primitive", Mesh::RM_LINES ) );
516  mesh->loadGeometry( vertices, indices );
517  mesh->getCoreGeometry().addAttrib(
518  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ), colors );
519 
520  return mesh;
521 }
522 
523 MeshPtr Spline( const Core::Geometry::Spline<3, 3>& spline,
524  uint pointCount,
525  const Core::Utils::Color& color,
526  Scalar /*scale*/ ) {
527  Core::Vector3Array vertices;
528  vertices.reserve( pointCount );
529 
530  std::vector<uint> indices;
531  indices.reserve( pointCount * 2 - 2 );
532 
533  Scalar dt = Scalar( 1 ) / Scalar( pointCount - 1 );
534  for ( uint i = 0; i < pointCount; ++i ) {
535  Scalar t = dt * i;
536  vertices.push_back( spline.f( t ) );
537  }
538 
539  for ( uint i = 0; i < pointCount - 1; ++i ) {
540  indices.push_back( i );
541  indices.push_back( i + 1 );
542  }
543 
544  Core::Vector4Array colors( vertices.size(), color );
545 
546  MeshPtr mesh( new Mesh( "Spline Primitive", Mesh::RM_LINES ) );
547  mesh->loadGeometry( vertices, indices );
548  mesh->getCoreGeometry().addAttrib(
549  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ), colors );
550 
551  return mesh;
552 }
553 
554 MeshPtr LineStrip( const Core::Vector3Array& vertices, const Core::Vector4Array& colors ) {
555 
556  std::vector<uint> indices( vertices.size() );
557  std::iota( indices.begin(), indices.end(), 0 );
558  auto r = ( vertices.size() % 3 );
559  if ( r != 0 ) {
560  for ( ; r < 3; ++r ) {
561  indices.push_back( vertices.size() - 1 );
562  }
563  }
564  MeshPtr mesh( new Mesh( "Line Strip Primitive", Mesh::RM_LINE_STRIP ) );
565  mesh->loadGeometry( vertices, indices );
566  if ( colors.size() > 0 ) {
567  mesh->getCoreGeometry().addAttrib(
568  Ra::Core::Geometry::getAttribName( Ra::Core::Geometry::MeshAttrib::VERTEX_COLOR ),
569  colors );
570  }
571  return mesh;
572 }
573 } // namespace DrawPrimitives
574 } // namespace Data
575 } // namespace Engine
576 } // namespace Ra
An oriented bounding box.
Definition: Obb.hpp:12
Eigen::Matrix< Scalar, 3, 1 > worldCorner(int i) const
Returns the position of the ith corner of the OBB ( world space )
Definition: Obb.hpp:50
Handling spline curves of arbitrary dimensions.
Definition: Spline.hpp:24
Vector f(Scalar u) const
Definition: Spline.hpp:151
Mesh, own a Core::Geometry::TriangleMesh.
Definition: Mesh.hpp:414
void setParametersProvider(std::shared_ptr< Data::ShaderParameterProvider > provider, Core::Utils::Index pass=Core::Utils::Index(-1))
A component is an element that can be updated by a system. It is also linked to some other components...
Definition: Component.hpp:31
void getOrthogonalVectors(const Vector3 &fx, Eigen::Ref< Vector3 > fy, Eigen::Ref< Vector3 > fz)
MeshPtr Capsule(const Core::Vector3 &p1, const Core::Vector3 &p2, Scalar radius, const Core::Utils::Color &color)
Displays a capsule computed with given endpoints and radius.
LineMeshPtr Line(const Core::Vector3 &a, const Core::Vector3 &b, const Core::Utils::Color &color)
Displays given line.
LineMeshPtr CircleArc(const Core::Vector3 &center, const Core::Vector3 &normal, Scalar radius, Scalar angle, uint segments, const Core::Utils::Color &color)
MeshPtr ParametricSphere(const Core::Vector3 &center, Scalar radius, const Core::Utils::Color &color, bool generateTexCoord)
MeshPtr Disk(const Core::Vector3 &center, const Core::Vector3 &normal, Scalar radius, uint segments, const Core::Utils::Color &color)
AttribArrayDisplayablePtr Triangle(const Core::Vector3 &a, const Core::Vector3 &b, const Core::Vector3 &c, const Core::Utils::Color &color, bool fill)
MeshPtr AABB(const Core::Aabb &aabb, const Core::Utils::Color &color)
Display a wireframe AABB.
LineMeshPtr Vector(const Core::Vector3 &start, const Core::Vector3 &v, const Core::Utils::Color &color)
Displays given vector shown as an arrow originating from 'start'.
MeshPtr LineStrip(const Core::Vector3Array &vertices, const Core::Vector4Array &colors)
Display a line strip.
LineMeshPtr Normal(const Core::Vector3 &point, const Core::Vector3 &normal, const Core::Utils::Color &color, Scalar scale)
MeshPtr Sphere(const Core::Vector3 &center, Scalar radius, const Core::Utils::Color &color)
Displays geodesic sphere computed with given center and radius.
LineMeshPtr Circle(const Core::Vector3 &center, const Core::Vector3 &normal, Scalar radius, uint segments, const Core::Utils::Color &color)
LineMeshPtr Point(const Core::Vector3 &point, const Core::Utils::Color &color, Scalar scale)
Displays given point shown as the crossing of 3 lines of length 'scale'.
Rendering::RenderObject * Primitive(Scene::Component *component, const MeshPtr &mesh)
MeshPtr OBB(const Obb &obb, const Core::Utils::Color &color)
Display a wireframe OBB.
MeshPtr QuadStrip(const Core::Vector3 &a, const Core::Vector3 &x, const Core::Vector3 &y, uint quads, const Core::Utils::Color &color)
Displays a strip of n quads, starting at A and with directions X and Y.
Definition: Cage.cpp:3