Graphics/GraphicalMesh: Add AABB
This commit is contained in:
parent
a96722d4ec
commit
55f2937678
|
|
@ -226,11 +226,11 @@ int main()
|
|||
std::shared_ptr<Nz::MaterialInstance> planeMat = deferredMaterial->Instantiate();
|
||||
planeMat->SetTextureProperty("BaseColorMap", Nz::Texture::LoadFromFile(resourceDir / "dev_grey.png", texParams), planeSampler);
|
||||
|
||||
Nz::Model spaceshipModel(std::move(gfxMesh), spaceship->GetAABB());
|
||||
Nz::Model spaceshipModel(std::move(gfxMesh));
|
||||
for (std::size_t i = 0; i < spaceshipModel.GetSubMeshCount(); ++i)
|
||||
spaceshipModel.SetMaterial(i, spaceshipMat);
|
||||
|
||||
Nz::Model planeModel(std::move(planeMeshGfx), planeMesh->GetAABB());
|
||||
Nz::Model planeModel(std::move(planeMeshGfx));
|
||||
for (std::size_t i = 0; i < planeModel.GetSubMeshCount(); ++i)
|
||||
planeModel.SetMaterial(i, planeMat);
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ int main()
|
|||
std::size_t normalMapProperty = materialInstance->FindTextureProperty("NormalMap");
|
||||
materialInstance->SetTextureProperty(normalMapProperty, normalMap);
|
||||
|
||||
Nz::Model model(std::move(gfxMesh), sphereMesh->GetAABB());
|
||||
Nz::Model model(std::move(gfxMesh));
|
||||
for (std::size_t i = 0; i < model.GetSubMeshCount(); ++i)
|
||||
model.SetMaterial(i, materialInstance);
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ int main()
|
|||
material->SetTextureProperty("AlphaMap", Nz::Texture::LoadFromFile(resourceDir / "alphatile.png", texParams));
|
||||
material->SetTextureProperty("BaseColorMap", Nz::Texture::LoadFromFile(resourceDir / "Spaceship/Texture/diffuse.png", texParams));
|
||||
|
||||
std::shared_ptr<Nz::Model> model = std::make_shared<Nz::Model>(std::move(gfxMesh), spaceshipAABB);
|
||||
std::shared_ptr<Nz::Model> model = std::make_shared<Nz::Model>(std::move(gfxMesh));
|
||||
for (std::size_t i = 0; i < model->GetSubMeshCount(); ++i)
|
||||
model->SetMaterial(i, material);
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ int main()
|
|||
std::shared_ptr<Nz::Mesh> colliderMesh = Nz::Mesh::Build(shipCollider->GenerateMesh());
|
||||
std::shared_ptr<Nz::GraphicalMesh> colliderGraphicalMesh = Nz::GraphicalMesh::BuildFromMesh(*colliderMesh);
|
||||
|
||||
colliderModel = std::make_shared<Nz::Model>(colliderGraphicalMesh, spaceshipAABB);
|
||||
colliderModel = std::make_shared<Nz::Model>(colliderGraphicalMesh);
|
||||
for (std::size_t i = 0; i < colliderModel->GetSubMeshCount(); ++i)
|
||||
colliderModel->SetMaterial(i, colliderMat);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ int main()
|
|||
|
||||
//std::shared_ptr<Nz::Material> material = Nz::Graphics::Instance()->GetDefaultMaterials().basicTransparent;
|
||||
|
||||
std::shared_ptr<Nz::Model> bobModel = std::make_shared<Nz::Model>(std::move(bobGfxMesh), bobAABB);
|
||||
std::shared_ptr<Nz::Model> bobModel = std::make_shared<Nz::Model>(std::move(bobGfxMesh));
|
||||
std::vector<std::shared_ptr<Nz::MaterialInstance>> materials(bobMesh->GetMaterialCount());
|
||||
|
||||
std::bitset<5> alphaMaterials("01010");
|
||||
|
|
@ -212,7 +212,7 @@ int main()
|
|||
std::shared_ptr<Nz::MaterialInstance> sphereMat = Nz::Graphics::Instance()->GetDefaultMaterials().phongMaterial->Instantiate();
|
||||
sphereMat->SetTextureProperty("BaseColorMap", Nz::Texture::LoadFromFile(resourceDir / "Rusty/rustediron2_basecolor.png", srgbTexParams));
|
||||
|
||||
std::shared_ptr<Nz::Model> sphereModel = std::make_shared<Nz::Model>(std::move(gfxMesh), sphereMesh->GetAABB());
|
||||
std::shared_ptr<Nz::Model> sphereModel = std::make_shared<Nz::Model>(std::move(gfxMesh));
|
||||
for (std::size_t i = 0; i < sphereModel->GetSubMeshCount(); ++i)
|
||||
sphereModel->SetMaterial(i, sphereMat);
|
||||
|
||||
|
|
@ -318,7 +318,7 @@ int main()
|
|||
|
||||
floorBox = planeMesh.GetAABB();
|
||||
|
||||
std::shared_ptr<Nz::Model> planeModel = std::make_shared<Nz::Model>(std::move(planeMeshGfx), planeMesh.GetAABB());
|
||||
std::shared_ptr<Nz::Model> planeModel = std::make_shared<Nz::Model>(std::move(planeMeshGfx));
|
||||
planeModel->SetMaterial(0, planeMat);
|
||||
|
||||
auto& planeGfx = planeEntity.emplace<Nz::GraphicsComponent>();
|
||||
|
|
@ -336,7 +336,7 @@ int main()
|
|||
|
||||
std::shared_ptr<Nz::GraphicalMesh> boxMeshGfx = Nz::GraphicalMesh::BuildFromMesh(boxMesh);
|
||||
|
||||
std::shared_ptr<Nz::Model> boxModel = std::make_shared<Nz::Model>(std::move(boxMeshGfx), boxMesh.GetAABB());
|
||||
std::shared_ptr<Nz::Model> boxModel = std::make_shared<Nz::Model>(std::move(boxMeshGfx));
|
||||
boxModel->SetMaterial(0, planeMat);
|
||||
|
||||
entt::handle boxEntity = world.CreateEntity();
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ namespace Nz
|
|||
|
||||
inline void Clear();
|
||||
|
||||
inline const Boxf& GetAABB() const;
|
||||
inline const std::shared_ptr<RenderBuffer>& GetIndexBuffer(std::size_t subMesh) const;
|
||||
inline UInt32 GetIndexCount(std::size_t subMesh) const;
|
||||
inline IndexType GetIndexType(std::size_t subMesh) const;
|
||||
|
|
@ -38,6 +39,7 @@ namespace Nz
|
|||
inline const std::shared_ptr<const VertexDeclaration>& GetVertexDeclaration(std::size_t subMesh) const;
|
||||
inline std::size_t GetSubMeshCount() const;
|
||||
|
||||
inline void UpdateAABB(const Boxf& aabb);
|
||||
inline void UpdateSubMeshIndexCount(std::size_t subMeshIndex, UInt32 indexCount);
|
||||
|
||||
GraphicalMesh& operator=(const GraphicalMesh&) = delete;
|
||||
|
|
@ -52,12 +54,15 @@ namespace Nz
|
|||
UInt32 indexCount;
|
||||
};
|
||||
|
||||
static inline std::shared_ptr<GraphicalMesh> Build(const Primitive& primitive, const MeshParams& params = MeshParams());
|
||||
static inline std::shared_ptr<GraphicalMesh> Build(const PrimitiveList& primitiveList, const MeshParams& params = MeshParams());
|
||||
static std::shared_ptr<GraphicalMesh> BuildFromMesh(const Mesh& mesh);
|
||||
|
||||
NazaraSignal(OnInvalidated, GraphicalMesh* /*gfxMesh*/);
|
||||
|
||||
private:
|
||||
std::vector<SubMesh> m_subMeshes;
|
||||
Boxf m_aabb;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ namespace Nz
|
|||
OnInvalidated(this);
|
||||
}
|
||||
|
||||
inline const Boxf& GraphicalMesh::GetAABB() const
|
||||
{
|
||||
return m_aabb;
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<RenderBuffer>& GraphicalMesh::GetIndexBuffer(std::size_t subMesh) const
|
||||
{
|
||||
assert(subMesh < m_subMeshes.size());
|
||||
|
|
@ -60,6 +65,13 @@ namespace Nz
|
|||
return m_subMeshes.size();
|
||||
}
|
||||
|
||||
inline void GraphicalMesh::UpdateAABB(const Boxf& aabb)
|
||||
{
|
||||
m_aabb = aabb;
|
||||
|
||||
OnInvalidated(this);
|
||||
}
|
||||
|
||||
inline void GraphicalMesh::UpdateSubMeshIndexCount(std::size_t subMeshIndex, UInt32 indexCount)
|
||||
{
|
||||
NazaraAssert(subMeshIndex < m_subMeshes.size(), "invalid submesh index");
|
||||
|
|
@ -67,6 +79,25 @@ namespace Nz
|
|||
|
||||
OnInvalidated(this);
|
||||
}
|
||||
|
||||
inline std::shared_ptr<GraphicalMesh> GraphicalMesh::Build(const Primitive& primitive, const MeshParams& params)
|
||||
{
|
||||
Mesh mesh;
|
||||
mesh.CreateStatic();
|
||||
mesh.BuildSubMesh(primitive, params);
|
||||
|
||||
return BuildFromMesh(mesh);
|
||||
}
|
||||
|
||||
inline std::shared_ptr<GraphicalMesh> GraphicalMesh::Build(const PrimitiveList& primitiveList, const MeshParams& params)
|
||||
{
|
||||
Mesh mesh;
|
||||
mesh.CreateStatic();
|
||||
mesh.BuildSubMeshes(primitiveList, params);
|
||||
|
||||
return BuildFromMesh(mesh);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include <Nazara/Graphics/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace Nz
|
|||
class NAZARA_GRAPHICS_API Model : public InstancedRenderable
|
||||
{
|
||||
public:
|
||||
Model(std::shared_ptr<GraphicalMesh> graphicalMesh, const Boxf& aabb);
|
||||
Model(std::shared_ptr<GraphicalMesh> graphicalMesh);
|
||||
Model(const Model&) = delete;
|
||||
Model(Model&&) noexcept = default;
|
||||
~Model() = default;
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ namespace Nz
|
|||
gfxMesh->AddSubMesh(std::move(submeshData));
|
||||
}
|
||||
|
||||
gfxMesh->UpdateAABB(mesh.GetAABB());
|
||||
|
||||
return gfxMesh;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
Model::Model(std::shared_ptr<GraphicalMesh> graphicalMesh, const Boxf& aabb) :
|
||||
Model::Model(std::shared_ptr<GraphicalMesh> graphicalMesh) :
|
||||
m_graphicalMesh(std::move(graphicalMesh))
|
||||
{
|
||||
Graphics* graphics = Graphics::Instance();
|
||||
|
|
@ -34,10 +34,11 @@ namespace Nz
|
|||
|
||||
m_onInvalidated.Connect(m_graphicalMesh->OnInvalidated, [this](GraphicalMesh*)
|
||||
{
|
||||
UpdateAABB(m_graphicalMesh->GetAABB());
|
||||
OnElementInvalidated(this);
|
||||
});
|
||||
|
||||
UpdateAABB(aabb);
|
||||
UpdateAABB(m_graphicalMesh->GetAABB());
|
||||
}
|
||||
|
||||
void Model::BuildElement(ElementRendererRegistry& registry, const ElementData& elementData, std::size_t passIndex, std::vector<RenderElementOwner>& elements) const
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ int main()
|
|||
std::shared_ptr<Nz::MaterialInstance> materialInstance2 = std::make_shared<Nz::MaterialInstance>(material);
|
||||
materialInstance2->SetValueProperty(0, Nz::Color::Green());
|
||||
|
||||
Nz::Model model(std::move(gfxMesh), spaceshipMesh->GetAABB());
|
||||
Nz::Model model(std::move(gfxMesh));
|
||||
for (std::size_t i = 0; i < model.GetSubMeshCount(); ++i)
|
||||
model.SetMaterial(i, materialInstance);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue