Skip to content

Commit

Permalink
nifmopp: add havok mass property helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tazpn314 committed Sep 7, 2008
1 parent c7ad5ba commit b42c919
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 90 deletions.
17 changes: 9 additions & 8 deletions NifMopp.def
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
EXPORTS
_GenerateMoppCode@16
_RetrieveMoppCode@8
_RetrieveMoppOrigin@4
_RetrieveMoppScale@4
GenerateMoppCode=_GenerateMoppCode@16
RetrieveMoppCode=_RetrieveMoppCode@8
RetrieveMoppOrigin=_RetrieveMoppOrigin@4
RetrieveMoppScale=_RetrieveMoppScale@4
GenerateMoppCode
RetrieveMoppCode
RetrieveMoppOrigin
RetrieveMoppScale
CalcMassPropertiesSphere
CalcMassPropertiesBox
CalcMassPropertiesCylinder
CalcMassPropertiesCapsule
CalcMassPropertiesPolyhedron

Binary file modified NifMopp.dll
Binary file not shown.
8 changes: 4 additions & 4 deletions NifMopp.rc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEVERSION 1,1,0,1
PRODUCTVERSION 1,1,0,1
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -71,12 +71,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "NIF File Format Library and Tools"
VALUE "FileDescription", "NifMopp Dynamic Link Library"
VALUE "FileVersion", "1, 0, 0, 1"
VALUE "FileVersion", "1, 1, 0, 1"
VALUE "InternalName", "NifMopp"
VALUE "LegalCopyright", "Copyright (C) 2008"
VALUE "OriginalFilename", "NifMopp.dll"
VALUE "ProductName", "NifMopp Dynamic Link Library"
VALUE "ProductVersion", "1, 0, 0, 1"
VALUE "ProductVersion", "1, 1, 0, 1"
END
END
BLOCK "VarFileInfo"
Expand Down
20 changes: 16 additions & 4 deletions NifMopp.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(ProjectDir)..\..\..\niflib\include&quot;;&quot;$(ProjectDir)Loki/include&quot;;&quot;$(ProjectDir)..\..\..\..\vendor\Havok\hk550\Source&quot;"
AdditionalIncludeDirectories="&quot;$(ProjectDir)..\..\..\..\vendor\Havok\hk550\Source&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;GENMOPP_EXPORTS;_WIN32_WINNT=0x500;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;USE_NIFLIB_TEMPLATE_HELPERS;NIFLIB_STATIC_LINK;_SCL_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
Expand All @@ -60,7 +60,7 @@
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;$(ProjectDir)..\..\..\niflib\lib&quot;;&quot;$(ProjectDir)..\..\..\..\vendor\Havok\hk550\Lib\win32_net_8-0\debug_multithreaded&quot;"
AdditionalLibraryDirectories="&quot;$(ProjectDir)..\..\..\..\vendor\Havok\hk550\Lib\win32_net_8-0\debug_multithreaded&quot;"
ModuleDefinitionFile="$(ProjectName).def"
GenerateDebugInformation="true"
SubSystem="2"
Expand Down Expand Up @@ -116,7 +116,7 @@
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;$(ProjectDir)..\..\..\niflib\include&quot;;&quot;$(ProjectDir)Loki/include&quot;;&quot;$(ProjectDir)..\..\..\..\vendor\Havok\hk550\Source&quot;"
AdditionalIncludeDirectories="&quot;$(ProjectDir)..\..\..\..\vendor\Havok\hk550\Source&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GENMOPP_EXPORTS;_WIN32_WINNT=0x500;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;USE_NIFLIB_TEMPLATE_HELPERS;NIFLIB_STATIC_LINK;_SCL_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
WarningLevel="3"
Expand All @@ -134,7 +134,7 @@
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;$(ProjectDir)..\..\..\niflib\lib&quot;;&quot;$(ProjectDir)..\..\..\..\vendor\Havok\hk550\Lib\win32_net_8-0\release_multithreaded&quot;"
AdditionalLibraryDirectories="&quot;$(ProjectDir)..\..\..\..\vendor\Havok\hk550\Lib\win32_net_8-0\release_multithreaded&quot;"
ModuleDefinitionFile="$(ProjectName).def"
GenerateDebugInformation="true"
SubSystem="2"
Expand Down Expand Up @@ -180,12 +180,24 @@
RelativePath=".\genmopp.cpp"
>
</File>
<File
RelativePath=".\inertiahelper.cpp"
>
</File>
<File
RelativePath=".\program.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\NifMopp.h"
>
</File>
<File
RelativePath=".\resource.h"
>
Expand Down
85 changes: 11 additions & 74 deletions genmopp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,7 @@
//
// ***** END LICENSE BLOCK *****

#include "obj/NiTriBasedGeom.h"
#include "obj/NiTriBasedGeomData.h"
#include "obj/NiTriShape.h"
#include "obj/NiTriStrips.h"
#include "obj/bhkRigidBody.h"
#include "obj/bhkMoppBvTreeShape.h"
#include "obj/bhkNiTriStripsShape.h"
#include "obj/NiTriStripsData.h"
#include "obj/hkPackedNiTriStripsData.h"
#include "obj/bhkPackedNiTriStripsShape.h"
#include "NifMopp.h"

