Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
PostPosted: Wed Apr 20, 2011 1:38 am 
Offline

Joined: Sat Apr 09, 2011 8:12 pm
Posts: 11
im wondering how i would setup my mesh to have collision in bullet...

is there an export script(or whatever its called) in blender that i can use for Bullet Physics?


if so then please post a link, and i also wanna know how i would update my Blender to use this export..


Top
 Profile  
 
PostPosted: Wed Apr 20, 2011 5:18 am 
Offline
Site Admin
User avatar

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3744
Location: California, USA
The best is to use the built-in .bullet export in the Blender game engine, called through a Python command (the actual Bullet export happens in C/C++, unlike the common Python export scripts)

This requires Blender 2.57 (or later). Setup the collision shapes, rigid body info, constraints, soft body etc for the Blender game engine (BGE), hook up a BGE python script to a controller and run the BGE using the 'P' key/or menu. Here is the script:

Code:
import PhysicsConstraints;
PhysicsConstraints.exportBulletFile("testFile.bullet")


See also exportBulletFile.blend in this archive:
http://bulletphysics.com/ftp/pub/test/i ... iles-2.zip

It will export most collision shape types, rigid body info, constraints and soft body data in a .bullet file.
Thanks,
Erwin


Top
 Profile  
 
PostPosted: Wed Apr 20, 2011 10:15 pm 
Offline

Joined: Sat Apr 09, 2011 8:12 pm
Posts: 11
Hey i believe i have everything setup satisfyingly, but:


Erwin Coumans wrote:
hook up a BGE python script to a controller and run the BGE using the 'P' key/or menu. Here is the script:



i didnt completely understand what you were talking about. sorry, im not ultimately used to the new blender interface yet, you think you could give a few details?


also im glad for the answer


EDIT: i looked up some information and i figured out how to export it yay :D

now im wondering how i would use this in c++...


Top
 Profile  
 
PostPosted: Thu Apr 21, 2011 5:01 am 
Offline
Site Admin
User avatar

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3744
Location: California, USA
You can use btBulletWorldImporter.

See Bullet/Demos/SerializeDemo, it can load your .bullet file.
Thanks,
Erwin


Top
 Profile  
 
PostPosted: Thu Apr 21, 2011 10:53 pm 
Offline

Joined: Sat Apr 09, 2011 8:12 pm
Posts: 11
hey i got the importer to work, thanks to you xD but now im having another peoblem..


when i start my game, everything fine: gravity works and everything...

the only problem now, is that once my character falls, he falss through the landscape ._.


im wondering if something is wrong with the physics(i DID notice the box i set was moving slowly while on the plane in blender, i thought it was friction or whatever :/)




EDIT: hey i did some trial and error, and i found out that when i search for how many rigid bodies there are in the .bullet file, it says theres none...

is there a way to add them with the python code?


Top
 Profile  
 
PostPosted: Mon May 02, 2011 5:02 pm 
Offline

Joined: Sat Apr 30, 2011 2:28 pm
Posts: 8
Where did you find the .bullet file after running the script to export the file? I'm using Blender 2.57 and I believe the script is running (I see the print in the console and I added a print at the end which I also see in the console), but I can't find the .bullet file anywhere.

Thanks.


Top
 Profile  
 
PostPosted: Mon May 02, 2011 9:57 pm 
Offline
Site Admin
User avatar

Joined: Sun Jun 26, 2005 6:43 pm
Posts: 3744
Location: California, USA
The file should go in the current working directory, typically next to the Blender.exe, unless you start it from a debugger etc.

You can chose an absolute path, for example under windows:
Code:
PhysicsConstraints.exportBulletFile("c:/testFile.bullet")

Thanks,
Erwin


Top
 Profile  
 
PostPosted: Tue May 03, 2011 1:56 am 
Offline

Joined: Sat Apr 30, 2011 2:28 pm
Posts: 8
Thanks, Erwin. Based on your response, I noticed that I was using "\" instead of "/" when I tried the absolute path. The file is being created now.

Thanks again.


Top
 Profile  
 
PostPosted: Mon Dec 05, 2011 7:39 pm 
Offline

