Working version of mesh decimation code which acts directly on vertex/index buffers.
Also initial work on a 'dynamic' mesh for simplification... but this probably won't be needed now.
This commit is contained in:
@ -64,7 +64,7 @@ namespace PolyVox
|
||||
void clear(void);
|
||||
const bool isEmpty(void) const;
|
||||
|
||||
void smoothPositions(float fAmount, bool bIncludeEdgeVertices = false);
|
||||
void smoothPositions(float fAmount, bool bIncludeGeometryEdgeVertices = false);
|
||||
void sumNearbyNormals(bool bNormaliseResult = true);
|
||||
|
||||
POLYVOX_SHARED_PTR<IndexedSurfacePatch> extractSubset(std::set<uint8_t> setMaterials);
|
||||
@ -76,6 +76,14 @@ namespace PolyVox
|
||||
/*void growMaterialBoundary(void);
|
||||
int countMaterialBoundary(void);*/
|
||||
|
||||
bool isSubset(std::bitset<4> a, std::bitset<4> b);
|
||||
|
||||
void decimate(float fMinDotProductForCollapse = 0.999f);
|
||||
|
||||
uint32_t performDecimationPass(float fMinDotProductForCollapse);
|
||||
int noOfDegenerateTris(void);
|
||||
void removeDegenerateTris(void);
|
||||
|
||||
void makeProgressiveMesh(void);
|
||||
|
||||
Region m_Region;
|
||||
|
61
library/PolyVoxCore/include/Mesh.h
Normal file
61
library/PolyVoxCore/include/Mesh.h
Normal file
@ -0,0 +1,61 @@
|
||||
#pragma region License
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2005-2009 David Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_Mesh_H__
|
||||
#define __PolyVox_Mesh_H__
|
||||
|
||||
#include "MeshEdge.h"
|
||||
#include "MeshFace.h"
|
||||
#include "MeshVertex.h"
|
||||
|
||||
#include "PolyVoxImpl/TypeDef.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class POLYVOXCORE_API Mesh
|
||||
{
|
||||
public:
|
||||
|
||||
void buildFromISP(IndexedSurfacePatch* pIsp);
|
||||
void fillISP(IndexedSurfacePatch* pIsp);
|
||||
void matchEdgePairs(void);
|
||||
void computeEdgeCosts(void);
|
||||
|
||||
void removeEdge(MeshEdge* pMeshEdge);
|
||||
|
||||
void decimateAll(void);
|
||||
bool decimateOne(void);
|
||||
|
||||
bool isSane(void);
|
||||
|
||||
std::set<MeshEdge*> m_edges;
|
||||
std::set<MeshFace*> m_faces;
|
||||
std::set<MeshVertex*> m_vertices;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
61
library/PolyVoxCore/include/MeshEdge.h
Normal file
61
library/PolyVoxCore/include/MeshEdge.h
Normal file
@ -0,0 +1,61 @@
|
||||
#pragma region License
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2005-2009 David Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_MeshEdge_H__
|
||||
#define __PolyVox_MeshEdge_H__
|
||||
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
|
||||
#include "PolyVoxImpl/TypeDef.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class POLYVOXCORE_API MeshEdge
|
||||
{
|
||||
public:
|
||||
MeshEdge();
|
||||
|
||||
bool isSane(void);
|
||||
|
||||
void computeEdgeCost(Mesh* pParentMesh);
|
||||
|
||||
MeshEdge* m_pOtherEdge;
|
||||
MeshEdge* m_pNextEdge;
|
||||
MeshEdge* m_pPreviousEdge;
|
||||
|
||||
MeshVertex* m_pSrc;
|
||||
MeshVertex* m_pDest;
|
||||
|
||||
MeshFace* m_pFace;
|
||||
|
||||
float m_fCost;
|
||||
};
|
||||
|
||||
//FIXME - Rather than being global, these should just be used to sort within the set.
|
||||
bool operator==(const MeshEdge& lhs, const MeshEdge& rhs);
|
||||
bool operator<(const MeshEdge& lhs, const MeshEdge& rhs);
|
||||
}
|
||||
|
||||
#endif
|
49
library/PolyVoxCore/include/MeshFace.h
Normal file
49
library/PolyVoxCore/include/MeshFace.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma region License
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2005-2009 David Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_MeshFace_H__
|
||||
#define __PolyVox_MeshFace_H__
|
||||
|
||||
#include "MeshEdge.h"
|
||||
|
||||
#include "PolyVoxImpl/TypeDef.h"
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class POLYVOXCORE_API MeshFace
|
||||
{
|
||||
public:
|
||||
MeshFace();
|
||||
bool isSane(void);
|
||||
|
||||
MeshEdge* m_pEdge;
|
||||
|
||||
Vector3DFloat getNormal(void);
|
||||
bool collapseFlipsFace(MeshEdge* pEdgeToCollapse);
|
||||
bool collapseFlipsFaceImpl(Vector3DFloat fixed0, Vector3DFloat fixed1, Vector3DFloat oldPos, Vector3DFloat newPos);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
52
library/PolyVoxCore/include/MeshVertex.h
Normal file
52
library/PolyVoxCore/include/MeshVertex.h
Normal file
@ -0,0 +1,52 @@
|
||||
#pragma region License
|
||||
/*******************************************************************************
|
||||
Copyright (c) 2005-2009 David Williams
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
*******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_MeshVertex_H__
|
||||
#define __PolyVox_MeshVertex_H__
|
||||
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
#include "SurfaceVertex.h"
|
||||
|
||||
#include "PolyVoxImpl/TypeDef.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
class POLYVOXCORE_API MeshVertex
|
||||
{
|
||||
public:
|
||||
MeshVertex();
|
||||
SurfaceVertex m_vertexData;
|
||||
//MeshEdge* m_pEdge;
|
||||
//std::set<MeshFace*> m_faces;
|
||||
//std::set<MeshEdge*> m_edges; //Edges which have this vertex as the src
|
||||
long int m_index; //Bit wasteful to store this the whle time, as it's only used when converting to ISPs?
|
||||
|
||||
bool isSane(void);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -39,6 +39,13 @@ namespace PolyVox
|
||||
typedef Volume<uint16_t> UInt16Volume;
|
||||
//---------------------------------
|
||||
|
||||
//---------- Mesh ----------
|
||||
class Mesh;
|
||||
class MeshEdge;
|
||||
class MeshFace;
|
||||
class MeshVertex;
|
||||
//---------------------------------
|
||||
|
||||
class IndexedSurfacePatch;
|
||||
class Region;
|
||||
class SurfaceVertex;
|
||||
|
@ -29,8 +29,18 @@ freely, subject to the following restrictions:
|
||||
#include "PolyVoxImpl/TypeDef.h"
|
||||
#include "Vector.h"
|
||||
|
||||
#include <bitset>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
enum POLYVOXCORE_API VertexFlags
|
||||
{
|
||||
VF_ON_MATERIAL_EDGE = 0x00,
|
||||
VF_ON_GEOMETRY_EDGE_X = 0x01,
|
||||
VF_ON_GEOMETRY_EDGE_Y = 0x02,
|
||||
VF_ON_GEOMETRY_EDGE_Z = 0x03
|
||||
};
|
||||
|
||||
class POLYVOXCORE_API SurfaceVertex
|
||||
{
|
||||
public:
|
||||
@ -42,20 +52,26 @@ namespace PolyVox
|
||||
const Vector3DFloat& getNormal(void) const;
|
||||
const Vector3DFloat& getPosition(void) const;
|
||||
|
||||
bool isEdgeVertex(void) const;
|
||||
|
||||
void setEdgeVertex(bool isEdgeVertex);
|
||||
bool isOnEdge(void) const;
|
||||
bool isOnGeometryEdge(void) const;
|
||||
bool isOnGeometryEdgeX(void) const;
|
||||
bool isOnGeometryEdgeY(void) const;
|
||||
bool isOnGeometryEdgeZ(void) const;
|
||||
bool isOnMaterialEdge(void) const;
|
||||
|
||||
void setMaterial(float materialToSet);
|
||||
void setNormal(const Vector3DFloat& normalToSet);
|
||||
void setOnGeometryEdgeX(bool bOnRegionEdge);
|
||||
void setOnGeometryEdgeY(bool bOnRegionEdge);
|
||||
void setOnGeometryEdgeZ(bool bOnRegionEdge);
|
||||
void setOnMaterialEdge(bool bOnMaterialEdge);
|
||||
void setPosition(const Vector3DFloat& positionToSet);
|
||||
|
||||
public:
|
||||
Vector3DFloat position;
|
||||
Vector3DFloat normal;
|
||||
float material; //FIXME: This shouldn't be float on CPU?
|
||||
bool m_bIsEdgeVertex;
|
||||
bool m_bIsMaterialEdgeVertex;
|
||||
|
||||
std::bitset<4> m_bFlags;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user