~cpp
// static function
/*
Func - LoadAse
Desc - ��������� Ase ��������� ������������고 그 ��������� ������ ������계��������� ��������� ������������ ������ ������계��� ������������
각 ������������ ��������� ������ ��������� ������계��� 기��������� ��������� ������계��� ������������������ ��������������� ������������.( -> AniTM)
*/
bool CHS_GObject::LoadAse (char* filename)
{
FILE *s;
DWORD max_time = 0;
bool bResult;
if (!(s = fopen (filename, "r"))) {
char ds[255];
sprintf (ds, "# %s not found\n", filename);
OutputDebugString (ds);
return false;
}
else
bResult = GetAseAllInfo (s);
// 0��� ��������� ��������� ������ ������������ �����
pNodeList [0]->bIsSkinModel = TRUE;
// ��������� ��������� ������.
for (int i=0; i<nNodeNum; i++)
{
//pNodeList [i]->ModelAlloc ();
aseAllocate2CHS_Model (pNodeList [i]);
}
// ��������������� ������ ������ -----------------------------------------------
// : ������ ������������ ������ 구������������������ ������������ ������ ������.
for (int i1=0; i1<nNodeNum; i1++)
{
if (strcmp (pNodeList [i1]->ParentName, "")) {
for (int i2=0; i2<nNodeNum; i2++)
{
if (pNodeList [i1] != pNodeList [i2] &&
!strcmp (pNodeList [i1]->ParentName, pNodeList [i2]->Name))
{
pNodeList [i1]->SetParent (pNodeList [i2]); // ���������게 �������� ���구������ ������
pNodeList [i2]->AddChildNum (); // ��������� ��������� ������������ 1 ������
CHS_Model** pChildTmp = pNodeList [i2]->GetChildPointer (); // ������ ������
CHS_Model** pDest = new CHS_Model* [pNodeList [i2]->GetChildNum ()]; // ��� ��������� ������
memcpy (pDest, pChildTmp, sizeof (CHS_Model*) * (pNodeList [i2]->GetChildNum ()-1)); // ������
pDest[pNodeList [i2]->GetChildNum ()-1] = pNodeList [i1]; // ���������게 �������� ��� ������ ������
pNodeList [i2]->SetChildPointer (pDest); // ��� ������������ ������ ������������ ������
delete [] pChildTmp; // ������ ������ ������ ������
}
}
}
}
// ������ ��������� ���기 ---------------------------------------------------
CHS_GObject::GetAseAllData (s, &max_time);
// ��������� wcs -> lcs��� ������ -------------------------------------------
// ani_tm ������ update -------------------------------------------------
for (i=0; i<nNodeNum; i++) {
pNodeList[i]->InitObject (0);
if (i!=0) pNodeList[i]->MulMatInverse (FALSE);
// pNodeList[i]->MulMatInverse (FALSE);
pNodeList[i]->UpdateAniTM (FALSE);
// BoundingVolumn 계���
pNodeList[i]->CreateVolumn (pNodeList[i]->verts, pNodeList[i]->numVertex);
}
// ��������� ��������� ���기 -------------------------------------------------
// : ���구���
// ������ ������ ��������� 갱��� ----------------------------------------------
// : ������ ��������� �����고 ������ ������������ ���������.
// StlLink* pRL = &(s_RootList);
// for(StlListItor itorAll = pSL->begin (); itorAll!= pSL->end (); ++itorAll) {
for (i=0; i<nNodeNum; i++) {
CHS_Model* pTmp = pNodeList[i];
if (!strcmp(pTmp->ParentName, "")) {
//pRL->push_back ((void*)pTmp);
pTmp->SetTimeSkip (800);
pTmp->SetMaxTime (max_time);
pRootList [nRootNum] = pTmp;
nRootNum++;
char debug_buf[255];
sprintf (debug_buf,"\n#ROOT NODE: %s", pTmp->Name);
OutputDebugString (debug_buf);
}
}
fclose (s);
return true;
}
// static function
// ��������� ������ ������ ��� ������ ��������� 계���������.
// ������값: ��������� ��������� ���������
void CHS_GObject::UpdatePickedPoint (int &cl_x, int &cl_y, int &width, int &height)
{
// ������ 계���
PickedPoint [0][0] = float(cl_x)*2.0f/float(width) - 1.0f;
PickedPoint [0][1] = float(cl_y)*2.0f/float(height) - 1.0f;
PickedPoint [0][1] = -PickedPoint [0][1];
PickedPoint [0][2] = 5.0f;
mat44_t mat_mv, inv_mat_mv;
glGetFloatv (GL_PROJECTION_MATRIX, mat_mv);
matrix44_inverse (inv_mat_mv, mat_mv);
vectorCopy (PickedPoint[0], PickedPoint[1]);
PickedPoint[1][2] -= 10.0;
matrixMultiplyVector3 (inv_mat_mv, PickedPoint[0]);
matrixMultiplyVector3 (inv_mat_mv, PickedPoint[1]);
}
// static function
// s_AllList������ ������ ��������� ������������.
void CHS_GObject::ReleaseModels ()
{
/*
StlLink* pSL = &(CHS_GObject::s_AllList);
for(StlListItor itor=pSL->begin (); itor!=pSL->end ();++itor) {
delete (*itor);
itor = pSL->erase(itor);
}
*/
for (int i=0; i<nNodeNum; i++)
{
delete pNodeList[i];
}
}
// static function
bool CHS_GObject::GetAseAllInfo (FILE *s)
{
char data[255];
rewind (s); //������������������ ��� ���������..
CHS_Model* pM;
while (!feof (s)) //������ ������������ ������������ check!
{
fscanf (s, "%s", &data);
if (!strcmp (data, OBJECT_BEGIN))
{
pM = new CHS_Model;
//pLink->AddTail(pModel);
//CHS_GObject::s_AllList.push_back ((void*)pM);
pNodeList [nNodeNum] = pM;
nNodeNum++;
}
else if (!strcmp (data, OBJECT_NAME))
{ // ���기 ������ ������
char temp[128];
int c_index = 0;
while (fgetc (s) != '"') {}
while (1) {
temp [c_index++] = (char) fgetc (s);
if (temp [c_index-1] == '"') {
temp [c_index-1] = '\0';
break;
}
}
memcpy (pM->Name, temp, strlen(temp));
}
else if (!strcmp (data, OBJECT_PARENT))
{ // ������ ������ ������
char temp[128];
int c_index = 0;
while (fgetc (s) != '"') {}
while (1) {
temp [c_index++] = (char) fgetc (s);
if (temp [c_index-1] == '"') {
temp [c_index-1] = '\0';
break;
}
}
memcpy (pM->ParentName, temp, strlen(temp));
}
else if (!strcmp (data, OBJECT_POS))
{
// ������������ ascii export plug in��� ������������ 경���
// ��� pos 값��� ������ ��������� 계��������� ������������. *MESH��� ������������ vertex ������������
// ������ ������ ������������������������. ������ 각각��� ��������� Translate ��� Rotate���
// ��� ��������� ���������.
fscanf (s, "%f %f %f", &pM->Pos[0]
, &pM->Pos[2]
, &pM->Pos[1]);
pM->Pos[2] = -pM->Pos[2];
}
else if (!strcmp (data, OBJECT_ROTAXIS))
{
fscanf (s, "%f %f %f", &pM->Axis[0]
, &pM->Axis[2]
, &pM->Axis[1]);
pM->Axis[2] = -pM->Axis[2];
}
else if (!strcmp (data, OBJECT_ROTANGLE)) {
vec_t x;
fscanf (s, "%f", &x);
// pM->Angle = -x;
pM->Angle = x;
matrix_t tmp_trans, tmp_rot;
matrixIdentity (tmp_trans);
matrixIdentity (tmp_rot);
matrixIdentity (pM->tm);
matrixTranslate (tmp_trans, pM->Pos);
AngleAxis2Matrix (tmp_rot, pM->Axis, pM->Angle);
matrixMultiply (tmp_rot, tmp_trans, pM->tm);
matrix44_inverse (pM->inv_tm, pM->tm);
}
else if (!strcmp (data, OBJECT_ROW0))
{
fscanf (s, "%f %f %f", &pM->tm[0]
, &pM->tm[2]
, &pM->tm[1]);
pM->tm[2] = -pM->tm[2];
pM->tm[3] = 0.0f;
}
else if (!strcmp (data, OBJECT_ROW1))
{
fscanf (s, "%f %f %f", &pM->tm[8]
, &pM->tm[10]
, &pM->tm[9]);
pM->tm[10] = -pM->tm[10];
pM->tm[11] = 0.0f;
}
else if (!strcmp (data, OBJECT_ROW2))
{
fscanf (s, "%f %f %f", &pM->tm[4]
, &pM->tm[6]
, &pM->tm[5]);
pM->tm[6] = -pM->tm[6];
pM->tm[7] = 0.0f;
}
else if (!strcmp (data, OBJECT_ROW3))
{
fscanf (s, "%f %f %f", &pM->tm[12]
, &pM->tm[14]
, &pM->tm[13]);
pM->tm[14] = -pM->tm[14];
pM->tm[15] = 1.0f;
// matrix44_inverse (pM->inv_tm, pM->tm);
}
else if (!strcmp (data, NUM_VERTEX))
fscanf (s, "%d", &pM->numVertex);
else if (!strcmp (data, NUM_FACES))
fscanf (s, "%d", &pM->numFaces);
else if (!strcmp (data, NUM_TVERTEX)) //texture mapped vertex?
{
fscanf (s, "%d", &pM->numTexVertex);
pM->bTexture_on = 1; //������ ��������� ��������������� ��������������� ������객������ ��������� ������그 ���
}
else if (!strcmp (data, NUM_TFACES)) //texture mapped face?
fscanf (s, "%d", &pM->numTexFaces);
else if (!strcmp (data, NUM_TEXTURE))
{
// ������ ��������� ������ ��������� ������
/*
int n = (int) aseGetFloatVal(s);
pTex = new char*[n]; //pTex ��� ������ ���������
app_con.numTex = n;
*/
}
else if (!strcmp (data, NORMALS))
pM->bNormals = true;
else if (!strcmp (data, TEXTURE))
{
// ������ ��������� ������ ��������� ������
/*
aseGetTextureName1 (s);
*/
}
else if (!strcmp (data, OBJECT_ANI))
{ // rotate sample��� ������������ ������.
//pM->bRotKey = TRUE;
}
else if (!strcmp (data, OBJECT_ROT_EXIST))
{
pM->bRotKey = TRUE;
}
else if (!strcmp (data, OBJECT_POS_EXIST))
{
pM->bPosKey = TRUE;
}
else if (!strcmp (data, OBJECT_ROT_SAMPLE))
{
// pM->AddKeyNum (); // == pM->keyNum++
pM->rotkeyNum++;
}
else if (!strcmp (data, OBJECT_POS_SAMPLE))
{
pM->poskeyNum++;
}
else
fgets (data, sizeof (data), s);
}
// 각각��� ������ ������������ PV��� 개��� count
rewind (s);
while (!feof (s)) //������ ������������ ������������ check!
{
int x;
vec_t w;
char tmp_name[255];
char name[255];
fscanf (s, "%s", &data);
if (!strcmp (data, PV_NONBLEND)) {
fscanf (s, "%d ", &x);
int c_index = 0;
while (fgetc (s) != '"') {}
while (1) {
tmp_name [c_index++] = (char) fgetc (s);
if (tmp_name [c_index-1] == '"') {
tmp_name [c_index-1] = '\0';
break;
}
}
memcpy (name, tmp_name, strlen(tmp_name)+1);
for (int i=0;i<nNodeNum;i++) {
if (!strcmp (pNodeList [i]->Name, name))
pNodeList [i]->GetPSQInfo()->nPVertexCount++;
}
}
else if (!strcmp (data, PV_BLEND_ASSIGN)) {
fscanf (s, "%d %f ", &x, &w);
int c_index = 0;
while (fgetc (s) != '"') {}
while (1) {
tmp_name [c_index++] = (char) fgetc (s);
if (tmp_name [c_index-1] == '"') {
tmp_name [c_index-1] = '\0';
break;
}
}
memcpy (name, tmp_name, strlen(tmp_name)+1);
for (int i=0;i<nNodeNum;i++) {
if (!strcmp (pNodeList [i]->Name, name))
pNodeList [i]->GetPSQInfo()->nPVertexCount++;
}
}
else
fgets (data, sizeof (data), s);
}
// ������ ��� ������
for (int i=0;i<nNodeNum;i++) {
pNodeList [i]->SetKeyNum (1);
if (!pNodeList [i]->bPosKey)
pNodeList [i]->poskeyNum = 1;
if (!pNodeList [i]->bRotKey)
pNodeList [i]->rotkeyNum = 1;
if (pNodeList [i]->rotkeyNum > 1)
pNodeList [i]->SetKeyNum (pNodeList [i]->rotkeyNum);
if (pNodeList [i]->poskeyNum > pNodeList [i]->rotkeyNum)
pNodeList [i]->SetKeyNum (pNodeList [i]->poskeyNum);
}
return true;
}
// ��������� ��������� ������.
void CHS_GObject::ModelAlloc (CHS_GObject* pO)
{
}
// static
vec_t CHS_GObject::GetFloatVal (FILE *s)
{
vec_t v;
fscanf (s, " %f", &v);
return v;
}
// ��������� ������ ������ ������
void CHS_GObject::GetAseAllData (FILE *s, DWORD *max_time)
{
char data[255];
int count = 0;
int pv_count[50] = {0,};
int nBlendAssignIndex;
CHS_Model* pM = 0;
// StlListItor itor = s_AllList.begin ();
// pM = (CHS_Model*)*itor;
pM = pNodeList[0];
rewind (s);
while (!feof (s))
{
fscanf (s, "%s", &data);
if (strcmp (data, OBJECT_BEGIN) == 0)
{
if (count == 0)
//itor = CHS_GObject::s_AllList.begin ();
pM = pNodeList [0];
else
//itor++;
pM = pNodeList [count];
count++;
//pM = (CHS_Model*)*itor;
}
else if (strcmp (data, VERTEX) == 0)
{
//CHS_GObject::GetVertex (s, pM);
int index;
fscanf (s, "%d", &index);
// swap y and z cause 3dsm likes too
fscanf (s, "%f %f %f",
&pM->verts[index][0],
&pM->verts[index][2],
&pM->verts[index][1]);
// in 3dsm negative z goes out of the screen, we want it to go in
pM->verts[index][2] = -(pM->verts[index][2]);
}
else if (strcmp (data, TVERTEX) == 0)
{
//CHS_GObject::GetTVertex (s, pM);
int index;
fscanf (s, "%d", &index);
fscanf (s, "%f %f", &pM->texVerts[index][0], &pM->texVerts[index][1]);
}
else if (strcmp (data, NVERTEX) == 0)
{
//CHS_GObject::GetNVertex (s, pM);
int index;
fscanf (s, "%d", &index);
fscanf (s, "%f %f %f",
&pM->vertNorms[index][0],
&pM->vertNorms[index][2],
&pM->vertNorms[index][1]);
pM->vertNorms[index][2] = -pM->vertNorms[index][2];
}
else if (strcmp (data, FACE_NORMAL) == 0)
{
//CHS_GObject::GetFaceNormal (s, pM);
int index;
fscanf (s, "%d", &index);
fscanf (s, "%f %f %f",
&pM->faces[index].normal[0],
&pM->faces[index].normal[2],
&pM->faces[index].normal[1]);
pM->faces[index].normal[2] = -pM->faces[index].normal[2];
}
else if (strcmp (data, FACE) == 0)
{
//CHS_GObject::GetFace (s, pM);
int index;
fscanf (s, "%d:", &index);
fscanf (s, "\tA:\t%d B:\t%d C:\t%d",
&pM->faces[index].vertIndex[0],
&pM->faces[index].vertIndex[1],
&pM->faces[index].vertIndex[2]);
/* &pM->faces[index].vertIndex[2],
&pM->faces[index].vertIndex[1]);*/
}
else if (strcmp (data, TFACE) == 0)
{
//CHS_GObject::GetTFace (s, pM);
int index;
fscanf (s, "%d:", &index);
fscanf (s, "%d %d %d",
&pM->faces[index].coordIndex[0],
&pM->faces[index].coordIndex[1],
&pM->faces[index].coordIndex[2]);
}
/*
else if (strcmp (data, TEXTURE) == 0)
{
aseGetTextureName (s, p); //������t 구��������� ����������� ��������� ��������� ������x
//textureLink ��� ���거������ ������ ������
}
*/
else if (!strcmp (data, OBJECT_ROT_SAMPLE))
{
// animation - rotate sampling
static int nTmpCount = 0;
vec3_t v;
vec_t t;
// ��������� angular displacement?? ��� ������������ �����..
// fscanf (s, "%d", &(pM->pRotKey[nTmpCount].time)); fgetchar ();
// fscanf (s, "%f", &v[0]); fgetchar ();
// fscanf (s, "%f", &v[2]); fgetchar ();
// fscanf (s, "%f", &v[1]); fgetchar ();
// fscanf (s, "%f", &t);
fscanf (s, "%d", &(pM->pRotKey[nTmpCount].time)); fgetchar ();
fscanf (s, "%f", &v[0]); fgetchar ();
fscanf (s, "%f", &v[2]); fgetchar ();
fscanf (s, "%f", &v[1]); fgetchar ();
fscanf (s, "%f", &t);
// max_time 값 ������������
if (pM->pRotKey[nTmpCount].time > *max_time) *max_time = pM->pRotKey[nTmpCount].time;
v[2] = -v[2];
// -----------------------------------------------------------
// 180��� ������������ ������각��� ����� ������ ������ ������
// : ������������ ������고 ������각��� '각 = 360-각'������ ���������������.
// -----------------------------------------------------------
if (t >= degToRad(180)) {
t = degToRad(360) - t;
vectorScale (v, -1.0);
}
// ������������������ ������������ ������.
// !! ���기���.. angle��� ������ ������계��� 기��������� ������고 ���..
// ��������������� ��������� ������계��������� ��������� ���������.. (-t)
// AngleAxis2Quat (&pM->pRotKey[nTmpCount].q, v, -t);
AngleAxis2Quat (&pM->pRotKey[nTmpCount].q, v, t);
nTmpCount++;
if (nTmpCount == pM->rotkeyNum)
nTmpCount = 0;
}
else if (!strcmp (data, OBJECT_POS_SAMPLE))
{
// animation - position sampling
static int nTmpCount2 = 0;
vec3_t p;
fscanf (s, "%d", &(pM->pPosKey[nTmpCount2].time)); fgetchar ();
fscanf (s, "%f", &p[0]); fgetchar ();
fscanf (s, "%f", &p[2]); fgetchar ();
fscanf (s, "%f", &p[1]);
p[2] = -p[2];
// max_time 값 ������������
if (pM->pPosKey[nTmpCount2].time > *max_time) *max_time = pM->pPosKey[nTmpCount2].time;
memcpy (&pM->pPosKey[nTmpCount2].p, p, sizeof (vec3_t));
nTmpCount2++;
if (nTmpCount2 == pM->poskeyNum)
nTmpCount2 = 0;
}
else if (!strcmp (data, PV_NONBLEND))
{
int index;
char tmp_name[255];
char name[255];
fscanf (s, "%d ", &index);
int c_index = 0;
while (fgetc (s) != '"') {}
while (1) {
tmp_name [c_index++] = (char) fgetc (s);
if (tmp_name [c_index-1] == '"') {
tmp_name [c_index-1] = '\0';
break;
}
}
// memcpy (name, tmp_name+1, strlen(tmp_name)-2);
memcpy (name, tmp_name, strlen(tmp_name)+1);
// name [strlen(tmp_name)-2] = '\0';
for (int i=0;i<nNodeNum;i++) {
if (!strcmp (pNodeList [i]->Name, name))
{
pNodeList [i]->GetPSQInfo()->pV[pv_count[i]].nVIndex = index;
pNodeList [i]->GetPSQInfo()->pV[pv_count[i]].weight = 1.0;
pv_count[i]++;
}
}
}
else if (!strcmp (data, PV_BLEND_ASSIGNMODE))
{
fscanf (s, "%d", &nBlendAssignIndex);
}
else if (!strcmp (data, PV_BLEND_ASSIGN))
{
int index;
vec_t w;
char tmp_name[255];
char name[255];
//fscanf (s, "%d %f %s", &index, &w, &tmp_name);
fscanf (s, "%d %f ", &index, &w);
int c_index = 0;
while (fgetc (s) != '"') {}
while (1) {
tmp_name [c_index++] = (char) fgetc (s);
if (tmp_name [c_index-1] == '"') {
tmp_name [c_index-1] = '\0';
break;
}
}
memcpy (name, tmp_name, strlen(tmp_name)+1);
// memcpy (name, tmp_name+1, strlen(tmp_name)-2);
// name [strlen(tmp_name)-2] = '\0';
for (int i=0;i<nNodeNum;i++) {
if (!strcmp (pNodeList [i]->Name, name))
{
pNodeList [i]->GetPSQInfo()->pV[pv_count[i]].nVIndex = nBlendAssignIndex;
pNodeList [i]->GetPSQInfo()->pV[pv_count[i]].weight = w;
pv_count[i]++;
}
}
}
else if (strcmp (data, TEXTURE_ID) == 0)
{
pM->texture.texId = (int) GetFloatVal (s);
}
// ������ ��������� ��������� ������.. 그���고 texture��� ������과��� ��������� ������������ ����� ������ �� �����.
// ������������ ������������ ������ ������ ��������� ������������ ��� �� �����.
else if (strcmp (data, UTILE) == 0)
{
pM->texture.uTile = GetFloatVal (s);
}
else if (strcmp (data, VTILE) == 0)
{
pM->texture.vTile = GetFloatVal (s);
}
else if (strcmp (data, UOFFSET) == 0)
{
pM->texture.uOffset = GetFloatVal (s);
}
else if (strcmp (data, VOFFSET) == 0)
{
pM->texture.vOffset = GetFloatVal (s);
}
else
fgets (data, sizeof (data), s);
}
mat44_t parent_inv, tmp_out;
for (int i=0;i<nNodeNum;i++) {
if (!pNodeList [i]->bPosKey) {
matrixIdentity (parent_inv);
matrixIdentity (tmp_out);
pNodeList[i]->pPosKey[0].time = 0;
// ��������������� ��������� ��������� ������������..
if (pNodeList [i]->RetParent ()) matrix44_inverse (parent_inv, pNodeList [i]->RetParent ()->tm);
matrixMultiply (pNodeList [i]->tm, parent_inv, tmp_out);
pNodeList[i]->pPosKey[0].p[0] = tmp_out[12];
pNodeList[i]->pPosKey[0].p[1] = tmp_out[13];
pNodeList[i]->pPosKey[0].p[2] = tmp_out[14];
}
if (!pNodeList [i]->bRotKey) {
pNodeList[i]->pRotKey[0].time = 0;
AngleAxis2Quat (&pNodeList[i]->pRotKey[0].q, pNodeList[i]->Axis, pNodeList[i]->Angle);
}
}
}