mirror of
https://github.com/minetest/minetest.git
synced 2024-07-04 15:05:27 +02:00
Move data directly rather than copying
This commit is contained in:
parent
818ac9ea3d
commit
b734119d05
@ -199,6 +199,9 @@ class ISkinnedMesh : public IAnimatedMesh
|
|||||||
//! Adds a new meshbuffer to the mesh, access it as last one
|
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||||
virtual SSkinMeshBuffer *addMeshBuffer() = 0;
|
virtual SSkinMeshBuffer *addMeshBuffer() = 0;
|
||||||
|
|
||||||
|
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||||
|
virtual void addMeshBuffer(SSkinMeshBuffer &&meshbuf) = 0;
|
||||||
|
|
||||||
//! Adds a new joint to the mesh, access it as last one
|
//! Adds a new joint to the mesh, access it as last one
|
||||||
virtual SJoint *addJoint(SJoint *parent = 0) = 0;
|
virtual SJoint *addJoint(SJoint *parent = 0) = 0;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "IMeshBuffer.h"
|
#include "IMeshBuffer.h"
|
||||||
#include "S3DVertex.h"
|
#include "S3DVertex.h"
|
||||||
|
#include "irrArray.h"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@ -24,10 +25,14 @@ struct SSkinMeshBuffer : public IMeshBuffer
|
|||||||
MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER),
|
MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER),
|
||||||
HWBuffer(NULL),
|
HWBuffer(NULL),
|
||||||
BoundingBoxNeedsRecalculated(true)
|
BoundingBoxNeedsRecalculated(true)
|
||||||
|
{}
|
||||||
|
|
||||||
|
//! Constructor for standard vertices
|
||||||
|
SSkinMeshBuffer(core::array<video::S3DVertex> &&vertices, core::array<u16> &&indices) :
|
||||||
|
SSkinMeshBuffer()
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
Vertices_Standard = vertices;
|
||||||
setDebugName("SSkinMeshBuffer");
|
Indices = indices;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Get Material of this buffer.
|
//! Get Material of this buffer.
|
||||||
@ -303,26 +308,7 @@ struct SSkinMeshBuffer : public IMeshBuffer
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! append the vertices and indices to the current buffer
|
//! append the vertices and indices to the current buffer
|
||||||
void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) override {
|
void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) override {}
|
||||||
if (vertices == getVertices())
|
|
||||||
throw std::logic_error("can't append own vertices");
|
|
||||||
|
|
||||||
if (VertexType != video::EVT_STANDARD)
|
|
||||||
throw std::logic_error("invalid vertex type");
|
|
||||||
|
|
||||||
const u32 prevVertexCount = getVertexCount();
|
|
||||||
|
|
||||||
Vertices_Standard.reallocate(prevVertexCount + numVertices);
|
|
||||||
for (u32 i=0; i < numVertices; ++i) {
|
|
||||||
Vertices_Standard.push_back(static_cast<const video::S3DVertex* const>(vertices)[i]);
|
|
||||||
BoundingBox.addInternalPoint(static_cast<const video::S3DVertex* const>(vertices)[i].Pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
Indices.reallocate(getIndexCount() + numIndices);
|
|
||||||
for (u32 i=0; i < numIndices; ++i) {
|
|
||||||
Indices.push_back(indices[i] + prevVertexCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//! get the current hardware mapping hint for vertex buffers
|
//! get the current hardware mapping hint for vertex buffers
|
||||||
E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const override
|
E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const override
|
||||||
|
@ -45,6 +45,9 @@ class array
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Move constructor
|
||||||
|
array(std::vector<T> &&data) : m_data(data), is_sorted(false) {}
|
||||||
|
|
||||||
//! Reallocates the array, make it bigger or smaller.
|
//! Reallocates the array, make it bigger or smaller.
|
||||||
/** \param new_size New size of array.
|
/** \param new_size New size of array.
|
||||||
\param canShrink Specifies whether the array is reallocated even if
|
\param canShrink Specifies whether the array is reallocated even if
|
||||||
|
@ -429,9 +429,8 @@ void CGLTFMeshFileLoader::MeshExtractor::loadMesh(
|
|||||||
indices = generateIndices(vertices->size());
|
indices = generateIndices(vertices->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto *meshbuf = m_irr_model->addMeshBuffer();
|
m_irr_model->addMeshBuffer(
|
||||||
meshbuf->append(vertices->data(), vertices->size(),
|
SSkinMeshBuffer(std::move(*vertices), std::move(indices)));
|
||||||
indices.data(), indices.size());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -686,7 +685,7 @@ std::optional<tiniergltf::GlTF> CGLTFMeshFileLoader::tryParseGLTF(io::IReadFile*
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return tiniergltf::GlTF(json);
|
return tiniergltf::GlTF(json);
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
} catch (const std::out_of_range &e) {
|
} catch (const std::out_of_range &e) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include "CBoneSceneNode.h"
|
#include "CBoneSceneNode.h"
|
||||||
#include "IAnimatedMeshSceneNode.h"
|
#include "IAnimatedMeshSceneNode.h"
|
||||||
|
#include "SSkinMeshBuffer.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -1061,6 +1062,11 @@ scene::SSkinMeshBuffer *CSkinnedMesh::addMeshBuffer()
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSkinnedMesh::addMeshBuffer(SSkinMeshBuffer &&meshbuf)
|
||||||
|
{
|
||||||
|
LocalBuffers.push_back(new SSkinMeshBuffer(std::move(meshbuf)));
|
||||||
|
}
|
||||||
|
|
||||||
CSkinnedMesh::SJoint *CSkinnedMesh::addJoint(SJoint *parent)
|
CSkinnedMesh::SJoint *CSkinnedMesh::addJoint(SJoint *parent)
|
||||||
{
|
{
|
||||||
SJoint *joint = new SJoint;
|
SJoint *joint = new SJoint;
|
||||||
|
@ -129,6 +129,9 @@ class CSkinnedMesh : public ISkinnedMesh
|
|||||||
//! Adds a new meshbuffer to the mesh, access it as last one
|
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||||
SSkinMeshBuffer *addMeshBuffer() override;
|
SSkinMeshBuffer *addMeshBuffer() override;
|
||||||
|
|
||||||
|
//! Adds a new meshbuffer to the mesh, access it as last one
|
||||||
|
void addMeshBuffer(SSkinMeshBuffer &&meshbuf) override;
|
||||||
|
|
||||||
//! Adds a new joint to the mesh, access it as last one
|
//! Adds a new joint to the mesh, access it as last one
|
||||||
SJoint *addJoint(SJoint *parent = 0) override;
|
SJoint *addJoint(SJoint *parent = 0) override;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user