Work simplifying marching cubes implementations.
This commit is contained in:
		| @@ -42,7 +42,7 @@ namespace PolyVox | |||||||
| 	POLYVOX_API boost::uint32_t computeInitialRoughBitmaskForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask); | 	POLYVOX_API boost::uint32_t computeInitialRoughBitmaskForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask); | ||||||
| 	POLYVOX_API boost::uint32_t computeRoughBitmaskForSliceFromPrevious(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask, boost::uint8_t *previousBitmask); | 	POLYVOX_API boost::uint32_t computeRoughBitmaskForSliceFromPrevious(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask, boost::uint8_t *previousBitmask); | ||||||
| 	POLYVOX_API void generateRoughIndicesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, boost::uint8_t* bitmask0, boost::uint8_t* bitmask1, boost::int32_t vertexIndicesX0[],boost::int32_t vertexIndicesY0[],boost::int32_t vertexIndicesZ0[], boost::int32_t vertexIndicesX1[],boost::int32_t vertexIndicesY1[],boost::int32_t vertexIndicesZ1[]); | 	POLYVOX_API void generateRoughIndicesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, boost::uint8_t* bitmask0, boost::uint8_t* bitmask1, boost::int32_t vertexIndicesX0[],boost::int32_t vertexIndicesY0[],boost::int32_t vertexIndicesZ0[], boost::int32_t vertexIndicesX1[],boost::int32_t vertexIndicesY1[],boost::int32_t vertexIndicesZ1[]); | ||||||
| 	POLYVOX_API void generateRoughVerticesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, boost::uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[], Vector3DFloat vertlist[], boost::uint8_t vertMaterials[]); | 	POLYVOX_API void generateRoughVerticesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, boost::uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[]); | ||||||
|  |  | ||||||
| 	POLYVOX_API void generateReferenceMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch); | 	POLYVOX_API void generateReferenceMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch); | ||||||
| 	POLYVOX_API Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod); | 	POLYVOX_API Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod); | ||||||
|   | |||||||
| @@ -40,7 +40,7 @@ namespace PolyVox | |||||||
| 	POLYVOX_API boost::uint32_t computeInitialDecimatedBitmaskForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask); | 	POLYVOX_API boost::uint32_t computeInitialDecimatedBitmaskForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask); | ||||||
| 	POLYVOX_API boost::uint32_t computeDecimatedBitmaskForSliceFromPrevious(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask, boost::uint8_t *previousBitmask); | 	POLYVOX_API boost::uint32_t computeDecimatedBitmaskForSliceFromPrevious(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, boost::uint8_t *bitmask, boost::uint8_t *previousBitmask); | ||||||
| 	POLYVOX_API void generateDecimatedIndicesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, boost::uint8_t* bitmask0, boost::uint8_t* bitmask1, boost::int32_t vertexIndicesX0[],boost::int32_t vertexIndicesY0[],boost::int32_t vertexIndicesZ0[], boost::int32_t vertexIndicesX1[],boost::int32_t vertexIndicesY1[],boost::int32_t vertexIndicesZ1[]); | 	POLYVOX_API void generateDecimatedIndicesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, const Region& regSlice, IndexedSurfacePatch* singleMaterialPatch, const Vector3DFloat& offset, boost::uint8_t* bitmask0, boost::uint8_t* bitmask1, boost::int32_t vertexIndicesX0[],boost::int32_t vertexIndicesY0[],boost::int32_t vertexIndicesZ0[], boost::int32_t vertexIndicesX1[],boost::int32_t vertexIndicesY1[],boost::int32_t vertexIndicesZ1[]); | ||||||
| 	POLYVOX_API void generateDecimatedVerticesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, boost::uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[], Vector3DFloat vertlist[], boost::uint8_t vertMaterials[]); | 	POLYVOX_API void generateDecimatedVerticesForSlice(BlockVolumeIterator<boost::uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, boost::uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[]); | ||||||
|  |  | ||||||
| 	POLYVOX_API void generateDecimatedMeshDataForRegionSlow(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch); | 	POLYVOX_API void generateDecimatedMeshDataForRegionSlow(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ namespace PolyVox | |||||||
| 	public:	 | 	public:	 | ||||||
| 		SurfaceVertex(); | 		SurfaceVertex(); | ||||||
| 		SurfaceVertex(Vector3DFloat positionToSet, float materialToSet, float alphaToSet); | 		SurfaceVertex(Vector3DFloat positionToSet, float materialToSet, float alphaToSet); | ||||||
| 		SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet);	 | 		SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet, float materialToSet, float alphaToSet);	 | ||||||
|  |  | ||||||
| 		friend bool operator==(const SurfaceVertex& lhs, const SurfaceVertex& rhs); | 		friend bool operator==(const SurfaceVertex& lhs, const SurfaceVertex& rhs); | ||||||
| 		friend bool operator < (const SurfaceVertex& lhs, const SurfaceVertex& rhs); | 		friend bool operator < (const SurfaceVertex& lhs, const SurfaceVertex& rhs); | ||||||
|   | |||||||
| @@ -29,7 +29,7 @@ namespace PolyVox | |||||||
| 			regionGeometry.m_patchSingleMaterial = new IndexedSurfacePatch(false); | 			regionGeometry.m_patchSingleMaterial = new IndexedSurfacePatch(false); | ||||||
| 			regionGeometry.m_v3dRegionPosition = iterChangedRegions->getLowerCorner(); | 			regionGeometry.m_v3dRegionPosition = iterChangedRegions->getLowerCorner(); | ||||||
|  |  | ||||||
| 			generateRoughMeshDataForRegion(volume.getVolumeData(), *iterChangedRegions, regionGeometry.m_patchSingleMaterial); | 			generateDecimatedMeshDataForRegion(volume.getVolumeData(), *iterChangedRegions, regionGeometry.m_patchSingleMaterial); | ||||||
|  |  | ||||||
| 			//genMultiFromSingle(regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial); | 			//genMultiFromSingle(regionGeometry.m_patchSingleMaterial, regionGeometry.m_patchMultiMaterial); | ||||||
|  |  | ||||||
| @@ -73,10 +73,6 @@ namespace PolyVox | |||||||
| 		//Offset from volume corner | 		//Offset from volume corner | ||||||
| 		const Vector3DFloat offset = static_cast<Vector3DFloat>(region.getLowerCorner()); | 		const Vector3DFloat offset = static_cast<Vector3DFloat>(region.getLowerCorner()); | ||||||
|  |  | ||||||
| 		//Temporary space use to store the vertices |  | ||||||
| 		Vector3DFloat vertlist[12]; |  | ||||||
| 		uint8_t vertMaterials[12]; |  | ||||||
|  |  | ||||||
| 		//Create a region corresponding to the first slice | 		//Create a region corresponding to the first slice | ||||||
| 		Region regSlice0(region); | 		Region regSlice0(region); | ||||||
| 		regSlice0.setUpperCorner(Vector3DInt32(regSlice0.getUpperCorner().getX(),regSlice0.getUpperCorner().getY(),regSlice0.getLowerCorner().getZ())); | 		regSlice0.setUpperCorner(Vector3DInt32(regSlice0.getUpperCorner().getX(),regSlice0.getUpperCorner().getY(),regSlice0.getLowerCorner().getZ())); | ||||||
| @@ -89,7 +85,7 @@ namespace PolyVox | |||||||
| 		if(uNoOfNonEmptyCellsForSlice0 != 0) | 		if(uNoOfNonEmptyCellsForSlice0 != 0) | ||||||
| 		{ | 		{ | ||||||
| 			//If there were some non-empty cells then generate initial slice vertices for them | 			//If there were some non-empty cells then generate initial slice vertices for them | ||||||
| 			generateRoughVerticesForSlice(volIter,regSlice0, offset, bitmask0, singleMaterialPatch, vertexIndicesX0, vertexIndicesY0, vertexIndicesZ0, /*regTwoSlice.getUpperCorner(),*/ vertlist, vertMaterials); | 			generateRoughVerticesForSlice(volIter,regSlice0, offset, bitmask0, singleMaterialPatch, vertexIndicesX0, vertexIndicesY0, vertexIndicesZ0); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		for(boost::uint32_t uSlice = 0; ((uSlice <= POLYVOX_REGION_SIDE_LENGTH-1) && (uSlice + offset.getZ() < region.getUpperCorner().getZ())); ++uSlice) | 		for(boost::uint32_t uSlice = 0; ((uSlice <= POLYVOX_REGION_SIDE_LENGTH-1) && (uSlice + offset.getZ() < region.getUpperCorner().getZ())); ++uSlice) | ||||||
| @@ -101,7 +97,7 @@ namespace PolyVox | |||||||
|  |  | ||||||
| 			if(uNoOfNonEmptyCellsForSlice1 != 0) | 			if(uNoOfNonEmptyCellsForSlice1 != 0) | ||||||
| 			{ | 			{ | ||||||
| 				generateRoughVerticesForSlice(volIter,regSlice1, offset, bitmask1, singleMaterialPatch, vertexIndicesX1, vertexIndicesY1, vertexIndicesZ1, vertlist, vertMaterials);				 | 				generateRoughVerticesForSlice(volIter,regSlice1, offset, bitmask1, singleMaterialPatch, vertexIndicesX1, vertexIndicesY1, vertexIndicesZ1);				 | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			if((uNoOfNonEmptyCellsForSlice0 != 0) || (uNoOfNonEmptyCellsForSlice1 != 0)) | 			if((uNoOfNonEmptyCellsForSlice0 != 0) || (uNoOfNonEmptyCellsForSlice1 != 0)) | ||||||
| @@ -403,7 +399,7 @@ namespace PolyVox | |||||||
| 		return uNoOfNonEmptyCells; | 		return uNoOfNonEmptyCells; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	void generateRoughVerticesForSlice(BlockVolumeIterator<uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[], Vector3DFloat vertlist[], uint8_t vertMaterials[]) | 	void generateRoughVerticesForSlice(BlockVolumeIterator<uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[]) | ||||||
| 	{ | 	{ | ||||||
| 		//Iterate over each cell in the region | 		//Iterate over each cell in the region | ||||||
| 		volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ()); | 		volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ()); | ||||||
| @@ -432,11 +428,10 @@ namespace PolyVox | |||||||
| 			{ | 			{ | ||||||
| 				if((x + offset.getX()) != regSlice.getUpperCorner().getX()) | 				if((x + offset.getX()) != regSlice.getUpperCorner().getX()) | ||||||
| 				{ | 				{ | ||||||
| 					vertlist[0].setX(x + 0.5f); | 					const Vector3DFloat v3dPosition(x + 0.5f, y, z); | ||||||
| 					vertlist[0].setY(y); | 					const Vector3DFloat v3dNormal(1.0f, 0.0f, 0.0f); | ||||||
| 					vertlist[0].setZ(z); | 					const uint8_t uMaterial = v000 | volIter.peekVoxel1px0py0pz(); //Because one of these is 0, the or operation takes the max. | ||||||
| 					vertMaterials[0] = v000 | volIter.peekVoxel1px0py0pz(); //Because one of these is 0, the or operation takes the max. | 					const SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0); | ||||||
| 					SurfaceVertex surfaceVertex(vertlist[0],vertMaterials[0], 1.0); |  | ||||||
| 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | ||||||
| 					vertexIndicesX[getIndex(x,y)] = singleMaterialPatch->m_vecVertices.size()-1; | 					vertexIndicesX[getIndex(x,y)] = singleMaterialPatch->m_vecVertices.size()-1; | ||||||
| 				} | 				} | ||||||
| @@ -445,11 +440,10 @@ namespace PolyVox | |||||||
| 			{ | 			{ | ||||||
| 				if((y + offset.getY()) != regSlice.getUpperCorner().getY()) | 				if((y + offset.getY()) != regSlice.getUpperCorner().getY()) | ||||||
| 				{ | 				{ | ||||||
| 					vertlist[3].setX(x); | 					const Vector3DFloat v3dPosition(x, y + 0.5f, z); | ||||||
| 					vertlist[3].setY(y + 0.5f); | 					const Vector3DFloat v3dNormal(0.0f, 1.0f, 0.0f); | ||||||
| 					vertlist[3].setZ(z); | 					const uint8_t uMaterial = v000 | volIter.peekVoxel0px1py0pz(); | ||||||
| 					vertMaterials[3] = v000 | volIter.peekVoxel0px1py0pz(); | 					SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0); | ||||||
| 					SurfaceVertex surfaceVertex(vertlist[3],vertMaterials[3], 1.0); |  | ||||||
| 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | ||||||
| 					vertexIndicesY[getIndex(x,y)] = singleMaterialPatch->m_vecVertices.size()-1; | 					vertexIndicesY[getIndex(x,y)] = singleMaterialPatch->m_vecVertices.size()-1; | ||||||
| 				} | 				} | ||||||
| @@ -458,11 +452,10 @@ namespace PolyVox | |||||||
| 			{ | 			{ | ||||||
| 				//if((z + offset.getZ()) != upperCorner.getZ()) | 				//if((z + offset.getZ()) != upperCorner.getZ()) | ||||||
| 				{ | 				{ | ||||||
| 					vertlist[8].setX(x); | 					const Vector3DFloat v3dPosition(x, y, z + 0.5f); | ||||||
| 					vertlist[8].setY(y); | 					const Vector3DFloat v3dNormal(0.0f, 0.0f, 1.0f); | ||||||
| 					vertlist[8].setZ(z + 0.5f); | 					const uint8_t uMaterial = v000 | volIter.peekVoxel0px0py1pz(); | ||||||
| 					vertMaterials[8] = v000 | volIter.peekVoxel0px0py1pz(); | 					SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0); | ||||||
| 					SurfaceVertex surfaceVertex(vertlist[8],vertMaterials[8], 1.0); |  | ||||||
| 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | ||||||
| 					vertexIndicesZ[getIndex(x,y)] = singleMaterialPatch->m_vecVertices.size()-1; | 					vertexIndicesZ[getIndex(x,y)] = singleMaterialPatch->m_vecVertices.size()-1; | ||||||
| 				} | 				} | ||||||
|   | |||||||
| @@ -46,10 +46,6 @@ namespace PolyVox | |||||||
| 		//Offset from volume corner | 		//Offset from volume corner | ||||||
| 		const Vector3DFloat offset = static_cast<Vector3DFloat>(region.getLowerCorner()); | 		const Vector3DFloat offset = static_cast<Vector3DFloat>(region.getLowerCorner()); | ||||||
|  |  | ||||||
| 		//Temporary space use to store the vertices |  | ||||||
| 		Vector3DFloat vertlist[12]; |  | ||||||
| 		uint8_t vertMaterials[12]; |  | ||||||
|  |  | ||||||
| 		//Create a region corresponding to the first slice | 		//Create a region corresponding to the first slice | ||||||
| 		Region regSlice0(region); | 		Region regSlice0(region); | ||||||
| 		regSlice0.setUpperCorner(Vector3DInt32(regSlice0.getUpperCorner().getX(),regSlice0.getUpperCorner().getY(),regSlice0.getLowerCorner().getZ())); | 		regSlice0.setUpperCorner(Vector3DInt32(regSlice0.getUpperCorner().getX(),regSlice0.getUpperCorner().getY(),regSlice0.getLowerCorner().getZ())); | ||||||
| @@ -62,7 +58,7 @@ namespace PolyVox | |||||||
| 		if(uNoOfNonEmptyCellsForSlice0 != 0) | 		if(uNoOfNonEmptyCellsForSlice0 != 0) | ||||||
| 		{ | 		{ | ||||||
| 			//If there were some non-empty cells then generate initial slice vertices for them | 			//If there were some non-empty cells then generate initial slice vertices for them | ||||||
| 			generateDecimatedVerticesForSlice(volIter,regSlice0, offset, bitmask0, singleMaterialPatch, vertexIndicesX0, vertexIndicesY0, vertexIndicesZ0, /*regTwoSlice.getUpperCorner(),*/ vertlist, vertMaterials); | 			generateDecimatedVerticesForSlice(volIter,regSlice0, offset, bitmask0, singleMaterialPatch, vertexIndicesX0, vertexIndicesY0, vertexIndicesZ0); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		for(boost::uint32_t uSlice = 0; ((uSlice <= POLYVOX_REGION_SIDE_LENGTH-1) && (uSlice + offset.getZ() < region.getUpperCorner().getZ())); uSlice += 2) | 		for(boost::uint32_t uSlice = 0; ((uSlice <= POLYVOX_REGION_SIDE_LENGTH-1) && (uSlice + offset.getZ() < region.getUpperCorner().getZ())); uSlice += 2) | ||||||
| @@ -74,7 +70,7 @@ namespace PolyVox | |||||||
|  |  | ||||||
| 			if(uNoOfNonEmptyCellsForSlice1 != 0) | 			if(uNoOfNonEmptyCellsForSlice1 != 0) | ||||||
| 			{ | 			{ | ||||||
| 				generateDecimatedVerticesForSlice(volIter,regSlice1, offset, bitmask1, singleMaterialPatch, vertexIndicesX1, vertexIndicesY1, vertexIndicesZ1, vertlist, vertMaterials);				 | 				generateDecimatedVerticesForSlice(volIter,regSlice1, offset, bitmask1, singleMaterialPatch, vertexIndicesX1, vertexIndicesY1, vertexIndicesZ1);				 | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			if((uNoOfNonEmptyCellsForSlice0 != 0) || (uNoOfNonEmptyCellsForSlice1 != 0)) | 			if((uNoOfNonEmptyCellsForSlice0 != 0) || (uNoOfNonEmptyCellsForSlice1 != 0)) | ||||||
| @@ -101,13 +97,13 @@ namespace PolyVox | |||||||
| 		delete[] vertexIndicesZ1; | 		delete[] vertexIndicesZ1; | ||||||
|  |  | ||||||
|  |  | ||||||
| 		std::vector<SurfaceVertex>::iterator iterSurfaceVertex = singleMaterialPatch->getVertices().begin(); | 		/*std::vector<SurfaceVertex>::iterator iterSurfaceVertex = singleMaterialPatch->getVertices().begin(); | ||||||
| 		while(iterSurfaceVertex != singleMaterialPatch->getVertices().end()) | 		while(iterSurfaceVertex != singleMaterialPatch->getVertices().end()) | ||||||
| 		{ | 		{ | ||||||
| 			Vector3DFloat tempNormal = computeDecimatedNormal(volumeData, static_cast<Vector3DFloat>(iterSurfaceVertex->getPosition() + offset), CENTRAL_DIFFERENCE); | 			Vector3DFloat tempNormal = computeDecimatedNormal(volumeData, static_cast<Vector3DFloat>(iterSurfaceVertex->getPosition() + offset), CENTRAL_DIFFERENCE); | ||||||
| 			const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal); | 			const_cast<SurfaceVertex&>(*iterSurfaceVertex).setNormal(tempNormal); | ||||||
| 			++iterSurfaceVertex; | 			++iterSurfaceVertex; | ||||||
| 		} | 		}*/ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	boost::uint32_t computeInitialDecimatedBitmaskForSlice(BlockVolumeIterator<uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask) | 	boost::uint32_t computeInitialDecimatedBitmaskForSlice(BlockVolumeIterator<uint8_t>& volIter, const Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask) | ||||||
| @@ -118,9 +114,9 @@ namespace PolyVox | |||||||
| 		//volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ()); | 		//volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ()); | ||||||
| 		//volIter.setValidRegion(regSlice); | 		//volIter.setValidRegion(regSlice); | ||||||
| 		//do | 		//do | ||||||
| 		for(uint16_t y = regSlice.getLowerCorner().getY(); y < regSlice.getUpperCorner().getY(); y += 2) | 		for(uint16_t y = regSlice.getLowerCorner().getY(); y <= regSlice.getUpperCorner().getY(); y += 2) | ||||||
| 		{ | 		{ | ||||||
| 			for(uint16_t x = regSlice.getLowerCorner().getX(); x < regSlice.getUpperCorner().getX(); x += 2) | 			for(uint16_t x = regSlice.getLowerCorner().getX(); x <= regSlice.getUpperCorner().getX(); x += 2) | ||||||
| 		{		 | 		{		 | ||||||
| 			//Current position | 			//Current position | ||||||
| 			//const uint16_t x = volIter.getPosX() - offset.getX(); | 			//const uint16_t x = volIter.getPosX() - offset.getX(); | ||||||
| @@ -291,9 +287,9 @@ namespace PolyVox | |||||||
| 		//volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ()); | 		//volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ()); | ||||||
| 		//volIter.setValidRegion(regSlice); | 		//volIter.setValidRegion(regSlice); | ||||||
| 		//do | 		//do | ||||||
| 		for(uint16_t y = regSlice.getLowerCorner().getY(); y < regSlice.getUpperCorner().getY(); y += 2) | 		for(uint16_t y = regSlice.getLowerCorner().getY(); y <= regSlice.getUpperCorner().getY()+1; y += 2) | ||||||
| 		{ | 		{ | ||||||
| 			for(uint16_t x = regSlice.getLowerCorner().getX(); x < regSlice.getUpperCorner().getX(); x += 2) | 			for(uint16_t x = regSlice.getLowerCorner().getX(); x <= regSlice.getUpperCorner().getX()+1; x += 2) | ||||||
| 		{	 | 		{	 | ||||||
| 			//Current position | 			//Current position | ||||||
| 			//const uint16_t x = volIter.getPosX() - offset.getX(); | 			//const uint16_t x = volIter.getPosX() - offset.getX(); | ||||||
| @@ -413,16 +409,16 @@ namespace PolyVox | |||||||
| 		return uNoOfNonEmptyCells; | 		return uNoOfNonEmptyCells; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	void generateDecimatedVerticesForSlice(BlockVolumeIterator<uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[], Vector3DFloat vertlist[], uint8_t vertMaterials[]) | 	void generateDecimatedVerticesForSlice(BlockVolumeIterator<uint8_t>& volIter, Region& regSlice, const Vector3DFloat& offset, uint8_t* bitmask, IndexedSurfacePatch* singleMaterialPatch,boost::int32_t vertexIndicesX[],boost::int32_t vertexIndicesY[],boost::int32_t vertexIndicesZ[]) | ||||||
| 	{ | 	{ | ||||||
| 		//Iterate over each cell in the region | 		//Iterate over each cell in the region | ||||||
| 		//volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ()); | 		//volIter.setPosition(regSlice.getLowerCorner().getX(),regSlice.getLowerCorner().getY(), regSlice.getLowerCorner().getZ()); | ||||||
| 		//volIter.setValidRegion(regSlice); | 		//volIter.setValidRegion(regSlice); | ||||||
| 		//while(volIter.moveForwardInRegionXYZ()) | 		//while(volIter.moveForwardInRegionXYZ()) | ||||||
| 		//do | 		//do | ||||||
| 		for(uint16_t y = regSlice.getLowerCorner().getY(); y < regSlice.getUpperCorner().getY(); y += 2) | 		for(uint16_t y = regSlice.getLowerCorner().getY(); y < regSlice.getUpperCorner().getY()+1; y += 2) | ||||||
| 		{ | 		{ | ||||||
| 			for(uint16_t x = regSlice.getLowerCorner().getX(); x < regSlice.getUpperCorner().getX(); x += 2) | 			for(uint16_t x = regSlice.getLowerCorner().getX(); x < regSlice.getUpperCorner().getX()+1; x += 2) | ||||||
| 		{		 | 		{		 | ||||||
| 			//Current position | 			//Current position | ||||||
| 			//const uint16_t x = volIter.getPosX() - offset.getX(); | 			//const uint16_t x = volIter.getPosX() - offset.getX(); | ||||||
| @@ -446,12 +442,11 @@ namespace PolyVox | |||||||
| 			{ | 			{ | ||||||
| 				if((x) != regSlice.getUpperCorner().getX()) | 				if((x) != regSlice.getUpperCorner().getX()) | ||||||
| 				{ | 				{ | ||||||
| 					vertlist[0].setX(x - offset.getX() + 0.5f * 2.0f); | 					const Vector3DFloat v3dPosition(x - offset.getX() + 0.5f * 2.0f, y - offset.getY(), z - offset.getZ()); | ||||||
| 					vertlist[0].setY(y - offset.getY()); | 					const Vector3DFloat v3dNormal(1.0,0.0,0.0); | ||||||
| 					vertlist[0].setZ(z - offset.getZ()); |  | ||||||
| 					volIter.setPosition(x+2,y,z); | 					volIter.setPosition(x+2,y,z); | ||||||
| 					vertMaterials[0] = v000 | volIter.getMaxedVoxel(); //Because one of these is 0, the or operation takes the max. | 					const uint8_t uMaterial = v000 | volIter.getMaxedVoxel(); //Because one of these is 0, the or operation takes the max. | ||||||
| 					SurfaceVertex surfaceVertex(vertlist[0],vertMaterials[0], 1.0); | 					SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0); | ||||||
| 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | ||||||
| 					vertexIndicesX[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1; | 					vertexIndicesX[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1; | ||||||
| 				} | 				} | ||||||
| @@ -460,12 +455,11 @@ namespace PolyVox | |||||||
| 			{ | 			{ | ||||||
| 				if((y) != regSlice.getUpperCorner().getY()) | 				if((y) != regSlice.getUpperCorner().getY()) | ||||||
| 				{ | 				{ | ||||||
| 					vertlist[3].setX(x - offset.getX()); | 					const Vector3DFloat v3dPosition(x - offset.getX(), y - offset.getY() + 0.5f * 2.0f, z - offset.getZ()); | ||||||
| 					vertlist[3].setY(y - offset.getY() + 0.5f * 2.0f); | 					const Vector3DFloat v3dNormal(0.0,1.0,0.0); | ||||||
| 					vertlist[3].setZ(z - offset.getZ()); |  | ||||||
| 					volIter.setPosition(x,y+2,z); | 					volIter.setPosition(x,y+2,z); | ||||||
| 					vertMaterials[3] = v000 | volIter.getMaxedVoxel(); | 					const uint8_t uMaterial = v000 | volIter.getMaxedVoxel(); //Because one of these is 0, the or operation takes the max. | ||||||
| 					SurfaceVertex surfaceVertex(vertlist[3],vertMaterials[3], 1.0); | 					SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0); | ||||||
| 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | ||||||
| 					vertexIndicesY[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1; | 					vertexIndicesY[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1; | ||||||
| 				} | 				} | ||||||
| @@ -474,12 +468,11 @@ namespace PolyVox | |||||||
| 			{ | 			{ | ||||||
| 				//if((z + offset.getZ()) != upperCorner.getZ()) | 				//if((z + offset.getZ()) != upperCorner.getZ()) | ||||||
| 				{ | 				{ | ||||||
| 					vertlist[8].setX(x - offset.getX()); | 					const Vector3DFloat v3dPosition(x - offset.getX(), y - offset.getY(), z - offset.getZ() + 0.5f * 2.0f); | ||||||
| 					vertlist[8].setY(y - offset.getY()); | 					const Vector3DFloat v3dNormal(0.0,0.0,1.0); | ||||||
| 					vertlist[8].setZ(z - offset.getZ() + 0.5f * 2.0f); |  | ||||||
| 					volIter.setPosition(x,y,z+2); | 					volIter.setPosition(x,y,z+2); | ||||||
| 					vertMaterials[8] = v000 | volIter.getMaxedVoxel(); | 					const uint8_t uMaterial = v000 | volIter.getMaxedVoxel(); //Because one of these is 0, the or operation takes the max. | ||||||
| 					SurfaceVertex surfaceVertex(vertlist[8],vertMaterials[8], 1.0); | 					const SurfaceVertex surfaceVertex(v3dPosition, v3dNormal, uMaterial, 1.0); | ||||||
| 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | 					singleMaterialPatch->m_vecVertices.push_back(surfaceVertex); | ||||||
| 					vertexIndicesZ[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1; | 					vertexIndicesZ[getDecimatedIndex(x - offset.getX(),y - offset.getY())] = singleMaterialPatch->m_vecVertices.size()-1; | ||||||
| 				} | 				} | ||||||
| @@ -498,9 +491,9 @@ namespace PolyVox | |||||||
| 		//volIter.setPosition(regCroppedSlice.getLowerCorner().getX(),regCroppedSlice.getLowerCorner().getY(), regCroppedSlice.getLowerCorner().getZ()); | 		//volIter.setPosition(regCroppedSlice.getLowerCorner().getX(),regCroppedSlice.getLowerCorner().getY(), regCroppedSlice.getLowerCorner().getZ()); | ||||||
| 		//volIter.setValidRegion(regCroppedSlice); | 		//volIter.setValidRegion(regCroppedSlice); | ||||||
| 		//do | 		//do | ||||||
| 		for(uint16_t y = regCroppedSlice.getLowerCorner().getY() - offset.getY(); y < regCroppedSlice.getUpperCorner().getY() - offset.getY(); y += 2) | 		for(uint16_t y = regCroppedSlice.getLowerCorner().getY() - offset.getY(); y <= regCroppedSlice.getUpperCorner().getY() - offset.getY(); y += 2) | ||||||
| 		{ | 		{ | ||||||
| 			for(uint16_t x = regCroppedSlice.getLowerCorner().getX() - offset.getX(); x < regCroppedSlice.getUpperCorner().getX() - offset.getX(); x += 2) | 			for(uint16_t x = regCroppedSlice.getLowerCorner().getX() - offset.getX(); x <= regCroppedSlice.getUpperCorner().getX() - offset.getX(); x += 2) | ||||||
| 		{		 | 		{		 | ||||||
| 			//Current position | 			//Current position | ||||||
| 			//const uint16_t x = volIter.getPosX() - offset.getX(); | 			//const uint16_t x = volIter.getPosX() - offset.getX(); | ||||||
|   | |||||||
| @@ -38,9 +38,11 @@ namespace PolyVox | |||||||
| 		 | 		 | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	SurfaceVertex::SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet) | 	SurfaceVertex::SurfaceVertex(Vector3DFloat positionToSet, Vector3DFloat normalToSet, float materialToSet, float alphaToSet) | ||||||
| 		:position(positionToSet) | 		:position(positionToSet) | ||||||
| 		,normal(normalToSet) | 		,normal(normalToSet) | ||||||
|  | 		,material(materialToSet) | ||||||
|  | 		,alpha(alphaToSet) | ||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user