Added index iterators

Former-commit-id: de3ed77ba9e3c48aa68020e23ded679066b9878f
This commit is contained in:
Lynix 2013-06-05 15:33:43 +02:00
parent fbc0d7404e
commit 146ca80a63
7 changed files with 297 additions and 67 deletions

View File

@ -12,6 +12,7 @@
#include <Nazara/Math/Matrix4.hpp> #include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector2.hpp> #include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp> #include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/IndexIterator.hpp>
#include <Nazara/Utility/Mesh.hpp> #include <Nazara/Utility/Mesh.hpp>
NAZARA_API void NzComputeBoxIndexVertexCount(const NzVector3ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount); NAZARA_API void NzComputeBoxIndexVertexCount(const NzVector3ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount);
@ -20,12 +21,11 @@ NAZARA_API void NzComputeIcoSphereIndexVertexCount(unsigned int recursionLevel,
NAZARA_API void NzComputePlaneIndexVertexCount(const NzVector2ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount); NAZARA_API void NzComputePlaneIndexVertexCount(const NzVector2ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount);
NAZARA_API void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int stackCount, unsigned int* indexCount, unsigned int* vertexCount); NAZARA_API void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int stackCount, unsigned int* indexCount, unsigned int* vertexCount);
///TODO: Itérateur sur les indices NAZARA_API void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
NAZARA_API void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); NAZARA_API void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
NAZARA_API void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); NAZARA_API void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
NAZARA_API void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); NAZARA_API void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position, const NzVector3f& normal, const NzVector2f& size, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
NAZARA_API void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position, const NzVector3f& normal, const NzVector2f& size, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0); NAZARA_API void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
NAZARA_API void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
inline void NzTransformVertex(NzMeshVertex* vertex, const NzMatrix4f& matrix); inline void NzTransformVertex(NzMeshVertex* vertex, const NzMatrix4f& matrix);
inline void NzTransformVertices(NzMeshVertex* vertices, unsigned int vertexCount, const NzMatrix4f& matrix); inline void NzTransformVertices(NzMeshVertex* vertices, unsigned int vertexCount, const NzMatrix4f& matrix);

View File

