Page 1 of 1

Importing multiple objects in one obj.-file

Posted: Thu Mar 21, 2019 6:20 pm
by Chrishansa
I am very new to Bullet, and playing with the .obj import example (Obj2RigidBody Optimize) in the BulletPhysicsExampleBrowser on my Mac.

I have created two separate cube objects in Blender, and exported them to .obj file format.

The .obj file looks like this:

# Blender v2.79 (sub 0) OBJ File: '2cubes.blend'
# www.blender.org
mtllib 2cubes.mtl
o Cube.001
v 0.970610 -0.324785 5.291652
v 0.970610 0.675215 5.291652
v 0.970610 -0.324785 4.291652
v 0.970610 0.675215 4.291652
v 1.970610 -0.324785 5.291652
v 1.970610 0.675215 5.291652
v 1.970610 -0.324785 4.291652
v 1.970610 0.675215 4.291652
vn -1.0000 0.0000 0.0000
vn 0.0000 0.0000 -1.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 0.0000 1.0000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
usemtl None
s off
f 1//1 2//1 4//1 3//1
f 3//2 4//2 8//2 7//2
f 7//3 8//3 6//3 5//3
f 5//4 6//4 2//4 1//4
f 3//5 7//5 5//5 1//5
f 8//6 4//6 2//6 6//6
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
vn 1.0000 0.0000 0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn 0.0000 0.0000 -1.0000
usemtl Material
s off
f 9//7 10//7 11//7 12//7
f 13//8 16//8 15//8 14//8
f 9//9 13//9 14//9 10//9
f 10//10 14//10 15//10 11//10
f 11//11 15//11 16//11 12//11
f 13//12 9//12 12//12 16//12


When I import this file simply by replacing the line

const char* fileName = "teddy.obj";

in void RigidBodyFromObjExample::initPhysics()

with

const char* fileName = "/Users/Chris/Desktop/2cubes.obj";

where 2cubes.obj is above posted .obj file, I get two cubes, as anticipated, but they act as one body when I try to move them around by clicking and dragging with the mouse.

See this video https://youtu.be/zlqs3gD0mUU.

Is this intended behaviour? How would I go about importing two objects from one .obj file in bullet? Or would I need to create separate obj. files for individual objects?

Re: Importing multiple objects in one obj.-file

Posted: Thu Mar 21, 2019 6:56 pm
by drleviathan
I believe that is the intended behavior. The OBJ file is used to describe the btShape of a btCollisionObject. In other words, the two "objects" in the OBJ file are interpreted as distinct convex parts (subshapes) of a btCompoundShape. This provides an easy way to build "concave" shapes which are really a collection of convex parts.

It would be possible to write your own custom Demo which interprets OBJ files differently.