#include "orimpexptool_engine.h"
#include <math.h>
bool ORImportExportEngine::ImportFile( const char* pFileName )
{
return true;
}
void ORImportExportEngine::ImportScene()
{
lFlag = CreateTexturedMesh("flag");
lRoot = CreateCube("cube");
lFlag->Selected = true;
lFlag->Children.Add(lRoot);
lPos[0]=100.0;
lPos[1]=0.0;
lPos[2]=0.0;
lRot[0]=lRot[1]=lRot[2]=0.0;
lSca[0]=lSca[1]=lSca[2]=1.0;
lPos[0]=-100.0;
lPos[1]=0.0;
lPos[2]=0.0;
lRot[0]=lRot[1]=lRot[2]=0.0;
lSca[0]=lSca[1]=lSca[2]=1.0;
FBFCurve* lCurveX;
FBFCurve* lCurveY;
FBFCurve* lCurveZ;
FBAnimationNode* lNodeTranslation;
FBAnimationNode* lNodeTrans_X;
FBAnimationNode* lNodeTrans_Y;
FBAnimationNode* lNodeTrans_Z;
lRoot->Translation.SetAnimated(true);
lNodeTrans_X = FindAnimationNode( lNodeTranslation, "X");
lNodeTrans_Y = FindAnimationNode( lNodeTranslation, "Y");
lNodeTrans_Z = FindAnimationNode( lNodeTranslation, "Z");
lCurveX = (FBFCurve*) lNodeTrans_X->FCurve;
lCurveY = (FBFCurve*) lNodeTrans_Y->FCurve;
lCurveZ = (FBFCurve*) lNodeTrans_Z->FCurve;
if(!lCurveX) lCurveX = new FBFCurve;
else lCurveX->Keys.RemoveAll();
if(!lCurveY) lCurveY = new FBFCurve;
else lCurveY->Keys.RemoveAll();
if(!lCurveZ) lCurveZ = new FBFCurve;
else lCurveZ->Keys.RemoveAll();
FBTime lStart,lStop;
lStart.SetMilliSeconds(0);
lStop.SetMilliSeconds(1000);
lCurveX->KeyAdd(lStart,0);
lCurveX->KeyAdd(lStop,100);
lCurveY->KeyAdd(lStart,0);
lCurveY->KeyAdd(lStop,100);
lCurveZ->KeyAdd(lStart,0);
lCurveZ->KeyAdd(lStop,100);
count=lCurveZ->Keys.GetCount();
lNodeTrans_X->FCurve = lCurveX;
lNodeTrans_Y->FCurve = lCurveY;
lNodeTrans_Z->FCurve = lCurveZ;
lRoot->Show = true;
}
void ORImportExportEngine::ImportAnimation()
{
}
void ORImportExportEngine::ImportOptical()
{
FBModelOptical* opticalModel = CreateOpticalModel();
FBAnimationNode* lNodeTranslation;
FBAnimationNode* lNodeTrans_X;
FBAnimationNode* lNodeTrans_Y;
FBAnimationNode* lNodeTrans_Z;
opticalModel->Translation.SetAnimated(true);
lNodeTrans_X = FindAnimationNode( lNodeTranslation, "X" );
lNodeTrans_Y = FindAnimationNode( lNodeTranslation, "Y" );
lNodeTrans_Z = FindAnimationNode( lNodeTranslation, "Z" );
ImportFCurve( lNodeTrans_X );
ImportFCurve( lNodeTrans_Y );
ImportFCurve( lNodeTrans_Z );
ImportOpticalModelAnimation( opticalModel );
opticalModel->Show = true;
}
FBModel *ORImportExportEngine::CreateCube( const char* pName )
{
FBModel* lModel = new FBModel( pName );
FBMesh* lMesh = new FBMesh("Cube");
lModel->Geometry = lMesh;
FBMaterial* lMaterial = new FBMaterial( "OR - Material" );
FBColor Diffuse (1.0,0.0,0.0);
FBColor Ambient ( Diffuse[0]-0.15,Diffuse[1]-0.15,Diffuse[2]-0.15);
FBColor Specular(0.0,0.0,0.0);
if (Ambient[0]<0) Ambient[0]=0;
if (Ambient[1]<0) Ambient[1]=0;
if (Ambient[2]<0) Ambient[2]=0;
lMaterial->Ambient = Ambient;
lMaterial->Diffuse = Diffuse;
lMaterial->Specular = Specular;
lModel->Materials.Add( lMaterial );
FBTexture* lTexture = new FBTexture( FBString(mSystem.PathImages)+"/openreality_tooldemo-l.png" );
lMaterial->Diffuse.ConnectSrc( lTexture );
int P0a,P0e,P0d;
int P1a,P1b,P1e;
int P2a,P2b,P2c;
int P3a,P3c,P3d;
int P4d,P4e,P4f;
int P5b,P5e,P5f;
int P6b,P6c,P6f;
int P7c,P7d,P7f;
lMesh->GeometryBegin();
lMesh->VertexInit(24, false, false);
lMesh->VertexNormalSet(0.0,-1.0,0.0);
lMesh->VertexUVSet(0.0,0.0);
P0a = lMesh->VertexAdd( 0.0, 0.0, 0.0 );
lMesh->VertexUVSet(0.0,1.0);
P1a = lMesh->VertexAdd( 0.0, 0.0, len );
lMesh->VertexUVSet(1.0,1.0);
P2a = lMesh->VertexAdd( len, 0.0, len );
lMesh->VertexUVSet(1.0,0.0);
P3a = lMesh->VertexAdd( len, 0.0, 0.0 );
lMesh->VertexNormalSet(0,0,1);
lMesh->VertexUVSet(0.0,0.0);
P1b = lMesh->VertexAdd( 0.0, 0.0, len );
lMesh->VertexUVSet(1.0,0.0);
P2b = lMesh->VertexAdd( len, 0.0, len );
lMesh->VertexUVSet(0.0,1.0);
P5b = lMesh->VertexAdd( 0.0, len, len );
lMesh->VertexUVSet(1.0,1.0);
P6b = lMesh->VertexAdd( len, len, len );
lMesh->VertexNormalSet(1,0,0);
P2c = lMesh->VertexAdd( len, 0.0, len );
P3c = lMesh->VertexAdd( len, 0.0, 0.0 );
P6c = lMesh->VertexAdd( len, len, len );
P7c = lMesh->VertexAdd( len, len, 0.0 );
lMesh->VertexNormalSet(0,0,-1);
P0d = lMesh->VertexAdd( 0.0, 0.0, 0.0 );
P3d = lMesh->VertexAdd( len, 0.0, 0.0 );
P7d = lMesh->VertexAdd( len, len, 0.0 );
P4d = lMesh->VertexAdd( 0.0, len, 0.0 );
lMesh->VertexNormalSet(-1,0,0);
P0e = lMesh->VertexAdd( 0.0, 0.0, 0.0 );
P1e = lMesh->VertexAdd( 0.0, 0.0, len );
P4e = lMesh->VertexAdd( 0.0, len, 0.0 );
P5e = lMesh->VertexAdd( 0.0, len, len );
lMesh->VertexNormalSet(0,1,0);
P4f = lMesh->VertexAdd( 0.0, len, 0.0 );
P5f = lMesh->VertexAdd( 0.0, len, len );
P6f = lMesh->VertexAdd( len, len, len );
P7f = lMesh->VertexAdd( len, len, 0.0 );
lMesh->PolygonBegin();
lMesh->PolygonVertexAdd(P0a);
lMesh->PolygonVertexAdd(P3a);
lMesh->PolygonVertexAdd(P2a);
lMesh->PolygonVertexAdd(P1a);
lMesh->PolygonEnd();
lMesh->PolygonBegin();
lMesh->PolygonVertexAdd(P1b);
lMesh->PolygonVertexAdd(P2b);
lMesh->PolygonVertexAdd(P6b);
lMesh->PolygonVertexAdd(P5b);
lMesh->PolygonEnd();
lMesh->PolygonBegin();
lMesh->PolygonVertexAdd(P2c);
lMesh->PolygonVertexAdd(P3c);
lMesh->PolygonVertexAdd(P7c);
lMesh->PolygonVertexAdd(P6c);
lMesh->PolygonEnd();
lMesh->PolygonBegin();
lMesh->PolygonVertexAdd(P0d);
lMesh->PolygonVertexAdd(P4d);
lMesh->PolygonVertexAdd(P7d);
lMesh->PolygonVertexAdd(P3d);
lMesh->PolygonEnd();
lMesh->PolygonBegin();
lMesh->PolygonVertexAdd(P1e);
lMesh->PolygonVertexAdd(P5e);
lMesh->PolygonVertexAdd(P4e);
lMesh->PolygonVertexAdd(P0e);
lMesh->PolygonEnd();
lMesh->PolygonBegin();
lMesh->PolygonVertexAdd(P4f);
lMesh->PolygonVertexAdd(P5f);
lMesh->PolygonVertexAdd(P6f);
lMesh->PolygonVertexAdd(P7f);
lMesh->PolygonEnd();
lMesh->GeometryEnd();
lModel->Show = true;
return lModel;
}
FBModel *ORImportExportEngine::CreateTexturedMesh( const char* pName )
{
FBModel* lModel = new FBModel( pName );
FBMesh* lMesh = new FBMesh("Mesh");
lModel->Geometry = lMesh;
FBTexture* lTexture = new FBTexture( FBString(mSystem.PathImages)+"/openreality_tooldemo-l.png" );
FBMaterial* lMaterial = new FBMaterial( "SDK material" );
lMaterial->Diffuse.ConnectSrc(lTexture);
lModel->Materials.Add(lMaterial);
FBColor Diffuse (1.0,0.0,0.0);
FBColor Ambient ( Diffuse[0]-0.15,Diffuse[1]-0.15,Diffuse[2]-0.15);
FBColor Specular(0.0,0.0,0.0);
if (Ambient[0]<0) Ambient[0]=0;
if (Ambient[1]<0) Ambient[1]=0;
if (Ambient[2]<0) Ambient[2]=0;
lMaterial->Ambient = Ambient;
lMaterial->Diffuse = Diffuse;
lMaterial->Specular = Specular;
lMesh->GeometryBegin();
lMesh->VertexInit(MESH_STEP_X * MESH_STEP_Y, false, true);
lMesh->VertexNormalSet(0.0,0.0,1.0);
float len = 100.0;
float stepX =(float)len/(float) MESH_STEP_X;
float stepY =(float)len/(float) MESH_STEP_Y;
float stepU =(float)1.0/(float) MESH_STEP_X;
float stepV =(float)1.0/(float) MESH_STEP_Y;
for(x=0;x<=MESH_STEP_X;x++)
{
for(y=0;y<=MESH_STEP_Y;y++)
{
lMesh->VertexUVSet(x*stepU,y*stepV);
V[
x][y] = lMesh->VertexAdd(x*stepX,y*stepY, 0.0 );
}
}
for(x=0;x<MESH_STEP_X;x++)
{
for(y=0;y<MESH_STEP_Y;y++)
{
lMesh->PolygonBegin();
lMesh->PolygonVertexAdd(V[x][y]);
lMesh->PolygonVertexAdd(V[x+1][y]);
lMesh->PolygonVertexAdd(V[x+1][y+1]);
lMesh->PolygonVertexAdd(V[x][y+1]);
lMesh->PolygonEnd();
}
}
lMesh->GeometryEnd();
lModel->Show = true;
return lModel;
}
bool ORImportExportEngine::ExportAnimationNode(
FILE* pFile, FBAnimationNode* pNode,
const char* pParentName )
{
FBString timeString;
FBTime time;
name = pParentName;
name += "/";
name += pNode->Name;
if(pNode->Nodes.GetCount()==0)
{
fprintf(pFile,"Node name:%s UserName:%s\n",(const char *)name, (const char *)pNode->UserName);
curve = pNode->FCurve;
if(curve)
{
int keyCount = curve->Keys.GetCount();
fprintf(pFile,"%d Key Frames\n", keyCount);
for(int i=0;i<keyCount;i++)
{
time = curve->Keys[
i].Time;
timeString = (char *)time.GetTimeString();
fprintf(pFile,"KeyIndex[%d]: Time[%s] Val[%lf] Deriv[%.2lf,%.2lf] TCB[%.2lf,%.2lf,%.2lf]\n",
i,
(char *)timeString,
(double)curve->Keys[i].Value,
(double)curve->Keys[i].LeftDerivative,
(double)curve->Keys[i].RightDerivative,
(double)curve->Keys[i].Tension,
(double)curve->Keys[i].Continuity,
(double)curve->Keys[i].Bias
);
}
fprintf(pFile,"\n");
}
else
{
fprintf(pFile,"Node has no recorded data\n");
}
}
for(i=0;i<pNode->Nodes.GetCount();i++)
{
ExportAnimationNode(pFile, pNode->Nodes[i], (char *)name) ;
}
return true;
}
bool ORImportExportEngine::ExportOpticalModel(
FILE *pFile, FBModelOptical* pModel )
{
FBModelMarkerOptical* marker =
NULL;
start = pModel->SamplingStart;
end = pModel->SamplingStop;
period = pModel->SamplingPeriod;
fprintf(pFile,"\nAnimation: start:%s end:%s period: %lf (%lf Hz)\n",
(char *)start.GetTimeString(),
(char *)end.GetTimeString(),
(double)period.GetMilliSeconds(),
1.0/(double)period.GetMilliSeconds());
if(pModel->ExportSetup())
{
for(i=0;i< pModel->Children.GetCount();i++)
{
marker = (FBModelMarkerOptical*)pModel->Children[i];
frameCount = marker->ExportBegin();
fprintf(pFile," Marker[%d]: name:%s length:%d frames\n",i,(const char *)marker->Name,frameCount);
for(f=0;f< frameCount;f++)
{
if(marker->ExportKey( &x,&y,&z,&o))
{
fprintf(pFile," frame[%d]= [%.2lf,%.2lf,%.2lf,%.2lf]\n",f, x,y,z,o);
}
else
{
fprintf(pFile,"------------Error at frame %d\n",f);
}
}
marker->ExportEnd();
}
}
return true;
}
bool ORImportExportEngine::ExportVoice( const char* pFileName )
{
pf=fopen(pFileName,"wt");
for( int c = 0; c<mSystem.Scene->Devices.GetCount(); c++ )
{
FBDevice* voiceDevice;
voiceDevice = mSystem.Scene->Devices[c];
if (strstr(voiceDevice->FbxGetObjectSubType(),"Voice")!=0)
{
fprintf(pf,"Voice device found\n");
FBAnimationNode*
node = voiceDevice->AnimationNodeOutGet();
ExportAnimationNode(pf, node, "Voice");
break;
}
}
fclose(pf);
return true;
}
bool ORImportExportEngine::ExportSelected( const char* pFileName )
{
FBModel* lRootModel;
lRootModel = mSystem.SceneRootModel;
lFile = fopen(pFileName,"wt");
ExportHierarchy( lFile, lRootModel, true );
fclose( lFile );
return true;
}
bool ORImportExportEngine::ExportHierarchy(
FILE* pFile, FBModel* pModel,
bool pIfSelected )
{
if( !pIfSelected || ( pModel->Selected && pIfSelected ) )
{
if( pModel->Is( FBModelOptical::TypeInfo ) )
{
ExportOpticalModel( pFile, (FBModelOptical*)pModel );
}
else
{
ExportModel( pFile, pModel );
ExportAnimationNode( pFile, pModel->AnimationNode, pModel->Name.AsString() );
}
}
for(i=0;i<pModel->Children.GetCount();i++)
{
ExportHierarchy(pFile, pModel->Children[i], pIfSelected);
}
return true;
}
bool ORImportExportEngine::ExportModel(
FILE *pFile, FBModel* pModel )
{
int polyCount=0,vertexCount=0,lMaterialCount=0,lTextureCount=0;
int matId =0;
FBMesh* lMesh = pModel->TessellatedMesh;
polyCount = lMesh->PolygonCount();
vertexCount = lMesh->VertexCount();
lMaterialCount = pModel->Materials.GetCount();
name = pModel->Name;
fprintf(pFile,"______________________________________________________________________________________\n");
fprintf(pFile,"Model Name: %s (typeId=%d) [%d polygons, %d vertices, %d materials, %d textures]\n",
(char *)name, pModel->TypeInfo, polyCount,vertexCount,lMaterialCount,lTextureCount);
if(pModel->Is(FBModel::TypeInfo))
fprintf(pFile,"Derives from class FBModel\n");
if(pModel->Is(FBModelOptical::TypeInfo))
fprintf(pFile,"Derives from class FBModelOptical\n");
if(pModel->Is(FBModelMarker::TypeInfo))
fprintf(pFile,"Derives from class FBModelMarker\n");
if(pModel->Is(FBModelMarkerOptical::TypeInfo))
fprintf(pFile,"Derives from class FBModelMarkerOptical\n");
if(pModel->Is(FBModelNull::TypeInfo))
fprintf(pFile,"Derives from class FBModelNull\n");
if(pModel->Is(FBModelRoot::TypeInfo))
fprintf(pFile,"Derives from class FBModelRoot\n");
if(pModel->Is(FBCamera::TypeInfo))
fprintf(pFile,"Derives from class FBCamera\n");
if(pModel->Is(FBLight::TypeInfo))
fprintf(pFile,"Derives from class FBLight\n");
fprintf(pFile,"\nTransformation:\n");
fprintf(pFile," Global TRS: T=[%.2lf,%.2lf,%.2lf] R=[%.2lf,%.2lf,%.2lf] S=[%.2lf,%.2lf,%.2lf]\n",
GT[0],GT[1],GT[2],
GR[0],GR[1],GR[2],
GS[0],GS[1],GS[2]);
fprintf(pFile,"\nMaterials: count=%d\n",lMaterialCount);
fprintf(pFile," Material mapping mode:");
switch(lMesh->MaterialMappingMode)
{
default: fprintf(pFile,"[Unknown]\n"); break;
}
for(i=0;i< lMaterialCount;i++)
{
FBMaterial* lMaterial = pModel->Materials[
i];
fprintf(pFile," ");
fprintf(pFile,"Material[%s] ",(const char *)(lMaterial->LongName));
fprintf(pFile,"Id[%d]\n",i);
FBColor lPropColorValue;
float lPropDoubleValue;
FBTexture* lPropTex;
lPropColorValue = lMaterial->Ambient;
fprintf(pFile,
"AmbientValue=[%.2lf,%.2lf,%.2lf] AmbientTex=[%s]\n", lPropColorValue[0], lPropColorValue[1],lPropColorValue[2], lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropDoubleValue = lMaterial->AmbientFactor;
fprintf(pFile,
"AmbientFactorValue=[%.2lf] AmbientTex=[%s]\n", lPropDoubleValue, lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropColorValue = lMaterial->Emissive;
fprintf(pFile,
"EmissiveValue=[%.2lf,%.2lf,%.2lf] EmissiveTex=[%s]\n", lPropColorValue[0], lPropColorValue[1],lPropColorValue[2], lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropDoubleValue = lMaterial->EmissiveFactor;
fprintf(pFile,
"EmissiveFactorValue=[%.2lf] EmissiveTex=[%s]\n", lPropDoubleValue, lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropColorValue = lMaterial->Diffuse;
fprintf(pFile,
"DiffuseValue=[%.2lf,%.2lf,%.2lf] DiffuseTex=[%s]\n", lPropColorValue[0], lPropColorValue[1],lPropColorValue[2], lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropDoubleValue = lMaterial->DiffuseFactor;
fprintf(pFile,
"DiffuseFactorValue=[%.2lf] DiffuseFactorTex=[%s]\n", lPropDoubleValue, lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropColorValue = lMaterial->TransparentColor;
fprintf(pFile,
"TransparentColorValue=[%.2lf,%.2lf,%.2lf] TransparentColorTex=[%s]\n", lPropColorValue[0], lPropColorValue[1],lPropColorValue[2], lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropDoubleValue = lMaterial->TransparencyFactor;
fprintf(pFile,
"TransparencyFactorValue=[%.2lf] TransparencyFactorTex=[%s]\n", lPropDoubleValue, lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropColorValue = lMaterial->Bump;
fprintf(pFile,
"BumpValue=[%.2lf,%.2lf,%.2lf] BumpTex=[%s]\n", lPropColorValue[0], lPropColorValue[1],lPropColorValue[2], lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropColorValue = lMaterial->NormalMap;
fprintf(pFile,
"NormalMapValue=[%.2lf,%.2lf,%.2lf] NormalMapTex=[%s]\n", lPropColorValue[0], lPropColorValue[1],lPropColorValue[2], lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropColorValue = lMaterial->Specular;
fprintf(pFile,
"SpecularValue=[%.2lf,%.2lf,%.2lf] SpecularTex=[%s]\n", lPropColorValue[0], lPropColorValue[1],lPropColorValue[2], lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropDoubleValue = lMaterial->SpecularFactor;
fprintf(pFile,
"SpecularFactorValue=[%.2lf] SpecularFactorTex=[%s]\n", lPropDoubleValue, lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropDoubleValue = lMaterial->Shininess;
fprintf(pFile,
"ShininessValue=[%.2lf] ShininessTex=[%s]\n", lPropDoubleValue, lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropColorValue = lMaterial->Reflection;
fprintf(pFile,
"ReflectionValue=[%.2lf,%.2lf,%.2lf] ReflectionTex=[%s]\n", lPropColorValue[0], lPropColorValue[1],lPropColorValue[2], lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
lPropDoubleValue = lMaterial->ReflectionFactor;
fprintf(pFile,
"ReflectionFactorValue=[%.2lf] ReflectionFactorTex=[%s]\n", lPropDoubleValue, lPropTex? (
const char*)(lPropTex->LongName) :
NULL);
fprintf(pFile,"\n\n");
}
fprintf(pFile,"\nVertices:\n");
for(i=0;i< vertexCount;i++)
{
vertex = lMesh->VertexGet(i);
normal = lMesh->VertexNormalGet(i);
lUV = lMesh->VertexUVGet(i);
fprintf(pFile," Vertex[%3d] P=[%.2lf,%.2lf,%.2lf] N=[%.2lf,%.2lf,%.2lf] Mat=[%d] UV=[%.2lf,%.2lf]\n",
i,
vertex[0],vertex[1],vertex[2],
normal[0],normal[1],normal[2],
matId,
lUV[0],lUV[1]);
}
fprintf(pFile,"\nPolygons:\n");
for(i=0;i< polyCount;i++)
{
fprintf(pFile," Poly[%d] Vert=[",i);
for(int j=0;j<lMesh->PolygonVertexCount(i);j++)
{
fprintf(pFile,"%d ",lMesh->PolygonVertexIndex(i,j));
}
fprintf(pFile,"] ");
fprintf(pFile,"MatId=[%d] ",lMesh->PolygonMaterialIdGet(i));
}
return true;
}
void ORImportExportEngine::ImportFCurve(FBAnimationNode* pNode)
{
FBFCurve* fcurve = (FBFCurve*)pNode->FCurve;
FBTime oneFrame (0,0,0,1);
FBTime time;
double freq = 0.01;
double amplitude = 10.0;
int keyIndex;
double tmpl,tmpr;
if(!fcurve) fcurve = new FBFCurve;
else fcurve->Keys.RemoveAll();
time = 0;
for(int i=0;i<200;i++)
{
time = time + oneFrame;
keyIndex = fcurve->KeyAdd( time, amplitude*sin(freq*(double)time.GetMilliSeconds()) );
tmpl = fcurve->Keys[keyIndex].LeftDerivative;
tmpr = fcurve->Keys[keyIndex].RightDerivative;
fcurve->Keys[keyIndex].LeftDerivative = 0.0;
fcurve->Keys[keyIndex].RightDerivative = 0.0;
fcurve->Keys[keyIndex].Tension = 1.0;
fcurve->Keys[keyIndex].Continuity = 1.0;
fcurve->Keys[keyIndex].Bias = 1.0;
}
count=fcurve->Keys.GetCount();
pNode->FCurve = fcurve;
}
void ORImportExportEngine::ImportOpticalModelAnimation(FBModelOptical* pModel)
{
FBTime start = 0;
FBTime oneFrame (0,0,0,1);
stop.SetMilliSeconds(200*oneFrame.GetMilliSeconds());
pModel->SamplingStart =
start;
pModel->SamplingStop =
stop;
pModel->SamplingPeriod = oneFrame;
pModel->ImportSetup();
FBTime time;
time = 0;
double freq = 0.01;
double amplitude = 10.0;
double lPos[3];
FBModelMarkerOptical* marker =
NULL;
int sampleCount;
for(
int m=0;
m<pModel->Children.GetCount();
m++)
{
marker = (FBModelMarkerOptical*) pModel->Children[
m];
sampleCount = marker->ImportBegin();
for(int i=0;i<sampleCount;i++)
{
time = time + oneFrame;
lPos[0] = 1.3*amplitude*sin(0.567*freq*(double)time.GetMilliSeconds());
lPos[1] = 0.7*amplitude*sin(1.6*freq*(double)time.GetMilliSeconds());
lPos[2] = amplitude*sin(freq*(double)time.GetMilliSeconds());
marker->ImportKey(lPos[0],lPos[1],lPos[2]);
}
marker->ImportEnd();
}
}
FBModelOptical* ORImportExportEngine::CreateOpticalModel()
{
char name[256];
FBModelOptical* model = new FBModelOptical( "test" );
model->MarkerSize =10.0;
model->Show = true;
FBModelMarkerOptical* opticalMarker;
int markerCount = 2;
for(int i=0;i<markerCount;i++)
{
sprintf(name,"m%d", i);
opticalMarker = new FBModelMarkerOptical (name);
opticalMarker->Show = true;
model->Children.Add(opticalMarker);
}
lPos[0]=100.0;
lPos[1]=0.0;
lPos[2]=0.0;
lRot[2]=lRot[1]=lRot[0]=0.0;
lSca[2]=lSca[1]=lSca[0]=1.0;
return model;
}
FBAnimationNode* ORImportExportEngine::FindAnimationNode( FBAnimationNode* pNode, const char* pName )
{
const char* lName;
for(int i=0;i < pNode->Nodes.GetCount();i++)
{
lName = pNode->Nodes[
i]->Name;
if(strcmp(lName,pName)==0)
{
}
}
}