This interface is used for build specific mesh pack data.
360 {
362
364
365 auto ApplyMatrixInPositions = [&](auto& positions, const glm::mat4& matrix) {
366
367 for (uint64_t i = 0; i < positions.size(); i++)
368 {
369 glm::vec4 p = matrix * glm::vec4(positions[i], 1.0f);
370 positions[i] = { p.x, p.y, p.z };
371 }
372 };
373
374 auto ApplyMatrixInNormals = [&](auto& normals, const glm::mat4& matrix) {
375
376 for (uint64_t i = 0; i < normals.size(); i++)
377 {
378 glm::vec4 n = matrix * glm::vec4(normals[i], 1.0f);
379 normals[i] = { n.x, n.y, n.z };
380 }
381 };
382
383 auto CopyToVertices = [&](auto& resources) {
384
388 resources.positions.attributes->begin(),
389 resources.positions.attributes->end()
390 );
391
395 resources.normals.attributes->begin(),
396 resources.normals.attributes->end()
397 );
398
402 resources.colors.attributes->begin(),
403 resources.colors.attributes->end()
404 );
405
409 resources.texCoords.attributes->begin(),
410 resources.texCoords.attributes->end()
411 );
412
414 for (auto& vertex : *resources.vertices.attributes)
415 {
417 vertex.x + nPositions ,
418 vertex.y + nNormals ,
419 vertex.z + nColors ,
420 vertex.w + nTexCoords
421 });
422 }
423
425 for (auto& primitiveVertex : *resources.primitiveVertices.attributes)
426 {
428 primitiveVertex.x + nVertices,
429 primitiveVertex.y + nVertices,
430 primitiveVertex.z + nVertices
431 });
432 }
433 };
434
435
436 {
438 pack.OnCreatePack(false);
439 const glm::mat4 tran = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -0.5f));
440
441 auto& resources = pack.GetResource();
442
443 const auto positions = resources.positions.attributes;
444 ApplyMatrixInPositions(*positions, tran);
445
446 const auto normals = resources.normals.attributes;
447 ApplyMatrixInNormals(*normals, tran);
448
449 CopyToVertices(resources);
450 }
451
452
453 {
455 pack.OnCreatePack(false);
456 const glm::mat4 tran = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.5f));
457 const glm::mat4 rot = glm::toMat4(glm::quat({0.0f, glm::radians(180.0f), 0.0f}));
458
459 auto& resources = pack.GetResource();
460
461 const auto positions = resources.positions.attributes;
462 ApplyMatrixInPositions(*positions, tran * rot);
463
464 const auto normals = resources.normals.attributes;
465 ApplyMatrixInNormals(*normals, tran * rot);
466
467 CopyToVertices(resources);
468 }
469
470
471 {
473 pack.OnCreatePack(false);
474 const glm::mat4 tran = glm::translate(glm::mat4(1.0f), glm::vec3(0.5f, 0.0f, 0.0f));
475 const glm::mat4 rot = glm::toMat4(glm::quat({ 0.0f, glm::radians(-90.0f), 0.0f }));
476
477 auto& resources = pack.GetResource();
478
479 const auto positions = resources.positions.attributes;
480 ApplyMatrixInPositions(*positions, tran * rot);
481
482 const auto normals = resources.normals.attributes;
483 ApplyMatrixInNormals(*normals, tran * rot);
484
485 CopyToVertices(resources);
486 }
487
488
489 {
491 pack.OnCreatePack(false);
492 const glm::mat4 tran = glm::translate(glm::mat4(1.0f), glm::vec3(-0.5f, 0.0f, 0.0f));
493 const glm::mat4 rot = glm::toMat4(glm::quat({ 0.0f, glm::radians(90.0f), 0.0f }));
494
495 auto& resources = pack.GetResource();
496
497 const auto positions = resources.positions.attributes;
498 ApplyMatrixInPositions(*positions, tran * rot);
499
500 const auto normals = resources.normals.attributes;
501 ApplyMatrixInNormals(*normals, tran * rot);
502
503 CopyToVertices(resources);
504 }
505
506
507 {
509 pack.OnCreatePack(false);
510 const glm::mat4 tran = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, -0.5f, 0.0f));
511 const glm::mat4 rot = glm::toMat4(glm::quat({ glm::radians(-90.0f), 0.0f, 0.0f }));
512
513 auto& resources = pack.GetResource();
514
515 const auto positions = resources.positions.attributes;
516 ApplyMatrixInPositions(*positions, tran * rot);
517
518 const auto normals = resources.normals.attributes;
519 ApplyMatrixInNormals(*normals, tran * rot);
520
521 CopyToVertices(resources);
522 }
523
524
525 {
527 pack.OnCreatePack(false);
528 const glm::mat4 tran = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.5f, 0.0f));
529 const glm::mat4 rot = glm::toMat4(glm::quat({ glm::radians(90.0f), 0.0f, 0.0f }));
530
531 auto& resources = pack.GetResource();
532
533 const auto positions = resources.positions.attributes;
534 ApplyMatrixInPositions(*positions, tran * rot);
535
536 const auto normals = resources.normals.attributes;
537 ApplyMatrixInNormals(*normals, tran * rot);
538
539 CopyToVertices(resources);
540 }
541
542 if (isCreateBuffer)
543 {
546 }
547
548 return true;
549 }
#define SPICES_PROFILE_ZONE
uint32_t m_Columns
How much cols number we use.
uint32_t m_Rows
How much rows number we use.
virtual bool OnCreatePack(bool isCreateBuffer=true)
This interface is used for build specific mesh pack data.
MeshResource m_MeshResource
Mesh Resources.
void CreateBuffer()
Create Vertices buffer anf Indices buffer.
static void GenerateMeshLodClusterHierarchy(MeshPack *meshPack)
Generate Mesh Lod Resources.
std::shared_ptr< std::vector< T > > attributes
Attribute Data Array.
Positions positions
Declare value.
PrimitiveVertices primitiveVertices