Tidying up normal generation code.
This commit is contained in:
@ -24,6 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#include "BlockVolumeIterator.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
template <typename VoxelType>
|
||||
@ -37,6 +39,9 @@ namespace PolyVox
|
||||
|
||||
template <typename VoxelType>
|
||||
Vector3DFloat computeSobelGradient(const BlockVolumeIterator<VoxelType>& volIter);
|
||||
|
||||
POLYVOX_API void computeNormalsForVertices(BlockVolume<boost::uint8_t>* volumeData, RegionGeometry& regGeom, NormalGenerationMethod normalGenerationMethod);
|
||||
POLYVOX_API Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
|
||||
}
|
||||
|
||||
#include "GradientEstimators.inl"
|
||||
|
@ -36,9 +36,9 @@ namespace PolyVox
|
||||
|
||||
return Vector3DFloat
|
||||
(
|
||||
static_cast<float>(voxel1px) - static_cast<float>(voxel1nx),
|
||||
static_cast<float>(voxel1py) - static_cast<float>(voxel1ny),
|
||||
static_cast<float>(voxel1pz) - static_cast<float>(voxel1nz)
|
||||
static_cast<float>(voxel1nx) - static_cast<float>(voxel1px),
|
||||
static_cast<float>(voxel1ny) - static_cast<float>(voxel1py),
|
||||
static_cast<float>(voxel1nz) - static_cast<float>(voxel1pz)
|
||||
);
|
||||
}
|
||||
|
||||
@ -61,9 +61,9 @@ namespace PolyVox
|
||||
|
||||
return Vector3DFloat
|
||||
(
|
||||
static_cast<float>(voxel1px) - static_cast<float>(voxel1nx),
|
||||
static_cast<float>(voxel1py) - static_cast<float>(voxel1ny),
|
||||
static_cast<float>(voxel1pz) - static_cast<float>(voxel1nz)
|
||||
static_cast<float>(voxel1nx) - static_cast<float>(voxel1px),
|
||||
static_cast<float>(voxel1ny) - static_cast<float>(voxel1py),
|
||||
static_cast<float>(voxel1nz) - static_cast<float>(voxel1pz)
|
||||
);
|
||||
}
|
||||
|
||||
@ -134,50 +134,50 @@ namespace PolyVox
|
||||
const VoxelType pVoxel1px1py0pz = volIter.peekVoxel1px1py0pz() > 0 ? 1: 0;
|
||||
const VoxelType pVoxel1px1py1pz = volIter.peekVoxel1px1py1pz() > 0 ? 1: 0;
|
||||
|
||||
const int xGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
|
||||
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
|
||||
pVoxel1nx1ny1pz - weights[0][1][0] * pVoxel1nx0py1nz -
|
||||
weights[1][1][0] * pVoxel1nx0py0pz - weights[2][1][0] *
|
||||
pVoxel1nx0py1pz - weights[0][2][0] * pVoxel1nx1py1nz -
|
||||
weights[1][2][0] * pVoxel1nx1py0pz - weights[2][2][0] *
|
||||
pVoxel1nx1py1pz + weights[0][0][2] * pVoxel1px1ny1nz +
|
||||
weights[1][0][2] * pVoxel1px1ny0pz + weights[2][0][2] *
|
||||
pVoxel1px1ny1pz + weights[0][1][2] * pVoxel1px0py1nz +
|
||||
weights[1][1][2] * pVoxel1px0py0pz + weights[2][1][2] *
|
||||
pVoxel1px0py1pz + weights[0][2][2] * pVoxel1px1py1nz +
|
||||
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
|
||||
pVoxel1px1py1pz);
|
||||
|
||||
const int yGrad(- weights[0][0][0] * pVoxel1nx1ny1nz -
|
||||
weights[1][0][0] * pVoxel1nx1ny0pz - weights[2][0][0] *
|
||||
pVoxel1nx1ny1pz + weights[0][2][0] * pVoxel1nx1py1nz +
|
||||
weights[1][2][0] * pVoxel1nx1py0pz + weights[2][2][0] *
|
||||
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz -
|
||||
weights[1][0][1] * pVoxel0px1ny0pz - weights[2][0][1] *
|
||||
pVoxel0px1ny1pz + weights[0][2][1] * pVoxel0px1py1nz +
|
||||
weights[1][2][1] * pVoxel0px1py0pz + weights[2][2][1] *
|
||||
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz -
|
||||
weights[1][0][2] * pVoxel1px1ny0pz - weights[2][0][2] *
|
||||
pVoxel1px1ny1pz + weights[0][2][2] * pVoxel1px1py1nz +
|
||||
weights[1][2][2] * pVoxel1px1py0pz + weights[2][2][2] *
|
||||
pVoxel1px1py1pz);
|
||||
|
||||
const int xGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) -
|
||||
weights[1][0][0] * ( pVoxel1nx1ny0pz) - weights[2][0][0] *
|
||||
( pVoxel1nx1ny1pz) - weights[0][1][0] * ( pVoxel1nx0py1nz) -
|
||||
weights[1][1][0] * ( pVoxel1nx0py0pz) - weights[2][1][0] *
|
||||
( pVoxel1nx0py1pz) - weights[0][2][0] * ( pVoxel1nx1py1nz) -
|
||||
weights[1][2][0] * ( pVoxel1nx1py0pz) - weights[2][2][0] *
|
||||
( pVoxel1nx1py1pz) + weights[0][0][2] * ( pVoxel1px1ny1nz) +
|
||||
weights[1][0][2] * ( pVoxel1px1ny0pz) + weights[2][0][2] *
|
||||
( pVoxel1px1ny1pz) + weights[0][1][2] * ( pVoxel1px0py1nz) +
|
||||
weights[1][1][2] * ( pVoxel1px0py0pz) + weights[2][1][2] *
|
||||
( pVoxel1px0py1pz) + weights[0][2][2] * ( pVoxel1px1py1nz) +
|
||||
weights[1][2][2] * ( pVoxel1px1py0pz) + weights[2][2][2] *
|
||||
( pVoxel1px1py1pz));
|
||||
const int zGrad(- weights[0][0][0] * pVoxel1nx1ny1nz +
|
||||
weights[2][0][0] * pVoxel1nx1ny1pz - weights[0][1][0] *
|
||||
pVoxel1nx0py1nz + weights[2][1][0] * pVoxel1nx0py1pz -
|
||||
weights[0][2][0] * pVoxel1nx1py1nz + weights[2][2][0] *
|
||||
pVoxel1nx1py1pz - weights[0][0][1] * pVoxel0px1ny1nz +
|
||||
weights[2][0][1] * pVoxel0px1ny1pz - weights[0][1][1] *
|
||||
pVoxel0px0py1nz + weights[2][1][1] * pVoxel0px0py1pz -
|
||||
weights[0][2][1] * pVoxel0px1py1nz + weights[2][2][1] *
|
||||
pVoxel0px1py1pz - weights[0][0][2] * pVoxel1px1ny1nz +
|
||||
weights[2][0][2] * pVoxel1px1ny1pz - weights[0][1][2] *
|
||||
pVoxel1px0py1nz + weights[2][1][2] * pVoxel1px0py1pz -
|
||||
weights[0][2][2] * pVoxel1px1py1nz + weights[2][2][2] *
|
||||
pVoxel1px1py1pz);
|
||||
|
||||
const int yGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) -
|
||||
weights[1][0][0] * ( pVoxel1nx1ny0pz) - weights[2][0][0] *
|
||||
( pVoxel1nx1ny1pz) + weights[0][2][0] * ( pVoxel1nx1py1nz) +
|
||||
weights[1][2][0] * ( pVoxel1nx1py0pz) + weights[2][2][0] *
|
||||
( pVoxel1nx1py1pz) - weights[0][0][1] * ( pVoxel0px1ny1nz) -
|
||||
weights[1][0][1] * ( pVoxel0px1ny0pz) - weights[2][0][1] *
|
||||
( pVoxel0px1ny1pz) + weights[0][2][1] * ( pVoxel0px1py1nz) +
|
||||
weights[1][2][1] * ( pVoxel0px1py0pz) + weights[2][2][1] *
|
||||
( pVoxel0px1py1pz) - weights[0][0][2] * ( pVoxel1px1ny1nz) -
|
||||
weights[1][0][2] * ( pVoxel1px1ny0pz) - weights[2][0][2] *
|
||||
( pVoxel1px1ny1pz) + weights[0][2][2] * ( pVoxel1px1py1nz) +
|
||||
weights[1][2][2] * ( pVoxel1px1py0pz) + weights[2][2][2] *
|
||||
( pVoxel1px1py1pz));
|
||||
|
||||
const int zGrad(- weights[0][0][0] * ( pVoxel1nx1ny1nz) +
|
||||
weights[2][0][0] * ( pVoxel1nx1ny1pz) - weights[0][1][0] *
|
||||
( pVoxel1nx0py1nz) + weights[2][1][0] * ( pVoxel1nx0py1pz) -
|
||||
weights[0][2][0] * ( pVoxel1nx1py1nz) + weights[2][2][0] *
|
||||
( pVoxel1nx1py1pz) - weights[0][0][1] * ( pVoxel0px1ny1nz) +
|
||||
weights[2][0][1] * ( pVoxel0px1ny1pz) - weights[0][1][1] *
|
||||
( pVoxel0px0py1nz) + weights[2][1][1] * ( pVoxel0px0py1pz) -
|
||||
weights[0][2][1] * ( pVoxel0px1py1nz) + weights[2][2][1] *
|
||||
( pVoxel0px1py1pz) - weights[0][0][2] * ( pVoxel1px1ny1nz) +
|
||||
weights[2][0][2] * ( pVoxel1px1ny1pz) - weights[0][1][2] *
|
||||
( pVoxel1px0py1nz) + weights[2][1][2] * ( pVoxel1px0py1pz) -
|
||||
weights[0][2][2] * ( pVoxel1px1py1nz) + weights[2][2][2] *
|
||||
( pVoxel1px1py1pz));
|
||||
|
||||
return Vector3DFloat(static_cast<float>(xGrad),static_cast<float>(yGrad),static_cast<float>(zGrad));
|
||||
//Note: The above actually give gradients going from low density to high density.
|
||||
//For our normals we want the the other way around, so we switch the components as we return them.
|
||||
return Vector3DFloat(static_cast<float>(-xGrad),static_cast<float>(-yGrad),static_cast<float>(-zGrad));
|
||||
}
|
||||
}
|
||||
|
38
PolyVoxCore/include/SurfaceAdjusters.h
Normal file
38
PolyVoxCore/include/SurfaceAdjusters.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma region License
|
||||
/******************************************************************************
|
||||
This file is part of the PolyVox library
|
||||
Copyright (C) 2006 David Williams
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#ifndef __PolyVox_SurfaceAdjusters_H__
|
||||
#define __PolyVox_SurfaceAdjusters_H__
|
||||
|
||||
#pragma region Headers
|
||||
#include "Constants.h"
|
||||
#include "PolyVoxForwardDeclarations.h"
|
||||
#include "TypeDef.h"
|
||||
|
||||
#include "boost/cstdint.hpp"
|
||||
#pragma endregion
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
POLYVOX_API void smoothRegionGeometry(BlockVolume<boost::uint8_t>* volumeData, RegionGeometry& regGeom);
|
||||
}
|
||||
|
||||
#endif
|
@ -45,7 +45,6 @@ namespace PolyVox
|
||||
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 Vector3DFloat computeNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
|
||||
|
||||
POLYVOX_API void generateSmoothMeshDataForRegion(BlockVolume<boost::uint8_t>* volumeData, Region region, IndexedSurfacePatch* singleMaterialPatch);
|
||||
POLYVOX_API Vector3DFloat computeSmoothNormal(BlockVolume<boost::uint8_t>* volumeData, const Vector3DFloat& position, NormalGenerationMethod normalGenerationMethod);
|
||||
|
@ -45,6 +45,7 @@ namespace PolyVox
|
||||
void setAlpha(float alphaToSet);
|
||||
void setMaterial(float materialToSet);
|
||||
void setNormal(const Vector3DFloat& normalToSet);
|
||||
void setPosition(const Vector3DFloat& positionToSet);
|
||||
|
||||
std::string tostring(void) const;
|
||||
|
||||
|
Reference in New Issue
Block a user