// Copyright (C) 2020 Jérôme Leclercq // This file is part of the "Nazara Engine - Graphics module" // For conditions of distribution and use, see copyright notice in Config.hpp #pragma once #ifndef NAZARA_MODEL_HPP #define NAZARA_MODEL_HPP #include #include #include #include #include #include #include #include #include #include namespace Nz { struct NAZARA_GRAPHICS_API ModelParameters : ResourceParameters { ModelParameters(); bool loadMaterials = true; MaterialParams material; MeshParams mesh; bool IsValid() const; }; class Model; using ModelConstRef = ObjectRef; using ModelLibrary = ObjectLibrary; using ModelLoader = ResourceLoader; using ModelManager = ResourceManager; using ModelRef = ObjectRef; using ModelSaver = ResourceSaver; class NAZARA_GRAPHICS_API Model : public InstancedRenderable, public Resource { friend ModelLibrary; friend ModelLoader; friend ModelManager; friend ModelSaver; public: inline Model(); Model(const Model& model); Model(Model&& model) = delete; virtual ~Model(); void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData, const Recti& scissorRect) const override; inline void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, int renderOrder = 0, const Recti& scissorRect = Recti(-1, -1, -1, -1)) const; std::unique_ptr Clone() const override; using InstancedRenderable::GetMaterial; const MaterialRef& GetMaterial(const std::string& subMeshName) const; const MaterialRef& GetMaterial(std::size_t skinIndex, const std::string& subMeshName) const; Mesh* GetMesh() const; virtual bool IsAnimated() const; using InstancedRenderable::SetMaterial; bool SetMaterial(const std::string& subMeshName, MaterialRef material); bool SetMaterial(std::size_t skinIndex, const std::string& subMeshName, MaterialRef material); virtual void SetMesh(Mesh* mesh); Model& operator=(const Model& node) = default; Model& operator=(Model&& node) = delete; static ModelRef LoadFromFile(const std::filesystem::path& filePath, const ModelParameters& params = ModelParameters()); static ModelRef LoadFromMemory(const void* data, std::size_t size, const ModelParameters& params = ModelParameters()); static ModelRef LoadFromStream(Stream& stream, const ModelParameters& params = ModelParameters()); template static ModelRef New(Args&&... args); protected: void MakeBoundingVolume() const override; MeshRef m_mesh; NazaraSlot(Mesh, OnMeshInvalidateAABB, m_meshAABBInvalidationSlot); static ModelLibrary::LibraryMap s_library; static ModelLoader::LoaderList s_loaders; static ModelManager::ManagerMap s_managerMap; static ModelManager::ManagerParams s_managerParameters; static ModelSaver::SaverList s_savers; }; } #include #endif // NAZARA_MODEL_HPP