2007-11-04 03:34:51 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#include "qd_skeletons.h"
|
|
|
|
#include "skeletons.h"
|
|
|
|
#include "qd_fmodel.h"
|
|
|
|
#include "angles.h"
|
|
|
|
#include "token.h"
|
|
|
|
#include "qdata.h"
|
|
|
|
#include "reference.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <memory.h>
|
|
|
|
|
|
|
|
|
|
|
|
// We're assuming no more than 16 reference points, with no more than 32 characters in the name
|
|
|
|
char RefPointNameList[REF_MAX_POINTS][REF_MAX_STRLEN];
|
2012-03-17 20:01:54 +00:00
|
|
|
int RefPointNum = 0;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
Skeletalfmheader_t g_skelModel;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void ClearSkeletalModel(){
|
2007-11-04 03:34:51 +00:00
|
|
|
g_skelModel.type = SKEL_NULL;
|
|
|
|
g_skelModel.clustered = false;
|
|
|
|
g_skelModel.references = REF_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// LoadHRCClustered
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
// Places the null terminated src string into the dest string less any trailing digits or underscores
|
2012-03-17 20:01:54 +00:00
|
|
|
void StripTrailingDigits( char *src, char *dest ){
|
2007-11-04 03:34:51 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
int max = SKELETAL_NAME_MAX; // should be sufficient for inteded use on names from hrc files
|
|
|
|
#endif
|
|
|
|
int i = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( src[i] != '\0' )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
++i;
|
|
|
|
#ifndef NDEBUG
|
2012-03-17 20:01:54 +00:00
|
|
|
assert( i < max );
|
2007-11-04 03:34:51 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( ( src[--i] >= '0' && src[i] <= '9' ) || src[i] == '_' )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
memcpy( dest, src, ++i );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
dest[i] = '\0';
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void LoadHRCClustered( char *fileName, int **clusterList, int *num_verts, int skelType ){
|
|
|
|
extern void HandleHRCModel( triangle_t **triList, int *triangleCount,
|
|
|
|
mesh_node_t **nodesList, int *num_mesh_nodes, int ActiveNode, int Depth );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
extern mesh_node_t *pmnodes;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
triangle_t *triList;
|
2012-03-17 20:01:54 +00:00
|
|
|
// mesh_node_t *nodesList;
|
2007-11-04 03:34:51 +00:00
|
|
|
int num_mesh_nodes = 0, triangleCount = 0;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
int i;
|
|
|
|
int j, numVerts;
|
|
|
|
char stripped[SKELETAL_NAME_MAX];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 1; i < numJointsInSkeleton[skelType] + 1; ++i )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
num_verts[i] = 0;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_OpenSource( fileName );
|
|
|
|
TK_FetchRequire( TK_HRCH );
|
|
|
|
TK_FetchRequire( TK_COLON );
|
|
|
|
TK_FetchRequire( TK_SOFTIMAGE );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_CLUSTERS );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( TK_Search( TK_CLUSTER_NAME ) != TK_EOF )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_STRING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
StripTrailingDigits( tk_String, stripped );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numJointsInSkeleton[skelType]; ++i )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( stricmp( stripped, skeletonJointNames[skeletonNameOffsets[skelType] + i] ) == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
i = -i + numJointsInSkeleton[skelType] - 1;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_BeyondRequire( TK_NUM_CLUSTER_VERTICES, TK_INTNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
numVerts = tk_IntNumber;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !num_verts[i + 1] ) { // first set of verts for cluster
|
|
|
|
clusterList[i] = SafeMalloc( numVerts * sizeof( int ), "LoadHRCClustered" );
|
|
|
|
assert( clusterList[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else // any later sets of verts need to copy current
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
int *temp;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
temp = SafeMalloc( ( num_verts[i + 1] + numVerts ) * sizeof( int ), "LoadHRCClustered" );
|
|
|
|
assert( temp );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
memcpy( temp + numVerts, clusterList[i], num_verts[i + 1] * sizeof( int ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
free( clusterList[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
clusterList[i] = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// currently this function is only called by LoadModelClusters.
|
2012-03-17 20:01:54 +00:00
|
|
|
// Apparently the matching free has disappeared,
|
2007-11-04 03:34:51 +00:00
|
|
|
// should probably be free at the end of FMCmd_Base
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_LBRACE );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < numVerts; ++j )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_INTNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
clusterList[i][j] = tk_IntNumber;
|
|
|
|
TK_Fetch();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
num_verts[i + 1] += numVerts;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
num_verts[0] = numJointsInSkeleton[skelType];
|
|
|
|
#endif
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#if 1 // get the index number localized to the root
|
2007-11-04 03:34:51 +00:00
|
|
|
// for( i = 1; i < numJointsInSkeleton[skelType] + 1; ++i)
|
|
|
|
// {
|
|
|
|
// g_skelModel.num_verts[i] = 0;
|
|
|
|
// }
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_OpenSource( fileName );
|
|
|
|
TK_FetchRequire( TK_HRCH );
|
|
|
|
TK_FetchRequire( TK_COLON );
|
|
|
|
TK_FetchRequire( TK_SOFTIMAGE );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// prime it
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_MODEL );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
triList = (triangle_t *) SafeMalloc( MAXTRIANGLES * sizeof( triangle_t ), "Triangle list" );
|
|
|
|
memset( triList,0,MAXTRIANGLES * sizeof( triangle_t ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
// nodesList = SafeMalloc(MAX_FM_MESH_NODES * sizeof(mesh_node_t), "Mesh Node List");
|
2012-03-17 20:01:54 +00:00
|
|
|
pmnodes = (mesh_node_t *) SafeMalloc( MAX_FM_MESH_NODES * sizeof( mesh_node_t ), "Mesh Node List" );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
memset( pmnodes, 0, MAX_FM_MESH_NODES * sizeof( mesh_node_t ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// this should eventually use a stripped down version of this
|
2012-03-17 20:01:54 +00:00
|
|
|
HandleHRCModel( &triList, &triangleCount, &pmnodes, &num_mesh_nodes, 0, 0 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// free(nodesList);
|
2012-03-17 20:01:54 +00:00
|
|
|
free( triList );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
num_verts[0] = numJointsInSkeleton[skelType];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void ReadHRCClusterList( mesh_node_t *meshNode, int baseIndex ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int i, j, numVerts;
|
|
|
|
tokenType_t nextToken;
|
|
|
|
char stripped[SKELETAL_NAME_MAX];
|
|
|
|
|
|
|
|
meshNode->clustered = true;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
nextToken = TK_Get( TK_CLUSTER_NAME );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( nextToken == TK_CLUSTER_NAME )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_STRING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
StripTrailingDigits( tk_String, stripped );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numJointsInSkeleton[g_skelModel.type]; ++i )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( stricmp( stripped, skeletonJointNames[skeletonNameOffsets[g_skelModel.type] + i] ) == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
i = -i + numJointsInSkeleton[g_skelModel.type] - 1;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_BeyondRequire( TK_NUM_CLUSTER_VERTICES, TK_INTNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
numVerts = tk_IntNumber;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !baseIndex ) {
|
|
|
|
meshNode->clusters[i] = (int *) SafeMalloc( numVerts * sizeof( int ), "ReadHRCClusterList" );
|
|
|
|
assert( meshNode->clusters[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
int *temp;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
temp = meshNode->clusters[i];
|
2012-03-17 20:01:54 +00:00
|
|
|
meshNode->clusters[i] = (int *) SafeMalloc( ( meshNode->num_verts[i + 1] + numVerts ) * sizeof( int ), "ReadHRCClusterList" );
|
|
|
|
assert( meshNode->clusters[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
memcpy( meshNode->clusters[i], temp, meshNode->num_verts[i + 1] * sizeof( int ) );
|
|
|
|
free( temp );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// currently this function is only called by LoadModelClusters.
|
2012-03-17 20:01:54 +00:00
|
|
|
// Apparently the matching free has disappeared,
|
2007-11-04 03:34:51 +00:00
|
|
|
// should probably be free at the end of FMCmd_Base
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_LBRACE );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < numVerts; ++j )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_INTNUMBER );
|
|
|
|
meshNode->clusters[i][baseIndex + j] = tk_IntNumber + baseIndex;
|
2007-11-04 03:34:51 +00:00
|
|
|
TK_Fetch();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( baseIndex ) {
|
|
|
|
meshNode->num_verts[i + 1] += numVerts;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
meshNode->num_verts[i + 1] = numVerts;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_BeyondRequire( TK_CLUSTER_STATE, TK_INTNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
nextToken = TK_Fetch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void LoadHRCGlobals( char *fileName ){
|
2007-11-04 03:34:51 +00:00
|
|
|
int i;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_OpenSource( fileName );
|
|
|
|
TK_FetchRequire( TK_HRCH );
|
|
|
|
TK_FetchRequire( TK_COLON );
|
|
|
|
TK_FetchRequire( TK_SOFTIMAGE );
|
|
|
|
TK_Beyond( TK_MODEL );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_SCALING );
|
|
|
|
for ( i = 0; i < 3; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
g_skelModel.scaling[i] = tk_FloatNumber;
|
|
|
|
TK_Fetch();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_ROTATION );
|
|
|
|
for ( i = 0; i < 3; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
g_skelModel.rotation[i] = tk_FloatNumber;
|
|
|
|
TK_Fetch();
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_TRANSLATION );
|
|
|
|
for ( i = 0; i < 3; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
g_skelModel.translation[i] = tk_FloatNumber;
|
|
|
|
TK_Fetch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void ParseVec3( vec3_t in ){
|
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[1] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[2] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[0] = tk_FloatNumber;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void ParseVec3d( vec3d_t in ){
|
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[1] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[2] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[0] = tk_FloatNumber;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void ParseRotation3( vec3_t in ){
|
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[1] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[2] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[0] = tk_FloatNumber;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void ParseRotation3d( vec3d_t in ){
|
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[1] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[2] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[0] = tk_FloatNumber;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void ParseTranslation3( vec3_t in ){
|
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[1] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[2] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[0] = tk_FloatNumber;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void ParseTranslation3d( vec3d_t in ){
|
|
|
|
TK_Require( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[1] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[2] = tk_FloatNumber;
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_FetchRequire( TK_FLOATNUMBER );
|
2007-11-04 03:34:51 +00:00
|
|
|
in[0] = tk_FloatNumber;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void LoadHRCJointList( char *fileName, QD_SkeletalJoint_t *jointList, int skelType ){
|
2007-11-04 03:34:51 +00:00
|
|
|
#define MAX_STACK 64
|
|
|
|
int i, j;
|
|
|
|
vec3d_t curTranslation[MAX_STACK], curRotation[MAX_STACK], curScale[MAX_STACK];
|
|
|
|
int curCorrespondingJoint[MAX_STACK];
|
|
|
|
int currentStack = 0, stackSize;
|
|
|
|
double cx, sx, cy, sy, cz, sz;
|
|
|
|
double rx, ry, rz;
|
|
|
|
double x2, y2, z2;
|
|
|
|
char stripped[SKELETAL_NAME_MAX];
|
|
|
|
Placement_d_t *placement;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_OpenSource( fileName );
|
|
|
|
TK_FetchRequire( TK_HRCH );
|
|
|
|
TK_FetchRequire( TK_COLON );
|
|
|
|
TK_FetchRequire( TK_SOFTIMAGE );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_MODEL );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( TK_Search( TK_NAME ) != TK_EOF )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_STRING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
StripTrailingDigits( tk_String, stripped );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( stricmp( stripped, skeletonRootNames[skeletonRNameOffsets[skelType]] ) == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( tk_Token == TK_EOF ) {
|
|
|
|
Error( "Bone Chain Root: %s not found\n", skeletonRootNames[skeletonRNameOffsets[skelType]] );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_SCALING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3d( curScale[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_ROTATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseRotation3d( curRotation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_TRANSLATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3d( curTranslation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// account for global model translation
|
|
|
|
curTranslation[currentStack][1] += g_skelModel.translation[0];
|
|
|
|
curTranslation[currentStack][2] += g_skelModel.translation[1];
|
|
|
|
curTranslation[currentStack][0] += g_skelModel.translation[2];
|
|
|
|
|
|
|
|
curCorrespondingJoint[currentStack] = -1;
|
|
|
|
|
|
|
|
++currentStack;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numJointsInSkeleton[skelType]; ++i )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( 1 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_MODEL );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_BeyondRequire( TK_NAME, TK_STRING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
StripTrailingDigits( tk_String, stripped );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( stricmp( stripped, skeletonJointNames[skeletonNameOffsets[skelType] + i] ) == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_SCALING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3d( curScale[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_ROTATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseRotation3d( curRotation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_TRANSLATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3d( curTranslation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
curCorrespondingJoint[currentStack] = -1;
|
|
|
|
|
|
|
|
++currentStack;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_SCALING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3d( curScale[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_ROTATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseRotation3d( curRotation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
jointList[i].rotation[1] = curRotation[currentStack][1];
|
|
|
|
jointList[i].rotation[2] = curRotation[currentStack][2];
|
|
|
|
jointList[i].rotation[0] = curRotation[currentStack][0];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_TRANSLATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3d( curTranslation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// jointList[i].placement.origin[1] = curTranslation[currentStack][1];
|
|
|
|
// jointList[i].placement.origin[2] = curTranslation[currentStack][2];
|
|
|
|
// jointList[i].placement.origin[0] = curTranslation[currentStack][0];
|
|
|
|
|
|
|
|
jointList[i].placement.origin[1] = 0.0;
|
|
|
|
jointList[i].placement.origin[2] = 0.0;
|
|
|
|
jointList[i].placement.origin[0] = 0.0;
|
|
|
|
|
|
|
|
jointList[i].placement.direction[1] = 20.0;
|
|
|
|
jointList[i].placement.direction[2] = 0.0;
|
|
|
|
jointList[i].placement.direction[0] = 0.0;
|
|
|
|
|
|
|
|
jointList[i].placement.up[1] = 0.0;
|
|
|
|
jointList[i].placement.up[2] = 20.0;
|
|
|
|
jointList[i].placement.up[0] = 0.0;
|
|
|
|
|
|
|
|
curCorrespondingJoint[currentStack] = i;
|
|
|
|
|
|
|
|
++currentStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
stackSize = currentStack;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// rotate the direction and up vectors to correspond to the rotation
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numJointsInSkeleton[skelType]; ++i )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
rx = jointList[i].rotation[0] * ANGLE_TO_RAD;
|
|
|
|
ry = jointList[i].rotation[1] * ANGLE_TO_RAD;
|
|
|
|
rz = jointList[i].rotation[2] * ANGLE_TO_RAD;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cx = cos( rx );
|
|
|
|
sx = sin( rx );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cy = cos( ry );
|
|
|
|
sy = sin( ry );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cz = cos( rz );
|
|
|
|
sz = sin( rz );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// y-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[i].placement.direction[0] * cy + jointList[i].placement.direction[2] * sy;
|
|
|
|
z2 = -jointList[i].placement.direction[0] * sy + jointList[i].placement.direction[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.direction[0] = x2;
|
|
|
|
jointList[i].placement.direction[2] = z2;
|
|
|
|
|
|
|
|
// y-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[i].placement.up[0] * cy + jointList[i].placement.up[2] * sy;
|
|
|
|
z2 = -jointList[i].placement.up[0] * sy + jointList[i].placement.up[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.up[0] = x2;
|
|
|
|
jointList[i].placement.up[2] = z2;
|
|
|
|
|
|
|
|
// z-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[i].placement.direction[0] * cz - jointList[i].placement.direction[1] * sz;
|
|
|
|
y2 = jointList[i].placement.direction[0] * sz + jointList[i].placement.direction[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.direction[0] = x2;
|
|
|
|
jointList[i].placement.direction[1] = y2;
|
|
|
|
|
|
|
|
// z-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[i].placement.up[0] * cz - jointList[i].placement.up[1] * sz;
|
|
|
|
y2 = jointList[i].placement.up[0] * sz + jointList[i].placement.up[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.up[0] = x2;
|
|
|
|
jointList[i].placement.up[1] = y2;
|
|
|
|
|
|
|
|
// x-axis rotation for direction vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = jointList[i].placement.direction[1] * cx - jointList[i].placement.direction[2] * sx;
|
|
|
|
z2 = jointList[i].placement.direction[1] * sx + jointList[i].placement.direction[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.direction[1] = y2;
|
|
|
|
jointList[i].placement.direction[2] = z2;
|
|
|
|
|
|
|
|
// x-axis rotation for up vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = jointList[i].placement.up[1] * cx - jointList[i].placement.up[2] * sx;
|
|
|
|
z2 = jointList[i].placement.up[1] * sx + jointList[i].placement.up[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[i].placement.up[1] = y2;
|
|
|
|
jointList[i].placement.up[2] = z2;
|
|
|
|
|
|
|
|
// translate direction to a point in the model
|
|
|
|
jointList[i].placement.direction[0] += jointList[i].placement.origin[0];
|
|
|
|
jointList[i].placement.direction[1] += jointList[i].placement.origin[1];
|
|
|
|
jointList[i].placement.direction[2] += jointList[i].placement.origin[2];
|
|
|
|
|
|
|
|
// translate up to a point in the model
|
|
|
|
jointList[i].placement.up[0] += jointList[i].placement.origin[0];
|
|
|
|
jointList[i].placement.up[1] += jointList[i].placement.origin[1];
|
|
|
|
jointList[i].placement.up[2] += jointList[i].placement.origin[2];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = stackSize - 1; i >= 0; --i )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
rx = curRotation[i][0] * ANGLE_TO_RAD;
|
|
|
|
ry = curRotation[i][1] * ANGLE_TO_RAD;
|
|
|
|
rz = curRotation[i][2] * ANGLE_TO_RAD;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cx = cos( rx );
|
|
|
|
sx = sin( rx );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cy = cos( ry );
|
|
|
|
sy = sin( ry );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cz = cos( rz );
|
|
|
|
sz = sin( rz );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
#if 1
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = i; j < stackSize; ++j )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( curCorrespondingJoint[j] != -1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
placement = &jointList[curCorrespondingJoint[j]].placement;
|
|
|
|
|
|
|
|
// y-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->origin[0] * cy + placement->origin[2] * sy;
|
|
|
|
z2 = -placement->origin[0] * sy + placement->origin[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->origin[0] = x2;
|
|
|
|
placement->origin[2] = z2;
|
|
|
|
|
|
|
|
// y-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->direction[0] * cy + placement->direction[2] * sy;
|
|
|
|
z2 = -placement->direction[0] * sy + placement->direction[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->direction[0] = x2;
|
|
|
|
placement->direction[2] = z2;
|
|
|
|
|
|
|
|
// y-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->up[0] * cy + placement->up[2] * sy;
|
|
|
|
z2 = -placement->up[0] * sy + placement->up[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->up[0] = x2;
|
|
|
|
placement->up[2] = z2;
|
|
|
|
|
|
|
|
// z-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->origin[0] * cz - placement->origin[1] * sz;
|
|
|
|
y2 = placement->origin[0] * sz + placement->origin[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->origin[0] = x2;
|
|
|
|
placement->origin[1] = y2;
|
|
|
|
|
|
|
|
// z-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->direction[0] * cz - placement->direction[1] * sz;
|
|
|
|
y2 = placement->direction[0] * sz + placement->direction[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->direction[0] = x2;
|
|
|
|
placement->direction[1] = y2;
|
|
|
|
|
|
|
|
// z-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->up[0] * cz - placement->up[1] * sz;
|
|
|
|
y2 = placement->up[0] * sz + placement->up[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->up[0] = x2;
|
|
|
|
placement->up[1] = y2;
|
|
|
|
|
|
|
|
// x-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = placement->origin[1] * cx - placement->origin[2] * sx;
|
|
|
|
z2 = placement->origin[1] * sx + placement->origin[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->origin[1] = y2;
|
|
|
|
placement->origin[2] = z2;
|
|
|
|
|
|
|
|
// x-axis rotation for direction vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = placement->direction[1] * cx - placement->direction[2] * sx;
|
|
|
|
z2 = placement->direction[1] * sx + placement->direction[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->direction[1] = y2;
|
|
|
|
placement->direction[2] = z2;
|
|
|
|
|
|
|
|
// x-axis rotation for up vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = placement->up[1] * cx - placement->up[2] * sx;
|
|
|
|
z2 = placement->up[1] * sx + placement->up[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->up[1] = y2;
|
|
|
|
placement->up[2] = z2;
|
|
|
|
|
|
|
|
// translate origin
|
|
|
|
placement->origin[0] += curTranslation[i][0];
|
|
|
|
placement->origin[1] += curTranslation[i][1];
|
|
|
|
placement->origin[2] += curTranslation[i][2];
|
|
|
|
|
|
|
|
// translate back to local coord
|
|
|
|
placement->direction[0] += curTranslation[i][0];
|
|
|
|
placement->direction[1] += curTranslation[i][1];
|
|
|
|
placement->direction[2] += curTranslation[i][2];
|
|
|
|
|
|
|
|
// translate back to local coord
|
|
|
|
placement->up[0] += curTranslation[i][0];
|
|
|
|
placement->up[1] += curTranslation[i][1];
|
|
|
|
placement->up[2] += curTranslation[i][2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
// This screwed up and needs to be sorted out!!!
|
|
|
|
// The stack info needs to be written too instead of the jointList for j > numJoints for Skeleton
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = i - 1; j < stackSize - 1; ++j )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
// y-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.origin[0] * cy + jointList[j].placement.origin[2] * sy;
|
|
|
|
z2 = -jointList[j].placement.origin[0] * sy + jointList[j].placement.origin[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.origin[0] = x2;
|
|
|
|
jointList[j].placement.origin[2] = z2;
|
|
|
|
|
|
|
|
// y-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.direction[0] * cy + jointList[j].placement.direction[2] * sy;
|
|
|
|
z2 = -jointList[j].placement.direction[0] * sy + jointList[j].placement.direction[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.direction[0] = x2;
|
|
|
|
jointList[j].placement.direction[2] = z2;
|
|
|
|
|
|
|
|
// y-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.up[0] * cy + jointList[j].placement.up[2] * sy;
|
|
|
|
z2 = -jointList[j].placement.up[0] * sy + jointList[j].placement.up[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.up[0] = x2;
|
|
|
|
jointList[j].placement.up[2] = z2;
|
|
|
|
|
|
|
|
// z-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.origin[0] * cz - jointList[j].placement.origin[1] * sz;
|
|
|
|
y2 = jointList[j].placement.origin[0] * sz + jointList[j].placement.origin[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.origin[0] = x2;
|
|
|
|
jointList[j].placement.origin[1] = y2;
|
|
|
|
|
|
|
|
// z-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.direction[0] * cz - jointList[j].placement.direction[1] * sz;
|
|
|
|
y2 = jointList[j].placement.direction[0] * sz + jointList[j].placement.direction[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.direction[0] = x2;
|
|
|
|
jointList[j].placement.direction[1] = y2;
|
|
|
|
|
|
|
|
// z-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = jointList[j].placement.up[0] * cz - jointList[j].placement.up[1] * sz;
|
|
|
|
y2 = jointList[j].placement.up[0] * sz + jointList[j].placement.up[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.up[0] = x2;
|
|
|
|
jointList[j].placement.up[1] = y2;
|
|
|
|
|
|
|
|
// x-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = jointList[j].placement.origin[1] * cx - jointList[j].placement.origin[2] * sx;
|
|
|
|
z2 = jointList[j].placement.origin[1] * sx + jointList[j].placement.origin[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.origin[1] = y2;
|
|
|
|
jointList[j].placement.origin[2] = z2;
|
|
|
|
|
|
|
|
// x-axis rotation for direction vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = jointList[j].placement.direction[1] * cx - jointList[j].placement.direction[2] * sx;
|
|
|
|
z2 = jointList[j].placement.direction[1] * sx + jointList[j].placement.direction[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.direction[1] = y2;
|
|
|
|
jointList[j].placement.direction[2] = z2;
|
|
|
|
|
|
|
|
// x-axis rotation for up vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = jointList[j].placement.up[1] * cx - jointList[j].placement.up[2] * sx;
|
|
|
|
z2 = jointList[j].placement.up[1] * sx + jointList[j].placement.up[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
jointList[j].placement.up[1] = y2;
|
|
|
|
jointList[j].placement.up[2] = z2;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( curCorrespondingJoint[j + 1] != -1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// translate origin
|
2012-03-17 20:01:54 +00:00
|
|
|
jointList[j].placement.origin[0] += curTranslation[i - 1][0];
|
|
|
|
jointList[j].placement.origin[1] += curTranslation[i - 1][1];
|
|
|
|
jointList[j].placement.origin[2] += curTranslation[i - 1][2];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// translate back to local coord
|
2012-03-17 20:01:54 +00:00
|
|
|
jointList[j].placement.direction[0] += curTranslation[i - 1][0];
|
|
|
|
jointList[j].placement.direction[1] += curTranslation[i - 1][1];
|
|
|
|
jointList[j].placement.direction[2] += curTranslation[i - 1][2];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// translate back to local coord
|
2012-03-17 20:01:54 +00:00
|
|
|
jointList[j].placement.up[0] += curTranslation[i - 1][0];
|
|
|
|
jointList[j].placement.up[1] += curTranslation[i - 1][1];
|
|
|
|
jointList[j].placement.up[2] += curTranslation[i - 1][2];
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void LoadModelTransform( char *fileName ){
|
2007-11-04 03:34:51 +00:00
|
|
|
FILE *file1;
|
2012-03-17 20:01:54 +00:00
|
|
|
int dot = '.';
|
2007-11-04 03:34:51 +00:00
|
|
|
char *dotstart;
|
2012-03-17 20:01:54 +00:00
|
|
|
char InputFileName[256];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dotstart = strrchr( fileName,dot ); // Does it already have an extension on the file name?
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !dotstart ) {
|
|
|
|
strcpy( InputFileName, fileName );
|
|
|
|
strcat( InputFileName, ".hrc" );
|
|
|
|
if ( ( file1 = fopen( InputFileName, "rb" ) ) != NULL ) {
|
|
|
|
fclose( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadHRCGlobals( InputFileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( " - assuming .HRC\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "\n Could not open file '%s':\n"
|
|
|
|
"No HRC match.\n", fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( file1 = fopen( fileName, "rb" ) ) != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// printf("\n");
|
2012-03-17 20:01:54 +00:00
|
|
|
fclose( file1 );
|
|
|
|
if ( strcmp( dotstart,".hrc" ) == 0 || strcmp( dotstart,".HRC" ) == 0 ) {
|
|
|
|
LoadHRCGlobals( fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "Could not open file '%s':\n",fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void LoadModelClusters( char *fileName, int **clusterList, int *num_verts, int skelType ){
|
2007-11-04 03:34:51 +00:00
|
|
|
FILE *file1;
|
2012-03-17 20:01:54 +00:00
|
|
|
int dot = '.';
|
2007-11-04 03:34:51 +00:00
|
|
|
char *dotstart;
|
2012-03-17 20:01:54 +00:00
|
|
|
char InputFileName[256];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dotstart = strrchr( fileName,dot ); // Does it already have an extension on the file name?
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !dotstart ) {
|
|
|
|
strcpy( InputFileName, fileName );
|
|
|
|
strcat( InputFileName, ".hrc" );
|
|
|
|
if ( ( file1 = fopen( InputFileName, "rb" ) ) != NULL ) {
|
|
|
|
fclose( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadHRCClustered( InputFileName, clusterList, num_verts, skelType );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( " - assuming .HRC\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "\n Could not open file '%s':\n"
|
|
|
|
"No HRC match.\n", fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( file1 = fopen( fileName, "rb" ) ) != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// printf("\n");
|
2012-03-17 20:01:54 +00:00
|
|
|
fclose( file1 );
|
|
|
|
if ( strcmp( dotstart,".hrc" ) == 0 || strcmp( dotstart,".HRC" ) == 0 ) {
|
|
|
|
LoadHRCClustered( fileName, clusterList, num_verts, skelType );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "Could not open file '%s':\n",fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void LoadSkeleton( char *fileName, QD_SkeletalJoint_t *jointList, int skelType ){
|
2007-11-04 03:34:51 +00:00
|
|
|
FILE *file1;
|
2012-03-17 20:01:54 +00:00
|
|
|
int dot = '.';
|
2007-11-04 03:34:51 +00:00
|
|
|
char *dotstart;
|
2012-03-17 20:01:54 +00:00
|
|
|
char InputFileName[256];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dotstart = strrchr( fileName,dot ); // Does it already have an extension on the file name?
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !dotstart ) {
|
|
|
|
strcpy( InputFileName, fileName );
|
|
|
|
strcat( InputFileName, ".hrc" );
|
|
|
|
if ( ( file1 = fopen( InputFileName, "rb" ) ) != NULL ) {
|
|
|
|
fclose( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadHRCJointList( InputFileName, jointList, skelType );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( " - assuming .HRC\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "\n Could not open file '%s':\n"
|
|
|
|
"No HRC.\n", fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( file1 = fopen( fileName, "rb" ) ) != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// printf("\n");
|
2012-03-17 20:01:54 +00:00
|
|
|
fclose( file1 );
|
|
|
|
if ( strcmp( dotstart,".hrc" ) == 0 || strcmp( dotstart,".HRC" ) == 0 ) {
|
|
|
|
LoadHRCJointList( fileName, jointList, skelType );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "Could not open file '%s':\n",fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
GrabSkeletalFrame
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void GrabSkeletalFrame( char *frame ){
|
|
|
|
char file1[1024];
|
|
|
|
char *framefile;
|
|
|
|
fmframe_t *fr;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
framefile = FindFrameFile( frame );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s", cdarchive, framefile );
|
|
|
|
ExpandPathAndArchive( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s",cddir, framefile );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "Grabbing Skeletal Frame %s\n", file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
fr = &g_frames[fmheader.num_frames - 1]; // last frame read in
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadSkeleton( file1, fr->joints, g_skelModel.type );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===============
|
|
|
|
GrabModelTransform
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
void GrabModelTransform( char *frame ){
|
|
|
|
char file1[1024];
|
|
|
|
char *framefile;
|
|
|
|
fmframe_t *fr;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
framefile = FindFrameFile( frame );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s", cdarchive, framefile );
|
|
|
|
ExpandPathAndArchive( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s",cddir, framefile );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// printf ("grabbing %s\n", file1);
|
|
|
|
|
|
|
|
fr = &g_frames[fmheader.num_frames - 1]; // last frame read in
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadModelTransform( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void Cmd_FMCluster(){
|
2007-11-04 03:34:51 +00:00
|
|
|
char file1[1024];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetScriptToken( false );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "---------------------\n" );
|
|
|
|
sprintf( file1, "%s/%s", cdpartial, token );
|
|
|
|
printf( "%s\n", file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ExpandPathAndArchive( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s", cddir, token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
g_skelModel.clustered = -1;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadModelClusters( file1, (int **)&g_skelModel.clusters, (int *)&g_skelModel.num_verts, g_skelModel.type );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
g_skelModel.new_num_verts[0] = g_skelModel.num_verts[0];
|
|
|
|
|
|
|
|
g_skelModel.clustered = true;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void Cmd_FMSkeleton(){
|
|
|
|
GetScriptToken( false );
|
|
|
|
g_skelModel.type = atoi( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void Cmd_FMSkeletalFrame(){
|
|
|
|
while ( ScriptTokenAvailable() )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
GetScriptToken( false );
|
|
|
|
if ( g_skipmodel ) {
|
|
|
|
GetScriptToken( false );
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( g_release || g_archive ) {
|
|
|
|
fmheader.num_frames = 1; // don't skip the writeout
|
|
|
|
GetScriptToken( false );
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
H_printf( "#define FRAME_%-16s\t%i\n", token, fmheader.num_frames );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GrabModelTransform( token );
|
|
|
|
GrabFrame( token );
|
|
|
|
GrabSkeletalFrame( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// need to add the up and dir points to the frame bounds here
|
|
|
|
// using AddPointToBounds (ptrivert[index_xyz].v, fr->mins, fr->maxs);
|
|
|
|
// then remove fudge in determining scale on frame write out
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
static void LoadHRCReferences( char *fileName, fmframe_t *fr ){
|
2007-11-04 03:34:51 +00:00
|
|
|
#define MAX_STACK 64
|
|
|
|
int i, j, k;
|
|
|
|
vec3d_t curTranslation[MAX_STACK], curRotation[MAX_STACK];
|
|
|
|
int curCorrespondingJoint[MAX_STACK];
|
|
|
|
int currentStack, stackSize;
|
|
|
|
double cx, sx, cy, sy, cz, sz;
|
|
|
|
double rx, ry, rz;
|
|
|
|
double x2, y2, z2;
|
|
|
|
char stripped[SKELETAL_NAME_MAX];
|
|
|
|
Placement_d_t *placement;
|
|
|
|
int refnum;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_OpenSource( fileName );
|
|
|
|
TK_FetchRequire( TK_HRCH );
|
|
|
|
TK_FetchRequire( TK_COLON );
|
|
|
|
TK_FetchRequire( TK_SOFTIMAGE );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( RefPointNum <= 0 ) { // There were no labels indicated in the QDT, so use the hard-coded stuff.
|
2007-11-04 03:34:51 +00:00
|
|
|
refnum = numReferences[g_skelModel.references];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
refnum = RefPointNum;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( k = 0; k < refnum; ++k )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
currentStack = 0;
|
|
|
|
|
|
|
|
// Load the root to get translation and initial rotation
|
|
|
|
// TK_Beyond(TK_MODEL);
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( TK_Search( TK_NAME ) != TK_EOF )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Require( TK_STRING );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
StripTrailingDigits( tk_String, stripped );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( RefPointNum == 0 ) { // Hard coded refpoint labels
|
|
|
|
if ( stricmp( stripped,
|
|
|
|
referenceRootNames[referenceRootNameOffsets[g_skelModel.references] + k] ) == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-03-17 20:01:54 +00:00
|
|
|
{ // labels indicated by the QDT
|
|
|
|
if ( stricmp( stripped, RefPointNameList[k] ) == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( tk_Token == TK_EOF ) {
|
|
|
|
if ( RefPointNum == 0 ) { // Hard coded refpoint labels
|
|
|
|
Error( "Bone Chain Root: %s not found\n", referenceRootNames[referenceRootNameOffsets[g_skelModel.references]] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
2012-03-17 20:01:54 +00:00
|
|
|
{ // labels indicated by the QDT
|
|
|
|
Error( "Bone Chain Root: %s not found\n", RefPointNameList[k] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TK_Beyond(TK_SCALING);
|
|
|
|
|
|
|
|
// ParseVec3d(curScale[currentStack]);
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_ROTATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseRotation3d( curRotation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_TRANSLATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseVec3d( curTranslation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// account for global model translation
|
|
|
|
curTranslation[currentStack][1] += g_skelModel.translation[0];
|
|
|
|
curTranslation[currentStack][2] += g_skelModel.translation[1];
|
|
|
|
curTranslation[currentStack][0] += g_skelModel.translation[2];
|
|
|
|
|
|
|
|
curCorrespondingJoint[currentStack] = -1;
|
|
|
|
|
|
|
|
// rjr - this one not needed, as there is also a stack increment 20 lines below???
|
|
|
|
// ++currentStack;
|
|
|
|
|
|
|
|
// Load the joint to get orientation
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_MODEL );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// TK_Beyond(TK_SCALING);
|
|
|
|
|
|
|
|
// ParseVec3d(curScale[currentStack]);
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
TK_Beyond( TK_ROTATION );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ParseRotation3d( curRotation[currentStack] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// TK_Beyond(TK_TRANSLATION);
|
|
|
|
|
|
|
|
// ParseVec3d(curTranslation[currentStack]);
|
|
|
|
|
|
|
|
fr->references[k].placement.origin[1] = 0.0;
|
|
|
|
fr->references[k].placement.origin[2] = 0.0;
|
|
|
|
fr->references[k].placement.origin[0] = 0.0;
|
|
|
|
|
|
|
|
fr->references[k].placement.direction[1] = 20.0;
|
|
|
|
fr->references[k].placement.direction[2] = 0.0;
|
|
|
|
fr->references[k].placement.direction[0] = 0.0;
|
|
|
|
|
|
|
|
fr->references[k].placement.up[1] = 0.0;
|
|
|
|
fr->references[k].placement.up[2] = 20.0;
|
|
|
|
fr->references[k].placement.up[0] = 0.0;
|
|
|
|
|
|
|
|
curCorrespondingJoint[currentStack] = k;
|
|
|
|
|
|
|
|
++currentStack;
|
|
|
|
|
|
|
|
stackSize = currentStack;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = stackSize - 1; i >= 0; --i )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
rx = curRotation[i][0] * ANGLE_TO_RAD;
|
|
|
|
ry = curRotation[i][1] * ANGLE_TO_RAD;
|
|
|
|
rz = curRotation[i][2] * ANGLE_TO_RAD;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cx = cos( rx );
|
|
|
|
sx = sin( rx );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cy = cos( ry );
|
|
|
|
sy = sin( ry );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
cz = cos( rz );
|
|
|
|
sz = sin( rz );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = i; j < stackSize; ++j )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( curCorrespondingJoint[j] != -1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
placement = &fr->references[curCorrespondingJoint[j]].placement;
|
|
|
|
|
|
|
|
// y-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->origin[0] * cy + placement->origin[2] * sy;
|
|
|
|
z2 = -placement->origin[0] * sy + placement->origin[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->origin[0] = x2;
|
|
|
|
placement->origin[2] = z2;
|
|
|
|
|
|
|
|
// y-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->direction[0] * cy + placement->direction[2] * sy;
|
|
|
|
z2 = -placement->direction[0] * sy + placement->direction[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->direction[0] = x2;
|
|
|
|
placement->direction[2] = z2;
|
|
|
|
|
|
|
|
// y-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->up[0] * cy + placement->up[2] * sy;
|
|
|
|
z2 = -placement->up[0] * sy + placement->up[2] * cy;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->up[0] = x2;
|
|
|
|
placement->up[2] = z2;
|
|
|
|
|
|
|
|
// z-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->origin[0] * cz - placement->origin[1] * sz;
|
|
|
|
y2 = placement->origin[0] * sz + placement->origin[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->origin[0] = x2;
|
|
|
|
placement->origin[1] = y2;
|
|
|
|
|
|
|
|
// z-axis rotation for direction
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->direction[0] * cz - placement->direction[1] * sz;
|
|
|
|
y2 = placement->direction[0] * sz + placement->direction[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->direction[0] = x2;
|
|
|
|
placement->direction[1] = y2;
|
|
|
|
|
|
|
|
// z-axis rotation for up
|
2012-03-17 20:01:54 +00:00
|
|
|
x2 = placement->up[0] * cz - placement->up[1] * sz;
|
|
|
|
y2 = placement->up[0] * sz + placement->up[1] * cz;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->up[0] = x2;
|
|
|
|
placement->up[1] = y2;
|
|
|
|
|
|
|
|
// x-axis rotation for origin
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = placement->origin[1] * cx - placement->origin[2] * sx;
|
|
|
|
z2 = placement->origin[1] * sx + placement->origin[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->origin[1] = y2;
|
|
|
|
placement->origin[2] = z2;
|
|
|
|
|
|
|
|
// x-axis rotation for direction vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = placement->direction[1] * cx - placement->direction[2] * sx;
|
|
|
|
z2 = placement->direction[1] * sx + placement->direction[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->direction[1] = y2;
|
|
|
|
placement->direction[2] = z2;
|
|
|
|
|
|
|
|
// x-axis rotation for up vector
|
2012-03-17 20:01:54 +00:00
|
|
|
y2 = placement->up[1] * cx - placement->up[2] * sx;
|
|
|
|
z2 = placement->up[1] * sx + placement->up[2] * cx;
|
2007-11-04 03:34:51 +00:00
|
|
|
placement->up[1] = y2;
|
|
|
|
placement->up[2] = z2;
|
|
|
|
|
|
|
|
// translate origin
|
|
|
|
placement->origin[0] += curTranslation[i][0];
|
|
|
|
placement->origin[1] += curTranslation[i][1];
|
|
|
|
placement->origin[2] += curTranslation[i][2];
|
|
|
|
|
|
|
|
// translate back to local coord
|
|
|
|
placement->direction[0] += curTranslation[i][0];
|
|
|
|
placement->direction[1] += curTranslation[i][1];
|
|
|
|
placement->direction[2] += curTranslation[i][2];
|
|
|
|
|
|
|
|
// translate back to local coord
|
|
|
|
placement->up[0] += curTranslation[i][0];
|
|
|
|
placement->up[1] += curTranslation[i][1];
|
|
|
|
placement->up[2] += curTranslation[i][2];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "%f, %f, %f\n", placement->origin[0], placement->origin[1], placement->origin[2] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void Cmd_FMReferenced(){
|
2007-11-04 03:34:51 +00:00
|
|
|
int i;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetScriptToken( false );
|
|
|
|
g_skelModel.references = atoi( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// Guess what? Now, we now want a list of strings to look for here instead of a hard-coded list
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < REF_MAX_POINTS; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ScriptTokenAvailable() ) { // There is yet another reference point waiting.
|
|
|
|
GetScriptToken( false );
|
|
|
|
strcpy( RefPointNameList[i], token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPointNum = i;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( RefPointNum > 0 ) {
|
|
|
|
printf( "Searching for %d different reference points.\n", RefPointNum );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "Using built-in reference points.\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void LoadReferences( char *fileName, fmframe_t *fr ){
|
2007-11-04 03:34:51 +00:00
|
|
|
FILE *file1;
|
2012-03-17 20:01:54 +00:00
|
|
|
int dot = '.';
|
2007-11-04 03:34:51 +00:00
|
|
|
char *dotstart;
|
2012-03-17 20:01:54 +00:00
|
|
|
char InputFileName[256];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
dotstart = strrchr( fileName,dot ); // Does it already have an extension on the file name?
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !dotstart ) {
|
|
|
|
strcpy( InputFileName, fileName );
|
|
|
|
strcat( InputFileName, ".hrc" );
|
|
|
|
if ( ( file1 = fopen( InputFileName, "rb" ) ) != NULL ) {
|
|
|
|
fclose( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadHRCReferences( InputFileName, fr );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( " - assuming .HRC\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "\n Could not open file '%s':\n"
|
|
|
|
"No HRC.\n", fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ( file1 = fopen( fileName, "rb" ) ) != NULL ) {
|
|
|
|
printf( "\n" );
|
|
|
|
fclose( file1 );
|
|
|
|
if ( strcmp( dotstart,".hrc" ) == 0 || strcmp( dotstart,".HRC" ) == 0 ) {
|
|
|
|
LoadHRCReferences( fileName, fr );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "Could not open file '%s':\n",fileName );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void GrabReferencedFrame( char *frame ){
|
|
|
|
char file1[1024];
|
|
|
|
char *framefile;
|
|
|
|
fmframe_t *fr;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
framefile = FindFrameFile( frame );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s", cdarchive, framefile );
|
|
|
|
ExpandPathAndArchive( file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( file1, "%s/%s",cddir, framefile );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
printf( "Grabbing Referenced %s\n", file1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
fr = &g_frames[fmheader.num_frames - 1]; // last frame read in
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadReferences( file1, fr );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|