@ -0,0 +1,79 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_INDEXITERATOR_HPP
#define NAZARA_INDEXITERATOR_HPP
#include <Nazara/Prerequesites.hpp>
class NzIndexMapper;
class NzIndexIterator
{
friend NzIndexMapper;
public:
class Reference;
NzIndexIterator();
NzIndexIterator(const NzIndexIterator& iterator);
~NzIndexIterator() = default;
Reference operator*() const;
Reference operator[](unsigned int index) const;
NzIndexIterator& operator=(const NzIndexIterator& iterator);
NzIndexIterator operator+(unsigned int indexCount);
NzIndexIterator operator-(unsigned int indexCount);
NzIndexIterator& operator+=(unsigned int indexCount);
NzIndexIterator& operator-=(unsigned int indexCount);
NzIndexIterator& operator++();
NzIndexIterator operator++(int);
NzIndexIterator& operator--();
NzIndexIterator operator--(int);
friend bool operator==(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
friend bool operator!=(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
friend bool operator<(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
friend bool operator<=(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
friend bool operator>(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
friend bool operator>=(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
private:
NzIndexIterator(NzIndexMapper* mapper, unsigned int index);
NzIndexMapper* m_mapper;
unsigned int m_index;
};
class NzIndexIterator::Reference
{
friend NzIndexIterator;
public:
Reference(const Reference& reference) = default;
~Reference() = default;
Reference& operator=(nzUInt32 value);
Reference& operator=(const Reference& reference);
operator nzUInt32() const;
private:
Reference(NzIndexMapper* mapper, unsigned int index);
NzIndexMapper* m_mapper;
unsigned int m_index;
};
#include <Nazara/Utility/IndexIterator.inl>
#endif // NAZARA_INDEXITERATOR_HPP

View File

@ -0,0 +1,158 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/IndexMapper.hpp>
#include <Nazara/Utility/Debug.hpp>
inline NzIndexIterator::NzIndexIterator() :
m_mapper(nullptr),
m_index(0)
{
}
inline NzIndexIterator::NzIndexIterator(const NzIndexIterator& iterator) :
m_mapper(iterator.m_mapper),
m_index(iterator.m_index)
{
}
inline NzIndexIterator::NzIndexIterator(NzIndexMapper* mapper, unsigned int index) :
m_mapper(mapper),
m_index(index)
{
}
inline NzIndexIterator::Reference NzIndexIterator::operator*() const
{
return Reference(m_mapper, m_index);
}
inline NzIndexIterator::Reference NzIndexIterator::operator[](unsigned int index) const
{
return Reference(m_mapper, m_index+index);
}
inline NzIndexIterator& NzIndexIterator::operator=(const NzIndexIterator& iterator)
{
m_mapper = iterator.m_mapper;
m_index = iterator.m_index;
return *this;
}
inline NzIndexIterator NzIndexIterator::operator+(unsigned int indexCount)
{
return NzIndexIterator(m_mapper, m_index + indexCount);
}
inline NzIndexIterator NzIndexIterator::operator-(unsigned int indexCount)
{
return NzIndexIterator(m_mapper, m_index - indexCount);
}
inline NzIndexIterator& NzIndexIterator::operator+=(unsigned int indexCount)
{
m_index += indexCount;
return *this;
}
inline NzIndexIterator& NzIndexIterator::operator-=(unsigned int indexCount)
{
m_index += indexCount;
return *this;
}
inline NzIndexIterator& NzIndexIterator::operator++()
{
m_index++;
return *this;
}
inline NzIndexIterator NzIndexIterator::operator++(int)
{
NzIndexIterator iterator(*this);
operator++();
return iterator;
}
inline NzIndexIterator& NzIndexIterator::operator--()
{
m_index--;
return *this;
}
inline NzIndexIterator NzIndexIterator::operator--(int)
{
NzIndexIterator iterator(*this);
operator--();
return iterator;
}
inline bool operator==(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
{
return lhs.m_mapper == rhs.m_mapper && lhs.m_index == rhs.m_index;
}
inline bool operator!=(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
{
return !operator==(lhs, rhs);
}
inline bool operator<(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
{
if (lhs.m_mapper == rhs.m_mapper)
return lhs.m_index < rhs.m_index;
else
return lhs.m_mapper < rhs.m_mapper;
}
inline bool operator<=(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
{
return !operator<(rhs, lhs);
}
inline bool operator>(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
{
return operator<(rhs, lhs);
}
inline bool operator>=(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
{
return !operator<(lhs, rhs);
}
/**************************NzIndexIterator::Reference*************************/
inline NzIndexIterator::Reference::Reference(NzIndexMapper* mapper, unsigned int index) :
m_mapper(mapper),
m_index(index)
{
}
inline NzIndexIterator::Reference& NzIndexIterator::Reference::operator=(nzUInt32 value)
{
m_mapper->Set(m_index, value);
return *this;
}
inline NzIndexIterator::Reference& NzIndexIterator::Reference::operator=(const NzIndexIterator::Reference& reference)
{
m_mapper->Set(m_index, reference); // Conversion implicite en UInt32
return *this;
}
inline NzIndexIterator::Reference::operator nzUInt32() const
{
return m_mapper->Get(m_index);
}
#include <Nazara/Core/DebugOff.hpp>

View File

@ -11,6 +11,7 @@
#include <Nazara/Utility/BufferMapper.hpp> #include <Nazara/Utility/BufferMapper.hpp>
class NzIndexBuffer; class NzIndexBuffer;
class NzIndexIterator;
class NzSubMesh; class NzSubMesh;
using NzIndexMapperGetter = nzUInt32 (*)(const void* buffer, unsigned int i); using NzIndexMapperGetter = nzUInt32 (*)(const void* buffer, unsigned int i);
@ -26,15 +27,24 @@ class NAZARA_API NzIndexMapper
nzUInt32 Get(unsigned int i) const; nzUInt32 Get(unsigned int i) const;
const NzIndexBuffer* GetBuffer() const; const NzIndexBuffer* GetBuffer() const;
unsigned int GetIndexCount() const;
void Set(unsigned int i, nzUInt32 value); void Set(unsigned int i, nzUInt32 value);
void Unmap(); void Unmap();
// Méthodes STD
NzIndexIterator begin();
//NzIndexConstIterator begin() const;
NzIndexIterator end();
//NzIndexIterator end() const;
// Méthodes STD
private: private:
NzBufferMapper<NzIndexBuffer> m_mapper; NzBufferMapper<NzIndexBuffer> m_mapper;
NzIndexMapperGetter m_getter; NzIndexMapperGetter m_getter;
NzIndexMapperSetter m_setter; NzIndexMapperSetter m_setter;
unsigned int m_indexCount;
}; };
#endif // NAZARA_INDEXMAPPER_HPP #endif // NAZARA_INDEXMAPPER_HPP

View File

@ -17,7 +17,7 @@ namespace
{ {
} }
void Generate(float size, unsigned int recursionLevel, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) void Generate(float size, unsigned int recursionLevel, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
{ {
// Grandement inspiré de http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html // Grandement inspiré de http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html
const float t = (1.f + 2.236067f)/2.f; const float t = (1.f + 2.236067f)/2.f;
@ -202,7 +202,7 @@ void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int sta
*vertexCount = sliceCount * stackCount; *vertexCount = sliceCount * stackCount;
} }
void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
{ {
unsigned int xIndexCount, yIndexCount, zIndexCount; unsigned int xIndexCount, yIndexCount, zIndexCount;
unsigned int xVertexCount, yVertexCount, zVertexCount; unsigned int xVertexCount, yVertexCount, zVertexCount;
@ -258,7 +258,7 @@ void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, co
} }
} }
void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
{ {
unsigned int vertexCount; unsigned int vertexCount;
NzComputeBoxIndexVertexCount(NzVector3ui(subdivision), nullptr, &vertexCount); NzComputeBoxIndexVertexCount(NzVector3ui(subdivision), nullptr, &vertexCount);
@ -281,13 +281,13 @@ void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4
} }
} }
void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
{ {
IcoSphereBuilder builder(matrix); IcoSphereBuilder builder(matrix);
builder.Generate(size, recursionLevel, vertices, indices, aabb, indexOffset); builder.Generate(size, recursionLevel, vertices, indices, aabb, indexOffset);
} }
void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position, const NzVector3f& normal, const NzVector2f& size, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position, const NzVector3f& normal, const NzVector2f& size, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
{ {
// Le nombre de faces appartenant à un axe est équivalent à 2 exposant la subdivision (1,2,4,8,16,32,...) // Le nombre de faces appartenant à un axe est équivalent à 2 exposant la subdivision (1,2,4,8,16,32,...)
unsigned int horizontalFaceCount = (1 << subdivision.x); unsigned int horizontalFaceCount = (1 << subdivision.x);
@ -344,7 +344,7 @@ void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position,
aabb->Set(rotation * NzVector3f(-halfSizeX, 0.f, -halfSizeY), rotation * NzVector3f(halfSizeX, 0.f, halfSizeY)); aabb->Set(rotation * NzVector3f(-halfSizeX, 0.f, -halfSizeY), rotation * NzVector3f(halfSizeX, 0.f, halfSizeY));
} }
void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb, unsigned int indexOffset) void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
{ {
// http://stackoverflow.com/questions/14080932/implementing-opengl-sphere-example-code // http://stackoverflow.com/questions/14080932/implementing-opengl-sphere-example-code
float invSliceCount = 1.f / (sliceCount-1); float invSliceCount = 1.f / (sliceCount-1);

View File

@ -4,6 +4,7 @@
#include <Nazara/Utility/IndexMapper.hpp> #include <Nazara/Utility/IndexMapper.hpp>
#include <Nazara/Utility/IndexBuffer.hpp> #include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/IndexIterator.hpp>
#include <Nazara/Utility/SubMesh.hpp> #include <Nazara/Utility/SubMesh.hpp>
#include <Nazara/Utility/Debug.hpp> #include <Nazara/Utility/Debug.hpp>
@ -101,6 +102,14 @@ NzIndexMapper(subMesh->GetIndexBuffer())
nzUInt32 NzIndexMapper::Get(unsigned int i) const nzUInt32 NzIndexMapper::Get(unsigned int i) const
{ {
#if NAZARA_UTILITY_SAFE
if (i >= m_indexCount)
{
NazaraError("Index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_indexCount) + ')');
return 0;
}
#endif
return m_getter(m_mapper.GetPointer(), i); return m_getter(m_mapper.GetPointer(), i);
} }
@ -109,8 +118,21 @@ const NzIndexBuffer* NzIndexMapper::GetBuffer() const
return m_mapper.GetBuffer(); return m_mapper.GetBuffer();
} }
unsigned int NzIndexMapper::GetIndexCount() const
{
return m_indexCount;
}
void NzIndexMapper::Set(unsigned int i, nzUInt32 value) void NzIndexMapper::Set(unsigned int i, nzUInt32 value)
{ {
#if NAZARA_UTILITY_SAFE
if (i >= m_indexCount)
{
NazaraError("Index out of range (" + NzString::Number(i) + " >= " + NzString::Number(m_indexCount) + ')');
return;
}
#endif
m_setter(m_mapper.GetPointer(), i, value); m_setter(m_mapper.GetPointer(), i, value);
} }
@ -118,3 +140,13 @@ void NzIndexMapper::Unmap()
{ {
m_mapper.Unmap(); m_mapper.Unmap();
} }
NzIndexIterator NzIndexMapper::begin()
{
return NzIndexIterator(this, 0);
}
NzIndexIterator NzIndexMapper::end()
{
return NzIndexIterator(this, m_indexCount); // Post-end
}

View File

@ -188,20 +188,10 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params)
vertexBuffer.reset(new NzVertexBuffer(GetDeclaration(), vertexCount, params.storage, nzBufferUsage_Static)); vertexBuffer.reset(new NzVertexBuffer(GetDeclaration(), vertexCount, params.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false); vertexBuffer->SetPersistent(false);
///TODO: Remplacer par un itérateur sur les indices
std::vector<nzUInt32> indices;
indices.resize(indexCount);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly); NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzGenerateBox(primitive.box.lengths, primitive.box.subdivision, primitive.box.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), &indices[0], &aabb);
vertexMapper.Unmap();
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly); NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
for (unsigned int i = 0; i < indexCount; ++i) NzGenerateBox(primitive.box.lengths, primitive.box.subdivision, primitive.box.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
indexMapper.Set(i, indices[i]);
indexMapper.Unmap();
break; break;
} }
@ -217,20 +207,10 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params)
vertexBuffer.reset(new NzVertexBuffer(GetDeclaration(), vertexCount, params.storage, nzBufferUsage_Static)); vertexBuffer.reset(new NzVertexBuffer(GetDeclaration(), vertexCount, params.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false); vertexBuffer->SetPersistent(false);
///TODO: Remplacer par un itérateur sur les indices
std::vector<nzUInt32> indices;
indices.resize(indexCount);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly); NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzGeneratePlane(primitive.plane.subdivision, primitive.plane.position, primitive.plane.normal, primitive.plane.size, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), &indices[0], &aabb);
vertexMapper.Unmap();
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly); NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
for (unsigned int i = 0; i < indexCount; ++i) NzGeneratePlane(primitive.plane.subdivision, primitive.plane.position, primitive.plane.normal, primitive.plane.size, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
indexMapper.Set(i, indices[i]);
indexMapper.Unmap();
break; break;
} }
@ -250,20 +230,10 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params)
vertexBuffer.reset(new NzVertexBuffer(GetDeclaration(), vertexCount, params.storage, nzBufferUsage_Static)); vertexBuffer.reset(new NzVertexBuffer(GetDeclaration(), vertexCount, params.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false); vertexBuffer->SetPersistent(false);
///TODO: Remplacer par un itérateur sur les indices
std::vector<nzUInt32> indices;
indices.resize(indexCount);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly); NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzGenerateCubicSphere(primitive.sphere.size, primitive.sphere.cubic.subdivision, primitive.sphere.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), &indices[0], &aabb);
vertexMapper.Unmap();
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly); NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
for (unsigned int i = 0; i < indexCount; ++i) NzGenerateCubicSphere(primitive.sphere.size, primitive.sphere.cubic.subdivision, primitive.sphere.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
indexMapper.Set(i, indices[i]);
indexMapper.Unmap();
break; break;
} }
@ -279,20 +249,10 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params)
vertexBuffer.reset(new NzVertexBuffer(GetDeclaration(), vertexCount, params.storage, nzBufferUsage_Static)); vertexBuffer.reset(new NzVertexBuffer(GetDeclaration(), vertexCount, params.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false); vertexBuffer->SetPersistent(false);
///TODO: Remplacer par un itérateur sur les indices
std::vector<nzUInt32> indices;
indices.resize(indexCount);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly); NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzGenerateIcoSphere(primitive.sphere.size, primitive.sphere.ico.recursionLevel, primitive.sphere.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), &indices[0], &aabb);
vertexMapper.Unmap();
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly); NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
for (unsigned int i = 0; i < indexCount; ++i) NzGenerateIcoSphere(primitive.sphere.size, primitive.sphere.ico.recursionLevel, primitive.sphere.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
indexMapper.Set(i, indices[i]);
indexMapper.Unmap();
break; break;
} }
@ -308,20 +268,11 @@ void NzMesh::Build(const NzPrimitiveList& list, const NzMeshParams& params)
vertexBuffer.reset(new NzVertexBuffer(GetDeclaration(), vertexCount, params.storage, nzBufferUsage_Static)); vertexBuffer.reset(new NzVertexBuffer(GetDeclaration(), vertexCount, params.storage, nzBufferUsage_Static));
vertexBuffer->SetPersistent(false); vertexBuffer->SetPersistent(false);
///TODO: Remplacer par un itérateur sur les indices
std::vector<nzUInt32> indices;
indices.resize(indexCount);
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly); NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
NzGenerateUvSphere(primitive.sphere.size, primitive.sphere.uv.slices, primitive.sphere.uv.stacks, primitive.sphere.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), &indices[0], &aabb);
vertexMapper.Unmap();
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly); NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
for (unsigned int i = 0; i < indexCount; ++i) NzGenerateUvSphere(primitive.sphere.size, primitive.sphere.uv.slices, primitive.sphere.uv.stacks, primitive.sphere.matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
indexMapper.Set(i, indices[i]); break;
indexMapper.Unmap();
} }
} }
break; break;