mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 08:34:40 +00:00
vhacd
added vhacd not working atm
This commit is contained in:
parent
b6f250e93c
commit
679f0ff065
5 changed files with 8513 additions and 56 deletions
|
|
@ -189,7 +189,7 @@ mark_as_advanced(PNG_PREFIX)
|
||||||
add_subdirectory(tinyxml ${TORQUE_LIB_TARG_DIRECTORY}/tinyxml EXCLUDE_FROM_ALL)
|
add_subdirectory(tinyxml ${TORQUE_LIB_TARG_DIRECTORY}/tinyxml EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(opcode ${TORQUE_LIB_TARG_DIRECTORY}/opcode EXCLUDE_FROM_ALL)
|
add_subdirectory(opcode ${TORQUE_LIB_TARG_DIRECTORY}/opcode EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(pcre ${TORQUE_LIB_TARG_DIRECTORY}/pcre EXCLUDE_FROM_ALL)
|
add_subdirectory(pcre ${TORQUE_LIB_TARG_DIRECTORY}/pcre EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(convexDecomp ${TORQUE_LIB_TARG_DIRECTORY}/convexDecomp EXCLUDE_FROM_ALL)
|
|
||||||
add_subdirectory(squish ${TORQUE_LIB_TARG_DIRECTORY}/squish EXCLUDE_FROM_ALL)
|
add_subdirectory(squish ${TORQUE_LIB_TARG_DIRECTORY}/squish EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(collada ${TORQUE_LIB_TARG_DIRECTORY}/collada EXCLUDE_FROM_ALL)
|
add_subdirectory(collada ${TORQUE_LIB_TARG_DIRECTORY}/collada EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(glad ${TORQUE_LIB_TARG_DIRECTORY}/glad EXCLUDE_FROM_ALL)
|
add_subdirectory(glad ${TORQUE_LIB_TARG_DIRECTORY}/glad EXCLUDE_FROM_ALL)
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ torqueAddSourceDirectories("gfx" "gfx/Null" "gfx/test" "gfx/bitmap" "gfx/bitmap/
|
||||||
|
|
||||||
# add the stb headers
|
# add the stb headers
|
||||||
set(TORQUE_INCLUDE_DIRECTORIES ${TORQUE_INCLUDE_DIRECTORIES} "gfx/bitmap/loaders/stb")
|
set(TORQUE_INCLUDE_DIRECTORIES ${TORQUE_INCLUDE_DIRECTORIES} "gfx/bitmap/loaders/stb")
|
||||||
|
set(TORQUE_INCLUDE_DIRECTORIES ${TORQUE_INCLUDE_DIRECTORIES} "ts/vhacd")
|
||||||
|
|
||||||
if (TORQUE_OPENGL)
|
if (TORQUE_OPENGL)
|
||||||
torqueAddSourceDirectories("gfx/gl" "gfx/gl/sdl" "gfx/gl/tGL")
|
torqueAddSourceDirectories("gfx/gl" "gfx/gl/sdl" "gfx/gl/tGL")
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||||
// IN THE SOFTWARE.
|
// IN THE SOFTWARE.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include "platform/platform.h"
|
#include "platform/platform.h"
|
||||||
|
|
||||||
#include "console/consoleTypes.h"
|
#include "console/consoleTypes.h"
|
||||||
|
|
@ -27,18 +26,12 @@
|
||||||
#include "ts/tsShapeConstruct.h"
|
#include "ts/tsShapeConstruct.h"
|
||||||
#include "console/engineAPI.h"
|
#include "console/engineAPI.h"
|
||||||
|
|
||||||
// define macros required for ConvexDecomp headers
|
|
||||||
#if defined( _WIN32 ) && !defined( WIN32 )
|
|
||||||
#define WIN32
|
|
||||||
#elif defined( __MACOSX__ ) && !defined( APPLE )
|
|
||||||
#define APPLE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "convexDecomp/NvFloatMath.h"
|
|
||||||
#include "convexDecomp/NvConvexDecomposition.h"
|
|
||||||
#include "convexDecomp/NvStanHull.h"
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define ENABLE_VHACD_IMPLEMENTATION 1
|
||||||
|
#define VHACD_DISABLE_THREADING 0
|
||||||
|
#include <VHACD.H>
|
||||||
|
|
||||||
static const Point3F sFacePlanes[] = {
|
static const Point3F sFacePlanes[] = {
|
||||||
Point3F( -1.0f, 0.0f, 0.0f ),
|
Point3F( -1.0f, 0.0f, 0.0f ),
|
||||||
Point3F( 1.0f, 0.0f, 0.0f ),
|
Point3F( 1.0f, 0.0f, 0.0f ),
|
||||||
|
|
@ -109,18 +102,18 @@ public:
|
||||||
|
|
||||||
void fitBox( U32 vertCount, const F32* verts )
|
void fitBox( U32 vertCount, const F32* verts )
|
||||||
{
|
{
|
||||||
CONVEX_DECOMPOSITION::fm_computeBestFitOBB( vertCount, verts, sizeof(F32)*3, (F32*)mBoxSides, (F32*)mBoxTransform );
|
//FLOAT_MATH::fm_computeBestFitOBB( vertCount, verts, sizeof(F32)*3, (F32*)mBoxSides, (F32*)mBoxTransform, false );
|
||||||
mBoxTransform.transpose();
|
mBoxTransform.transpose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void fitSphere( U32 vertCount, const F32* verts )
|
void fitSphere( U32 vertCount, const F32* verts )
|
||||||
{
|
{
|
||||||
mSphereRadius = CONVEX_DECOMPOSITION::fm_computeBestFitSphere( vertCount, verts, sizeof(F32)*3, (F32*)mSphereCenter );
|
//mSphereRadius = FLOAT_MATH::fm_computeBestFitSphere( vertCount, verts, sizeof(F32)*3, (F32*)mSphereCenter );
|
||||||
}
|
}
|
||||||
|
|
||||||
void fitCapsule( U32 vertCount, const F32* verts )
|
void fitCapsule( U32 vertCount, const F32* verts )
|
||||||
{
|
{
|
||||||
CONVEX_DECOMPOSITION::fm_computeBestFitCapsule( vertCount, verts, sizeof(F32)*3, mCapRadius, mCapHeight, (F32*)mCapTransform );
|
//FLOAT_MATH::fm_computeBestFitCapsule( vertCount, verts, sizeof(F32)*3, mCapRadius, mCapHeight, (F32*)mCapTransform );
|
||||||
mCapTransform.transpose();
|
mCapTransform.transpose();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -572,6 +565,7 @@ void MeshFit::fitK_DOP( const Vector<Point3F>& planes )
|
||||||
// Collect the intersection points of any 3 planes that lie inside
|
// Collect the intersection points of any 3 planes that lie inside
|
||||||
// the maximum distances found above
|
// the maximum distances found above
|
||||||
Vector<Point3F> points;
|
Vector<Point3F> points;
|
||||||
|
Vector<U32> pointIndices;
|
||||||
for ( S32 i = 0; i < planes.size()-2; i++ )
|
for ( S32 i = 0; i < planes.size()-2; i++ )
|
||||||
{
|
{
|
||||||
for ( S32 j = i+1; j < planes.size()-1; j++ )
|
for ( S32 j = i+1; j < planes.size()-1; j++ )
|
||||||
|
|
@ -599,32 +593,48 @@ void MeshFit::fitK_DOP( const Vector<Point3F>& planes )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( addPoint )
|
if (addPoint)
|
||||||
points.push_back( p );
|
{
|
||||||
|
points.push_back(p);
|
||||||
|
pointIndices.push_back(points.size() - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a convex hull from the point set
|
VHACD::IVHACD::Parameters p;
|
||||||
CONVEX_DECOMPOSITION::HullDesc hd;
|
p.m_fillMode = VHACD::FillMode::FLOOD_FILL;
|
||||||
hd.mVcount = points.size();
|
p.m_maxNumVerticesPerCH = 64;
|
||||||
hd.mVertices = (F32*)points.address();
|
p.m_shrinkWrap = true;
|
||||||
hd.mVertexStride = sizeof(Point3F);
|
p.m_maxRecursionDepth = 64;
|
||||||
hd.mMaxVertices = 64;
|
p.m_minimumVolumePercentErrorAllowed = 10;
|
||||||
hd.mSkinWidth = 0.0f;
|
p.m_resolution = 10000;
|
||||||
|
p.m_maxConvexHulls = 1;
|
||||||
|
|
||||||
CONVEX_DECOMPOSITION::HullLibrary hl;
|
VHACD::IVHACD* iface = VHACD::CreateVHACD();
|
||||||
CONVEX_DECOMPOSITION::HullResult result;
|
|
||||||
hl.CreateConvexHull( hd, result );
|
iface->Compute((F32*)points.address(), points.size(), (U32*)pointIndices.address(), pointIndices.size(), p);
|
||||||
|
|
||||||
|
// safety loop.
|
||||||
|
while (!iface->IsReady())
|
||||||
|
{
|
||||||
|
Platform::sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// we only get the 1 in dop?
|
||||||
|
VHACD::IVHACD::ConvexHull ch;
|
||||||
|
iface->GetConvexHull(0, ch);
|
||||||
|
|
||||||
// Create TSMesh from convex hull
|
// Create TSMesh from convex hull
|
||||||
mMeshes.increment();
|
mMeshes.increment();
|
||||||
MeshFit::Mesh& lastMesh = mMeshes.last();
|
MeshFit::Mesh& lastMesh = mMeshes.last();
|
||||||
lastMesh.type = MeshFit::Hull;
|
lastMesh.type = MeshFit::Hull;
|
||||||
lastMesh.transform.identity();
|
lastMesh.transform.identity();
|
||||||
lastMesh.tsmesh = createTriMesh(result.mOutputVertices, result.mNumOutputVertices,
|
lastMesh.tsmesh = createTriMesh((F32*)&ch.m_points, ch.m_points.size(),
|
||||||
result.mIndices, result.mNumFaces );
|
(U32*)&ch.m_triangles, ch.m_triangles.size());
|
||||||
lastMesh.tsmesh->computeBounds();
|
lastMesh.tsmesh->computeBounds();
|
||||||
|
|
||||||
|
iface->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------
|
//---------------------------
|
||||||
|
|
@ -635,31 +645,30 @@ void MeshFit::fitConvexHulls( U32 depth, F32 mergeThreshold, F32 concavityThresh
|
||||||
const F32 SkinWidth = 0.0f;
|
const F32 SkinWidth = 0.0f;
|
||||||
const F32 SplitThreshold = 2.0f;
|
const F32 SplitThreshold = 2.0f;
|
||||||
|
|
||||||
CONVEX_DECOMPOSITION::iConvexDecomposition *ic = CONVEX_DECOMPOSITION::createConvexDecomposition();
|
VHACD::IVHACD::Parameters p;
|
||||||
|
p.m_fillMode = VHACD::FillMode::FLOOD_FILL;
|
||||||
|
p.m_maxNumVerticesPerCH = maxHullVerts;
|
||||||
|
p.m_shrinkWrap = true;
|
||||||
|
p.m_maxRecursionDepth = 64;
|
||||||
|
p.m_minimumVolumePercentErrorAllowed = 10;
|
||||||
|
p.m_resolution = 10000;
|
||||||
|
p.m_maxConvexHulls = depth;
|
||||||
|
|
||||||
for ( S32 i = 0; i < mIndices.size(); i += 3 )
|
VHACD::IVHACD* iface = VHACD::CreateVHACD();
|
||||||
|
|
||||||
|
iface->Compute((F32*)mVerts.address(), mVerts.size(), (U32*)mIndices.address(), mIndices.size(), p);
|
||||||
|
|
||||||
|
// safety loop.
|
||||||
|
while (!iface->IsReady())
|
||||||
{
|
{
|
||||||
ic->addTriangle( (F32*)mVerts[mIndices[i]],
|
Platform::sleep(1000);
|
||||||
(F32*)mVerts[mIndices[i+1]],
|
|
||||||
(F32*)mVerts[mIndices[i+2]] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ic->computeConvexDecomposition(
|
|
||||||
SkinWidth,
|
|
||||||
depth,
|
|
||||||
maxHullVerts,
|
|
||||||
concavityThreshold,
|
|
||||||
mergeThreshold,
|
|
||||||
SplitThreshold,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
false );
|
|
||||||
|
|
||||||
// Add a TSMesh for each hull
|
// Add a TSMesh for each hull
|
||||||
for ( S32 i = 0; i < ic->getHullCount(); i++ )
|
for ( S32 i = 0; i < iface->GetNConvexHulls(); i++ )
|
||||||
{
|
{
|
||||||
CONVEX_DECOMPOSITION::ConvexHullResult result;
|
VHACD::IVHACD::ConvexHull ch;
|
||||||
ic->getConvexHullResult( i, result );
|
iface->GetConvexHull(i, ch);
|
||||||
|
|
||||||
eMeshType meshType = MeshFit::Hull;
|
eMeshType meshType = MeshFit::Hull;
|
||||||
|
|
||||||
|
|
@ -667,23 +676,23 @@ void MeshFit::fitConvexHulls( U32 depth, F32 mergeThreshold, F32 concavityThresh
|
||||||
if (( boxMaxError > 0 ) || ( sphereMaxError > 0 ) || ( capsuleMaxError > 0 ))
|
if (( boxMaxError > 0 ) || ( sphereMaxError > 0 ) || ( capsuleMaxError > 0 ))
|
||||||
{
|
{
|
||||||
// Compute error between actual mesh and fitted primitives
|
// Compute error between actual mesh and fitted primitives
|
||||||
F32 meshVolume = CONVEX_DECOMPOSITION::fm_computeMeshVolume( result.mVertices, result.mTcount, result.mIndices );
|
F32 meshVolume = 10.0f; // FLOAT_MATH::fm_computeMeshVolume((F32*)&ch.m_points, ch.m_triangles.size(), (U32*)&ch.m_triangles);
|
||||||
PrimFit primFitter;
|
PrimFit primFitter;
|
||||||
|
|
||||||
F32 boxError = 100.0f, sphereError = 100.0f, capsuleError = 100.0f;
|
F32 boxError = 100.0f, sphereError = 100.0f, capsuleError = 100.0f;
|
||||||
if ( boxMaxError > 0 )
|
if ( boxMaxError > 0 )
|
||||||
{
|
{
|
||||||
primFitter.fitBox( result.mVcount, result.mVertices );
|
primFitter.fitBox(ch.m_points.size(), (F32*)&ch.m_points);
|
||||||
boxError = 100.0f * ( 1.0f - ( meshVolume / primFitter.getBoxVolume() ) );
|
boxError = 100.0f * ( 1.0f - ( meshVolume / primFitter.getBoxVolume() ) );
|
||||||
}
|
}
|
||||||
if ( sphereMaxError > 0 )
|
if ( sphereMaxError > 0 )
|
||||||
{
|
{
|
||||||
primFitter.fitSphere( result.mVcount, result.mVertices );
|
primFitter.fitSphere(ch.m_points.size(), (F32*)&ch.m_points);
|
||||||
sphereError = 100.0f * ( 1.0f - ( meshVolume / primFitter.getSphereVolume() ) );
|
sphereError = 100.0f * ( 1.0f - ( meshVolume / primFitter.getSphereVolume() ) );
|
||||||
}
|
}
|
||||||
if ( capsuleMaxError > 0 )
|
if ( capsuleMaxError > 0 )
|
||||||
{
|
{
|
||||||
primFitter.fitCapsule( result.mVcount, result.mVertices );
|
primFitter.fitCapsule(ch.m_points.size(), (F32*)&ch.m_points);
|
||||||
capsuleError = 100.0f * ( 1.0f - ( meshVolume / primFitter.getCapsuleVolume() ) );
|
capsuleError = 100.0f * ( 1.0f - ( meshVolume / primFitter.getCapsuleVolume() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -722,12 +731,12 @@ void MeshFit::fitConvexHulls( U32 depth, F32 mergeThreshold, F32 concavityThresh
|
||||||
MeshFit::Mesh& lastMesh = mMeshes.last();
|
MeshFit::Mesh& lastMesh = mMeshes.last();
|
||||||
lastMesh.type = MeshFit::Hull;
|
lastMesh.type = MeshFit::Hull;
|
||||||
lastMesh.transform.identity();
|
lastMesh.transform.identity();
|
||||||
lastMesh.tsmesh = createTriMesh(result.mVertices, result.mVcount, result.mIndices, result.mTcount);
|
lastMesh.tsmesh = createTriMesh((F32*)&ch.m_points, ch.m_points.size(), (U32*)&ch.m_triangles, ch.m_triangles.size());
|
||||||
lastMesh.tsmesh->computeBounds();
|
lastMesh.tsmesh->computeBounds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CONVEX_DECOMPOSITION::releaseConvexDecomposition( ic );
|
iface->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
8447
Engine/source/ts/vhacd/VHACD.h
Normal file
8447
Engine/source/ts/vhacd/VHACD.h
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -15,7 +15,7 @@ set(TORQUE_COMPILE_DEFINITIONS ICE_NO_DLL PCRE_STATIC TORQUE_ADVANCED_LIGHTING T
|
||||||
|
|
||||||
# All link libraries. Modules should append to this the path to specify additional link libraries (.a, .lib, .dylib, .so)
|
# All link libraries. Modules should append to this the path to specify additional link libraries (.a, .lib, .dylib, .so)
|
||||||
set(TORQUE_LINK_LIBRARIES tinyxml collada squish opcode assimp FLAC FLAC++ ogg vorbis
|
set(TORQUE_LINK_LIBRARIES tinyxml collada squish opcode assimp FLAC FLAC++ ogg vorbis
|
||||||
vorbisfile vorbisenc opus sndfile SDL2 glad pcre convexDecomp zlib)
|
vorbisfile vorbisenc opus sndfile SDL2 glad pcre zlib)
|
||||||
|
|
||||||
if(TORQUE_TESTING)
|
if(TORQUE_TESTING)
|
||||||
set(TORQUE_LINK_LIBRARIES ${TORQUE_LINK_LIBRARIES} gtest gmock)
|
set(TORQUE_LINK_LIBRARIES ${TORQUE_LINK_LIBRARIES} gtest gmock)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue