Dumping out a Softbody Tree

elethiomel
Posts: 10
Joined: Wed Oct 27, 2010 11:05 pm

Dumping out a Softbody Tree

Post by elethiomel »

Hi guys, I'm trying to dump out a softbody's tree, including its AABBs and triangles in the leaves. the internal nodes seem OK and I get what looks like valid AABBs for the model. Unfortunately when I try dump the data in the leaf things get strange.

The Face I get from casting the leaf->data pointer doesn't seem right. for one thing, it's m_leaf which I would assume should point back to the leaf is NULL.
Each one of the three Node pointers in m_n array always point to unaddressable memory.

This is simply code I stuck into the SoftBody demo to dump out the Bunny's Tree.

Bullet 2.77 on Ubuntu 10.10 x86_64

Code: Select all

void traverse_softbody_tree(btSoftBody* psb)
{
	traverse_softbody_tree_rec(psb->m_ndbvt.m_root);
}

static int node_num = 0;
void traverse_softbody_tree_rec(const btDbvtNode *n)
{
	std::cout << "\nIn node : " << node_num++ << std::endl;
	std::cout << n->volume.Mins().getX() << " : ";
	std::cout << n->volume.Mins().getY() << " : ";
	std::cout << n->volume.Mins().getZ() << std::endl;

	std::cout << n->volume.Maxs().getX() << " : ";
	std::cout << n->volume.Maxs().getY() << " : ";
	std::cout << n->volume.Maxs().getZ() << std::endl;

	if (n->isleaf()) {
		std::cout << "In Leaf: data is " << (n->dataAsInt) << std::endl;
		std::cout << "In Leaf: data is " << (n->data) << std::endl;
		btSoftBody::Face& f = *(btSoftBody::Face*) n->data;

		for (int i = 0; i < 3; ++i) {
			btVector3 & m = f.m_n[i]->m_x;  //This is always a nonsense address :(
			for (int j = 0; j < 3; ++j) {
				std::cout << m.m_floats[j] << " : ";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;

		return;
	}

	assert(n->isinternal());

	traverse_softbody_tree_rec(n->childs[0]);
	traverse_softbody_tree_rec(n->childs[1]);
}

Any help much appreciated. This is driving me mad!
elethiomel
Posts: 10
Joined: Wed Oct 27, 2010 11:05 pm

Re: Dumping out a Softbody Tree

Post by elethiomel »

OK problem 1 solved. I was traversing the node tree (m_ndbvt) and the pointer should have been cast to a Node.
I assume I should have been traversing the face tree (m_fdbvt). For some reason this is empty...

In what cases does it get built?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Dumping out a Softbody Tree

Post by Erwin Coumans »

It is best to check out the debug drawing code in
http://code.google.com/p/bullet/source/ ... ld.cpp#158

The face tree is only created if the softbody contains faces. It is up to the user to create soft bodies that contain a mix of constraints between nodes, faces or tetrahedra. It is best to examine the BulletSoftBody demo.

Thanks,
Erwin
elethiomel
Posts: 10
Joined: Wed Oct 27, 2010 11:05 pm

Re: Dumping out a Softbody Tree

Post by elethiomel »

Thanks for the reply Erwin!

I'm currently using btSoftBodyHelpers::CreateFromTriMesh to build a SoftBody from the bunny mesh. I thought that would create a Softbody with all the trimmings. I'll dig further into the SoftBody Demo. Eventually I want a Softbody that will collide as accurately as possible with all given objects and I need there to be an AABB of faces for my own use.

BTW are the trees refit each step or are they rebuilt?
elethiomel
Posts: 10
Joined: Wed Oct 27, 2010 11:05 pm

Re: Dumping out a Softbody Tree

Post by elethiomel »

I added a check to the SoftDemo after each SoftBody is created and the psb->m_fdbvt.m_root is always NULL, no matter what the demo. There never seems to be a case when the face tree is built :(