2024-03-21 20:13:15 +01:00
|
|
|
// Copyright (C) 2002-2012 Nikolaus Gebhardt
|
|
|
|
// This file is part of the "Irrlicht Engine".
|
|
|
|
// For conditions of distribution and use, see copyright notice in irrlicht.h
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-08-17 19:49:11 +02:00
|
|
|
#include <vector>
|
2024-03-21 20:13:15 +01:00
|
|
|
#include "IMesh.h"
|
|
|
|
#include "IMeshBuffer.h"
|
|
|
|
#include "aabbox3d.h"
|
|
|
|
|
|
|
|
namespace irr
|
|
|
|
{
|
|
|
|
namespace scene
|
|
|
|
{
|
|
|
|
//! Simple implementation of the IMesh interface.
|
|
|
|
struct SMesh : public IMesh
|
|
|
|
{
|
|
|
|
//! constructor
|
|
|
|
SMesh()
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
setDebugName("SMesh");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//! destructor
|
|
|
|
virtual ~SMesh()
|
|
|
|
{
|
|
|
|
// drop buffers
|
2024-08-17 19:49:11 +02:00
|
|
|
for (auto *buf : MeshBuffers)
|
|
|
|
buf->drop();
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! clean mesh
|
|
|
|
virtual void clear()
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
for (auto *buf : MeshBuffers)
|
|
|
|
buf->drop();
|
2024-03-21 20:13:15 +01:00
|
|
|
MeshBuffers.clear();
|
|
|
|
BoundingBox.reset(0.f, 0.f, 0.f);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! returns amount of mesh buffers.
|
|
|
|
u32 getMeshBufferCount() const override
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
return static_cast<u32>(MeshBuffers.size());
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! returns pointer to a mesh buffer
|
|
|
|
IMeshBuffer *getMeshBuffer(u32 nr) const override
|
|
|
|
{
|
|
|
|
return MeshBuffers[nr];
|
|
|
|
}
|
|
|
|
|
|
|
|
//! returns a meshbuffer which fits a material
|
|
|
|
/** reverse search */
|
|
|
|
IMeshBuffer *getMeshBuffer(const video::SMaterial &material) const override
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
for (auto it = MeshBuffers.rbegin(); it != MeshBuffers.rend(); it++) {
|
|
|
|
if (material == (*it)->getMaterial())
|
|
|
|
return *it;
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
2024-08-17 19:49:11 +02:00
|
|
|
return nullptr;
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
|
|
|
|
2024-09-02 14:50:30 +02:00
|
|
|
u32 getTextureSlot(u32 meshbufNr) const override
|
|
|
|
{
|
|
|
|
return TextureSlots.at(meshbufNr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTextureSlot(u32 meshbufNr, u32 textureSlot)
|
|
|
|
{
|
|
|
|
TextureSlots.at(meshbufNr) = textureSlot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-21 20:13:15 +01:00
|
|
|
//! returns an axis aligned bounding box
|
|
|
|
const core::aabbox3d<f32> &getBoundingBox() const override
|
|
|
|
{
|
|
|
|
return BoundingBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! set user axis aligned bounding box
|
|
|
|
void setBoundingBox(const core::aabbox3df &box) override
|
|
|
|
{
|
|
|
|
BoundingBox = box;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! recalculates the bounding box
|
|
|
|
void recalculateBoundingBox()
|
|
|
|
{
|
|
|
|
bool hasMeshBufferBBox = false;
|
2024-08-17 19:49:11 +02:00
|
|
|
for (auto *buf : MeshBuffers) {
|
|
|
|
const core::aabbox3df &bb = buf->getBoundingBox();
|
2024-03-21 20:13:15 +01:00
|
|
|
if (!bb.isEmpty()) {
|
|
|
|
if (!hasMeshBufferBBox) {
|
|
|
|
hasMeshBufferBBox = true;
|
|
|
|
BoundingBox = bb;
|
|
|
|
} else {
|
|
|
|
BoundingBox.addInternalBox(bb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasMeshBufferBBox)
|
|
|
|
BoundingBox.reset(0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
//! adds a MeshBuffer
|
|
|
|
/** The bounding box is not updated automatically. */
|
|
|
|
void addMeshBuffer(IMeshBuffer *buf)
|
|
|
|
{
|
|
|
|
if (buf) {
|
|
|
|
buf->grab();
|
|
|
|
MeshBuffers.push_back(buf);
|
2024-09-02 14:50:30 +02:00
|
|
|
TextureSlots.push_back(getMeshBufferCount() - 1);
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! set the hardware mapping hint, for driver
|
|
|
|
void setHardwareMappingHint(E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) override
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
for (auto *buf : MeshBuffers)
|
|
|
|
buf->setHardwareMappingHint(newMappingHint, buffer);
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! flags the meshbuffer as changed, reloads hardware buffers
|
|
|
|
void setDirty(E_BUFFER_TYPE buffer = EBT_VERTEX_AND_INDEX) override
|
|
|
|
{
|
2024-08-17 19:49:11 +02:00
|
|
|
for (auto *buf : MeshBuffers)
|
|
|
|
buf->setDirty(buffer);
|
2024-03-21 20:13:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//! The meshbuffers of this mesh
|
2024-08-17 19:49:11 +02:00
|
|
|
std::vector<IMeshBuffer *> MeshBuffers;
|
2024-09-02 14:50:30 +02:00
|
|
|
//! Mapping from meshbuffer number to bindable texture slot
|
|
|
|
std::vector<u32> TextureSlots;
|
2024-03-21 20:13:15 +01:00
|
|
|
|
|
|
|
//! The bounding box of this mesh
|
|
|
|
core::aabbox3d<f32> BoundingBox;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace scene
|
|
|
|
} // end namespace irr
|