Vertices now carry general purpose 'data' rather than a 'material', though the data will be treated as a material in many cases. This is part of making the architecture more generic and involves some renaming.
This commit is contained in:
		| @@ -222,7 +222,7 @@ namespace PolyVox | ||||
| 				//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. | ||||
| 				CubicVertex<typename VolumeType::VoxelType> cubicVertex; | ||||
| 				cubicVertex.position.setElements(static_cast<uint8_t>(uX), static_cast<uint8_t>(uY), static_cast<uint8_t>(uZ)); | ||||
| 				cubicVertex.material = uMaterialIn; | ||||
| 				cubicVertex.data = uMaterialIn; | ||||
| 				rEntry.iIndex = m_meshCurrent->addVertex(cubicVertex); | ||||
| 				rEntry.uMaterial = uMaterialIn; | ||||
|  | ||||
| @@ -275,9 +275,9 @@ namespace PolyVox | ||||
| 	template<typename VolumeType, typename IsQuadNeeded> | ||||
| 	bool CubicSurfaceExtractor<VolumeType, IsQuadNeeded>::mergeQuads(Quad& q1, Quad& q2) | ||||
| 	{ | ||||
| 		//All four vertices of a given quad have the same material, | ||||
| 		//All four vertices of a given quad have the same data, | ||||
| 		//so just check that the first pair of vertices match. | ||||
| 		if(m_meshCurrent->getVertices()[q1.vertices[0]].material == m_meshCurrent->getVertices()[q2.vertices[0]].material) | ||||
| 		if (m_meshCurrent->getVertices()[q1.vertices[0]].data == m_meshCurrent->getVertices()[q2.vertices[0]].data) | ||||
| 		{ | ||||
| 			//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 | ||||
|   | ||||
| @@ -463,7 +463,7 @@ namespace PolyVox | ||||
| 					MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex; | ||||
| 					surfaceVertex.position = v3dPositionAsUint; | ||||
| 					surfaceVertex.normal = v3dNormal; | ||||
| 					surfaceVertex.material = uMaterial; | ||||
| 					surfaceVertex.data = uMaterial; | ||||
|  | ||||
| 					const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); | ||||
| 					m_pCurrentVertexIndicesX[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; | ||||
| @@ -497,7 +497,7 @@ namespace PolyVox | ||||
| 					MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex; | ||||
| 					surfaceVertex.position = v3dPositionAsUint; | ||||
| 					surfaceVertex.normal = v3dNormal; | ||||
| 					surfaceVertex.material = uMaterial; | ||||
| 					surfaceVertex.data = uMaterial; | ||||
|  | ||||
| 					uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); | ||||
| 					m_pCurrentVertexIndicesY[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; | ||||
| @@ -530,7 +530,7 @@ namespace PolyVox | ||||
| 					MarchingCubesVertex<typename VolumeType::VoxelType> surfaceVertex; | ||||
| 					surfaceVertex.position = v3dPositionAsUint; | ||||
| 					surfaceVertex.normal = v3dNormal; | ||||
| 					surfaceVertex.material = uMaterial; | ||||
| 					surfaceVertex.data = uMaterial; | ||||
|  | ||||
| 					const uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex); | ||||
| 					m_pCurrentVertexIndicesZ[iXVolSpace - m_regSizeInVoxels.getLowerX()][iYVolSpace - m_regSizeInVoxels.getLowerY()] = uLastVertexIndex; | ||||
|   | ||||
| @@ -102,9 +102,9 @@ namespace PolyVox | ||||
| 	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::DataType > > decode(const MeshType& mesh) | ||||
| 	{ | ||||
| 		Mesh< Vertex< typename MeshType::VertexType::VoxelType > > result; | ||||
| 		Mesh< Vertex< typename MeshType::VertexType::DataType > > result; | ||||
| 		result.m_vecVertices.resize(mesh.m_vecVertices.size()); | ||||
|  | ||||
| 		for(uint32_t ct = 0; ct < mesh.m_vecVertices.size(); ct++) | ||||
|   | ||||
| @@ -36,68 +36,68 @@ namespace PolyVox | ||||
| 	#ifdef SWIG | ||||
| 	struct Vertex | ||||
| #else | ||||
| 	template<typename _VoxelType> | ||||
| 	template<typename _DataType> | ||||
| 	struct POLYVOX_API Vertex | ||||
| #endif | ||||
| 	{ | ||||
| 		typedef _VoxelType VoxelType; | ||||
| 		typedef _DataType DataType; | ||||
|  | ||||
| 		Vector3DFloat position; | ||||
| 		Vector3DFloat normal; | ||||
| 		VoxelType material; | ||||
| 		DataType data; | ||||
| 	}; | ||||
|  | ||||
| #ifdef SWIG | ||||
| 	struct CubicVertex | ||||
| #else | ||||
| 	template<typename _VoxelType> | ||||
| 	template<typename _DataType> | ||||
| 	struct POLYVOX_API CubicVertex | ||||
| #endif | ||||
| 	{ | ||||
| 		typedef _VoxelType VoxelType; | ||||
| 		typedef _DataType DataType; | ||||
|  | ||||
| 		Vector3DUint8 position; | ||||
| 		uint8_t normal; | ||||
| 		VoxelType material; | ||||
| 		DataType data; | ||||
| 	}; | ||||
|  | ||||
| #ifdef SWIG | ||||
| 	struct MarchingCubesVertex | ||||
| #else | ||||
| 	template<typename _VoxelType> | ||||
| 	template<typename _DataType> | ||||
| 	struct POLYVOX_API MarchingCubesVertex | ||||
| #endif | ||||
| 	{ | ||||
| 		typedef _VoxelType VoxelType; | ||||
| 		typedef _DataType DataType; | ||||
|  | ||||
| 		Vector3DUint16 position; | ||||
| 		Vector3DFloat normal; | ||||
| 		VoxelType material; | ||||
| 		DataType data; | ||||
| 	}; | ||||
|  | ||||
| 	// 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) | ||||
| 	template<typename DataType> | ||||
| 	Vertex<DataType> decode(const CubicVertex<DataType>& cubicVertex) | ||||
| 	{ | ||||
| 		Vertex<VoxelType> result; | ||||
| 		Vertex<DataType> result; | ||||
| 		Vector3DUint8 temp = cubicVertex.position; // For some reason we can't cast Vector3DUint8 to Vector3DFloat - investigate why. | ||||
| 		result.position = Vector3DFloat(temp.getX(), temp.getY(), temp.getZ()) - Vector3DFloat(0.5, 0.5, 0.5); | ||||
| 		//result.normal = cubicVertex.normal; | ||||
| 		result.material = cubicVertex.material; | ||||
| 		result.data = cubicVertex.data; | ||||
| 		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) | ||||
| 	template<typename DataType> | ||||
| 	Vertex<DataType> decode(const MarchingCubesVertex<DataType>& cubicVertex) | ||||
| 	{ | ||||
| 		Vertex<VoxelType> result; | ||||
| 		Vertex<DataType> result; | ||||
| 		result.position = Vector3DFloat(cubicVertex.position.getX(), cubicVertex.position.getY(), cubicVertex.position.getZ()); | ||||
| 		result.position *= (1.0 / 256.0); | ||||
| 		result.normal = cubicVertex.normal; | ||||
| 		result.material = cubicVertex.material; | ||||
| 		result.data = cubicVertex.data; | ||||
| 		return result; | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user