diff --git a/src/dawn/display/RenderPipeline.hpp b/src/dawn/display/RenderPipeline.hpp index bdfb3f04..da1bcd64 100644 --- a/src/dawn/display/RenderPipeline.hpp +++ b/src/dawn/display/RenderPipeline.hpp @@ -6,7 +6,7 @@ #pragma once #include "dawnlibs.hpp" #include "scene/components/display/Material.hpp" -#include "scene/components/display/MeshRenderer.hpp" +#include "scene/components/display/mesh/MeshRenderer.hpp" #include "scene/components/display/Camera.hpp" #include "scene/components/scene/SubSceneController.hpp" #include "scene/components/ui/UIComponent.hpp" diff --git a/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp b/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp index 5a570f87..888a2fdc 100644 --- a/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp +++ b/src/dawn/prefabs/SimpleSpinningCubePrefab.hpp @@ -7,7 +7,7 @@ #include "prefab/SceneItemPrefab.hpp" #include "display/mesh/CubeMesh.hpp" #include "scene/components/display/MeshRenderer.hpp" -#include "scene/components/display/MeshHost.hpp" +#include "scene/components/display/CubeMeshHost.hpp" #include "scene/components/display/material/SimpleTexturedMaterial.hpp" #include "scene/components/example/ExampleSpin.hpp" #include "scene/components/physics/3d/CubeCollider.hpp" @@ -17,7 +17,6 @@ namespace Dawn { public SceneItemPrefab { public: - MeshHost *meshHost; SimpleTexturedMaterial *material; static std::vector prefabAssets(AssetManager *man) { @@ -31,13 +30,10 @@ namespace Dawn { void prefabInit(AssetManager *man) override { auto meshRenderer = this->addComponent(); - meshHost = this->addComponent(); + auto meshHost = this->addComponent(); material = this->addComponent(); auto spinning = this->addComponent(); auto collider = this->addComponent(); - - meshHost->mesh.createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT); - CubeMesh::buffer(&meshHost->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0); } }; } \ No newline at end of file diff --git a/src/dawn/scene/components/display/CMakeLists.txt b/src/dawn/scene/components/display/CMakeLists.txt index 661db97b..8ab850d7 100644 --- a/src/dawn/scene/components/display/CMakeLists.txt +++ b/src/dawn/scene/components/display/CMakeLists.txt @@ -9,9 +9,9 @@ target_sources(${DAWN_TARGET_NAME} AnimationController.cpp Camera.cpp Material.cpp - MeshHost.cpp - MeshRenderer.cpp PixelPerfectCamera.cpp TiledSprite.cpp SimpleRenderTargetQuad.cpp -) \ No newline at end of file +) + +add_subdirectory(mesh) \ No newline at end of file diff --git a/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp b/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp index 854b0614..a7b1809c 100644 --- a/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp +++ b/src/dawn/scene/components/display/SimpleRenderTargetQuad.hpp @@ -4,7 +4,7 @@ // https://opensource.org/licenses/MIT #pragma once -#include "scene/components/display/MeshHost.hpp" +#include "scene/components/display/mesh/MeshHost.hpp" #include "display/RenderTarget.hpp" #include "display/mesh/QuadMesh.hpp" diff --git a/src/dawn/scene/components/display/TiledSprite.hpp b/src/dawn/scene/components/display/TiledSprite.hpp index 1022c9c4..a3efbac7 100644 --- a/src/dawn/scene/components/display/TiledSprite.hpp +++ b/src/dawn/scene/components/display/TiledSprite.hpp @@ -5,8 +5,8 @@ #pragma once #include "scene/SceneItemComponent.hpp" -#include "scene/components/display/MeshRenderer.hpp" -#include "scene/components/display/MeshHost.hpp" +#include "scene/components/display/mesh/MeshRenderer.hpp" +#include "scene/components/display/mesh/MeshHost.hpp" #include "display/mesh/QuadMesh.hpp" #include "display/Tileset.hpp" diff --git a/src/dawn/scene/components/display/mesh/CMakeLists.txt b/src/dawn/scene/components/display/mesh/CMakeLists.txt new file mode 100644 index 00000000..fe2b8ef1 --- /dev/null +++ b/src/dawn/scene/components/display/mesh/CMakeLists.txt @@ -0,0 +1,12 @@ +# Copyright (c) 2023 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + MeshRenderer.cpp + CubeMeshHost.cpp + MeshHost.cpp +) \ No newline at end of file diff --git a/src/dawn/scene/components/display/mesh/CubeMeshHost.cpp b/src/dawn/scene/components/display/mesh/CubeMeshHost.cpp new file mode 100644 index 00000000..d55a91b9 --- /dev/null +++ b/src/dawn/scene/components/display/mesh/CubeMeshHost.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "CubeMeshHost.hpp" + +using namespace Dawn; + +CubeMeshHost::CubeMeshHost(SceneItem *item) : + MeshHost(item), + size(glm::vec3(1,1,1)) +{ +} + +void CubeMeshHost::onStart() { + this->mesh.createBuffers( + CUBE_VERTICE_COUNT, + CUBE_INDICE_COUNT + ); + + useEffect([&]{ + CubeMesh::buffer(&this->mesh, glm::vec3(this->size) * -0.5f, this->size, 0, 0); + }, this->size)(); +} \ No newline at end of file diff --git a/src/dawn/scene/components/display/mesh/CubeMeshHost.hpp b/src/dawn/scene/components/display/mesh/CubeMeshHost.hpp new file mode 100644 index 00000000..b15266df --- /dev/null +++ b/src/dawn/scene/components/display/mesh/CubeMeshHost.hpp @@ -0,0 +1,20 @@ +// Copyright (c) 2023 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "MeshHost.hpp" +#include "display/mesh/CubeMesh.hpp" + +namespace Dawn { + class CubeMeshHost : public MeshHost { + public: + // @optional + StateProperty size; + + CubeMeshHost(SceneItem *item); + + void onStart() override; + }; +} \ No newline at end of file diff --git a/src/dawn/scene/components/display/MeshHost.cpp b/src/dawn/scene/components/display/mesh/MeshHost.cpp similarity index 100% rename from src/dawn/scene/components/display/MeshHost.cpp rename to src/dawn/scene/components/display/mesh/MeshHost.cpp diff --git a/src/dawn/scene/components/display/MeshHost.hpp b/src/dawn/scene/components/display/mesh/MeshHost.hpp similarity index 100% rename from src/dawn/scene/components/display/MeshHost.hpp rename to src/dawn/scene/components/display/mesh/MeshHost.hpp diff --git a/src/dawn/scene/components/display/MeshRenderer.cpp b/src/dawn/scene/components/display/mesh/MeshRenderer.cpp similarity index 96% rename from src/dawn/scene/components/display/MeshRenderer.cpp rename to src/dawn/scene/components/display/mesh/MeshRenderer.cpp index dca8d22c..235dd065 100644 --- a/src/dawn/scene/components/display/MeshRenderer.cpp +++ b/src/dawn/scene/components/display/mesh/MeshRenderer.cpp @@ -1,27 +1,27 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "MeshRenderer.hpp" -#include "MeshHost.hpp" -#include "scene/SceneItem.hpp" - -using namespace Dawn; - -MeshRenderer::MeshRenderer(SceneItem *item) : SceneItemComponent(item) { -} - -std::vector MeshRenderer::getDependencies() { - return std::vector{ - this->meshHost = this->item->getComponent() - }; -} - -void MeshRenderer::onStart() { - SceneItemComponent::onStart(); - - if(this->mesh == nullptr && this->meshHost != nullptr) { - this->mesh = &this->meshHost->mesh; - } +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "MeshRenderer.hpp" +#include "MeshHost.hpp" +#include "scene/SceneItem.hpp" + +using namespace Dawn; + +MeshRenderer::MeshRenderer(SceneItem *item) : SceneItemComponent(item) { +} + +std::vector MeshRenderer::getDependencies() { + return std::vector{ + this->meshHost = this->item->getComponent() + }; +} + +void MeshRenderer::onStart() { + SceneItemComponent::onStart(); + + if(this->mesh == nullptr && this->meshHost != nullptr) { + this->mesh = &this->meshHost->mesh; + } } \ No newline at end of file diff --git a/src/dawn/scene/components/display/MeshRenderer.hpp b/src/dawn/scene/components/display/mesh/MeshRenderer.hpp similarity index 95% rename from src/dawn/scene/components/display/MeshRenderer.hpp rename to src/dawn/scene/components/display/mesh/MeshRenderer.hpp index 83f8432e..73437c41 100644 --- a/src/dawn/scene/components/display/MeshRenderer.hpp +++ b/src/dawn/scene/components/display/mesh/MeshRenderer.hpp @@ -1,31 +1,31 @@ -// Copyright (c) 2022 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "scene/SceneItemComponent.hpp" -#include "display/mesh/Mesh.hpp" - -namespace Dawn { - class MeshHost; - - class MeshRenderer : public SceneItemComponent { - protected: - MeshHost *meshHost = nullptr; - - public: - // @optional - Mesh * mesh = nullptr; - - /** - * Constructs a MeshRenderer scene item component. - * - * @param item Scene Item this mesh renderer belongs to. - */ - MeshRenderer(SceneItem *item); - - std::vector getDependencies() override; - void onStart() override; - }; +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "scene/SceneItemComponent.hpp" +#include "display/mesh/Mesh.hpp" + +namespace Dawn { + class MeshHost; + + class MeshRenderer : public SceneItemComponent { + protected: + MeshHost *meshHost = nullptr; + + public: + // @optional + Mesh * mesh = nullptr; + + /** + * Constructs a MeshRenderer scene item component. + * + * @param item Scene Item this mesh renderer belongs to. + */ + MeshRenderer(SceneItem *item); + + std::vector getDependencies() override; + void onStart() override; + }; } \ No newline at end of file diff --git a/src/dawn/scene/components/example/ExampleSpin.cpp b/src/dawn/scene/components/example/ExampleSpin.cpp index 3c0ad2f3..f5ef392f 100644 --- a/src/dawn/scene/components/example/ExampleSpin.cpp +++ b/src/dawn/scene/components/example/ExampleSpin.cpp @@ -5,7 +5,7 @@ #include "ExampleSpin.hpp" #include "game/DawnGame.hpp" -#include "scene/components/display/MeshRenderer.hpp" +#include "scene/components/display/mesh/MeshRenderer.hpp" #include "display/mesh/CubeMesh.hpp" #include "scene/components/display/material/SimpleTexturedMaterial.hpp" diff --git a/src/dawnopengl/display/shader/SimpleTexturedShader.cpp b/src/dawnopengl/display/shader/SimpleTexturedShader.cpp index b3941761..78acefcb 100644 --- a/src/dawnopengl/display/shader/SimpleTexturedShader.cpp +++ b/src/dawnopengl/display/shader/SimpleTexturedShader.cpp @@ -4,7 +4,7 @@ // https://opensource.org/licenses/MIT #include "SimpleTexturedShader.hpp" -#include "scene/components/display/MeshRenderer.hpp" +#include "scene/components/display/mesh/MeshRenderer.hpp" #include "scene/components/display/Camera.hpp" using namespace Dawn; diff --git a/src/dawnrose/scenes/HelloWorldScene.hpp b/src/dawnrose/scenes/HelloWorldScene.hpp index c4a4383c..4a0a656c 100644 --- a/src/dawnrose/scenes/HelloWorldScene.hpp +++ b/src/dawnrose/scenes/HelloWorldScene.hpp @@ -7,7 +7,6 @@ #include "scene/Scene.hpp" #include "scene/components/GameCamera.hpp" #include "prefabs/Player.hpp" -#include "prefabs/SpinningCube.hpp" #include "prefabs/ui/debug/FPSLabel.hpp" #include "display/mesh/CapsuleMesh.hpp" #include "display/mesh/CubeMesh.hpp" @@ -21,9 +20,6 @@ namespace Dawn { void stage() override { auto player = Player::create(this); - CapsuleMesh::create(&player->meshHost->mesh, 0.5f, 1.5f); - player->meshHost->mesh.createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT); - CubeMesh::buffer(&player->meshHost->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0); canvas = UICanvas::create(this);