@ -18,64 +18,17 @@
# include "export_nel.h"
# include "export_appdata.h"
# include "nel/3d/skeleton_shape.h"
# include "iskin.h"
using namespace NLMISC ;
using namespace NL3D ;
// ***************************************************************************
# define SKIN_INTERFACE 0x00010000
// ***************************************************************************
# define SKIN_CLASS_ID Class_ID(9815843,87654)
# define PHYSIQUE_CLASS_ID Class_ID(PHYSIQUE_CLASS_ID_A, PHYSIQUE_CLASS_ID_B)
// ***************************************************************************
class ISkinContextData
{
public :
virtual int GetNumPoints ( ) = 0 ;
virtual int GetNumAssignedBones ( int vertexIdx ) = 0 ;
virtual int GetAssignedBone ( int vertexIdx , int boneIdx ) = 0 ;
virtual float GetBoneWeight ( int vertexIdx , int boneIdx ) = 0 ;
virtual int GetSubCurveIndex ( int vertexIdx , int boneIdx ) = 0 ;
virtual int GetSubSegmentIndex ( int vertexIdx , int boneIdx ) = 0 ;
virtual float GetSubSegmentDistance ( int vertexIdx , int boneIdx ) = 0 ;
virtual Point3 GetTangent ( int vertexIdx , int boneIdx ) = 0 ;
virtual Point3 GetOPoint ( int vertexIdx , int boneIdx ) = 0 ;
virtual void SetWeight ( int vertexIdx , int boneIdx , float weight ) = 0 ;
virtual void SetWeight ( int vertexIdx , INode * bone , float weight ) = 0 ;
virtual void SetWeights ( int vertexIdx , Tab < int > boneIdx , Tab < float > weights ) = 0 ;
virtual void SetWeights ( int vertexIdx , INodeTab boneIdx , Tab < float > weights ) = 0 ;
} ;
// ***************************************************************************
class ISkin
{
public :
ISkin ( ) { }
~ ISkin ( ) { }
virtual int GetBoneInitTM ( INode * pNode , Matrix3 & InitTM , bool bObjOffset = false ) = 0 ;
virtual int GetSkinInitTM ( INode * pNode , Matrix3 & InitTM , bool bObjOffset = false ) = 0 ;
virtual int GetNumBones ( ) = 0 ;
virtual INode * GetBone ( int idx ) = 0 ;
virtual DWORD GetBoneProperty ( int idx ) = 0 ;
virtual ISkinContextData * GetContextInterface ( INode * pNode ) = 0 ;
virtual BOOL AddBone ( INode * bone ) = 0 ;
virtual BOOL AddBones ( INodeTab * bones ) = 0 ;
virtual BOOL RemoveBone ( INode * bone ) = 0 ;
virtual void Invalidate ( ) = 0 ;
} ;
// ***************************************************************************
void CExportNel : : buildSkeletonShape ( CSkeletonShape & skeletonShape , INode & node , mapBoneBindPos * mapBindPos , TInodePtrInt & mapId ,
TimeValue time )
{
@ -410,7 +363,8 @@ void CExportNel::buildSkeleton (std::vector<CBoneBase>& bonesArray, INode& node,
bonesArray . push_back ( bone ) ;
// **** Call on child
for ( int children = 0 ; children < node . NumberOfChildren ( ) ; children + + )
const int numChildren = node . NumberOfChildren ( ) ;
for ( int children = 0 ; children < numChildren ; children + + )
buildSkeleton ( bonesArray , * node . GetChildNode ( children ) , mapBindPos , mapId , nameSet , time , + + idCount , id ) ;
}
@ -422,7 +376,7 @@ bool CExportNel::isSkin (INode& node)
bool ok = false ;
// Get the skin modifier
Modifier * skin = getModifier ( & node , SKIN_CLASS _ ID) ;
Modifier * skin = getModifier ( & node , SKIN_CLASS ID) ;
// Found it ?
if ( skin )
@ -431,7 +385,7 @@ bool CExportNel::isSkin (INode& node)
//if (skin->IsEnabled())
{
// Get a com_skin2 interface
ISkin * comSkinInterface = ( ISkin * ) skin - > GetInterface ( SKIN_INTERFACE ) ;
ISkin * comSkinInterface = ( ISkin * ) skin - > GetInterface ( I_ SKIN) ;
// Found com_skin2 ?
if ( comSkinInterface )
@ -446,7 +400,7 @@ bool CExportNel::isSkin (INode& node)
ok = true ;
// Release the interface
skin - > ReleaseInterface ( SKIN_INTERFACE , comSkinInterface ) ;
skin - > ReleaseInterface ( I_ SKIN, comSkinInterface ) ;
}
}
}
@ -490,7 +444,7 @@ uint CExportNel::buildSkinning (CMesh::CMeshBuild& buildMesh, const TInodePtrInt
uint ok = NoError ;
// Get the skin modifier
Modifier * skin = getModifier ( & node , SKIN_CLASS _ ID) ;
Modifier * skin = getModifier ( & node , SKIN_CLASS ID) ;
// Build a the name array
buildMesh . BonesNames . resize ( skeletonShape . size ( ) ) ;
@ -513,7 +467,7 @@ uint CExportNel::buildSkinning (CMesh::CMeshBuild& buildMesh, const TInodePtrInt
// ********** COMSKIN EXPORT **********
// Get a com_skin2 interface
ISkin * comSkinInterface = ( ISkin * ) skin - > GetInterface ( SKIN_INTERFACE ) ;
ISkin * comSkinInterface = ( ISkin * ) skin - > GetInterface ( I_ SKIN) ;
// Should been controled with isSkin before.
nlassert ( comSkinInterface ) ;
@ -645,7 +599,7 @@ uint CExportNel::buildSkinning (CMesh::CMeshBuild& buildMesh, const TInodePtrInt
}
// Release the interface
skin - > ReleaseInterface ( SKIN_INTERFACE , comSkinInterface ) ;
skin - > ReleaseInterface ( I_ SKIN, comSkinInterface ) ;
}
else
{
@ -881,13 +835,13 @@ INode* CExportNel::getSkeletonRootBone (INode& node)
INode * ret = NULL ;
// Get the skin modifier
Modifier * skin = getModifier ( & node , SKIN_CLASS _ ID) ;
Modifier * skin = getModifier ( & node , SKIN_CLASS ID) ;
// Found it ?
if ( skin )
{
// Get a com_skin2 interface
ISkin * comSkinInterface = ( ISkin * ) skin - > GetInterface ( SKIN_INTERFACE ) ;
ISkin * comSkinInterface = ( ISkin * ) skin - > GetInterface ( I_ SKIN) ;
// Found com_skin2 ?
if ( comSkinInterface )
@ -921,7 +875,7 @@ INode* CExportNel::getSkeletonRootBone (INode& node)
}
// Release the interface
skin - > ReleaseInterface ( SKIN_INTERFACE , comSkinInterface ) ;
skin - > ReleaseInterface ( I_ SKIN, comSkinInterface ) ;
}
}
else
@ -961,40 +915,47 @@ INode* CExportNel::getSkeletonRootBone (INode& node)
// Get a vertex interface
IPhyVertexExport * vertexInterface = localData - > GetVertexInterface ( vtx ) ;
// Check if it is a rigid vertex or a blended vertex
int type = vertexInterface - > GetVertexType ( ) ;
if ( type = = RIGID_TYPE )
{
// this is a rigid vertex
IPhyRigidVertex * rigidInterface = ( IPhyRigidVertex * ) vertexInterface ;
// Get the bone
INode * newBone = rigidInterface - > GetNode ( ) ;
// Get the root of the hierarchy
ret = getRoot ( newBone ) ;
found = true ;
break ;
}
else
if ( vertexInterface )
{
// It must be a blendable vertex
nlassert ( type = = RIGID_BLENDED_TYPE ) ;
IPhyBlendedRigidVertex * blendedInterface = ( IPhyBlendedRigidVertex * ) vertexInterface ;
// For each bones
uint bone ;
uint count = ( uint ) blendedInterface - > GetNumberNodes ( ) ;
for ( bone = 0 ; bone < count ; bone + + )
// Check if it is a rigid vertex or a blended vertex
int type = vertexInterface - > GetVertexType ( ) ;
if ( type = = RIGID_TYPE )
{
// Get the bone pointer
INode * newBone = blendedInterface - > GetNode ( bone ) ;
// this is a rigid vertex
IPhyRigidVertex * rigidInterface = ( IPhyRigidVertex * ) vertexInterface ;
// Get the bone
INode * newBone = rigidInterface - > GetNode ( ) ;
// Get the root of the hierarchy
ret = getRoot ( newBone ) ;
found = true ;
break ;
}
else
{
// It must be a blendable vertex
nlassert ( type = = RIGID_BLENDED_TYPE ) ;
IPhyBlendedRigidVertex * blendedInterface = ( IPhyBlendedRigidVertex * ) vertexInterface ;
// For each bones
uint bone ;
uint count = ( uint ) blendedInterface - > GetNumberNodes ( ) ;
for ( bone = 0 ; bone < count ; bone + + )
{
// Get the bone pointer
INode * newBone = blendedInterface - > GetNode ( bone ) ;
// Get the root of the hierarchy
ret = getRoot ( newBone ) ;
found = true ;
break ;
}
}
}
else
{
nlwarning ( " Physique vertex interface NULL " ) ;
}
// Release vertex interfaces
@ -1030,13 +991,13 @@ void CExportNel::addSkeletonBindPos (INode& skinedNode, mapBoneBindPos& boneBind
uint ok = NoError ;
// Get the skin modifier
Modifier * skin = getModifier ( & skinedNode , SKIN_CLASS _ ID) ;
Modifier * skin = getModifier ( & skinedNode , SKIN_CLASS ID) ;
// Found it ?
if ( skin )
{
// Get a com_skin2 interface
ISkin * comSkinInterface = ( ISkin * ) skin - > GetInterface ( SKIN_INTERFACE ) ;
ISkin * comSkinInterface = ( ISkin * ) skin - > GetInterface ( I_ SKIN) ;
// Should been controled with isSkin before.
nlassert ( comSkinInterface ) ;
@ -1082,7 +1043,7 @@ void CExportNel::addSkeletonBindPos (INode& skinedNode, mapBoneBindPos& boneBind
}
// Release the interface
skin - > ReleaseInterface ( SKIN_INTERFACE , comSkinInterface ) ;
skin - > ReleaseInterface ( I_ SKIN, comSkinInterface ) ;
}
}
else
@ -1267,7 +1228,7 @@ void CExportNel::addSkeletonBindPos (INode& skinedNode, mapBoneBindPos& boneBind
}
// Release the interface
skin - > ReleaseInterface ( SKIN_INTERFACE , physiqueInterface ) ;
skin - > ReleaseInterface ( I_ SKIN, physiqueInterface ) ;
}
}
}
@ -1279,7 +1240,7 @@ void CExportNel::addSkeletonBindPos (INode& skinedNode, mapBoneBindPos& boneBind
void CExportNel : : enableSkinModifier ( INode & node , bool enable )
{
// Get the skin modifier
Modifier * skin = getModifier ( & node , SKIN_CLASS _ ID) ;
Modifier * skin = getModifier ( & node , SKIN_CLASS ID) ;
// Found it ?
if ( skin )