aabbTest at subshape-level of compound - no such feature?

Post Reply
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

aabbTest at subshape-level of compound - no such feature?

Post by hyyou »

In a world that contains many btRigidBody, and each btRigidBody has btCompoundShape as its shape,
how can I know which plain shapes (small shape inside btCompoundShape) are in a certain AABB volume?

Here is how I currently call. It works, but I can only get callback as body, not shape.

Code: Select all

bool process(const btBroadphaseProxy* proxy) override{
	btRigidBody* rigid=static_cast<btRigidBody*>(proxy->m_clientObject);
//Here I can access rigid->getUserPointer(), but I can't find a way to get index of shape or any shape-related information
	return true;
}
.....
broadphase->aabbTest(minn,maxx,callbacker);
scorpion81
Posts: 11
Joined: Sun Apr 08, 2012 10:01 am

Re: aabbTest at subshape-level of compound - no such feature

Post by scorpion81 »

Hello,

in my Fracture Modifier Compound implementation (which unfortunately works only partially, as in not good controllable)
I created a btHashMap of ObjectID and ShardID as key (combined string) and stored the shape indexes there....
to be able to track which shard ids map to which shape indexes.
(i use a subclass of btDynamicsWorld ... btFractureDynamicsWorld)

btw m_idCallback calls a blender function which returns the shard and object IDs...

see for example here
https://developer.blender.org/diffusion ... d26f63$493

This is added to the btFractureDynamicsWorld...

Code: Select all

m_childIndexHash = new btHashMap<btHashString, int>();
Here I populate the hashmap...

Code: Select all

...
			for (int i=0; i<numChildren; i++)
			{
				int obIndex, shIndex;
				btCollisionShape *cshape = newCompound->getChildShape(i);
				m_idCallback(cshape->getUserPointer(), &obIndex, &shIndex);
				m_childIndexHash->insert(to_str(obIndex, shIndex), i);
			}

			newBody->recomputeConnectivityByConstraints(this);
...
See also this file...
https://developer.blender.org/diffusion ... 1d26f63$91

Here I access this hashmap "m_childIndexHash" like following...

Code: Select all

void btFractureBody::recomputeConnectivityByConstraints(btCollisionWorld *world1)
{
	btFractureDynamicsWorld *world = (btFractureDynamicsWorld*)world1;

	if (world->m_idCallback != NULL)
	{
		int i, size = world->m_compoundConstraints.size();
		m_connections.clear();

		for (i=0; i<size;i++)
		{
			btCompoundConstraint *con = world->m_compoundConstraints[i];

			if (con->isEnabled())
			{
				int obIdA, shardIdA, obIdB, shardIdB;
				btFractureBody *obA = (btFractureBody*)&con->getRigidBodyA();
				btFractureBody *obB = (btFractureBody*)&con->getRigidBodyB();

				//if (this == obA || this == obB)
				{
					int *index0 = NULL, *index1 = NULL;
					world->m_idCallback(obA->getUserPointer(), &obIdA, &shardIdA);
					world->m_idCallback(obB->getUserPointer(), &obIdB, &shardIdB);

					index0 = world->m_childIndexHash->find(to_str(obIdA, shardIdA));
					index1 = world->m_childIndexHash->find(to_str(obIdB, shardIdB));

					if ((obIdA == obIdB) && (shardIdA != shardIdB) &&
					    index0 && index1 && *index0 > -1 && *index1 > -1)
					{
						btConnection tmp;
						tmp.m_childIndex0 = *index0;
						tmp.m_childIndex1 = *index1;
						tmp.m_childShape0 = obA->getCollisionShape();
						tmp.m_childShape1 = obB->getCollisionShape();
						tmp.m_strength = con->getBreakingImpulseThreshold();
						tmp.m_obA = obA;
						tmp.m_obB = obB;
						tmp.m_parent = this;
						tmp.m_id = i;
						m_connections.push_back(tmp);
					}

					//break;
				}
			}
		}

		m_connections.quickSort(btConnectionSortPredicate());
		//build a connection map
		m_connection_map->clear();

		size = m_connections.size();
		for (i=0; i < size; i++)
		{
			btConnection& con = m_connections[i];
			btAlignedObjectArray<int> *adjacents = m_connection_map->find(con.m_childIndex0);
			if (!adjacents) {
				btAlignedObjectArray<int> adj;
				adj.push_back(con.m_childIndex1);
				m_connection_map->insert(con.m_childIndex0, adj);
			}
			else
			{
				if (adjacents->size() != adjacents->findLinearSearch(con.m_childIndex1))
					adjacents->push_back(con.m_childIndex1);
			}
		}
	}
}
Thats the general idea how i map shape indexes to shards.
Hope this helps you a bit.

Greetings, scorpion81
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

Re: aabbTest at subshape-level of compound - no such feature

Post by hyyou »

Wow, it is such an honor for me that the legendary scorpion81 reply, thank!

I want to find all plain shapes (of enemy) in a certain world's AABB.
They will be damaged by hero's area-damage weapon in a game.

I am afraid that finding adjacent shapes (from connections of compoundConstraint) is not what I want for now, but that information will be really useful as a great reference.

Thank again.
Post Reply