//
// Math and base include
Expand Down Expand Up @@ -79,15 +70,15 @@
#pragma managed(push, off)
#endif

static hkpSimpleMeshShape* ConstructHKMesh( int nVerts, Niflib::Vector3 const* verts, int nTris, Niflib::Triangle const * tris)
static hkpSimpleMeshShape* ConstructHKMesh( int nVerts, Point3 const* verts, int nTris, Triangle const * tris)
{
hkpSimpleMeshShape * storageMeshShape = new hkpSimpleMeshShape( 0.01f );
hkArray<hkVector4> &vertices = storageMeshShape->m_vertices;
hkArray<hkpSimpleMeshShape::Triangle> &triangles = storageMeshShape->m_triangles;

triangles.setSize( 0 );
for (int i=0;i<nTris;++i) {
Niflib::Triangle const &tri = tris[i];
Triangle const &tri = tris[i];
hkpSimpleMeshShape::Triangle hktri;
hktri.m_a = tri[0];
hktri.m_b = tri[1];
Expand All @@ -97,7 +88,7 @@ static hkpSimpleMeshShape* ConstructHKMesh( int nVerts, Niflib::Vector3 const* v

vertices.setSize( 0 );
for (int i=0;i<nVerts;++i) {
Niflib::Vector3 const &vert = verts[i];
Point3 const &vert = verts[i];
vertices.pushBack( hkVector4(vert.x, vert.y, vert.z) );
}
//storageMeshShape->setRadius(1.0f);
Expand All @@ -106,60 +97,17 @@ static hkpSimpleMeshShape* ConstructHKMesh( int nVerts, Niflib::Vector3 const* v

static hkpMoppCode* k_phkpMoppCode = NULL;



static void HK_CALL errorReport(const char* msg, void*)
{
//printf("%s", msg);
}


static hkThreadMemory* threadMemory = NULL;
static char* stackBuffer = NULL;
static void InitializeHavok()
{
if ( threadMemory == NULL )
{
// Initialize the base system including our memory system
hkPoolMemory* memoryManager = new hkPoolMemory();
threadMemory = new hkThreadMemory(memoryManager, 16);
hkBaseSystem::init( memoryManager, threadMemory, errorReport );
memoryManager->removeReference();

// We now initialize the stack area to 100k (fast temporary memory to be used by the engine).
{
int stackSize = 0x100000;
stackBuffer = hkAllocate<char>( stackSize, HK_MEMORY_CLASS_BASE);
hkThreadMemory::getInstance().setStackArea( stackBuffer, stackSize);
}
}
}

static void CloseHavok()
extern void CloseHavokMopp()
{
if (k_phkpMoppCode)
{
k_phkpMoppCode->removeReference();
k_phkpMoppCode = NULL;
}

// Deallocate stack area
if (threadMemory)
{
threadMemory->setStackArea(0, 0);
hkDeallocate(stackBuffer);

threadMemory->removeReference();
threadMemory = NULL;
stackBuffer = NULL;
}

// Quit base system
hkBaseSystem::quit();
}


static int InternalGenerateCode(int nVerts, Niflib::Vector3 const* verts, int nTris, Niflib::Triangle const *tris)
static int InternalGenerateCode(int nVerts, Point3 const* verts, int nTris, Triangle const *tris)
{
int retCode = 0;
InitializeHavok();
Expand All @@ -184,8 +132,8 @@ static int InternalGenerateCode(int nVerts, Niflib::Vector3 const* verts, int nT
return k_phkpMoppCode->m_data.getSize();
}

extern "C" __declspec(dllexport)
int __stdcall GenerateMoppCode(int nVerts, Niflib::Vector3 const* verts, int nTris, Niflib::Triangle const *tris)
extern "C"
int __stdcall GenerateMoppCode(int nVerts, Point3 const* verts, int nTris, Triangle const *tris)
{
int retcode = 0;
__try
Expand All @@ -199,7 +147,7 @@ int __stdcall GenerateMoppCode(int nVerts, Niflib::Vector3 const* verts, int nTr
return retcode;
}

extern "C" __declspec(dllexport)
extern "C"
int __stdcall RetrieveMoppCode(int nBuffer, hkUint8 *buffer)
{
if ( k_phkpMoppCode == NULL )
Expand All @@ -212,7 +160,7 @@ int __stdcall RetrieveMoppCode(int nBuffer, hkUint8 *buffer)
return k_phkpMoppCode->m_data.getSize();
}

extern "C" __declspec(dllexport)
extern "C"
int __stdcall RetrieveMoppScale(float *value)
{
if ( k_phkpMoppCode == NULL )
Expand All @@ -225,7 +173,7 @@ int __stdcall RetrieveMoppScale(float *value)
return 1;
}

extern "C" __declspec(dllexport)
extern "C"
int __stdcall RetrieveMoppOrigin( float value[3] )
{
if ( k_phkpMoppCode == NULL )
Expand All @@ -240,17 +188,6 @@ int __stdcall RetrieveMoppOrigin( float value[3] )
return 1;
}

BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
if ( ul_reason_for_call == DLL_PROCESS_DETACH )
CloseHavok();
return TRUE;
}


#ifdef _MANAGED
#pragma managed(pop)
#endif
Expand Down

0 comments on commit b42c919

Please sign in to comment.