Use ofxBullet joints to articulate tree branches structure

Hi, I am building a tree structure with some branches. Here you can see a screenshot of one tree example with only one branch:

I want to limit or constraint the (angles) movements of the linked segments of the full branch. I have a particle system with points on any junction/join. I want to use this boxes just as “flexible” bones; only for that function. One way could be to use the boxes with joints; something this:

EDIT: But I am not sure if it’s a good way, and maybe it should work easier with a spring/joint between balls; a ball on each join. I don’t know if in bullet joints can’t work like springs… or if it’s possible to limit the movents without using the boxes around each branch segment.

There’s a very nice project made by Rui Madeira, very similiar but in 2D: https://vimeo.com/4789754


@pelintra said:

each branch is made of particles connected with springs, using a Verlet integration (there is a lot of information about this, and several add ons for verlet physics). The motion is then creating by applying forces to the particles. For the wind i’m creating forces using perlin noise.

So, searching around I found some similar stuff like:

Here you can see some types of joints:
http://www.ode.org/ode-latest-userguide.html#sec_3_8_0

And here you can see the antenna of this tank too, where each segment has a perpendicular joint:
http://box2d.org/forum/viewtopic.php?f=3&t=7211&p=31810&hilit=tank#p31811

As you can see I am very lost…

Hi

Limiting the angle each branch can bend can be a good alternative. I used a slightly easier option where each branch has a default direction and has a force constantly being applied in that direction. These forces are what keeps the tree standing up and prevents from falling because of gravity.
It was then a matter of trying different values to get the desired motion.

I only used 2D when i made Parque but the same principle could be used with 3D.

Hope it helps

Rui

1 Like

Thanks a lot @pelintra for the tips !!

Do you think can I avoid the use of boxes on each branch fragment and use only balls on the nodes/particles/joins + limited joints between them?

My main problem now is to understand how the joints constraints works:

/******************************/
	// call before calling add() //
	void	setLinearLowerLimit( ofVec3f a_limit );
	void	setLinearLowerLimit( float a_x, float a_y, float a_z );
	void	setLinearUpperLimit( ofVec3f a_limit );
	void	setLinearUpperLimit( float a_x, float a_y, float a_z );
	void	setAngularLowerLimit( ofVec3f a_limit );
	void	setAngularLowerLimit( float a_x, float a_y, float a_z );
	void	setAngularUpperLimit( ofVec3f a_limit );
	void	setAngularUpperLimit( float a_x, float a_y, float a_z );
	/******************************/

Now I am trying to understand what are this functions doing, and if they are referenced from the joint line to the shapes rotations or what.

Ok, cool! :smile: It seems it’s doing something nice to start with:

Both screenshots are taken moving the last sphere (the farthest from the ground) dragging the mouse left to right.

The code I used to create the spheres and the joints inside a for loop is something like this:

  for (int i = 0 ; i < numSegments ; i++) { 

    // ...

    // sphere particles

    posSphere.set(pointTo);
    spheres.push_back( new ofxBulletSphere() );
    ((ofxBulletSphere*)spheres[spheres.size()-1])->create(world.world, posSphere, boxMasa, sphereRadius);
    spheres[spheres.size()-1]->add();

    //-
    
    // joints:

    spheresJoints.push_back( new ofxBulletJoint() );
    spheresJoints[spheresJoints.size()-1]->create(world.world, spheres[i-1], spheres[i]->getPosition());

    // call before calling add() //
    spheresJoints[spheresJoints.size()-1]->setLinearUpperLimit ( 0.01, 0.01, 0.01 );
    spheresJoints[spheresJoints.size()-1]->setLinearLowerLimit ( 0.01, 0.01, 0.01 );
    spheresJoints[spheresJoints.size()-1]->setAngularUpperLimit( 0.01, 0.01, 0.01 );
    spheresJoints[spheresJoints.size()-1]->setAngularLowerLimit( 0.01, 0.01, 0.01 );
    
    spheresJoints[spheresJoints.size()-1]->add();
 }

And on update function, to update joints/pivots:

    for (int i = 0 ; i < spheresJoints.size() ; i++) {
         spheresJoints[i]->updatePivotPos( spheres[i+1]->getPosition(), jointLengthNOTUSED );
    }

I don’t understand 100% how this constraints works, but for the moment all the spheres are keeping the original locked distances and angles between them (when click mouse is released).

Dragging from other spheres (close to the ground) do not “move” the other ones; because the joints seems they “link” only in one direction, and not backwards. Maybe there’s another way to update the pivot… or maybe creating 2 joints between any 2 Fspheres should do the work…

Anyway, it’s a good starting point to playing with forces! :sunny:

EDIT: The other idea of using boxes on segments it’s being unestable. I think I would try to put the pivots on the top & bottom of the boxes; not on the center like on the above top screenshots. Also, I would like to set a contact point between each 2 boxes… and disable collisions. Anyway I can’t predict the benefits of using boxes/bones vs particle/spheres…

Awesome!

1 Like