diff --git a/Assets/Models/Cone/Cone_Cone.asset b/Assets/Models/Cone/Cone_Cone.asset deleted file mode 100644 index 6b8de492..00000000 Binary files a/Assets/Models/Cone/Cone_Cone.asset and /dev/null differ diff --git a/Assets/Models/Cone/Cone_Prefab.asset b/Assets/Models/Cone/Cone_Prefab.asset deleted file mode 100644 index f8abab8c..00000000 Binary files a/Assets/Models/Cone/Cone_Prefab.asset and /dev/null differ diff --git a/Assets/Models/Cone/M_Cone_glb_0.asset b/Assets/Models/Cone/M_Cone_glb_0.asset deleted file mode 100644 index 8e00fe8d..00000000 Binary files a/Assets/Models/Cone/M_Cone_glb_0.asset and /dev/null differ diff --git a/Assets/Models/Cube/Cube_Cube_001.asset b/Assets/Models/Cube/Cube_Cube_001.asset deleted file mode 100644 index e840bfa9..00000000 Binary files a/Assets/Models/Cube/Cube_Cube_001.asset and /dev/null differ diff --git a/Assets/Models/Cube/Cube_Prefab.asset b/Assets/Models/Cube/Cube_Prefab.asset deleted file mode 100644 index b621810f..00000000 Binary files a/Assets/Models/Cube/Cube_Prefab.asset and /dev/null differ diff --git a/Assets/Models/Cube/M_Cube_glb_0.asset b/Assets/Models/Cube/M_Cube_glb_0.asset deleted file mode 100644 index dd093a38..00000000 Binary files a/Assets/Models/Cube/M_Cube_glb_0.asset and /dev/null differ diff --git a/Assets/Models/Cylinder/Cylinder_Cylinder.asset b/Assets/Models/Cylinder/Cylinder_Cylinder.asset deleted file mode 100644 index 24f1afc6..00000000 Binary files a/Assets/Models/Cylinder/Cylinder_Cylinder.asset and /dev/null differ diff --git a/Assets/Models/Cylinder/Cylinder_Prefab.asset b/Assets/Models/Cylinder/Cylinder_Prefab.asset deleted file mode 100644 index 4ce2f0bd..00000000 Binary files a/Assets/Models/Cylinder/Cylinder_Prefab.asset and /dev/null differ diff --git a/Assets/Models/Cylinder/M_Cylinder_glb_0.asset b/Assets/Models/Cylinder/M_Cylinder_glb_0.asset deleted file mode 100644 index 1a0e1b30..00000000 Binary files a/Assets/Models/Cylinder/M_Cylinder_glb_0.asset and /dev/null differ diff --git a/Assets/Models/Cylinder_Standing.glb b/Assets/Models/Cylinder_Standing.glb deleted file mode 100644 index 16fecc2d..00000000 --- a/Assets/Models/Cylinder_Standing.glb +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:26e86afc8d567b5689fbc6a7f63924719f67970557fac4496a39da278479c9f1 -size 7796 diff --git a/Assets/Models/Cylinder_Standing/Cylinder_Standing_Cylinder.asset b/Assets/Models/Cylinder_Standing/Cylinder_Standing_Cylinder.asset deleted file mode 100644 index 8615ca93..00000000 Binary files a/Assets/Models/Cylinder_Standing/Cylinder_Standing_Cylinder.asset and /dev/null differ diff --git a/Assets/Models/Cylinder_Standing/Cylinder_Standing_Prefab.asset b/Assets/Models/Cylinder_Standing/Cylinder_Standing_Prefab.asset deleted file mode 100644 index 974ab8c2..00000000 Binary files a/Assets/Models/Cylinder_Standing/Cylinder_Standing_Prefab.asset and /dev/null differ diff --git a/Assets/Models/Cylinder_Standing/M_Cylinder_Standing_glb_0.asset b/Assets/Models/Cylinder_Standing/M_Cylinder_Standing_glb_0.asset deleted file mode 100644 index 92e03dcd..00000000 Binary files a/Assets/Models/Cylinder_Standing/M_Cylinder_Standing_glb_0.asset and /dev/null differ diff --git a/Assets/Models/DamagedHelmet.glb b/Assets/Models/DamagedHelmet.glb deleted file mode 100644 index ddd1982f..00000000 --- a/Assets/Models/DamagedHelmet.glb +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9e290c8c9af4ac09dc49c49a7ba010f7c932d0f55cba39675ff20d9214aeb4d5 -size 8806720 diff --git a/Assets/Models/DamagedHelmet/DamagedHelmet_Prefab.asset b/Assets/Models/DamagedHelmet/DamagedHelmet_Prefab.asset deleted file mode 100644 index cf48165e..00000000 Binary files a/Assets/Models/DamagedHelmet/DamagedHelmet_Prefab.asset and /dev/null differ diff --git a/Assets/Models/DamagedHelmet/DamagedHelmet_mesh_helmet_LP_13930damagedHelmet.asset b/Assets/Models/DamagedHelmet/DamagedHelmet_mesh_helmet_LP_13930damagedHelmet.asset deleted file mode 100644 index 72b5a365..00000000 Binary files a/Assets/Models/DamagedHelmet/DamagedHelmet_mesh_helmet_LP_13930damagedHelmet.asset and /dev/null differ diff --git a/Assets/Models/DamagedHelmet/DamagedHelmet_tex0.asset b/Assets/Models/DamagedHelmet/DamagedHelmet_tex0.asset deleted file mode 100644 index 979dd86e..00000000 Binary files a/Assets/Models/DamagedHelmet/DamagedHelmet_tex0.asset and /dev/null differ diff --git a/Assets/Models/DamagedHelmet/DamagedHelmet_tex1.asset b/Assets/Models/DamagedHelmet/DamagedHelmet_tex1.asset deleted file mode 100644 index da7b6889..00000000 Binary files a/Assets/Models/DamagedHelmet/DamagedHelmet_tex1.asset and /dev/null differ diff --git a/Assets/Models/DamagedHelmet/DamagedHelmet_tex2.asset b/Assets/Models/DamagedHelmet/DamagedHelmet_tex2.asset deleted file mode 100644 index 0abe5a6d..00000000 Binary files a/Assets/Models/DamagedHelmet/DamagedHelmet_tex2.asset and /dev/null differ diff --git a/Assets/Models/DamagedHelmet/DamagedHelmet_tex3.asset b/Assets/Models/DamagedHelmet/DamagedHelmet_tex3.asset deleted file mode 100644 index 76302571..00000000 Binary files a/Assets/Models/DamagedHelmet/DamagedHelmet_tex3.asset and /dev/null differ diff --git a/Assets/Models/DamagedHelmet/Material_MR.asset b/Assets/Models/DamagedHelmet/Material_MR.asset deleted file mode 100644 index 5eebc79e..00000000 Binary files a/Assets/Models/DamagedHelmet/Material_MR.asset and /dev/null differ diff --git a/Assets/Models/IcoSphere/IcoSphere_Icosphere.asset b/Assets/Models/IcoSphere/IcoSphere_Icosphere.asset deleted file mode 100644 index 776b4044..00000000 Binary files a/Assets/Models/IcoSphere/IcoSphere_Icosphere.asset and /dev/null differ diff --git a/Assets/Models/IcoSphere/IcoSphere_Prefab.asset b/Assets/Models/IcoSphere/IcoSphere_Prefab.asset deleted file mode 100644 index 8a4fed7c..00000000 Binary files a/Assets/Models/IcoSphere/IcoSphere_Prefab.asset and /dev/null differ diff --git a/Assets/Models/IcoSphere/M_IcoSphere_glb_0.asset b/Assets/Models/IcoSphere/M_IcoSphere_glb_0.asset deleted file mode 100644 index 02499c5e..00000000 Binary files a/Assets/Models/IcoSphere/M_IcoSphere_glb_0.asset and /dev/null differ diff --git a/Assets/Models/Monkey/M_Monkey_glb_0.asset b/Assets/Models/Monkey/M_Monkey_glb_0.asset deleted file mode 100644 index dea5fca9..00000000 Binary files a/Assets/Models/Monkey/M_Monkey_glb_0.asset and /dev/null differ diff --git a/Assets/Models/Monkey/Monkey_Prefab.asset b/Assets/Models/Monkey/Monkey_Prefab.asset deleted file mode 100644 index 0b046228..00000000 Binary files a/Assets/Models/Monkey/Monkey_Prefab.asset and /dev/null differ diff --git a/Assets/Models/PF_Cone.asset b/Assets/Models/PF_Cone.asset new file mode 100644 index 00000000..b6bae2d4 Binary files /dev/null and b/Assets/Models/PF_Cone.asset differ diff --git a/Assets/Models/PF_Cube.asset b/Assets/Models/PF_Cube.asset new file mode 100644 index 00000000..c7c5db1a Binary files /dev/null and b/Assets/Models/PF_Cube.asset differ diff --git a/Assets/Models/PF_Cylinder.asset b/Assets/Models/PF_Cylinder.asset new file mode 100644 index 00000000..c94caf13 Binary files /dev/null and b/Assets/Models/PF_Cylinder.asset differ diff --git a/Assets/Models/PF_IcoSphere.asset b/Assets/Models/PF_IcoSphere.asset new file mode 100644 index 00000000..be94dfb6 Binary files /dev/null and b/Assets/Models/PF_IcoSphere.asset differ diff --git a/Assets/Models/PF_Monkey.asset b/Assets/Models/PF_Monkey.asset new file mode 100644 index 00000000..a71d87e3 Binary files /dev/null and b/Assets/Models/PF_Monkey.asset differ diff --git a/Assets/Models/PF_Plane.asset b/Assets/Models/PF_Plane.asset new file mode 100644 index 00000000..b5e87a0c Binary files /dev/null and b/Assets/Models/PF_Plane.asset differ diff --git a/Assets/Models/PF_Sphere.asset b/Assets/Models/PF_Sphere.asset new file mode 100644 index 00000000..e114352b Binary files /dev/null and b/Assets/Models/PF_Sphere.asset differ diff --git a/Assets/Models/PF_Torus.asset b/Assets/Models/PF_Torus.asset new file mode 100644 index 00000000..ebd19277 Binary files /dev/null and b/Assets/Models/PF_Torus.asset differ diff --git a/Assets/Models/Plane/M_Plane_glb_0.asset b/Assets/Models/Plane/M_Plane_glb_0.asset deleted file mode 100644 index 64a90b40..00000000 Binary files a/Assets/Models/Plane/M_Plane_glb_0.asset and /dev/null differ diff --git a/Assets/Models/Plane/Plane_Plane.asset b/Assets/Models/Plane/Plane_Plane.asset deleted file mode 100644 index edb97d17..00000000 Binary files a/Assets/Models/Plane/Plane_Plane.asset and /dev/null differ diff --git a/Assets/Models/Plane/Plane_Prefab.asset b/Assets/Models/Plane/Plane_Prefab.asset deleted file mode 100644 index 1c31a1e7..00000000 Binary files a/Assets/Models/Plane/Plane_Prefab.asset and /dev/null differ diff --git a/Assets/Models/SM_Cone.asset b/Assets/Models/SM_Cone.asset new file mode 100644 index 00000000..5bdcfd15 Binary files /dev/null and b/Assets/Models/SM_Cone.asset differ diff --git a/Assets/Models/SM_Cube.asset b/Assets/Models/SM_Cube.asset new file mode 100644 index 00000000..00cc148e Binary files /dev/null and b/Assets/Models/SM_Cube.asset differ diff --git a/Assets/Models/SM_Cylinder.asset b/Assets/Models/SM_Cylinder.asset new file mode 100644 index 00000000..8bfbdabf Binary files /dev/null and b/Assets/Models/SM_Cylinder.asset differ diff --git a/Assets/Models/SM_Icosphere.asset b/Assets/Models/SM_Icosphere.asset new file mode 100644 index 00000000..97656af4 Binary files /dev/null and b/Assets/Models/SM_Icosphere.asset differ diff --git a/Assets/Models/SM_Plane.asset b/Assets/Models/SM_Plane.asset new file mode 100644 index 00000000..719ef286 Binary files /dev/null and b/Assets/Models/SM_Plane.asset differ diff --git a/Assets/Models/Sphere/Sphere_Sphere.asset b/Assets/Models/SM_Sphere.asset similarity index 53% rename from Assets/Models/Sphere/Sphere_Sphere.asset rename to Assets/Models/SM_Sphere.asset index 7c5fac93..14b0e2c2 100644 Binary files a/Assets/Models/Sphere/Sphere_Sphere.asset and b/Assets/Models/SM_Sphere.asset differ diff --git a/Assets/Models/Monkey/Monkey_Suzanne.asset b/Assets/Models/SM_Suzanne.asset similarity index 78% rename from Assets/Models/Monkey/Monkey_Suzanne.asset rename to Assets/Models/SM_Suzanne.asset index 97864fbc..551e5c40 100644 Binary files a/Assets/Models/Monkey/Monkey_Suzanne.asset and b/Assets/Models/SM_Suzanne.asset differ diff --git a/Assets/Models/Torus/Torus_Torus.asset b/Assets/Models/SM_Torus.asset similarity index 78% rename from Assets/Models/Torus/Torus_Torus.asset rename to Assets/Models/SM_Torus.asset index 96d208ac..f7df3438 100644 Binary files a/Assets/Models/Torus/Torus_Torus.asset and b/Assets/Models/SM_Torus.asset differ diff --git a/Assets/Models/Sphere/M_Sphere_glb_0.asset b/Assets/Models/Sphere/M_Sphere_glb_0.asset deleted file mode 100644 index fb06f493..00000000 Binary files a/Assets/Models/Sphere/M_Sphere_glb_0.asset and /dev/null differ diff --git a/Assets/Models/Sphere/Sphere_Prefab.asset b/Assets/Models/Sphere/Sphere_Prefab.asset deleted file mode 100644 index 663deb07..00000000 Binary files a/Assets/Models/Sphere/Sphere_Prefab.asset and /dev/null differ diff --git a/Assets/Models/Torus/M_Torus_glb_0.asset b/Assets/Models/Torus/M_Torus_glb_0.asset deleted file mode 100644 index 1d3d45de..00000000 Binary files a/Assets/Models/Torus/M_Torus_glb_0.asset and /dev/null differ diff --git a/Assets/Models/Torus/Torus_Prefab.asset b/Assets/Models/Torus/Torus_Prefab.asset deleted file mode 100644 index bb960fde..00000000 Binary files a/Assets/Models/Torus/Torus_Prefab.asset and /dev/null differ diff --git a/Include/Components/CameraComponent.h b/Include/Components/CameraComponent.h index 2c1cba43..f49b76ce 100644 --- a/Include/Components/CameraComponent.h +++ b/Include/Components/CameraComponent.h @@ -3,26 +3,11 @@ namespace CE { - class BinaryGSONObject; class World; - class TransformComponent; class CameraComponent { public: - const glm::mat4& GetViewProjection() const { return mViewProjection; } - const glm::mat4& GetView() const { return mView; } - const glm::mat4& GetProjection() const { return mProjection; } - const glm::mat4& GetOrthographicProjection() const { return mOrthographicProjection; } - - void UpdateView(glm::vec3 position, glm::vec3 forward, glm::vec3 up, bool recalulateViewProjection = true); - void UpdateView(const TransformComponent& transform, bool recalulateViewProjection = true); - void UpdateProjection(glm::vec2 viewportSize, bool recalculateViewProjection = true); - void UpdateProjection(float aspectRatio, bool recalculateViewProjection = true); - - // By default, the view/proj are recalculated at the end of every frame. - void RecalculateViewProjection(); - /** * \brief Returns the selected camera. If none is selected, will lazily select one. * \return entt::null if no camera in the world, otherwise the owner of the camera. The owner is guaranteed to have a camera attached to it. @@ -39,7 +24,6 @@ namespace CE glm::mat4 mView{}; glm::mat4 mProjection{}; - glm::mat4 mOrthographicProjection{}; glm::mat4 mViewProjection{}; private: diff --git a/Include/Components/FlyCamControllerComponent.h b/Include/Components/FlyCamControllerComponent.h index 1400b02a..b3a79b18 100644 --- a/Include/Components/FlyCamControllerComponent.h +++ b/Include/Components/FlyCamControllerComponent.h @@ -8,7 +8,7 @@ namespace CE class FlyCamControllerComponent { public: - void ApplyTranslation(TransformComponent& transform, const glm::vec3& timeScaledMovementInput) const; + void ApplyTranslation(TransformComponent& transform, glm::vec3 timeScaledMovementInput) const; void ApplyRotation(TransformComponent& transform, const std::array& timeScaledRotations) const; float mMovementSpeed = 18.0f; diff --git a/Include/Components/StaticMeshComponent.h b/Include/Components/StaticMeshComponent.h index 03e3661d..20d0257a 100644 --- a/Include/Components/StaticMeshComponent.h +++ b/Include/Components/StaticMeshComponent.h @@ -14,12 +14,6 @@ namespace CE AssetHandle mMaterial{}; - bool mTilesWithMeshScale = false; - - float mTiling = 1; - - bool mHighlightedMesh = false; - private: friend ReflectAccess; static MetaType Reflect(); diff --git a/Include/Components/TransformComponent.h b/Include/Components/TransformComponent.h index 55030e09..d62b6770 100644 --- a/Include/Components/TransformComponent.h +++ b/Include/Components/TransformComponent.h @@ -17,20 +17,20 @@ namespace CE X, Y, Z, - Right = X, - Up = Y, - Forward = Z, + Forward = X, + Right = Y, + Up = Z, }; }; constexpr glm::vec3 ToVector3(Axis::Values axis) { glm::vec3 v{}; v[static_cast(axis)] = 1.0f; return v; } - constexpr glm::vec2 To2DRightForward(glm::vec3 v3) + constexpr glm::vec2 To2D(glm::vec3 v3) { return { v3[Axis::Right], v3[Axis::Forward] }; } - constexpr glm::vec3 To3DRightForward(glm::vec2 v2, float up = 0.0f) + constexpr glm::vec3 To3D(glm::vec2 v2, float up = 0.0f) { glm::vec3 v3{}; v3[Axis::Right] = v2.x; @@ -67,7 +67,7 @@ namespace CE glm::mat4 GetLocalMatrix() const; void SetLocalMatrix(const glm::mat4& matrix); - const glm::mat4& GetWorldMatrix() const; + glm::mat4 GetWorldMatrix() const; void SetWorldMatrix(const glm::mat4& matrix); std::tuple GetLocalPositionScaleOrientation() const; @@ -103,101 +103,66 @@ namespace CE // -----------------------------------------------------------------------------------------------------------------// glm::vec3 GetLocalPosition() const; - glm::vec2 GetLocalPosition2D() const; - glm::vec3 GetWorldPosition() const; - glm::vec2 GetWorldPosition2D() const; - - void SetLocalPosition(const glm::vec3 position); - void SetLocalPosition(const glm::vec2 position); - void TranslateLocalPosition(const glm::vec3 translation); - void TranslateLocalPosition(const glm::vec2 translation); + void SetLocalPosition(glm::vec3 position); + void SetLocalPosition(glm::vec2 position); void SetWorldPosition(glm::vec3 position); - void SetWorldPosition(const glm::vec2 position); - - void TranslateWorldPosition(const glm::vec3 translation); - void TranslateWorldPosition(const glm::vec2 translation); + void SetWorldPosition(glm::vec2 position); // -----------------------------------------------------------------------------------------------------------------// // Getting/setting the orientation // // -----------------------------------------------------------------------------------------------------------------// glm::quat GetLocalOrientation() const; - glm::vec3 GetLocalOrientationEuler() const; - glm::quat GetWorldOrientation() const; - glm::vec3 GetWorldOrientationEuler() const; - - // In radians - void SetLocalOrientation(const glm::vec3 rotationEuler); - void SetLocalOrientation(const glm::quat rotation); - // In radians - void SetWorldOrientation(const glm::vec3 rotationEuler); + void SetLocalOrientation(glm::quat rotation); void SetWorldOrientation(glm::quat orientation); glm::vec3 GetLocalForward() const; glm::vec3 GetLocalUp() const; glm::vec3 GetLocalRight() const; - glm::vec3 GetLocalAxis(const Axis::Values axis) const; + glm::vec3 GetLocalAxis(Axis::Values axis) const; glm::vec3 GetWorldForward() const; glm::vec3 GetWorldUp() const; glm::vec3 GetWorldRight() const; - glm::vec3 GetWorldAxis(const Axis::Values axis) const; - void SetLocalForward(const glm::vec3& forward); - void SetLocalUp(const glm::vec3& up); - void SetLocalRight(const glm::vec3& right); + glm::vec3 GetWorldAxis(Axis::Values axis) const; + + void SetLocalForward(glm::vec3 forward); + void SetLocalUp(glm::vec3 up); + void SetLocalRight(glm::vec3 right); - void SetWorldForward(const glm::vec3& forward); - void SetWorldUp(const glm::vec3& up); - void SetWorldRight(const glm::vec3& right); + void SetWorldForward(glm::vec3 forward); + void SetWorldUp(glm::vec3 up); + void SetWorldRight(glm::vec3 right); // -----------------------------------------------------------------------------------------------------------------// // Getting/setting the Scale // // -----------------------------------------------------------------------------------------------------------------// glm::vec3 GetLocalScale() const; - glm::vec2 GetLocalScale2D() const; float GetLocalScaleUniform() const; glm::vec3 GetWorldScale() const; - glm::vec2 GetWorldScale2D() const; float GetWorldScaleUniform() const; - float GetWorldScaleUniform2D() const; - void SetLocalScale(const float xyz); - void SetLocalScaleRightForward(const float scale); - void SetLocalScale(const glm::vec3 scale); - void SetLocalScale(const glm::vec2 scale); + void SetLocalScale(float xyz); + void SetLocalScale(glm::vec2 scale); + void SetLocalScale(glm::vec3 scale); - void SetWorldScale(const float xyz); + void SetWorldScale(float xyz); + void SetWorldScale(glm::vec2 scale); void SetWorldScale(glm::vec3 scale); - void SetWorldScale(const glm::vec2 scale); private: void AttachChild(TransformComponent& child); void DetachChild(TransformComponent& child); - void UpdateCachedWorldMatrix(); - - // We do not serialize the world - // matrix, so we require - // the archiver to call UpdateCachedWorldMatrix.. - friend Archiver; - - - // We don't have custom setter/getter support yet. - // WorldDetails may inspect mLocalPosition and - // adjust its value without ever updating the world - // matrix. - friend WorldDetails; - friend Registry; - friend ReflectAccess; static MetaType Reflect(); REFLECT_AT_START_UP(TransformComponent); @@ -208,8 +173,6 @@ namespace CE glm::quat mLocalOrientation = { 1.0f, 0.0f, 0.0f, 0.0f }; glm::vec3 mLocalScale = { 1.0f, 1.0f, 1.0f }; - glm::mat4 mCachedWorldMatrix{ 1.0f }; - // Storing a pointer is safe, as pointer stability has been enabled. TransformComponent* mParent{}; diff --git a/Include/Engine/Precomp/Precomp.h b/Include/Engine/Precomp/Precomp.h index abdf8174..47f8aa41 100644 --- a/Include/Engine/Precomp/Precomp.h +++ b/Include/Engine/Precomp/Precomp.h @@ -35,6 +35,8 @@ #pragma warning(disable : 4201) #endif +#define GLM_FORCE_LEFT_HANDED + #include "glm/glm.hpp" #include #include diff --git a/Include/Utilities/Geometry3d.h b/Include/Utilities/Geometry3d.h index 5cef4c08..8a8e287c 100644 --- a/Include/Utilities/Geometry3d.h +++ b/Include/Utilities/Geometry3d.h @@ -27,7 +27,7 @@ namespace CE inline AABB3D::AABB3D(std::span points) { - for (const glm::vec3& point : points) + for (glm::vec3 point : points) { mMin = glm::min(point, mMin); mMax = glm::max(point, mMax); diff --git a/Include/Utilities/Math.h b/Include/Utilities/Math.h index 9c761800..9d454252 100644 --- a/Include/Utilities/Math.h +++ b/Include/Utilities/Math.h @@ -63,7 +63,7 @@ namespace CE static glm::quat CalculateRotationBetweenOrientations(glm::quat start, glm::quat end); // Stolen from https://stackoverflow.com/questions/44705398/about-glm-quaternion-rotation - static glm::vec3 RotateVector(const glm::vec3& v, const glm::quat& q); + static glm::vec3 RotateVector(glm::vec3 v, const glm::quat& q); static constexpr uint32 floorlog2(uint32 x) { diff --git a/Source/Assets/Importers/ModelImporter.cpp b/Source/Assets/Importers/ModelImporter.cpp index 162a7596..f95e146f 100644 --- a/Source/Assets/Importers/ModelImporter.cpp +++ b/Source/Assets/Importers/ModelImporter.cpp @@ -35,29 +35,38 @@ namespace CE::AssetHandle mHandle{}; }; + std::string RemoveExtension(const auto& str) + { + return std::filesystem::path{ str }.filename().replace_extension().string(); + } + std::string GetEmbedTexName(const std::filesystem::path& modelPath, const int index) { - return modelPath.filename().replace_extension().string().append("_tex").append(std::to_string(index)); + return CE::Format("T_{}_{}", RemoveExtension(modelPath), index); } - std::string GetTexName(const char* name) + std::string GetTexName(std::string_view name) { - return std::filesystem::path(name).filename().replace_extension().string(); + return CE::Format("T_{}", RemoveExtension(name)); } - std::string GetMeshName(const std::filesystem::path& modelPath, const char* name) + std::string GetMeshName(std::string_view name) { - return modelPath.filename().replace_extension().string().append("_").append(name); + return CE::Format("SM_{}", RemoveExtension(name)); } std::string GetSceneName(const std::filesystem::path& modelPath) { - return modelPath.filename().replace_extension().string().append("_").append("Prefab"); + return CE::Format("PF_{}", RemoveExtension(modelPath)); } - std::string GetMaterialName(const std::filesystem::path& modelPath, const char* name, const int index) + std::string GetMaterialName(const std::filesystem::path& modelPath, std::string_view name, const int index) { - return (*name == *"") ? "M_" + modelPath.filename().string() + *"_Unnamed_Material_" + std::to_string(index) : name; + if (name.empty()) + { + return CE::Format("MT_{}_{}", RemoveExtension(modelPath), index); + } + return CE::Format("MT_{}", name); } int GetIndexFromAssimpTextureName(const char* name) @@ -178,7 +187,7 @@ std::optional> CE::ModelImporter::Import(const st { const aiMesh& mesh = *scene->mMeshes[i]; - const std::string meshName = GetMeshName(file, mesh.mName.C_Str()); + const std::string meshName = GetMeshName(mesh.mName.C_Str()); const std::span positions = { reinterpret_cast(mesh.mVertices), mesh.mNumVertices }; std::vector indices{}; @@ -279,8 +288,7 @@ std::optional> CE::ModelImporter::Import(const st StaticMeshComponent& meshComponent = reg.AddComponent(meshHolder); - meshComponent.mStaticMesh = dummyStaticMeshes.emplace_back(GetMeshName(file, - scene->mMeshes[node.mMeshes[i]]->mName.C_Str())).mHandle; + meshComponent.mStaticMesh = dummyStaticMeshes.emplace_back(GetMeshName(scene->mMeshes[node.mMeshes[i]]->mName.C_Str())).mHandle; meshComponent.mMaterial = std::move(mat); } diff --git a/Source/Assets/Level.cpp b/Source/Assets/Level.cpp index 789913b4..bf225626 100644 --- a/Source/Assets/Level.cpp +++ b/Source/Assets/Level.cpp @@ -263,23 +263,27 @@ CE::World CE::Level::CreateDefaultWorld() reg.AddComponent(camera, "Main Camera"); TransformComponent& transform = reg.AddComponent(camera); - transform.SetLocalPosition({ 5.5f, 2.5f, -7.5f }); - transform.SetLocalOrientation({ glm::radians(14.5f), glm::radians(-33.0f), 0.0f }); + transform.SetLocalPosition({ -10.0, 10.0f, 6.0f }); + transform.SetLocalOrientation(glm::quat{ glm::vec3{ 0.0f, glm::radians(22.5), glm::radians(-45.0f) } }); } + + const glm::vec3 mainLightDir{ glm::radians(0.0f), glm::radians(38.5f), glm::radians(-51.0f) }; + { const entt::entity light = reg.Create(); reg.AddComponent(light, "Main Light"); DirectionalLightComponent& lightComponent = reg.AddComponent(light); - lightComponent.mColor *= 6.0f; - reg.AddComponent(light).SetLocalOrientation({ glm::radians(-15.6), glm::radians(-47.6), glm::radians(51.6) }); + lightComponent.mColor *= .7f; + + reg.AddComponent(light).SetLocalOrientation(glm::quat{ mainLightDir }); } { const entt::entity light = reg.Create(); reg.AddComponent(light, "Secondary Light"); - reg.AddComponent(light).mColor *= 3.0f; - reg.AddComponent(light).SetLocalOrientation({ glm::radians(113.8), glm::radians(53.54), glm::radians(90.7) }); + reg.AddComponent(light).mColor *= .3f; + reg.AddComponent(light).SetLocalOrientation(glm::quat{ -mainLightDir }); } return world; diff --git a/Source/Assets/StaticMesh.cpp b/Source/Assets/StaticMesh.cpp index 0017fe4b..23ac6592 100644 --- a/Source/Assets/StaticMesh.cpp +++ b/Source/Assets/StaticMesh.cpp @@ -17,9 +17,7 @@ namespace hasIndices = 1, hasNormals = 1 << 1, hasTextureCoords = 1 << 2, - // hasColors = 1 << 3, // No longer used - areIndices16Bit = 1 << 4, // No longer used - hasTangents = 1 << 5 + hasTangents = 1 << 3 }; } @@ -51,29 +49,8 @@ CE::StaticMesh::StaticMesh(AssetLoadInfo& loadInfo) : const StaticMeshFlags flags = readContents.operator()(); const uint32 numOfVertices = readContents.operator()(); const std::span positions = { &readContents.operator()(numOfVertices), numOfVertices }; - - std::vector indicesBuffer{}; - const std::span indices = [flags, &readContents, &indicesBuffer]() -> std::span - { - if ((flags & hasIndices) == 0) - { - return {}; - } - - const uint32 numOfIndices = readContents.operator()(); - - if ((flags & areIndices16Bit) == 0) - { - return { &readContents.operator()(numOfIndices), numOfIndices }; - } - - const std::span shortIndices = { &readContents.operator() (numOfIndices), numOfIndices }; - - // Cast to uint32's, and find a place to store them for now - indicesBuffer = { shortIndices.begin(), shortIndices.end() }; - return indicesBuffer; - }(); - + const uint32 numOfIndices = readContents.operator()(); + const std::span indices = flags & hasIndices ? std::span{ &readContents.operator()(numOfIndices), numOfIndices } : std::span{}; const std::span normals = flags & hasNormals ? std::span{ &readContents.operator()(numOfVertices), numOfVertices } : std::span{}; const std::span textureCoordinates = flags & hasTextureCoords ? std::span{ &readContents.operator()(numOfVertices), numOfVertices } : std::span{}; const std::span tangents = flags & hasTangents ? std::span{ &readContents.operator()(numOfVertices), numOfVertices } : std::span{}; @@ -176,7 +153,14 @@ bool CE::Internal::SaveStaticMesh(AssetSaveInfo& saveInfo, }; writeBuffer(positions, flags); - writeBuffer(indices, hasIndices); + + if (flags & hasIndices) + { + const uint32 numOfIndices = static_cast(indices.size()); + str.write(reinterpret_cast(&numOfIndices), sizeof(numOfIndices)); + writeBuffer(indices, hasIndices); + } + writeBuffer(normals, hasNormals); writeBuffer(textureCoordinates, hasTextureCoords); writeBuffer(tangents, hasTangents); diff --git a/Source/Assets/Texture.cpp b/Source/Assets/Texture.cpp index a9e43ef0..13545fbc 100644 --- a/Source/Assets/Texture.cpp +++ b/Source/Assets/Texture.cpp @@ -34,6 +34,8 @@ CE::Texture::Texture(AssetLoadInfo& loadInfo) : const std::string data = StringFunctions::StreamToString(loadInfo.GetStream()); int channels{}; + stbi_set_flip_vertically_on_load(true); + std::byte* pixels = reinterpret_cast( stbi_load_from_memory( reinterpret_cast(data.data()), diff --git a/Source/Components/CameraComponent.cpp b/Source/Components/CameraComponent.cpp index d6d310ef..d01bbd05 100644 --- a/Source/Components/CameraComponent.cpp +++ b/Source/Components/CameraComponent.cpp @@ -1,50 +1,9 @@ #include "Precomp.h" #include "Components/CameraComponent.h" -#include "Components/TransformComponent.h" #include "Meta/MetaType.h" #include "Meta/MetaProps.h" #include "Utilities/Reflect/ReflectComponentType.h" -#include "World/WorldViewport.h" - -void CE::CameraComponent::UpdateView(const glm::vec3 position, const glm::vec3 forward, const glm::vec3 up, bool recalulateViewProjection) -{ - mView = glm::lookAt(position, position + forward, up); - - if (recalulateViewProjection) - { - RecalculateViewProjection(); - } -} - -void CE::CameraComponent::UpdateView(const TransformComponent& transform, bool recalulateViewProjection) -{ - UpdateView(transform.GetWorldPosition(), transform.GetWorldForward(), transform.GetWorldUp(), recalulateViewProjection); -} - -void CE::CameraComponent::UpdateProjection(const glm::vec2 viewportSize, bool recalculateViewProjection) -{ - UpdateProjection(viewportSize.x / viewportSize.y, recalculateViewProjection); -} - -void CE::CameraComponent::UpdateProjection(const float aspectRatio, bool recalculateViewProjection) -{ - mProjection = glm::perspective(mFOV, aspectRatio, mNear, mFar); - - // Calculating the orthographic projection is a matter to discuss and look into further, - // since it may not work as well on different resolution - mOrthographicProjection = glm::ortho(-aspectRatio, aspectRatio, -1.f, 1.f, -1.0f, 1.0f); - - if (recalculateViewProjection) - { - RecalculateViewProjection(); - } -} - -void CE::CameraComponent::RecalculateViewProjection() -{ - mViewProjection = mProjection * mView; -} entt::entity CE::CameraComponent::GetSelected(const World& world) { @@ -104,11 +63,6 @@ CE::MetaType CE::CameraComponent::Reflect() type.AddField(&CameraComponent::mFar, "mFar").GetProperties().Add(Props::sIsScriptableTag); type.AddField(&CameraComponent::mNear, "mNear").GetProperties().Add(Props::sIsScriptableTag); type.AddField(&CameraComponent::mFOV, "mFOV").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(&CameraComponent::GetViewProjection, "GetViewProjection", "").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(&CameraComponent::GetView, "GetView", "").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(&CameraComponent::GetProjection, "GetProjection", "").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(&CameraComponent::GetOrthographicProjection, "GetOrthographicProjection", "").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(&CameraComponent::RecalculateViewProjection, "RecalculateViewProjection", "").GetProperties().Add(Props::sIsScriptableTag); ReflectComponentType(type); diff --git a/Source/Components/FlyCamControllerComponent.cpp b/Source/Components/FlyCamControllerComponent.cpp index e665f201..398eeda2 100644 --- a/Source/Components/FlyCamControllerComponent.cpp +++ b/Source/Components/FlyCamControllerComponent.cpp @@ -6,7 +6,7 @@ #include "Meta/MetaProps.h" #include "Utilities/Reflect/ReflectComponentType.h" -void CE::FlyCamControllerComponent::ApplyTranslation(TransformComponent& transform, const glm::vec3& timeScaledMovementInput) const +void CE::FlyCamControllerComponent::ApplyTranslation(TransformComponent& transform, glm::vec3 timeScaledMovementInput) const { const glm::vec3 scaledMovementInput = timeScaledMovementInput * mMovementSpeed; @@ -16,7 +16,7 @@ void CE::FlyCamControllerComponent::ApplyTranslation(TransformComponent& transfo totalTranslation += scaledMovementInput[i] * transform.GetWorldAxis(static_cast(i)); } - transform.TranslateWorldPosition(totalTranslation); + transform.SetWorldPosition(transform.GetWorldPosition() + totalTranslation); } void CE::FlyCamControllerComponent::ApplyRotation(TransformComponent& transform, const std::array& timeScaledRotations) const diff --git a/Source/Components/GridSpawnerComponent.cpp b/Source/Components/GridSpawnerComponent.cpp index 9f96e21b..c5cefc01 100644 --- a/Source/Components/GridSpawnerComponent.cpp +++ b/Source/Components/GridSpawnerComponent.cpp @@ -71,7 +71,7 @@ void CE::GridSpawnerComponent::SpawnGrid() } const float angleStep = glm::two_pi() / static_cast(mNumOfPossibleRotations); - CE::DefaultRandomEngine cellGenerator{ Random::CreateSeed(transform->GetWorldPosition2D()) }; + CE::DefaultRandomEngine cellGenerator{ Random::CreateSeed(transform->GetWorldPosition()) }; const std::function randomUint = mUseWorldPositionAsSeed ? std::function @@ -144,7 +144,7 @@ void CE::GridSpawnerComponent::SpawnGrid() child->SetParent(transform); const glm::vec2 offset = { randomFloat(0.0f, mMaxRandomOffset), randomFloat(0.0f, mMaxRandomOffset) }; - child->SetLocalPosition(To3DRightForward(position + offset, randomFloat(mMinRandomHeightOffset, mMaxRandomHeightOffset))); + child->SetLocalPosition(To3D(position + offset, randomFloat(mMinRandomHeightOffset, mMaxRandomHeightOffset))); child->SetLocalScale(randomFloat(mMinRandomScale, mMaxRandomScale)); diff --git a/Source/Components/Physics2D/AABBColliderComponent.cpp b/Source/Components/Physics2D/AABBColliderComponent.cpp index 0ef27cf3..21249b9f 100644 --- a/Source/Components/Physics2D/AABBColliderComponent.cpp +++ b/Source/Components/Physics2D/AABBColliderComponent.cpp @@ -9,8 +9,8 @@ CE::TransformedAABB CE::AABBColliderComponent::CreateTransformedCollider(const TransformComponent& transform) const { - const glm::vec2 worldPosition = transform.GetWorldPosition2D(); - const glm::vec2 scale = transform.GetWorldScale2D(); + const glm::vec2 worldPosition = transform.GetWorldPosition(); + const glm::vec2 scale = transform.GetWorldScale(); const glm::vec2 scaledHalfExtends = mHalfExtends * scale; const glm::vec2 vertices[4] = @@ -26,7 +26,7 @@ CE::TransformedAABB CE::AABBColliderComponent::CreateTransformedCollider(const T for (int i = 0; i < 4; i++) { - const glm::vec2 transformedVertex = To2DRightForward(Math::RotateVector(To3DRightForward(vertices[i], 0.0f), orientation)); + const glm::vec2 transformedVertex = To2D(Math::RotateVector(To3D(vertices[i], 0.0f), orientation)); rotatedAABB.mMin = glm::min(rotatedAABB.mMin, transformedVertex); rotatedAABB.mMax = glm::max(rotatedAABB.mMax, transformedVertex); diff --git a/Source/Components/Physics2D/DiskColliderComponent.cpp b/Source/Components/Physics2D/DiskColliderComponent.cpp index 9444ba55..ffb7bd2e 100644 --- a/Source/Components/Physics2D/DiskColliderComponent.cpp +++ b/Source/Components/Physics2D/DiskColliderComponent.cpp @@ -8,7 +8,9 @@ CE::TransformedDisk CE::DiskColliderComponent::CreateTransformedCollider(const TransformComponent& transform) const { - return { transform.GetWorldPosition2D(), transform.GetWorldScaleUniform2D() * mRadius }; + const glm::vec2 scale = transform.GetWorldScale(); + const float scaleUniform = .5f * (scale.x + scale.y); + return { transform.GetWorldPosition(), scaleUniform * mRadius }; } CE::MetaType CE::DiskColliderComponent::Reflect() @@ -35,8 +37,8 @@ CE::MetaType CE::DiskColliderComponent::Reflect() LOG(LogPhysics, Error, "Entity {} passed to GetScaledRadius does not have a DiskColliderComponent.", entt::to_integral(owner)); return 0.0f; } - return collider->mRadius * transform->GetWorldScaleUniform2D(); + return collider->CreateTransformedCollider(*transform).mRadius; }, "GetScaledRadius", MetaFunc::ExplicitParams< entt::entity>{}, "Owner of Disk Collider").GetProperties().Add(Props::sIsScriptableTag).Set(Props::sIsScriptPure, true); diff --git a/Source/Components/Physics2D/PolygonColliderComponent.cpp b/Source/Components/Physics2D/PolygonColliderComponent.cpp index 1017f86b..7365bb83 100644 --- a/Source/Components/Physics2D/PolygonColliderComponent.cpp +++ b/Source/Components/Physics2D/PolygonColliderComponent.cpp @@ -14,7 +14,7 @@ CE::TransformedPolygon CE::PolygonColliderComponent::CreateTransformedCollider(c for (uint32 i = 0; i < mPoints.size(); i++) { - points[i] = To2DRightForward(worldMatrix * glm::vec4{ To3DRightForward(mPoints[i]), 1.0f }); + points[i] = To2D(worldMatrix * glm::vec4{ To3D(mPoints[i]), 1.0f }); } return points; diff --git a/Source/Components/StaticMeshComponent.cpp b/Source/Components/StaticMeshComponent.cpp index 86a3d7c4..1f4a1313 100644 --- a/Source/Components/StaticMeshComponent.cpp +++ b/Source/Components/StaticMeshComponent.cpp @@ -14,9 +14,6 @@ CE::MetaType CE::StaticMeshComponent::Reflect() props.Add(Props::sIsScriptableTag); type.AddField(&StaticMeshComponent::mStaticMesh, "mStaticMesh").GetProperties().Add(Props::sIsScriptableTag); type.AddField(&StaticMeshComponent::mMaterial, "mMaterial").GetProperties().Add(Props::sIsScriptableTag); - type.AddField(&StaticMeshComponent::mTilesWithMeshScale, "mTilesWithMeshScale").GetProperties().Add(Props::sIsScriptableTag); - type.AddField(&StaticMeshComponent::mTiling, "mTiling").GetProperties().Add(Props::sIsScriptableTag); - type.AddField(&StaticMeshComponent::mHighlightedMesh, "mHighlighted").GetProperties().Add(Props::sIsScriptableTag); ReflectComponentType(type); return type; } diff --git a/Source/Components/TransformComponent.cpp b/Source/Components/TransformComponent.cpp index 7b5fb530..c03ad67e 100644 --- a/Source/Components/TransformComponent.cpp +++ b/Source/Components/TransformComponent.cpp @@ -3,8 +3,6 @@ #include -#include "GSON/GSONBinary.h" -#include "World/World.h" #include "World/Registry.h" #include "Meta/MetaType.h" #include "Meta/MetaProps.h" @@ -92,16 +90,22 @@ void CE::TransformComponent::SetLocalMatrix(const glm::mat4& matrix) SetLocalScale(scale); } -const glm::mat4& CE::TransformComponent::GetWorldMatrix() const +glm::mat4 CE::TransformComponent::GetWorldMatrix() const { - return mCachedWorldMatrix; + const glm::mat4 localMatrix = GetLocalMatrix(); + + if (mParent == nullptr) + { + return localMatrix; + } + return mParent->GetWorldMatrix() * localMatrix; } void CE::TransformComponent::SetWorldMatrix(const glm::mat4& matrix) { const auto [pos, scale, orientation] = FromMatrix(matrix); - // TODO can be optimized to only call world matrix once + // Can be optimized to only call world matrix once SetWorldPosition(pos); SetWorldOrientation(orientation); SetWorldScale(scale); @@ -114,7 +118,7 @@ std::tuple CE::TransformComponent::GetLocalPosi std::tuple CE::TransformComponent::GetWorldPositionScaleOrientation() const { - return mParent == nullptr ? GetLocalPositionScaleOrientation() : FromMatrix(mCachedWorldMatrix); + return mParent == nullptr ? GetLocalPositionScaleOrientation() : FromMatrix(GetWorldMatrix()); } void CE::TransformComponent::SetLocalPositionScaleOrientation(glm::vec3 position, glm::vec3 scale, glm::quat orientation) @@ -172,10 +176,6 @@ void CE::TransformComponent::SetParent(TransformComponent* const parent, const b SetWorldOrientation(worldOrientationToRestore); SetWorldScale(worldScaleToRestore); } - else - { - UpdateCachedWorldMatrix(); - } } const CE::TransformComponent* CE::TransformComponent::GetParent() const @@ -203,16 +203,6 @@ glm::vec3 CE::TransformComponent::GetLocalPosition() const return mLocalPosition; } -glm::vec2 CE::TransformComponent::GetLocalPosition2D() const -{ - return To2DRightForward(mLocalPosition); -} - -glm::vec2 CE::TransformComponent::GetWorldPosition2D() const -{ - return To2DRightForward(GetWorldPosition()); -} - void CE::TransformComponent::SetLocalPosition(const glm::vec3 position) { if (mLocalPosition == position) @@ -221,37 +211,16 @@ void CE::TransformComponent::SetLocalPosition(const glm::vec3 position) } mLocalPosition = position; - UpdateCachedWorldMatrix(); } void CE::TransformComponent::SetLocalPosition(const glm::vec2 position) { - SetLocalPosition(To3DRightForward(position, GetLocalPosition()[Axis::Up])); -} - -void CE::TransformComponent::TranslateLocalPosition(const glm::vec3 translation) -{ - SetLocalPosition(GetLocalPosition() + translation); -} - -void CE::TransformComponent::TranslateLocalPosition(const glm::vec2 translation) -{ - TranslateLocalPosition(To3DRightForward(translation)); + SetLocalPosition(glm::vec3{ position.x, position.y, GetLocalPosition().z }); } void CE::TransformComponent::SetWorldPosition(const glm::vec2 position) { - SetWorldPosition(To3DRightForward(position, GetWorldPosition()[Axis::Up])); -} - -void CE::TransformComponent::TranslateWorldPosition(const glm::vec3 translation) -{ - SetWorldPosition(GetWorldPosition() + translation); -} - -void CE::TransformComponent::TranslateWorldPosition(const glm::vec2 translation) -{ - TranslateWorldPosition(To3DRightForward(translation)); + SetWorldPosition(To3D(position, GetWorldPosition()[Axis::Up])); } glm::quat CE::TransformComponent::GetLocalOrientation() const @@ -259,21 +228,6 @@ glm::quat CE::TransformComponent::GetLocalOrientation() const return mLocalOrientation; } -glm::vec3 CE::TransformComponent::GetLocalOrientationEuler() const -{ - return eulerAngles(GetLocalOrientation()); -} - -glm::vec3 CE::TransformComponent::GetWorldOrientationEuler() const -{ - return eulerAngles(GetWorldOrientation()); -} - -void CE::TransformComponent::SetLocalOrientation(const glm::vec3 rotationEuler) -{ - SetLocalOrientation(glm::quat{ rotationEuler }); -} - void CE::TransformComponent::SetLocalOrientation(const glm::quat rotation) { if (rotation == mLocalOrientation) @@ -282,12 +236,6 @@ void CE::TransformComponent::SetLocalOrientation(const glm::quat rotation) } mLocalOrientation = rotation; - UpdateCachedWorldMatrix(); -} - -void CE::TransformComponent::SetWorldOrientation(const glm::vec3 rotationEuler) -{ - SetWorldOrientation(glm::quat{ rotationEuler }); } glm::vec3 CE::TransformComponent::GetLocalForward() const @@ -330,32 +278,32 @@ glm::vec3 CE::TransformComponent::GetWorldAxis(const Axis::Values axis) const return Math::RotateVector(ToVector3(axis), GetWorldOrientation()); } -void CE::TransformComponent::SetLocalForward(const glm::vec3& forward) +void CE::TransformComponent::SetLocalForward(glm::vec3 forward) { SetLocalOrientation(Math::CalculateRotationBetweenOrientations(sForward, forward)); } -void CE::TransformComponent::SetLocalUp(const glm::vec3& up) +void CE::TransformComponent::SetLocalUp(glm::vec3 up) { SetLocalOrientation(Math::CalculateRotationBetweenOrientations(sUp, up)); } -void CE::TransformComponent::SetLocalRight(const glm::vec3& right) +void CE::TransformComponent::SetLocalRight(glm::vec3 right) { SetLocalOrientation(Math::CalculateRotationBetweenOrientations(sRight, right)); } -void CE::TransformComponent::SetWorldForward(const glm::vec3& forward) +void CE::TransformComponent::SetWorldForward(glm::vec3 forward) { SetWorldOrientation(Math::CalculateRotationBetweenOrientations(sForward, forward)); } -void CE::TransformComponent::SetWorldUp(const glm::vec3& up) +void CE::TransformComponent::SetWorldUp(glm::vec3 up) { SetWorldOrientation(Math::CalculateRotationBetweenOrientations(sUp, up)); } -void CE::TransformComponent::SetWorldRight(const glm::vec3& right) +void CE::TransformComponent::SetWorldRight(glm::vec3 right) { SetWorldOrientation(Math::CalculateRotationBetweenOrientations(sRight, right)); } @@ -365,44 +313,23 @@ glm::vec3 CE::TransformComponent::GetLocalScale() const return mLocalScale; } -glm::vec2 CE::TransformComponent::GetLocalScale2D() const -{ - return To2DRightForward(GetLocalScale()); -} - float CE::TransformComponent::GetLocalScaleUniform() const { const glm::vec3 scale = GetLocalScale(); return (scale.x + scale.y + scale.z) * (1.0f / 3.0f); } -glm::vec2 CE::TransformComponent::GetWorldScale2D() const -{ - return To2DRightForward(GetWorldScale()); -} - float CE::TransformComponent::GetWorldScaleUniform() const { const glm::vec3 scale = GetWorldScale(); return (scale.x + scale.y + scale.z) * (1.0f / 3.0f); } -float CE::TransformComponent::GetWorldScaleUniform2D() const -{ - const glm::vec2 scale = GetWorldScale2D(); - return (scale.x + scale.y) * (1.0f / 2.0f); -} - void CE::TransformComponent::SetLocalScale(const float xyz) { SetLocalScale(glm::vec3{ xyz }); } -void CE::TransformComponent::SetLocalScaleRightForward(const float scale) -{ - SetLocalScale(glm::vec3{ scale, GetLocalScale().y, scale }); -} - void CE::TransformComponent::SetLocalScale(const glm::vec3 scale) { if (mLocalScale == scale) @@ -411,12 +338,11 @@ void CE::TransformComponent::SetLocalScale(const glm::vec3 scale) } mLocalScale = scale; - UpdateCachedWorldMatrix(); } void CE::TransformComponent::SetLocalScale(const glm::vec2 scale) { - SetLocalScale(To3DRightForward(scale, GetLocalScale()[Axis::Up])); + SetLocalScale(To3D(scale, GetLocalScale()[Axis::Up])); } void CE::TransformComponent::SetWorldScale(const float xyz) @@ -426,7 +352,7 @@ void CE::TransformComponent::SetWorldScale(const float xyz) void CE::TransformComponent::SetWorldScale(const glm::vec2 scale) { - SetWorldScale(To3DRightForward(scale, GetWorldScale()[Axis::Up])); + SetWorldScale(To3D(scale, GetWorldScale()[Axis::Up])); } bool CE::TransformComponent::IsAForeFather(const TransformComponent& potentialForeFather) const @@ -473,8 +399,8 @@ void CE::TransformComponent::SetWorldOrientation(const glm::quat orientation) } else { - const glm::quat parentWorldOrienation = mParent->GetWorldOrientation(); - SetLocalOrientation(inverse(parentWorldOrienation) * orientation); + const glm::quat parentWorldOrientation = mParent->GetWorldOrientation(); + SetLocalOrientation(glm::inverse(parentWorldOrientation) * orientation); } } @@ -514,23 +440,6 @@ void CE::TransformComponent::DetachChild(TransformComponent& child) mChildren.erase(it); } -void CE::TransformComponent::UpdateCachedWorldMatrix() -{ - if (mParent == nullptr) - { - mCachedWorldMatrix = GetLocalMatrix(); - } - else - { - mCachedWorldMatrix = mParent->GetWorldMatrix() * GetLocalMatrix(); - } - - for (TransformComponent& child : mChildren) - { - child.UpdateCachedWorldMatrix(); - } -} - CE::MetaType CE::TransformComponent::Reflect() { MetaType type = MetaType{ MetaType::T{}, "TransformComponent" }; @@ -548,7 +457,7 @@ CE::MetaType CE::TransformComponent::Reflect() type.AddFunc([](const TransformComponent& transform) { - auto references = transform.GetChildren(); + const auto& references = transform.GetChildren(); std::vector owners(references.size()); @@ -565,19 +474,13 @@ CE::MetaType CE::TransformComponent::Reflect() type.AddFunc(&TransformComponent::IsAForeFather, "IsAForeFather", "", "potentialForeFather").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetOwner, "GetOwner", "").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetLocalPosition, "GetLocalPosition", "").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(&TransformComponent::GetLocalPosition2D, "GetLocalPosition2D", "").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetWorldPosition, "GetWorldPosition", "").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(&TransformComponent::GetWorldPosition2D, "GetWorldPosition2D", "").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(static_cast(&TransformComponent::SetLocalPosition), "SetLocalPosition", "", "position").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(static_cast(&TransformComponent::TranslateLocalPosition), "TranslateLocalPosition", "", "translation").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(static_cast(&TransformComponent::SetWorldPosition), "SetWorldPosition", "", "position").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(static_cast(&TransformComponent::TranslateWorldPosition), "TranslateWorldPosition", "", "translation").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetLocalOrientation, "GetLocalOrientation", "").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(&TransformComponent::GetLocalOrientationEuler, "GetLocalOrientationEuler", "").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetWorldOrientation, "GetWorldOrientation", "").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(&TransformComponent::GetWorldOrientationEuler, "GetWorldOrientationEuler", "").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(static_cast(&TransformComponent::SetLocalOrientation), "SetLocalOrientation", "", "rotation").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(static_cast(&TransformComponent::SetWorldOrientation), "SetWorldOrientation", "", "orientation").GetProperties().Add(Props::sIsScriptableTag); + type.AddFunc(&TransformComponent::SetLocalOrientation, "SetLocalOrientation", "", "rotation").GetProperties().Add(Props::sIsScriptableTag); + type.AddFunc(&TransformComponent::SetWorldOrientation, "SetWorldOrientation", "", "orientation").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetLocalForward, "GetLocalForward", "").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetLocalUp, "GetLocalUp", "").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetLocalRight, "GetLocalRight", "").GetProperties().Add(Props::sIsScriptableTag); @@ -591,10 +494,8 @@ CE::MetaType CE::TransformComponent::Reflect() type.AddFunc(&TransformComponent::SetWorldUp, "SetWorldUp", "", "up").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::SetWorldRight, "SetWorldRight", "", "right").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetLocalScale, "GetLocalScale", "").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(&TransformComponent::GetLocalScale2D, "GetLocalScale2D", "").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetLocalScaleUniform, "GetLocalScaleUniform", "").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetWorldScale, "GetWorldScale", "").GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc(&TransformComponent::GetWorldScale2D, "GetWorldScale2D", "").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(&TransformComponent::GetWorldScaleUniform, "GetWorldScaleUniform", "").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(static_cast(&TransformComponent::SetLocalScale), "SetLocalScale", "", "scale").GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(static_cast(&TransformComponent::SetWorldScale), "SetWorldScale", "", "scale").GetProperties().Add(Props::sIsScriptableTag); diff --git a/Source/EditorSystems/ThumbnailEditorSystem.cpp b/Source/EditorSystems/ThumbnailEditorSystem.cpp index 7e639a37..e5c6495e 100644 --- a/Source/EditorSystems/ThumbnailEditorSystem.cpp +++ b/Source/EditorSystems/ThumbnailEditorSystem.cpp @@ -35,7 +35,7 @@ void CE::ThumbnailEditorSystem::Tick(float deltaTime) Timer timeToRenderFrame{}; LOG(LogEditor, Verbose, "Rendering {} to thumbnail", current.mForAsset.GetMetaData().GetName()); - + current.mWorld.Render(¤t.mFrameBuffer); const auto result = mGeneratedThumbnails.emplace(std::piecewise_construct, @@ -184,13 +184,20 @@ bool CE::ThumbnailEditorSystem::DisplayImGuiImageButton(const WeakAssetHandle<>& { const ImVec2 cursorScreenPos = ImGui::GetCursorScreenPos(); const std::string_view id = forAsset != nullptr ? std::string_view{ forAsset.GetMetaData().GetName() } : "None"; - return ImGui::ImageButton(id.data(), ImGui::IsRectVisible(cursorScreenPos, cursorScreenPos + size) ? GetThumbnail(forAsset) : GetDefaultThumbnail(), size); + return ImGui::ImageButton(id.data(), + ImGui::IsRectVisible(cursorScreenPos, cursorScreenPos + size) ? GetThumbnail(forAsset) : GetDefaultThumbnail(), + size, + ImVec2(0, 1), + ImVec2(1, 0)); } void CE::ThumbnailEditorSystem::DisplayImGuiImage(const WeakAssetHandle<>& forAsset, ImVec2 size) { const ImVec2 cursorScreenPos = ImGui::GetCursorScreenPos(); - ImGui::Image(ImGui::IsRectVisible(cursorScreenPos, cursorScreenPos + size) ? GetThumbnail(forAsset) : GetDefaultThumbnail(), size); + ImGui::Image(ImGui::IsRectVisible(cursorScreenPos, cursorScreenPos + size) ? GetThumbnail(forAsset) : GetDefaultThumbnail(), + size, + ImVec2(0, 1), + ImVec2(1, 0)); } ImTextureID CE::ThumbnailEditorSystem::GetDefaultThumbnail() @@ -361,7 +368,7 @@ CE::GetThumbnailRet GetThumbNailImpl(const CE::WeakAssetHandle(entity).SetLocalScale(2.5f); CE::StaticMeshComponent& staticMeshComponent = reg.AddComponent(entity); - staticMeshComponent.mStaticMesh = CE::AssetManager::Get().TryGetAsset("Sphere_Sphere"); + staticMeshComponent.mStaticMesh = CE::AssetManager::Get().TryGetAsset("SM_Sphere"); if (staticMeshComponent.mStaticMesh == nullptr) { diff --git a/Source/Meta/ReflectedTypes/GLM/ReflectQuat.cpp b/Source/Meta/ReflectedTypes/GLM/ReflectQuat.cpp index 8642a94c..a502a016 100644 --- a/Source/Meta/ReflectedTypes/GLM/ReflectQuat.cpp +++ b/Source/Meta/ReflectedTypes/GLM/ReflectQuat.cpp @@ -22,7 +22,7 @@ MetaType Reflector::Reflect() type.AddFunc(std::equal_to(), OperatorType::equal, MetaFunc::ExplicitParams{}).GetProperties().Add(Props::sIsScriptableTag); type.AddFunc(std::not_equal_to(), OperatorType::inequal, MetaFunc::ExplicitParams{}).GetProperties().Add(Props::sIsScriptableTag); type.AddFunc([](const T& n) { return -n; }, OperatorType::negate, MetaFunc::ExplicitParams{}).GetProperties().Add(Props::sIsScriptableTag); - type.AddFunc([](const glm::vec3& n) { return glm::quat{ n }; }, "EulerToQuat (Radians)", MetaFunc::ExplicitParams{}).GetProperties().Add(Props::sIsScriptableTag); + type.AddFunc([](glm::vec3 n) { return glm::quat{ n }; }, "EulerToQuat (Radians)", MetaFunc::ExplicitParams{}).GetProperties().Add(Props::sIsScriptableTag); type.AddFunc([](const glm::quat& n) { return glm::eulerAngles(n); }, "QuatToEuler (Radians)", MetaFunc::ExplicitParams{}).GetProperties().Add(Props::sIsScriptableTag); type.AddFunc([](const glm::quat& n) { diff --git a/Source/Platform/PC/Core/Renderer.cpp b/Source/Platform/PC/Core/Renderer.cpp index 519cf6a9..c31a0ded 100644 --- a/Source/Platform/PC/Core/Renderer.cpp +++ b/Source/Platform/PC/Core/Renderer.cpp @@ -1,6 +1,7 @@ #include "Precomp.h" #include "Core/Renderer.h" +#include #include #include "Assets/Material.h" @@ -65,12 +66,13 @@ struct CE::StaticMeshPlatformImpl struct CE::FrameBufferPlatformImpl { + ~FrameBufferPlatformImpl(); + void Resize(glm::ivec2 size); + std::shared_ptr mColorTexture{}; GLuint mFrameBuffer{}; - GLuint mColorTexture{}; GLuint mDepthTexture{}; - glm::ivec2 mSize{}; bool mIsInitialized{}; }; @@ -82,31 +84,38 @@ CE::StaticMeshPlatformImpl::~StaticMeshPlatformImpl() CHECK_GL; } +CE::FrameBufferPlatformImpl::~FrameBufferPlatformImpl() +{ + glDeleteFramebuffers(1, &mFrameBuffer); + glDeleteRenderbuffers(1, &mDepthTexture); + CHECK_GL; +} + void CE::FrameBufferPlatformImpl::Resize(glm::ivec2 size) { - if (mSize == size) + if (mColorTexture->mSize == size) { return; } - mSize = size; + mColorTexture->mSize = size; - glBindTexture(GL_TEXTURE_2D, mColorTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, mSize.x, mSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); + glBindTexture(GL_TEXTURE_2D, mColorTexture->mId); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, size.x, size.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mColorTexture, 0); + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, mColorTexture->mId, 0); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, mSize.x, mSize.y, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size.x, size.y, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColorTexture, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mColorTexture->mId, 0); glBindRenderbuffer(GL_RENDERBUFFER, mDepthTexture); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, mSize.x, mSize.y); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size.x, size.y); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, mDepthTexture); CHECK_GL; } @@ -114,7 +123,7 @@ void CE::FrameBufferPlatformImpl::Resize(glm::ivec2 size) struct CE::RenderCommandQueue { static constexpr int sMaxNumLines = 1 << 7; - static constexpr int sNumFloatsPerLine = sizeof(glm::vec3) + sizeof(glm::vec4) * 2; // Pos + Colour * 2 + static constexpr int sNumFloatsPerLine = (3 + 4) * 2; // Pos + Colour * 2 std::array mLines; std::atomic_int mTotalNumOfLinesRequested{}; @@ -197,19 +206,34 @@ CE::Renderer::Renderer() : // Array buffer contains the attribute data glBindBuffer(GL_ARRAY_BUFFER, mImpl->mLinesVBO); - // Allocate into VBO - // const auto size = sizeof(mImpl->m_vertexArray); - // glBufferData(GL_ARRAY_BUFFER, RenderCommandQueue::sMaxNumLines * RenderCommandQueue::sNumFloatsPerLine, &mImpl->m_vertexArray[0], GL_STREAM_DRAW); + struct Test + { + float posX; + float posY; + float posZ; + float colR; + float colG; + float colB; + float colA; + }; + + static constexpr size_t sizePos = sizeof(glm::vec3); + static constexpr size_t sizeCol = sizeof(glm::vec4); + static constexpr size_t sizeTotal = sizePos + sizeCol; + static_assert(sizeTotal == sizeof(Test)); + static_assert(sizePos == offsetof(Test, colR)); - glEnableVertexAttribArray(1); - glVertexAttribPointer( - 1, 3, GL_FLOAT, GL_FALSE, 3 + 4, nullptr); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeTotal, nullptr); - glEnableVertexAttribArray(2); - glVertexAttribPointer( - 2, 4, GL_FLOAT, GL_FALSE, 3 + 4, reinterpret_cast(sizeof(glm::vec3))); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeTotal, reinterpret_cast(sizePos)); glBindVertexArray(0); + + glEnable(GL_DEPTH_TEST); + glFrontFace(GL_CW); + glEnable(GL_CULL_FACE); CHECK_GL; } @@ -277,6 +301,8 @@ void CE::Renderer::SetRenderTarget(RenderCommandQueue& context, const glm::mat4& void CE::Renderer::RunCommandQueues() { + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); + static constexpr auto isLastReference = [](const auto& sharedPtr) -> bool { return sharedPtr.use_count() <= 1; @@ -386,12 +412,12 @@ void CE::Renderer::RunCommandQueues() glGenFramebuffers(1, &frameBuffer->mFrameBuffer); glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer->mFrameBuffer); - glGenTextures(1, &frameBuffer->mColorTexture); + glGenTextures(1, &frameBuffer->mColorTexture->mId); glGenRenderbuffers(1, &frameBuffer->mDepthTexture); frameBuffer->Resize({ 1, 1 }); - glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, frameBuffer->mColorTexture, 0); + glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, frameBuffer->mColorTexture->mId, 0); const GLenum drawBuffer = GL_COLOR_ATTACHMENT0; glDrawBuffers(1, &drawBuffer); @@ -419,18 +445,14 @@ void CE::Renderer::RunCommandQueues() { glBindFramebuffer(GL_FRAMEBUFFER, target->mFrameBuffer); target->Resize(commandQueue->mRenderTargetEntry->mRenderSize); - glViewport(0, 0, target->mSize.x, target->mSize.y); + glViewport(0, 0, target->mColorTexture->mSize.x, target->mColorTexture->mSize.y); } // Clear the screen const glm::vec4 clearColor = commandQueue->mRenderTargetEntry->mClearColor; glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a); - glClearDepth(1.0); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); - - // Enable depth testing and set the depth function - glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); + CHECK_GL; // Activate the standard program @@ -524,17 +546,19 @@ void CE::Renderer::RunCommandQueues() } // SetRenderTarget debug lines - const int numOfLines = std::min(static_cast(commandQueue->mTotalNumOfLinesRequested), static_cast(RenderCommandQueue::sMaxNumLines)); + const int numOfLines = std::min(commandQueue->mTotalNumOfLinesRequested, RenderCommandQueue::sMaxNumLines); if (numOfLines > 0) { const glm::mat4 vp = commandQueue->mRenderTargetEntry->mProj * commandQueue->mRenderTargetEntry->mView; glUseProgram(mImpl->mLinesProgram); - glUniformMatrix4fv(1, 1, false, &vp[0][0]); - glBindVertexArray(mImpl->mLinesVAO); + glUniformMatrix4fv(glGetUniformLocation(mImpl->mLinesProgram, "u_worldviewproj"), 1, GL_FALSE, &vp[0][0]); + glBindVertexArray(mImpl->mLinesVAO); + glBindBuffer(GL_ARRAY_BUFFER, mImpl->mLinesVBO); - glBufferData(GL_ARRAY_BUFFER, numOfLines * RenderCommandQueue::sNumFloatsPerLine, commandQueue->mLines.data(), GL_DYNAMIC_DRAW); + const int numOfBytes = numOfLines * RenderCommandQueue::sNumFloatsPerLine * sizeof(float); + glBufferData(GL_ARRAY_BUFFER, numOfBytes, commandQueue->mLines.data(), GL_STREAM_DRAW); glDrawArrays(GL_LINES, 0, numOfLines * 2); glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -552,10 +576,10 @@ void CE::Renderer::RunCommandQueues() std::scoped_lock resourcesLock{ mImpl->mTexturesMutex, mImpl->mStaticMeshesMutex, mImpl->mFrameBuffersMutex }; - std::erase_if(mImpl->mTextures, isLastReference); - std::erase_if(mImpl->mStaticMeshes, isLastReference); std::erase_if(mImpl->mFrameBuffers, isLastReference); std::erase_if(mImpl->mCommandQueues, isLastReference); + std::erase_if(mImpl->mStaticMeshes, isLastReference); + std::erase_if(mImpl->mTextures, isLastReference); } std::shared_ptr CE::Renderer::CreateCommandQueue() @@ -603,18 +627,19 @@ std::shared_ptr CE::Renderer::CreateTexturePlatformImpl { return nullptr; } - - const GLuint colorTexture = frameBufferImpl->mColorTexture; - frameBufferImpl->mColorTexture = 0;; - - std::scoped_lock lock{ mImpl->mTexturesMutex }; - return mImpl->mTextures.emplace_back(std::make_shared(nullptr, frameBufferImpl->mSize, colorTexture)); + return frameBufferImpl->mColorTexture; } std::shared_ptr CE::Renderer::CreateFrameBufferPlatformImpl() { + std::shared_ptr colorTexture = [this] + { + std::scoped_lock lock{ mImpl->mTexturesMutex }; + return mImpl->mTextures.emplace_back(std::make_shared()); + }(); + std::scoped_lock lock{ mImpl->mFrameBuffersMutex }; - return mImpl->mFrameBuffers.emplace_back(std::make_shared()); + return mImpl->mFrameBuffers.emplace_back(std::make_shared(std::move(colorTexture))); } void* CE::Renderer::GetPlatformId(TexturePlatformImpl* platformImpl) @@ -624,7 +649,7 @@ void* CE::Renderer::GetPlatformId(TexturePlatformImpl* platformImpl) void* CE::Renderer::GetPlatformId(FrameBufferPlatformImpl* platformImpl) { - return platformImpl == nullptr ? nullptr : reinterpret_cast(static_cast(platformImpl->mColorTexture)); + return platformImpl == nullptr ? nullptr : GetPlatformId(platformImpl->mColorTexture.get()); } void CE::Renderer::ImplDeleter::operator()(Impl* impl) const @@ -813,9 +838,11 @@ GLuint CE::Internal::CompileLinesProgram() { return CompileProgram( R"(#version 460 core - layout (location = 1) in vec3 a_position; - layout (location = 2) in vec4 a_color; - layout (location = 1) uniform mat4 u_worldviewproj; + layout (location = 0) in vec3 a_position; + layout (location = 1) in vec4 a_color; + + uniform mat4 u_worldviewproj; + out vec4 v_color; void main() diff --git a/Source/Systems/PhysicsSystem.cpp b/Source/Systems/PhysicsSystem.cpp index 24d83128..63871b28 100644 --- a/Source/Systems/PhysicsSystem.cpp +++ b/Source/Systems/PhysicsSystem.cpp @@ -44,7 +44,7 @@ void CE::PhysicsSystem::Render(const World& world, RenderCommandQueue& commandQu for (auto [entity, disk, transform] : diskView.each()) { - AddDebugCircle(commandQueue, DebugDraw::Physics, To3DRightForward(disk.mCentre), disk.mRadius + 0.00001f, color); + AddDebugCircle(commandQueue, DebugDraw::Physics, To3D(disk.mCentre), disk.mRadius + 0.00001f, color); } const auto polyView = reg.View(); @@ -55,14 +55,14 @@ void CE::PhysicsSystem::Render(const World& world, RenderCommandQueue& commandQu { const glm::vec2 from = poly.mPoints[i]; const glm::vec2 to = poly.mPoints[(i + 1) % pointCount]; - AddDebugLine(commandQueue, DebugDraw::Physics, To3DRightForward(from), To3DRightForward(to), color); + AddDebugLine(commandQueue, DebugDraw::Physics, To3D(from), To3D(to), color); } } const auto aabbView = reg.View(); for (auto [entity, aabb, transform] : aabbView.each()) { - AddDebugBox(commandQueue, DebugDraw::Physics, To3DRightForward(aabb.GetCentre()), To3DRightForward(aabb.GetSize() * .5f), color); + AddDebugBox(commandQueue, DebugDraw::Physics, To3D(aabb.GetCentre()), To3D(aabb.GetSize() * .5f), color); } } for (const BVH& bvh : world.GetPhysics().GetBVHs()) @@ -88,7 +88,7 @@ void CE::PhysicsSystem::ApplyVelocities(World& world, float dt) continue; } - transform.TranslateWorldPosition(body.mLinearVelocity * dt); + transform.SetWorldPosition(To2D(transform.GetWorldPosition()) + body.mLinearVelocity * dt); } } diff --git a/Source/Systems/UpdateCameraMatricesSystem.cpp b/Source/Systems/UpdateCameraMatricesSystem.cpp index 14308574..2046107e 100644 --- a/Source/Systems/UpdateCameraMatricesSystem.cpp +++ b/Source/Systems/UpdateCameraMatricesSystem.cpp @@ -29,15 +29,10 @@ void CE::UpdateCameraMatricesSystem::UpdateMatrices(World& world) const auto viewWithTransform = world.GetRegistry().View(); for (auto [entity, camera, transform] : viewWithTransform.each()) { - camera.UpdateView(transform, false); - camera.UpdateProjection(aspectRatio, true); - } - - const auto viewWithoutTransform = world.GetRegistry().View(entt::exclude); - for (auto [entity, camera] : viewWithoutTransform.each()) - { - camera.UpdateView(glm::vec3{ 0.0f }, sForward, sUp, false); - camera.UpdateProjection(aspectRatio, true); + const glm::vec3 worldPos = transform.GetWorldPosition(); + camera.mView = glm::lookAt(worldPos, worldPos + transform.GetWorldForward(), transform.GetWorldUp()); + camera.mProjection = glm::perspective(camera.mFOV, aspectRatio, camera.mNear, camera.mFar); + camera.mViewProjection = camera.mProjection * camera.mView; } } diff --git a/Source/Systems/UpdateFlyCamSystem.cpp b/Source/Systems/UpdateFlyCamSystem.cpp index 9968cb02..fd207753 100644 --- a/Source/Systems/UpdateFlyCamSystem.cpp +++ b/Source/Systems/UpdateFlyCamSystem.cpp @@ -28,33 +28,27 @@ void CE::UpdateFlyCamSystem::Update(World& world, float dt) Input& input = Input::Get(); - float isMouseButtonHeld = static_cast(input.IsMouseButtonHeld(Input::MouseButton::Right)); - movementInput[Axis::Forward] = input.GetKeyboardAxis(Input::KeyboardKey::W, Input::KeyboardKey::S) * isMouseButtonHeld/* + -input.GetGamepadAxis(0, Input::GamepadAxis::StickLeftY)*/; + const float isMouseButtonHeld = input.IsMouseButtonHeld(Input::MouseButton::Right); + movementInput[Axis::Forward] = input.GetKeyboardAxis(Input::KeyboardKey::W, Input::KeyboardKey::S) * isMouseButtonHeld; movementInput[Axis::Up] = input.GetKeyboardAxis(Input::KeyboardKey::E, Input::KeyboardKey::Q) * isMouseButtonHeld; - movementInput[Axis::Right] = input.GetKeyboardAxis(Input::KeyboardKey::D, Input::KeyboardKey::A) * isMouseButtonHeld/* + input.GetGamepadAxis(0, Input::GamepadAxis::StickLeftX)*/; + movementInput[Axis::Right] = input.GetKeyboardAxis(Input::KeyboardKey::D, Input::KeyboardKey::A) * isMouseButtonHeld; const glm::vec3 timeScaledMovementInput = movementInput * dt; constexpr Axis::Values rotateAround[2] { - Axis::Right, - Axis::Up + Axis::Up, + Axis::Right }; const glm::vec2 mouseInput = input.GetDeltaMousePosition() / world.GetViewport().GetViewportSize() * static_cast(input.IsMouseButtonHeld(Input::MouseButton::Right, true)); - glm::vec2 timeScaledRotationInput - { - mouseInput.y/* + input.GetGamepadAxis(0, Input::GamepadAxis::StickRightY) * dt*/, - mouseInput.x/* + input.GetGamepadAxis(0, Input::GamepadAxis::StickRightX) * dt*/ - }; - - timeScaledRotationInput *= flyCam->mRotationSpeed; + const glm::vec2 timeScaledRotationInput = mouseInput * flyCam->mRotationSpeed; const std::array timeScaledRotations { - ToVector3(rotateAround[0]) * timeScaledRotationInput[0], ToVector3(rotateAround[1]) * timeScaledRotationInput[1], + ToVector3(rotateAround[0]) * timeScaledRotationInput[0], }; const bool emptyMovement = timeScaledMovementInput == glm::vec3{}; diff --git a/Source/Utilities/BVH.cpp b/Source/Utilities/BVH.cpp index f0d194fa..c3be2ef5 100644 --- a/Source/Utilities/BVH.cpp +++ b/Source/Utilities/BVH.cpp @@ -151,8 +151,8 @@ void CE::BVH::DebugDraw() const { AddDebugBox(mPhysics->GetWorld().GetRenderCommandQueue(), DebugDraw::AccelStructs, - To3DRightForward(node.mBoundingBox.GetCentre()), - To3DRightForward(node.mBoundingBox.GetSize() * .5f), glm::vec4{ 0.0f, 1.0f, 1.0f, 1.0f }); + To3D(node.mBoundingBox.GetCentre()), + To3D(node.mBoundingBox.GetSize() * .5f), glm::vec4{ 0.0f, 1.0f, 1.0f, 1.0f }); } } } diff --git a/Source/Utilities/Imgui/WorldDetailsPanel.cpp b/Source/Utilities/Imgui/WorldDetailsPanel.cpp index 9363b1c5..903e64c1 100644 --- a/Source/Utilities/Imgui/WorldDetailsPanel.cpp +++ b/Source/Utilities/Imgui/WorldDetailsPanel.cpp @@ -361,18 +361,4 @@ void CE::WorldDetails::Display(World& world, std::vector& selected Search::EndPopup(); } - - // We don't have custom setter/getter support yet. - // WorldDetails may inspect mLocalPosition and - // adjust its value without ever updating the world - // matrix. - for (entt::entity entity : selectedEntities) - { - TransformComponent* transform = reg.TryGet(entity); - - if (transform != nullptr) - { - transform->UpdateCachedWorldMatrix(); - } - } } \ No newline at end of file diff --git a/Source/Utilities/Imgui/WorldViewportPanel.cpp b/Source/Utilities/Imgui/WorldViewportPanel.cpp index 8fbd3a53..5d9b9984 100644 --- a/Source/Utilities/Imgui/WorldViewportPanel.cpp +++ b/Source/Utilities/Imgui/WorldViewportPanel.cpp @@ -150,8 +150,8 @@ bool CE::Internal::GizmoManipulateSelectedTransforms(World& world, { Registry& reg = world.GetRegistry(); - const glm::mat4& view = camera.GetView(); - const glm::mat4& proj = camera.GetProjection(); + const glm::mat4& view = camera.mView; + const glm::mat4& proj = camera.mProjection; // The snap needs to be converted to a vec3, otherwise the Y translation does not work. const float* snap{}; @@ -183,27 +183,20 @@ bool CE::Internal::GizmoManipulateSelectedTransforms(World& world, const glm::vec3 avgPosition = totalPosition / static_cast(transformComponents.size()); const glm::vec3 avgScale = totalScale / static_cast(transformComponents.size()); - glm::mat4 avgMatrix; + // A bold lie + const glm::quat avgOrientation = transformComponents.size() == 1 ? transformComponents[0]->GetWorldOrientation() : glm::quat{}; - ImGuizmo::RecomposeMatrixFromComponents(value_ptr(avgPosition), - value_ptr(transformComponents.size() == 1 ? transformComponents[0]->GetWorldOrientationEuler() * (360.0f / TWOPI) : glm::vec3{}), - value_ptr(avgScale), - &avgMatrix[0][0]); + glm::mat4 avgMatrix = TransformComponent::ToMatrix(avgPosition, avgScale, avgOrientation); glm::mat4 delta; bool isSelected{}; - if (Manipulate(value_ptr(view), value_ptr(proj), sGuizmoOperation, sGuizmoMode, value_ptr(avgMatrix), value_ptr(delta), snap, nullptr, nullptr, &isSelected)) + if (Manipulate(value_ptr(view), value_ptr(proj), sGuizmoOperation, sGuizmoMode, glm::value_ptr(avgMatrix), value_ptr(delta), snap, nullptr, nullptr, &isSelected)) { // Apply the delta to all transformComponents for (const auto transformComponent : transformComponents) { - glm::mat4 transformMatrix; - - ImGuizmo::RecomposeMatrixFromComponents(value_ptr(transformComponent->GetWorldPosition()), - value_ptr(transformComponent->GetWorldOrientationEuler() * (360.0f / TWOPI)), - value_ptr(transformComponent->GetWorldScale()), - &transformMatrix[0][0]); + glm::mat4 transformMatrix = transformComponent->GetWorldMatrix(); // TODO Fix the scaling of multiple items at a time if (sGuizmoOperation & ImGuizmo::SCALE) diff --git a/Source/Utilities/Math.cpp b/Source/Utilities/Math.cpp index 8cfa0379..67827c49 100644 --- a/Source/Utilities/Math.cpp +++ b/Source/Utilities/Math.cpp @@ -121,7 +121,7 @@ glm::quat CE::Math::CalculateRotationBetweenOrientations(glm::quat start, glm::q } // Stolen from https://stackoverflow.com/questions/44705398/about-glm-quaternion-rotation -glm::vec3 CE::Math::RotateVector(const glm::vec3& v, const glm::quat& q) +glm::vec3 CE::Math::RotateVector(glm::vec3 v, const glm::quat& q) { const glm::vec3 quatAsVector = { q.x, q.y, q.z }; return v * (q.w * q.w - dot(quatAsVector, quatAsVector)) + 2.0f * quatAsVector * dot(quatAsVector, v) + 2.0f * q.w * cross(quatAsVector, v); diff --git a/Source/World/Archiver.cpp b/Source/World/Archiver.cpp index 183d4cf1..982980a6 100644 --- a/Source/World/Archiver.cpp +++ b/Source/World/Archiver.cpp @@ -80,17 +80,6 @@ std::vector CE::Archiver::Deserialize(World& world, const BinaryGS DeserializeStorage(reg, serializedStorage, idRemappings); } - // Due to legacy reasons, - // we never serialized the world matrix. - // So we have to update them here - for (const auto [entity, transform] : reg.View().each()) - { - if (transform.IsOrphan()) - { - transform.UpdateCachedWorldMatrix(); - } - } - return entities; } diff --git a/Source/World/Registry.cpp b/Source/World/Registry.cpp index dc61a5cd..eee82b93 100644 --- a/Source/World/Registry.cpp +++ b/Source/World/Registry.cpp @@ -140,14 +140,18 @@ void CE::Registry::UpdateSystems(float dt) void CE::Registry::RenderSystems(RenderCommandQueue& commandQueue) const { - for (const FixedTickSystem& fixedTickSystem : mFixedTickSystems) - { - fixedTickSystem.mSystem->Render(mWorld, commandQueue); - } + std::vector> sortedSystems{ mFixedTickSystems.begin(), mFixedTickSystems.end() }; + sortedSystems.insert(sortedSystems.end(), mNonFixedSystems.begin(), mNonFixedSystems.end()); - for (const InternalSystem& internalSystem : mNonFixedSystems) + std::stable_sort(sortedSystems.begin(), sortedSystems.end(), + [](const InternalSystem& lhs, const InternalSystem& rhs) + { + return lhs.mTraits.mPriority > rhs.mTraits.mPriority; + }); + + for (const InternalSystem& system : sortedSystems) { - internalSystem.mSystem->Render(mWorld, commandQueue); + system.mSystem->Render(mWorld, commandQueue); } } @@ -182,34 +186,25 @@ entt::entity CE::Registry::CreateFromPrefab(const Prefab& prefab, if (transform != nullptr) { - if (localPosition != nullptr - || localOrientation != nullptr - || localScale != nullptr - || parent != nullptr) + if (localPosition != nullptr) { + transform->SetLocalPosition(*localPosition); + } - if (localPosition != nullptr) - { - transform->SetLocalPosition(*localPosition); - } - - if (localOrientation != nullptr) - { - transform->SetLocalOrientation(*localOrientation); - } - - if (localScale != nullptr) - { - transform->SetLocalScale(*localScale); - } + if (localOrientation != nullptr) + { + transform->SetLocalOrientation(*localOrientation); + } - if (parent != nullptr) - { - transform->SetParent(parent, false); - } + if (localScale != nullptr) + { + transform->SetLocalScale(*localScale); } - transform->UpdateCachedWorldMatrix(); + if (parent != nullptr) + { + transform->SetParent(parent, false); + } } // We wait with calling BeginPlay until all the diff --git a/Source/World/World.cpp b/Source/World/World.cpp index 4aba05cb..fdc159c5 100644 --- a/Source/World/World.cpp +++ b/Source/World/World.cpp @@ -99,6 +99,9 @@ void CE::World::Tick(const float unscaledDeltaTime) void CE::World::Render(FrameBuffer* renderTarget) { + mViewport->UpdateSize(renderTarget == nullptr ? Device::Get().GetDisplaySize() : renderTarget->mSize); + mRegistry->RenderSystems(*mRenderCommandQueue); + const entt::entity cameraEntity = CameraComponent::GetSelected(*this); if (cameraEntity == entt::null) @@ -109,9 +112,6 @@ void CE::World::Render(FrameBuffer* renderTarget) const CameraComponent& camera = mRegistry->Get(cameraEntity); Renderer::Get().SetRenderTarget(*mRenderCommandQueue, camera.mView, camera.mProjection, renderTarget); - mViewport->UpdateSize(renderTarget == nullptr ? Device::Get().GetDisplaySize() : renderTarget->mSize); - - mRegistry->RenderSystems(*mRenderCommandQueue); } void CE::World::BeginPlay()