SpiecsEngine
 
Loading...
Searching...
No Matches

◆ OnCreatePack()

bool Spices::CubePack::OnCreatePack ( bool isCreateBuffer = true)
overridevirtual

This interface is used for build specific mesh pack data.

Parameters
[in]isCreateBufferWhether it needs to create buffer.
Returns
Returns true if Create Pack successfully.

Reimplemented from Spices::MeshPack.

Definition at line 359 of file MeshPack.cpp.

360 {
362
363 if (MeshPack::OnCreatePack(isCreateBuffer)) return true;
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
385 uint64_t nPositions = m_MeshResource.positions.attributes->size();
388 resources.positions.attributes->begin(),
389 resources.positions.attributes->end()
390 );
391
392 uint64_t nNormals = m_MeshResource.normals.attributes->size();
395 resources.normals.attributes->begin(),
396 resources.normals.attributes->end()
397 );
398
399 uint64_t nColors = m_MeshResource.colors.attributes->size();
402 resources.colors.attributes->begin(),
403 resources.colors.attributes->end()
404 );
405
406 uint64_t nTexCoords = m_MeshResource.texCoords.attributes->size();
409 resources.texCoords.attributes->begin(),
410 resources.texCoords.attributes->end()
411 );
412
413 uint64_t nVertices = m_MeshResource.vertices.attributes->size();
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
424 uint64_t nPrimVertices = m_MeshResource.primitiveVertices.attributes->size();
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 // Front
436 {
437 PlanePack pack(m_Rows, m_Columns);
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 // Back
453 {
454 PlanePack pack(m_Rows, m_Columns);
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 // Left
471 {
472 PlanePack pack(m_Rows, m_Columns);
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 // Right
489 {
490 PlanePack pack(m_Rows, m_Columns);
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 // Top
507 {
508 PlanePack pack(m_Rows, m_Columns);
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 // Button
525 {
526 PlanePack pack(m_Rows, m_Columns);
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 {
545 CreateBuffer();
546 }
547
548 return true;
549 }
#define SPICES_PROFILE_ZONE
uint32_t m_Columns
How much cols number we use.
Definition MeshPack.h:486
uint32_t m_Rows
How much rows number we use.
Definition MeshPack.h:481
virtual bool OnCreatePack(bool isCreateBuffer=true)
This interface is used for build specific mesh pack data.
Definition MeshPack.cpp:119
MeshResource m_MeshResource
Mesh Resources.
Definition MeshPack.h:331
void CreateBuffer()
Create Vertices buffer anf Indices buffer.
Definition MeshPack.cpp:278
static void GenerateMeshLodClusterHierarchy(MeshPack *meshPack)
Generate Mesh Lod Resources.
std::shared_ptr< std::vector< T > > attributes
Attribute Data Array.
Definition Attribute.h:49
TexCoords texCoords
Definition MeshPack.h:71
Positions positions
Declare value.
Definition MeshPack.h:68
PrimitiveVertices primitiveVertices
Definition MeshPack.h:74

References Spices::MeshPack::CreateBuffer(), Spices::MeshProcessor::GenerateMeshLodClusterHierarchy(), Spices::MeshPack::GetResource(), m_Columns, m_Rows, Spices::MeshPack::OnCreatePack(), Spices::PlanePack::OnCreatePack(), and Spices::PlanePack::PlanePack().