Joined: Thu Apr 29, 2010 11:59 pm
Posts: 13
I am trying your script in Blender 2.6 and it says the module doesnt exist...

Do you know if it was it taken out? Renamed?


Edit, my apologies. It seems you cannot run the script from the text editor window and that you must run it in game. Thanks Erwin.


Top
 Profile  
 
PostPosted: Sat Apr 21, 2012 9:27 pm 
Offline

Joined: Thu Oct 01, 2009 1:23 pm
Posts: 3
Erwin Coumans wrote:
You can use btBulletWorldImporter.

See Bullet/Demos/SerializeDemo, it can load your .bullet file.
Thanks,
Erwin


I got this export to work from Blender 2.62, but I've been trying to find a way to identify the object by it's Blender name.

According to the Bullet binary serialization doc:

http://bulletphysics.org/mediawiki-1.5.8/index.php/Bullet_binary_serialization#Setting_and_Getting_the_name_for_bodies.2C_shapes_and_constraints

Quote:
Setting and Getting the name for bodies, shapes and constraints

The Dynamica Maya plugin and Blender create unique names for all objects. This is useful to recognize objects, shapes and constraints, for example to bind them with graphics objects.
When saving the file, the btDefaultSerializer is created, and all names are registered using the registerNameForPointer method.
When loading the .bullet file, the m_name field is part of the structures: btCollisionObjectData, btRigidBodyData, btCollisionShapeData and btTypedConstraintData.
Also the 'btBulletWorldImporter::createRigidBody' methods passes this nams as one of the arguments, when available.


However, the name is always exactly the same as the collision shape name, rather than a unique Blender name. This code:

Code:
   int i;
   for (i=0; i < m_dynamicsWorld->getNumCollisionObjects(); i++)
   {
      btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
      btRigidBody* body = btRigidBody::upcast(obj);
      
      printf("  object name = %s\n", body->getRootCollisionShape()->getName());
...


produces:

Quote:
object name = Box


for every box collision shape.


Top
 Profile  
 
PostPosted: Mon Apr 23, 2012 12:10 pm 
Offline

Joined: Thu Oct 01, 2009 1:23 pm
Posts: 3
Ok, I figured it out. It's not part of the btRigidBody object, but it must be extracted from the btBulletWorldImporter object:

Code:
   class btBulletWorldImporter*      m_fileLoader;
       ...

   int i;
   for (i=0; i < m_fileLoader->getNumRigidBodies(); i++)
   {
      btCollisionObject* coll =  m_fileLoader->getRigidBodyByIndex(i);
      btRigidBody* body = btRigidBody::upcast(coll);
      
      printf("  object name = %s\n", m_fileLoader->getNameForPointer(body));   // The Blender object name
        ...



jacket wrote:
Erwin Coumans wrote:
You can use btBulletWorldImporter.

See Bullet/Demos/SerializeDemo, it can load your .bullet file.
Thanks,
Erwin


I got this export to work from Blender 2.62, but I've been trying to find a way to identify the object by it's Blender name.

According to the Bullet binary serialization doc:

http://bulletphysics.org/mediawiki-1.5.8/index.php/Bullet_binary_serialization#Setting_and_Getting_the_name_for_bodies.2C_shapes_and_constraints

Quote:
Setting and Getting the name for bodies, shapes and constraints

The Dynamica Maya plugin and Blender create unique names for all objects. This is useful to recognize objects, shapes and constraints, for example to bind them with graphics objects.
When saving the file, the btDefaultSerializer is created, and all names are registered using the registerNameForPointer method.
When loading the .bullet file, the m_name field is part of the structures: btCollisionObjectData, btRigidBodyData, btCollisionShapeData and btTypedConstraintData.
Also the 'btBulletWorldImporter::createRigidBody' methods passes this nams as one of the arguments, when available.


However, the name is always exactly the same as the collision shape name, rather than a unique Blender name. This code:

Code:
   int i;
   for (i=0; i < m_dynamicsWorld->getNumCollisionObjects(); i++)
   {
      btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
      btRigidBody* body = btRigidBody::upcast(obj);
      
      printf("  object name = %s\n", body->getRootCollisionShape()->getName());
...


produces:

Quote:
object name = Box


for every box collision shape.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group