Import serialized file from blender

sjdowling
Posts: 4
Joined: Sat Jul 07, 2012 3:40 pm

Import serialized file from blender

Post by sjdowling »

*Edit: I'm not sure if this is the correct board, should I move this to the serialization board?

I am attempting to load the model I have built using Blender 2.63.0 r46461 from which I have successfully exported a 22KB .bullet file. I have adapted the serialize demo supplied with bullet 2.80-rev2531 with the following code.

Code: Select all

void	SerializeKuka::initPhysics()
{
	char* fileName = "kuka.bullet";
	setTexturing(true);
	setShadows(true);

	setCameraDistance(btScalar(SCALING*30.));

	setupEmptyDynamicsWorld();
	m_fileLoader = new btBulletWorldImporter(m_dynamicsWorld);
	 
	bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(fileName);
	//bulletFile2->parse(true);
	bulletFile2->parseData();

	m_fileLoader->setVerboseMode(true);

	if(!m_fileLoader->loadFileFromMemory(bulletFile2))
	{
		std::cout << "Failed to load file: " << fileName << std::endl;
		return;
	}
	/*
	if (!m_fileLoader->loadFile(fileName))
	{
		std::cout << "Failed to load file: " << fileName << std::endl;
		return;
	}
	*/
	std::cout << "Looking for bodies:\n Found "<< m_dynamicsWorld->getNumCollisionObjects() << " objects." <<  std::endl;
   for(int numBodies = 0; numBodies < m_dynamicsWorld->getNumCollisionObjects(); numBodies++)
   {
	   btCollisionObject* Body = m_dynamicsWorld->getCollisionObjectArray()[numBodies];
	   const char* name = Body->getCollisionShape()->getName() ;
	   std::cout << "found body " << name << std::endl; 
   }

	//clientResetScene();

}
Running this gives me a segmentation fault and gdb gives:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
0x00000000004f6042 in bParse::bFile::getNextBlock(bParse::bChunkInd*, char const*, int) ()
The backtrace is:

Code: Select all

(gdb) bt
#0  0x000000389e5380f0 in __memcpy_ssse3 () from /lib64/libc.so.6
#1  0x000000000052e59b in bParse::bFile::getNextBlock (this=0x8e42b0, 
    dataChunk=0x7fffffffd5d0, dataPtr=0xc <Address 0xc out of bounds>, flags=0)
    at /media/B0FC-7F98/bullet-2.80-rev2531/Extras/Serialize/BulletFileLoader/bFile.cpp:1265
#2  0x00000000005302ab in bParse::btBulletFile::parseData (this=0x8e42b0)
    at /media/B0FC-7F98/bullet-2.80-rev2531/Extras/Serialize/BulletFileLoader/btBulletFile.cpp:135
#3  0x00000000004754f4 in SerializeKuka::initPhysics (this=0x7fffffffd720)
    at /media/B0FC-7F98/bullet-2.80-rev2531/Demos/SerializeKuka/SerializeKuka.cpp:162
#4  0x000000000046c2e9 in main (argc=1, argv=0x7fffffffd948)
    at /media/B0FC-7F98/bullet-2.80-rev2531/Demos/SerializeKuka/main.cpp:32
Using the commented loadFile method returns false. I have attached the mentioned .bullet file, renamed to allow upload.
You do not have the required permissions to view the files attached to this post.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Import serialized file from blender

Post by Erwin Coumans »

The file loads fine here, using the unmodified Bullet/Demos/SerializeDemo (just rename the file to testFile.bullet and put it in the right place so your demo can find the file.
Of course you need to check if the file exists and if the parser is OK, that is what the original Bullet code does:

Code: Select all

bool	btBulletWorldImporter::loadFileFromMemory(  bParse::btBulletFile* bulletFile2)
{
	bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0;
	
	if (ok)
		bulletFile2->parse(m_verboseDumpAllTypes);
	else 
		return false;
	
	if (m_verboseDumpAllTypes)
	{
		bulletFile2->dumpChunks(bulletFile2->getFileDNA());
	}

	return convertAllObjects(bulletFile2);

}
Why didn't you use the btBulletWorldImporter?
sjdowling
Posts: 4
Joined: Sat Jul 07, 2012 3:40 pm

Re: Import serialized file from blender

Post by sjdowling »

The code does actually work, turns out I was just running from the wrong directory and the program was looking for the serialized file in the directory my shell was in rather than the directory the executable was in.

Boy is my face red.