Skip to content

Commit

Permalink
WIP: tentative to add a polymesh using filedata
Browse files Browse the repository at this point in the history
Current state: the object does not appear in the application
  • Loading branch information
nmellado authored and dlyr committed Jul 23, 2020
1 parent 44c3c60 commit 45fb56f
Showing 1 changed file with 67 additions and 38 deletions.
105 changes: 67 additions & 38 deletions tests/ExampleApps/DrawPrimitivesApp/minimalradium.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@

#include <minimalradium.hpp>

#include <Core/Asset/FileData.hpp>
#include <Core/Containers/MakeShared.hpp>
#include <Core/Geometry/MeshPrimitives.hpp>
#include <Core/Tasks/Task.hpp>
#include <Core/Tasks/TaskQueue.hpp>
#include <Core/Utils/Timer.hpp>

#include <Engine/Component/GeometryComponent.hpp>
#include <Engine/FrameInfo.hpp>
#include <Engine/Managers/EntityManager/EntityManager.hpp>
#include <Engine/Renderer/Material/BlinnPhongMaterial.hpp>
#include <Engine/Renderer/Material/LambertianMaterial.hpp>
#include <Engine/Renderer/Material/PlainMaterial.hpp>
Expand All @@ -18,10 +21,53 @@

#include <random>

/* This file contains a minimal radium/qt application which shows the
classic "Spinning Cube" demo. */
/* This file contains a minimal radium/qt application which shows the geometrical primitives
* supported by Radium
*/

namespace internal {
Ra::Core::Vector3Array getPolyMeshVertices() {
return Ra::Core::Vector3Array( {
// quad
{-1.1_ra, -0_ra, 0_ra},
{1.1_ra, -0_ra, 0_ra},
{1_ra, 1_ra, 0_ra},
{-1_ra, 1_ra, 0_ra},
// hepta
{2_ra, 2_ra, 0_ra},
{2_ra, 3_ra, 0_ra},
{0_ra, 4_ra, 0_ra},
{-2_ra, 3_ra, 0_ra},
{-2_ra, 2_ra, 0_ra},
// degen
{-1.1_ra, -2_ra, 0_ra},
{-0.5_ra, -2_ra, 0_ra},
{-0.3_ra, -2_ra, 0_ra},
{0.0_ra, -2_ra, 0_ra},
{0.0_ra, -2_ra, 0_ra},
{0.3_ra, -2_ra, 0_ra},
{0.5_ra, -2_ra, 0_ra},
{1.1_ra, -2_ra, 0_ra},
// degen2
{-1_ra, -3_ra, 0_ra},
{1_ra, -3_ra, 0_ra},
} );
}

/// This is a very basic component which holds a spinning cube.
Ra::Core::VectorNuArray getPolyMeshFaces() {
using VectorType = Eigen::Matrix<uint, Eigen::Dynamic, 1>;
auto quad = VectorType( 4 );
quad << 0, 1, 2, 3;
auto hepta = VectorType( 7 );
hepta << 3, 2, 4, 5, 6, 7, 8;
auto degen = VectorType( 10 );
degen << 1, 0, 9, 10, 11, 12, 13, 14, 15, 16;
auto degen2 = VectorType( 10 );
degen2 << 14, 13, 12, 11, 10, 9, 17, 18, 16, 15;

return Ra::Core::VectorNuArray( {quad, hepta, degen, degen2} );
}
} // namespace internal

MinimalComponent::MinimalComponent( Ra::Engine::Entity* entity ) :
Ra::Engine::Component( "Minimal Component", entity ) {}
Expand Down Expand Up @@ -482,32 +528,7 @@ void MinimalComponent::initialize() {
//// PolyMesh ////
{
Ra::Core::Geometry::PolyMesh polyMesh;
polyMesh.setVertices( {
// quad
{-1.1_ra, -0_ra, 0_ra},
{1.1_ra, -0_ra, 0_ra},
{1_ra, 1_ra, 0_ra},
{-1_ra, 1_ra, 0_ra},
// hepta
{2_ra, 2_ra, 0_ra},
{2_ra, 3_ra, 0_ra},
{0_ra, 4_ra, 0_ra},
{-2_ra, 3_ra, 0_ra},
{-2_ra, 2_ra, 0_ra},
// degen
{-1.1_ra, -2_ra, 0_ra},
{-0.5_ra, -2_ra, 0_ra},
{-0.3_ra, -2_ra, 0_ra},
{0.0_ra, -2_ra, 0_ra},
{0.0_ra, -2_ra, 0_ra},
{0.3_ra, -2_ra, 0_ra},
{0.5_ra, -2_ra, 0_ra},
{1.1_ra, -2_ra, 0_ra},
// degen2
{-1_ra, -3_ra, 0_ra},
{1_ra, -3_ra, 0_ra},

} );
polyMesh.setVertices( internal::getPolyMeshVertices() );

Vector3Array normals;
normals.resize( polyMesh.vertices().size() );
Expand All @@ -518,15 +539,7 @@ void MinimalComponent::initialize() {
[]( const Vector3& v ) { return ( v + Vector3( 0_ra, 0_ra, 1_ra ) ).normalized(); } );
polyMesh.setNormals( normals );

auto quad = VectorNui( 4 );
quad << 0, 1, 2, 3;
auto hepta = VectorNui( 7 );
hepta << 3, 2, 4, 5, 6, 7, 8;
auto degen = VectorNui( 10 );
degen << 1, 0, 9, 10, 11, 12, 13, 14, 15, 16;
auto degen2 = VectorNui( 10 );
degen2 << 14, 13, 12, 11, 10, 9, 17, 18, 16, 15;
polyMesh.setIndices( {quad, hepta, degen, degen2} );
polyMesh.setIndices( internal::getPolyMeshFaces() );

std::shared_ptr<Ra::Engine::PolyMesh> poly1(
new Ra::Engine::PolyMesh( "Poly", std::move( polyMesh ) ) );
Expand Down Expand Up @@ -558,4 +571,20 @@ void MinimalSystem::generateTasks( Ra::Core::TaskQueue* q, const Ra::Engine::Fra

void MinimalSystem::addComponent( Ra::Engine::Entity* ent, MinimalComponent* comp ) {
registerComponent( ent, comp );

//// POLYMESH FROM FILEDATA ////
{
using Ra::Core::Asset::GeometryData;

GeometryData geometry( "Geometry", GeometryData::POLY_MESH );
Ra::Core::Transform tr = {Ra::Core::Translation( Ra::Core::Vector3( 2, 0_ra, 2 ) ) *
Eigen::UniformScaling<Scalar>( 0.06_ra )};
geometry.setFrame( tr );
geometry.setVertices( internal::getPolyMeshVertices() );
geometry.setFaces( internal::getPolyMeshFaces() );

auto comp2 = new Ra::Engine::PolyMeshComponent( "GeometryComponent", ent, &geometry );
registerComponent( ent, comp2 );
comp2->initialize();
}
}

0 comments on commit 45fb56f

Please sign in to comment.