allow to export simulation to COLLADA
This commit is contained in:
@@ -87,6 +87,8 @@ extern int gForwardAxis;
|
||||
#include "dae.h"
|
||||
#include "dom/domCOLLADA.h"
|
||||
|
||||
DAE* collada = 0;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -138,6 +140,15 @@ const int maxNumObjects = 450;
|
||||
|
||||
SimdTransform startTransforms[maxNumObjects];
|
||||
|
||||
//quick test to export new position into a COLLADA .dae file
|
||||
#ifndef USE_FCOLLADA
|
||||
domTranslateRef translateRef[maxNumObjects];
|
||||
|
||||
domRotate_Array* rotateArray[maxNumObjects];
|
||||
|
||||
domMatrixRef matrixRef[maxNumObjects];
|
||||
#endif //USE_FCOLLADA
|
||||
|
||||
DefaultMotionState ms[maxNumObjects];
|
||||
CcdPhysicsController* physObjects[maxNumObjects] = {0,0,0,0};
|
||||
|
||||
@@ -844,8 +855,36 @@ bool ConvertColladaPhysicsToBulletPhysics(const FCDPhysicsSceneNode* inputNode)
|
||||
|
||||
GLDebugDrawer debugDrawer;
|
||||
|
||||
char* fixFileName(const char* lpCmdLine);
|
||||
char* getLastFileName();
|
||||
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
/// Import Collada 1.4 Physics objects
|
||||
|
||||
//char* filename = "analyticalGeomPhysicsTest.dae";//ColladaPhysics.dae";
|
||||
//char* filename = "colladaphysics_spherebox.dae";
|
||||
//char* filename = "friction.dae";
|
||||
char* filename = "jenga.dae";
|
||||
|
||||
printf("argc=%i\n",argc);
|
||||
{
|
||||
for (int i=0;i<argc;i++)
|
||||
{
|
||||
printf("argv[%i]=%s\n",i,argv[i]);
|
||||
}
|
||||
}
|
||||
if (argc>1)
|
||||
{
|
||||
#ifdef USE_FCOLLADA
|
||||
filename = argv[1];
|
||||
#else
|
||||
//COLLADA-DOM requires certain filename convention
|
||||
filename = fixFileName(argv[1]);
|
||||
#endif
|
||||
}
|
||||
|
||||
gCameraUp = SimdVector3(0,0,1);
|
||||
gForwardAxis = 1;
|
||||
|
||||
@@ -862,12 +901,6 @@ int main(int argc,char** argv)
|
||||
|
||||
|
||||
|
||||
/// Import Collada 1.4 Physics objects
|
||||
|
||||
//char* filename = "analyticalGeomPhysicsTest.dae";//ColladaPhysics.dae";
|
||||
//char* filename = "colladaphysics_spherebox.dae";
|
||||
//char* filename = "friction.dae";
|
||||
char* filename = "jenga.dae";
|
||||
|
||||
|
||||
#ifdef USE_FCOLLADA
|
||||
@@ -890,10 +923,23 @@ int main(int argc,char** argv)
|
||||
}
|
||||
#else
|
||||
//Collada-dom
|
||||
DAE *collada = new DAE;
|
||||
collada = new DAE;
|
||||
|
||||
//clear
|
||||
{
|
||||
|
||||
for (int i=0;i<maxNumObjects;i++)
|
||||
{
|
||||
translateRef[i] = 0;
|
||||
rotateArray[i] = 0;
|
||||
//rotateRef[i] = 0;
|
||||
matrixRef[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int res = collada->load(filename);//,docBuffer);
|
||||
|
||||
if (res != DAE_OK)
|
||||
{
|
||||
printf("DAE/Collada-dom: Couldn't load %s\n",filename);
|
||||
@@ -1392,53 +1438,58 @@ int main(int argc,char** argv)
|
||||
}
|
||||
|
||||
|
||||
//The 'target' points to a graphics element/node, which contains the start (world) transform
|
||||
daeElementRef elem = rigidbodyRef->getTarget().getElement();
|
||||
if (elem)
|
||||
{
|
||||
domNodeRef node = *(domNodeRef*)&elem;
|
||||
//The 'target' points to a graphics element/node, which contains the start (world) transform
|
||||
daeElementRef elem = rigidbodyRef->getTarget().getElement();
|
||||
if (elem)
|
||||
{
|
||||
domNodeRef node = *(domNodeRef*)&elem;
|
||||
|
||||
//find transform of the node that this rigidbody maps to
|
||||
//find transform of the node that this rigidbody maps to
|
||||
|
||||
int i;
|
||||
//either load the matrix (worldspace) or incrementally build the transform from 'translate'/'rotate'
|
||||
for (i=0;i<node->getMatrix_array().getCount();i++)
|
||||
{
|
||||
domMatrixRef matrixRef = node->getMatrix_array()[i];
|
||||
domFloat4x4 fl16 = matrixRef->getValue();
|
||||
SimdVector3 origin(fl16.get(3),fl16.get(7),fl16.get(11));
|
||||
startTransform.setOrigin(origin);
|
||||
SimdMatrix3x3 basis(fl16.get(0),fl16.get(1),fl16.get(2),
|
||||
fl16.get(4),fl16.get(5),fl16.get(6),
|
||||
fl16.get(8),fl16.get(9),fl16.get(10));
|
||||
startTransform.setBasis(basis);
|
||||
}
|
||||
int i;
|
||||
//either load the matrix (worldspace) or incrementally build the transform from 'translate'/'rotate'
|
||||
for (i=0;i<node->getMatrix_array().getCount();i++)
|
||||
{
|
||||
domMatrixRef matrixRef = node->getMatrix_array()[i];
|
||||
domFloat4x4 fl16 = matrixRef->getValue();
|
||||
SimdVector3 origin(fl16.get(3),fl16.get(7),fl16.get(11));
|
||||
startTransform.setOrigin(origin);
|
||||
SimdMatrix3x3 basis(fl16.get(0),fl16.get(1),fl16.get(2),
|
||||
fl16.get(4),fl16.get(5),fl16.get(6),
|
||||
fl16.get(8),fl16.get(9),fl16.get(10));
|
||||
startTransform.setBasis(basis);
|
||||
}
|
||||
|
||||
|
||||
for (i=0;i<node->getRotate_array().getCount();i++)
|
||||
{
|
||||
domRotateRef rotateRef = node->getRotate_array()[i];
|
||||
domFloat4 fl4 = rotateRef->getValue();
|
||||
float angleRad = SIMD_RADS_PER_DEG*fl4.get(3);
|
||||
SimdQuaternion rotQuat(SimdVector3(fl4.get(0),fl4.get(1),fl4.get(2)),angleRad);
|
||||
startTransform.getBasis() = startTransform.getBasis() * SimdMatrix3x3(rotQuat);
|
||||
}
|
||||
if (node->getRotate_array().getCount())
|
||||
{
|
||||
rotateArray[numObjects] = &node->getRotate_array();
|
||||
}
|
||||
|
||||
for (i=0;i<node->getTranslate_array().getCount();i++)
|
||||
{
|
||||
domTranslateRef translateRef = node->getTranslate_array()[i];
|
||||
domFloat3 fl3 = translateRef->getValue();
|
||||
startTransform.getOrigin() += SimdVector3(fl3.get(0),fl3.get(1),fl3.get(2));
|
||||
}
|
||||
for (i=0;i<node->getRotate_array().getCount();i++)
|
||||
{
|
||||
domRotateRef rotateRef = node->getRotate_array()[i];
|
||||
domFloat4 fl4 = rotateRef->getValue();
|
||||
float angleRad = SIMD_RADS_PER_DEG*fl4.get(3);
|
||||
SimdQuaternion rotQuat(SimdVector3(fl4.get(0),fl4.get(1),fl4.get(2)),angleRad);
|
||||
startTransform.getBasis() = startTransform.getBasis() * SimdMatrix3x3(rotQuat);
|
||||
}
|
||||
|
||||
for (i=0;i<node->getScale_array().getCount();i++)
|
||||
{
|
||||
domScaleRef scaleRef = node->getScale_array()[i];
|
||||
domFloat3 fl3 = scaleRef->getValue();
|
||||
startScale = SimdVector3(fl3.get(0),fl3.get(1),fl3.get(2));
|
||||
}
|
||||
for (i=0;i<node->getTranslate_array().getCount();i++)
|
||||
{
|
||||
translateRef[numObjects] = node->getTranslate_array()[i];
|
||||
domFloat3 fl3 = translateRef[numObjects]->getValue();
|
||||
startTransform.getOrigin() += SimdVector3(fl3.get(0),fl3.get(1),fl3.get(2));
|
||||
}
|
||||
|
||||
}
|
||||
for (i=0;i<node->getScale_array().getCount();i++)
|
||||
{
|
||||
domScaleRef scaleRef = node->getScale_array()[i];
|
||||
domFloat3 fl3 = scaleRef->getValue();
|
||||
startScale = SimdVector3(fl3.get(0),fl3.get(1),fl3.get(2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (colShape)
|
||||
@@ -1793,6 +1844,78 @@ void shootBox(const SimdVector3& destination)
|
||||
void clientKeyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
|
||||
#ifndef USE_FCOLLADA
|
||||
if (key =='e')
|
||||
{
|
||||
if (collada)
|
||||
{
|
||||
for (int i=0;i<numObjects;i++)
|
||||
{
|
||||
if (translateRef[i])
|
||||
{
|
||||
|
||||
float np[3];
|
||||
domFloat3 newPos = translateRef[i]->getValue();
|
||||
physObjects[i]->GetMotionState()->getWorldPosition(
|
||||
np[0],
|
||||
np[1],
|
||||
np[2]);
|
||||
newPos.set(0,np[0]);
|
||||
newPos.set(1,np[1]);
|
||||
newPos.set(2,np[2]);
|
||||
translateRef[i]->setValue(newPos);
|
||||
|
||||
}
|
||||
domRotate_Array* ptr = rotateArray[i];
|
||||
if (ptr)
|
||||
{
|
||||
//it is not easy to just clear/remove values, so we reset the rotation for all, except the first one
|
||||
//make all zero-rotations, except for first
|
||||
for (int i=0;i<ptr->getCount();i++)
|
||||
{
|
||||
ptr->get(i)->getValue().set(0,1);
|
||||
ptr->get(i)->getValue().set(1,0);
|
||||
ptr->get(i)->getValue().set(2,0);
|
||||
ptr->get(i)->getValue().set(3,0);
|
||||
}
|
||||
|
||||
float quatIma0,quatIma1,quatIma2,quatReal;
|
||||
|
||||
SimdQuaternion quat = physObjects[i]->GetRigidBody()->getCenterOfMassTransform().getRotation();
|
||||
SimdVector3 axis(quat.getX(),quat.getY(),quat.getZ());
|
||||
axis[3] = 0.f;
|
||||
//check for axis length
|
||||
SimdScalar len = axis.length2();
|
||||
if (len < SIMD_EPSILON*SIMD_EPSILON)
|
||||
axis = SimdVector3(1.f,0.f,0.f);
|
||||
else
|
||||
axis /= SimdSqrt(len);
|
||||
ptr->get(0)->getValue().set(0,axis[0]);
|
||||
ptr->get(0)->getValue().set(1,axis[1]);
|
||||
ptr->get(0)->getValue().set(2,axis[2]);
|
||||
ptr->get(0)->getValue().set(3,quat.getAngle()*SIMD_DEGS_PER_RAD);
|
||||
}
|
||||
if (matrixRef[i])
|
||||
{
|
||||
//not yet
|
||||
//printf
|
||||
|
||||
}
|
||||
}
|
||||
char saveName[550];
|
||||
static int saveCount=1;
|
||||
sprintf(saveName,"%s%i.dae\0",getLastFileName(),saveCount++);
|
||||
char* name = &saveName[0];
|
||||
if (name[0] == '/')
|
||||
{
|
||||
name = &saveName[1];
|
||||
}
|
||||
collada->saveAs(name);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (key == '.')
|
||||
{
|
||||
shootBox(SimdVector3(0,0,0));
|
||||
@@ -2007,3 +2130,51 @@ void clientMotionFunc(int x,int y)
|
||||
}
|
||||
}
|
||||
|
||||
//some code that de-mangles the windows filename passed in as argument
|
||||
char cleaned_filename[512];
|
||||
char* getLastFileName()
|
||||
{
|
||||
return cleaned_filename;
|
||||
}
|
||||
char* fixFileName(const char* lpCmdLine)
|
||||
{
|
||||
|
||||
|
||||
// We might get a windows-style path on the command line, this can mess up the DOM which expects
|
||||
// all paths to be URI's. This block of code does some conversion to try and make the input
|
||||
// compliant without breaking the ability to accept a properly formatted URI. Right now this only
|
||||
// displays the first filename
|
||||
const char *in = lpCmdLine;
|
||||
char* out = cleaned_filename;
|
||||
*out = NULL;
|
||||
// If the first character is a ", skip it (filenames with spaces in them are quoted)
|
||||
if(*in == '\"')
|
||||
{
|
||||
in++;
|
||||
}
|
||||
if(*(in+1) == ':')
|
||||
{
|
||||
// Second character is a :, assume we have a path with a drive letter and add a slash at the beginning
|
||||
*(out++) = '/';
|
||||
}
|
||||
int i;
|
||||
for(i =0; i<512; i++)
|
||||
{
|
||||
// If we hit a null or a quote, stop copying. This will get just the first filename.
|
||||
if(*in == NULL || *in == '\"')
|
||||
break;
|
||||
// Copy while swapping backslashes for forward ones
|
||||
if(*in == '\\')
|
||||
{
|
||||
*out = '/';
|
||||
}
|
||||
else
|
||||
{
|
||||
*out = *in;
|
||||
}
|
||||
in++;
|
||||
out++;
|
||||
}
|
||||
|
||||
return cleaned_filename;
|
||||
}
|
||||
Reference in New Issue
Block a user