diff --git a/demos/mesh_viewer/src/main.cpp b/demos/mesh_viewer/src/main.cpp index a0df8ba4eeaad5f0557123695c69eab1dd34234d..57951d93ef162ac5d8d25e76a305f4ef56f7b9a6 100644 --- a/demos/mesh_viewer/src/main.cpp +++ b/demos/mesh_viewer/src/main.cpp @@ -3,6 +3,9 @@ #include "phx/runtime_component.hpp" #include "phx/scene_loader.hpp" #include "phx/setup.hpp" +#include "phx/pli_processor.hpp" +#include "phx/line_segments.hpp" +#include "phx/mesh_handle.hpp" @@ -97,7 +100,19 @@ int main(int, char**) //load bunny phx::SceneLoader::InsertModelIntoScene("models/bunny.obj", scene.get()); - + + + //pli + phx::Entity* pli_entity = scene->CreateEntity(); + pli_entity->AddComponent<phx::Transform>(); + + auto mesh = phx::pli_prepare_data(); + mesh.Load(); + + phx::MeshHandle* mesh_handle = pli_entity->AddComponent<phx::MeshHandle>(); + mesh_handle->SetMesh(phx::ResourcePointer<phx::Mesh>(mesh)); + + //TODO create material handle engine->Run(); diff --git a/library/phx/dummy_mesh_loader.cpp b/library/phx/dummy_mesh_loader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9be34b635589b95a18ec36e05ad84543fff55a19 --- /dev/null +++ b/library/phx/dummy_mesh_loader.cpp @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// Project Phoenix +// +// Copyright (c) 2017-2018 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualization Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the 3-Clause BSD License (the "License"); +// you may not use this file except in compliance with the License. +// See the file LICENSE for the full text. +// You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "dummy_mesh_loader.hpp" + +#include <memory> +#include <utility> +#include <vector> + +#include "phx/mesh.hpp" + +namespace phx { + + DummyMeshLoader::DummyMeshLoader(std::vector<glm::vec3> &&vertices, + std::vector<glm::vec3> &&normals, + std::vector<unsigned int> &&indices) + : mesh_{ std::make_unique<phx::Mesh>() } { + mesh_->SetVertices(std::move(vertices)); + mesh_->SetNormals(std::move(normals)); + mesh_->SetIndices(std::move(indices)); + mesh_->SetTextureCoords( + std::vector<glm::vec2>(mesh_->GetVertices().size(), glm::vec2())); + } + + DummyMeshLoader::DummyMeshLoader(std::vector<glm::vec3> &&vertices, + std::vector<glm::vec3> &&normals, + std::vector<unsigned int> &&indices, + std::vector<glm::vec2> &&texture_coords) + : DummyMeshLoader(std::move(vertices), std::move(normals), + std::move(indices)) { + mesh_->SetTextureCoords(std::move(texture_coords)); + } + + std::unique_ptr<phx::Resource> DummyMeshLoader::Load( + const ResourceDeclaration &) { + auto new_mesh = std::make_unique<phx::Mesh>(); + *new_mesh = *mesh_; + return new_mesh; + } + +} // namespace phx diff --git a/library/phx/dummy_mesh_loader.hpp b/library/phx/dummy_mesh_loader.hpp new file mode 100644 index 0000000000000000000000000000000000000000..189a6ec8825e058348a73caf7916fc0343b3a6b7 --- /dev/null +++ b/library/phx/dummy_mesh_loader.hpp @@ -0,0 +1,68 @@ +//------------------------------------------------------------------------------ +// Project Phoenix +// +// Copyright (c) 2017-2018 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualization Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the 3-Clause BSD License (the "License"); +// you may not use this file except in compliance with the License. +// See the file LICENSE for the full text. +// You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef TESTS_TEST_UTILITIES_DUMMY_MESH_GENERATOR_HPP_ +#define TESTS_TEST_UTILITIES_DUMMY_MESH_GENERATOR_HPP_ + +#include <memory> +#include <utility> +#include <vector> + +#include "phx/suppress_warnings.hpp" + +SUPPRESS_WARNINGS_BEGIN +#include "glm/vec3.hpp" +SUPPRESS_WARNINGS_END + +#include "phx/resource_load_strategy.hpp" + +namespace phx { + class Mesh; + + class DummyMeshLoader : public ResourceLoadStrategy { + public: + DummyMeshLoader() = delete; + DummyMeshLoader(std::vector<glm::vec3> &&vertices, + std::vector<glm::vec3> &&normals, + std::vector<unsigned int> &&indices, + std::vector<glm::vec2> &&texture_coords); + DummyMeshLoader(std::vector<glm::vec3> &&vertices, + std::vector<glm::vec3> &&normals, + std::vector<unsigned int> &&indices); + DummyMeshLoader(const DummyMeshLoader &) = default; + DummyMeshLoader(DummyMeshLoader &&) = default; + ~DummyMeshLoader() override = default; + + DummyMeshLoader &operator=(const DummyMeshLoader &) = default; + DummyMeshLoader &operator=(DummyMeshLoader &&) = default; + + std::unique_ptr<Resource> Load( + const ResourceDeclaration &declaration) override; + + protected: + private: + std::unique_ptr<phx::Mesh> mesh_; + }; +} // namespace phx + +#endif // TESTS_TEST_UTILITIES_DUMMY_MESH_GENERATOR_HPP_ + diff --git a/library/phx/pli_processor.cpp b/library/phx/pli_processor.cpp index da9d19625436c3d3e851e591b0daa4ac801d8ae1..b684bbdd5ec64fc87e0d3efcd8a11fcebee81624 100644 --- a/library/phx/pli_processor.cpp +++ b/library/phx/pli_processor.cpp @@ -6,21 +6,24 @@ #include "phx/resource_manager.hpp" #include "phx/line_segments.hpp" #include "phx/resource_utils.hpp" +#include "phx/mesh.hpp" +#include "phx/dummy_mesh_loader.hpp" #include <string> namespace phx { - line_segments make_hedgehog(Resource* resource, const float length = 1.0f, const float radius = 1.0f) + line_segments make_hedgehog(phx::ResourcePointer<phx::PLIRegion> resource, const float length = 1.0f, const float radius = 1.0f) { - auto pli_region = dynamic_cast<PLIRegion *>(resource); - auto size = pli_region->GetSize(); + auto size = resource->GetSize(); //create return value line_segments segments; segments.radius = radius; + + //computer the size of the vectors first, in order to parallelize the loops for (auto z = 0; z < size[0]; z++) { for (auto x = 0; x < size[1]; x++) @@ -28,7 +31,7 @@ namespace phx { for (auto y = 0; y < size[2]; y++) { const auto center = glm::vec3(x, y, z); - const auto direction = glm::normalize(glm::vec3(pli_region->GetOrientation[z][0][x][y], pli_region->GetOrientation[z][1][x][y], pli_region->GetOrientation[z][2][x][y])); + const auto direction = glm::normalize(glm::vec3(resource->GetOrientation[z][0][x][y], resource->GetOrientation[z][1][x][y], resource->GetOrientation[z][2][x][y])); segments.vertices.push_back(center + length / 2.0f * direction); segments.vertices.push_back(center - length / 2.0f * direction); @@ -39,33 +42,40 @@ namespace phx { } } } - return segments; + return segments; } + ResourcePointer<Mesh> convert_to_mesh(line_segments segments) + { + std::vector<glm::vec3> vertices = std::vector<glm::vec3>({}); + std::vector<glm::vec3> normals = std::vector<glm::vec3>({}); + std::vector<glm::vec2> texture_coords = std::vector<glm::vec2>({}); + std::vector<unsigned int> indices = std::vector<unsigned int>({}); - void pli_prepare_data() { + //TODO - //TODO: find out how ResourceDeclaration/ nlohmann-json works - //TODO: find out why Load doesn't work - std::string addr("O:/Documents/MSA0309_s0536-0695.h5"); - ResourceDeclaration& declaration( - (ResourceDeclaration)addr, { { "from",{ { "X", 0.0f },{ "Y", 0.0f },{ "Z", 0.0f } } }, - { "to",{ { "X", 360.0f },{ "Y", 560.0f },{ "Z", 25.0f } } }, - { "stride",{ { "X", 3.0f },{ "Y", 3.0f },{ "Z", 3.0f } } } }, - false); + phx::ResourceManager::instance().RegisterResourceType( + "staticmesh", std::make_unique<phx::DummyMeshLoader>( + std::move(vertices), std::move(normals), + std::move(indices), std::move(texture_coords))); + auto mesh = phx::ResourceManager::instance().DeclareResource<phx::Mesh>( + { { "TYPE", "staticmesh" } }); + return mesh; + + } - auto pli_resource = PLILoader::Load(declaration); - /* + ResourcePointer<Mesh> pli_prepare_data() + { auto pli_resource = ResourceUtils::LoadResourceFromFile<phx::PLIRegion>( R"(O:\Documents\MSA0309_s0536-0695.h5)", { { "from",{ { "X", 0.0f },{ "Y", 0.0f },{ "Z", 0.0f } } }, { "to",{ { "X", 360.0f },{ "Y", 560.0f },{ "Z", 25.0f } } }, { "stride",{ { "X", 3.0f },{ "Y", 3.0f },{ "Z", 3.0f } } } }); - auto resource = dynamic_cast<Resource *>(pli_resource); - auto mesh = make_hedgehog(pli_resource, 1.0f, 1.0f); - */ - + auto hedgehog = make_hedgehog(pli_resource, 1.0f, 1.0f); + auto mesh = convert_to_mesh(hedgehog); + return mesh; } + } \ No newline at end of file diff --git a/library/phx/pli_processor.hpp b/library/phx/pli_processor.hpp index 3ec26c3ed8ed1dc7f620eae87f6fdeb9ed5d5201..91b9a7ae5cf6ee46297ff913f3dffeadec93b52e 100644 --- a/library/phx/pli_processor.hpp +++ b/library/phx/pli_processor.hpp @@ -8,11 +8,12 @@ #include "phx/resource_declaration.hpp" #include "phx/resource_manager.hpp" #include "phx/line_segments.hpp" +#include "phx/mesh.hpp" namespace phx{ - line_segments make_hedgehog(Resource* resource, const float length = 1.0f, const float radius = 1.0f); - + line_segments make_hedgehog(phx::ResourcePointer<phx::PLIRegion> resource, const float length = 1.0f, const float radius = 1.0f); + ResourcePointer<Mesh> pli_prepare_data(void); } #endif \ No newline at end of file