Simplified vertex types to structs with public members.
Added (currently dummy) decode methods.
This commit is contained in:
		| @@ -214,7 +214,10 @@ namespace PolyVox | ||||
| 			if(rEntry.iIndex == -1) | ||||
| 			{ | ||||
| 				//No vertices matched and we've now hit an empty space. Fill it by creating a vertex. The 0.5f offset is because vertices set between voxels in order to build cubes around them. | ||||
| 				rEntry.iIndex = m_meshCurrent->addVertex(CubicVertex<typename VolumeType::VoxelType>(Vector3DFloat(static_cast<float>(uX)-0.5f, static_cast<float>(uY)-0.5f, static_cast<float>(uZ)-0.5f), uMaterialIn)); | ||||
| 				CubicVertex<typename VolumeType::VoxelType> cubicVertex; | ||||
| 				cubicVertex.position.setElements(static_cast<float>(uX)-0.5f, static_cast<float>(uY)-0.5f, static_cast<float>(uZ)-0.5f); | ||||
| 				cubicVertex.material = uMaterialIn; | ||||
| 				rEntry.iIndex = m_meshCurrent->addVertex(cubicVertex); | ||||
| 				rEntry.uMaterial = uMaterialIn; | ||||
|  | ||||
| 				return rEntry.iIndex; | ||||
| @@ -268,7 +271,7 @@ namespace PolyVox | ||||
| 	{ | ||||
| 		//All four vertices of a given quad have the same material, | ||||
| 		//so just check that the first pair of vertices match. | ||||
| 		if(m_meshCurrent->getVertices()[q1.vertices[0]].getMaterial() == m_meshCurrent->getVertices()[q2.vertices[0]].getMaterial()) | ||||
| 		if(m_meshCurrent->getVertices()[q1.vertices[0]].material == m_meshCurrent->getVertices()[q2.vertices[0]].material) | ||||
| 		{ | ||||
| 			//Now check whether quad 2 is adjacent to quad one by comparing vertices. | ||||
| 			//Adjacent quads must share two vertices, and the second quad could be to the | ||||
|   | ||||
| @@ -459,7 +459,11 @@ namespace PolyVox | ||||
| 					// Allow the controller to decide how the material should be derived from the voxels. | ||||
| 					const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v100, fInterp); | ||||
|  | ||||
| 					const MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial); | ||||
| 					MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex; | ||||
| 					surfaceVertex.position = v3dPosition; | ||||
| 					surfaceVertex.normal = v3dNormal; | ||||
| 					surfaceVertex.material = uMaterial; | ||||
|  | ||||
| 					const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); | ||||
| 					m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; | ||||
|  | ||||
| @@ -488,7 +492,11 @@ namespace PolyVox | ||||
| 					// Allow the controller to decide how the material should be derived from the voxels. | ||||
| 					const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v010, fInterp); | ||||
|  | ||||
| 					MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial); | ||||
| 					MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex; | ||||
| 					surfaceVertex.position = v3dPosition; | ||||
| 					surfaceVertex.normal = v3dNormal; | ||||
| 					surfaceVertex.material = uMaterial; | ||||
|  | ||||
| 					uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); | ||||
| 					m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; | ||||
|  | ||||
| @@ -516,7 +524,11 @@ namespace PolyVox | ||||
| 					// Allow the controller to decide how the material should be derived from the voxels. | ||||
| 					const typename VolumeType::VoxelType uMaterial = m_controller.blendMaterials(v000, v001, fInterp); | ||||
|  | ||||
| 					const MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex(v3dPosition, v3dNormal, uMaterial); | ||||
| 					MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex; | ||||
| 					surfaceVertex.position = v3dPosition; | ||||
| 					surfaceVertex.normal = v3dNormal; | ||||
| 					surfaceVertex.material = uMaterial; | ||||
|  | ||||
| 					const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); | ||||
| 					m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; | ||||
|  | ||||
|   | ||||
| @@ -100,6 +100,24 @@ namespace PolyVox | ||||
|  | ||||
| 	template <typename VertexType> | ||||
| 	std::shared_ptr< Mesh<VertexType> > extractSubset(Mesh<VertexType>& inputMesh, std::set<uint8_t> setMaterials); | ||||
|  | ||||
| 	template <typename MeshType> | ||||
| 	Mesh< Vertex< typename MeshType::VertexType::VoxelType > > decode(const MeshType& mesh) | ||||
| 	{ | ||||
| 		Mesh< Vertex< typename MeshType::VertexType::VoxelType > > result; | ||||
| 		result.m_vecVertices.reserve(mesh.m_vecVertices.size()); | ||||
|  | ||||
| 		for(uint32_t ct = 0; ct < mesh.m_vecVertices.size(); ct++) | ||||
| 		{ | ||||
| 			result.m_vecVertices[ct] = decode(mesh.m_vecVertices[ct]); | ||||
| 		} | ||||
|  | ||||
| 		result.m_vecTriangleIndices = mesh.m_vecTriangleIndices; | ||||
|  | ||||
| 		result.m_Region = mesh.m_Region; | ||||
|  | ||||
| 		return result; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| #include "PolyVoxCore/Mesh.inl" | ||||
|   | ||||
| @@ -81,7 +81,7 @@ namespace PolyVox | ||||
| 	//////////////////////////////////////////////////////////////////////////////// | ||||
| 	// CubicVertex | ||||
| 	//////////////////////////////////////////////////////////////////////////////// | ||||
| 	template<typename VoxelType> class CubicVertex; | ||||
| 	template<typename VoxelType> struct CubicVertex; | ||||
|  | ||||
| 	//////////////////////////////////////////////////////////////////////////////// | ||||
| 	// Density | ||||
| @@ -111,7 +111,7 @@ namespace PolyVox | ||||
| 	//////////////////////////////////////////////////////////////////////////////// | ||||
| 	// MarchingCubesVertex | ||||
| 	//////////////////////////////////////////////////////////////////////////////// | ||||
| 	template<typename VoxelType> class MarchingCubesVertex; | ||||
| 	template<typename VoxelType> struct MarchingCubesVertex; | ||||
|  | ||||
| 	//////////////////////////////////////////////////////////////////////////////// | ||||
| 	// Material | ||||
|   | ||||
| @@ -32,134 +32,72 @@ freely, subject to the following restrictions: | ||||
| #include <vector> | ||||
|  | ||||
| namespace PolyVox | ||||
| {	 | ||||
| #ifdef SWIG | ||||
| 	class CubicVertex | ||||
| { | ||||
| 	#ifdef SWIG | ||||
| 	struct Vertex | ||||
| #else | ||||
| 	template<typename _VoxelType> | ||||
| 	class POLYVOX_API CubicVertex | ||||
| 	struct POLYVOX_API Vertex | ||||
| #endif | ||||
| 	{ | ||||
| 	public:	 | ||||
|  | ||||
| 		typedef _VoxelType VoxelType; | ||||
|  | ||||
| 		CubicVertex() | ||||
| 		{ | ||||
| 		} | ||||
|  | ||||
| 		CubicVertex(Vector3DFloat positionToSet, VoxelType materialToSet) | ||||
| 			:position(positionToSet) | ||||
| 			,material(materialToSet) | ||||
| 		{ | ||||
| 		} | ||||
|  | ||||
| 		CubicVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet, VoxelType materialToSet) | ||||
| 			:position(positionToSet) | ||||
| 			,normal(normalToSet) | ||||
| 			,material(materialToSet) | ||||
| 		{ | ||||
| 		} | ||||
|  | ||||
| 		VoxelType getMaterial(void) const | ||||
| 		{ | ||||
| 			return material; | ||||
| 		} | ||||
|  | ||||
| 		const Vector3DFloat& getNormal(void) const | ||||
| 		{ | ||||
| 			return normal; | ||||
| 		} | ||||
|  | ||||
| 		const Vector3DFloat& getPosition(void) const | ||||
| 		{ | ||||
| 			return position; | ||||
| 		} | ||||
|  | ||||
| 		void setMaterial(VoxelType materialToSet) | ||||
| 		{ | ||||
| 			material = materialToSet; | ||||
| 		} | ||||
|  | ||||
| 		void setNormal(const Vector3DFloat& normalToSet) | ||||
| 		{ | ||||
| 			normal = normalToSet; | ||||
| 		} | ||||
|  | ||||
| 		void setPosition(const Vector3DFloat& positionToSet) | ||||
| 		{ | ||||
| 			position = positionToSet; | ||||
| 		} | ||||
|  | ||||
| 	public: | ||||
| 		Vector3DFloat position; | ||||
| 		Vector3DFloat normal; | ||||
| 		VoxelType material; | ||||
| 	}; | ||||
|  | ||||
| #ifdef SWIG | ||||
| 	class MarchingCubesVertex | ||||
| 	struct CubicVertex | ||||
| #else | ||||
| 	template<typename _VoxelType> | ||||
| 	class POLYVOX_API MarchingCubesVertex | ||||
| 	struct POLYVOX_API CubicVertex | ||||
| #endif | ||||
| 	{ | ||||
| 	public: | ||||
|  | ||||
| 		typedef _VoxelType VoxelType; | ||||
|  | ||||
| 		MarchingCubesVertex() | ||||
| 		{ | ||||
| 		} | ||||
|  | ||||
| 		MarchingCubesVertex(Vector3DFloat positionToSet, VoxelType materialToSet) | ||||
| 			:position(positionToSet) | ||||
| 			, material(materialToSet) | ||||
| 		{ | ||||
| 		} | ||||
|  | ||||
| 		MarchingCubesVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet, VoxelType materialToSet) | ||||
| 			:position(positionToSet) | ||||
| 			, normal(normalToSet) | ||||
| 			, material(materialToSet) | ||||
| 		{ | ||||
| 		} | ||||
|  | ||||
| 		VoxelType getMaterial(void) const | ||||
| 		{ | ||||
| 			return material; | ||||
| 		} | ||||
|  | ||||
| 		const Vector3DFloat& getNormal(void) const | ||||
| 		{ | ||||
| 			return normal; | ||||
| 		} | ||||
|  | ||||
| 		const Vector3DFloat& getPosition(void) const | ||||
| 		{ | ||||
| 			return position; | ||||
| 		} | ||||
|  | ||||
| 		void setMaterial(VoxelType materialToSet) | ||||
| 		{ | ||||
| 			material = materialToSet; | ||||
| 		} | ||||
|  | ||||
| 		void setNormal(const Vector3DFloat& normalToSet) | ||||
| 		{ | ||||
| 			normal = normalToSet; | ||||
| 		} | ||||
|  | ||||
| 		void setPosition(const Vector3DFloat& positionToSet) | ||||
| 		{ | ||||
| 			position = positionToSet; | ||||
| 		} | ||||
|  | ||||
| 	public: | ||||
| 		Vector3DFloat position; | ||||
| 		Vector3DFloat normal; | ||||
| 		VoxelType material; | ||||
| 	}; | ||||
|  | ||||
| #ifdef SWIG | ||||
| 	struct MarchingCubesVertex | ||||
| #else | ||||
| 	template<typename _VoxelType> | ||||
| 	struct POLYVOX_API MarchingCubesVertex | ||||
| #endif | ||||
| 	{ | ||||
| 		typedef _VoxelType VoxelType; | ||||
|  | ||||
| 		Vector3DFloat position; | ||||
| 		Vector3DFloat normal; | ||||
| 		VoxelType material; | ||||
| 	}; | ||||
|  | ||||
| 	// Hopefully the compiler will implement the 'Return value optimization' here, but | ||||
| 	// performance critical code will most likely decode the vertices in a shader anyway. | ||||
| 	template<typename VoxelType> | ||||
| 	Vertex<VoxelType> decode(const CubicVertex<VoxelType>& cubicVertex) | ||||
| 	{ | ||||
| 		Vertex<VoxelType> result; | ||||
| 		result.position = cubicVertex.position; | ||||
| 		result.normal = cubicVertex.normal; | ||||
| 		result.material = cubicVertex.material; | ||||
| 		return result; | ||||
| 	} | ||||
|  | ||||
| 	// Hopefully the compiler will implement the 'Return value optimization' here, but | ||||
| 	// performance critical code will most likely decode the vertices in a shader anyway. | ||||
| 	template<typename VoxelType> | ||||
| 	Vertex<VoxelType> decode(const MarchingCubesVertex<VoxelType>& cubicVertex) | ||||
| 	{ | ||||
| 		Vertex<VoxelType> result; | ||||
| 		result.position = cubicVertex.position; | ||||
| 		result.normal = cubicVertex.normal; | ||||
| 		result.material = cubicVertex.material; | ||||
| 		return result; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| #endif | ||||
|   | ||||
		Reference in New Issue
	
	Block a user