Okay so I've successfully converted an ogre mesh to a physics mesh, using the TriangleMesh thingy to build it. When I try to put it in a RigidBody it just makes the vehicles jump all over the place which wasn't right at all. I then tried putting it in a CollisionObject instead, which worked a lot better, but for some reason my raycast vehicles won't drive on it - the chassis just sits on top and the wheels act as if nothing's there. I can still turn the wheels and stuff though, but trying to move them doesn't work. I can also easily roll spheres along it so it isn't a friction problem.
If I remove the mesh and use one of those infinite plane shapes instead, I can drive on it just fine.
Is this a problem with the raycaster that the vehicle uses? Would I need to roll my own instead of using the default vehicle raycaster, because it doesn't check CollisionObjects or something? I'm kinda stuck.
TriangleMesh CollisionObject and RaycastVehicle not working
-
- Posts: 25
- Joined: Thu Aug 11, 2011 6:42 pm
-
- Posts: 28
- Joined: Sun Jul 31, 2011 11:20 pm
Re: TriangleMesh CollisionObject and RaycastVehicle not work
I am using the raycast vehicle on a converted triangle mesh (from irrlicht) and it is working well with some minor issues of jerking while moving. Is it possible your wheel height, radius or suspension needs adjustment. I can stop vehicles that way. Have you set up debugDrawWorld() to ensure the chassis is not sitting on the level?
-
- Posts: 25
- Joined: Thu Aug 11, 2011 6:42 pm
Re: TriangleMesh CollisionObject and RaycastVehicle not work
my wheels have:
Radius = 0.7
Width = 0.5
SuspensionRestLength = 0.4
SpringStiffness = 200
SpringCompression = 4.2
SpringDamping = 20
FrictionSlip = 100
RollInfluence = 0.2
I can drive over BoxShapes and stuff like that just fine, just not this mesh.
And yes the chassis IS sitting on the level. That's the problem - the wheels are going right through it.
Radius = 0.7
Width = 0.5
SuspensionRestLength = 0.4
SpringStiffness = 200
SpringCompression = 4.2
SpringDamping = 20
FrictionSlip = 100
RollInfluence = 0.2
I can drive over BoxShapes and stuff like that just fine, just not this mesh.
And yes the chassis IS sitting on the level. That's the problem - the wheels are going right through it.
You do not have the required permissions to view the files attached to this post.
-
- Posts: 28
- Joined: Sun Jul 31, 2011 11:20 pm
Re: TriangleMesh CollisionObject and RaycastVehicle not work
The problem rings a bell but it's been a couple of weeks.
Did you create the collision shape with btBvhTriangleMeshShape after building a btTriangleIndexVertexArray?
Did you create the collision shape with btBvhTriangleMeshShape after building a btTriangleIndexVertexArray?
-
- Posts: 25
- Joined: Thu Aug 11, 2011 6:42 pm
Re: TriangleMesh CollisionObject and RaycastVehicle not work
I used a TriangleMesheagletree wrote:The problem rings a bell but it's been a couple of weeks.
Did you create the collision shape with btBvhTriangleMeshShape after building a btTriangleIndexVertexArray?
Code: Select all
var shape = new BvhTriangleMeshShape(OgreToBulletMesh.Convert(dslEnt, dslNode), true, true);
var body = new CollisionObject();
body.CollisionShape = shape;
body.SetCollisionGroup(PonykartCollisionGroups.Environment);
body.CollisionFlags = CollisionFlags.StaticObject;
body.Friction = 1;
body.ContactProcessingThreshold = 1f;
world.AddCollisionObject(body, PonykartCollisionGroups.Environment.ToBullet(), PonykartCollidesWithGroups.Environment.ToBullet());
Code: Select all
/// <summary>
/// Give it an entity and it'll create a BulletSharp.TriangleMesh out of it
/// </summary>
/// <param name="ent">The entity to convert. It'll grab its mesh and use all of its submeshes</param>
/// <param name="node">The node the entity is attached to. We aren't modifying it, but we'll use its transforms</param>
/// <returns>A bullet trimesh</returns>
public static TriangleMesh Convert(Entity ent, SceneNode node) {
// get our two main objects
MeshPtr OgreMesh = ent.GetMesh();
TriangleMesh BulletMesh = new TriangleMesh(true, false);
Launch.Log("[Loading] Converting " + OgreMesh.Name + " to a BulletSharp.TriangleMesh");
uint vertex_count = default(uint);
Vector3[] vertices = default(Vector3[]);
uint index_count = default(uint);
uint[] indices = default(uint[]);
GetMeshInformation(OgreMesh, ref vertex_count, ref vertices, ref index_count, ref indices, node.Position, node.Orientation, node.GetScale());
BulletMesh.PreallocateIndexes((int) index_count);
BulletMesh.PreallocateVertices((int) vertex_count);
BulletMesh.WeldingThreshold = 0.1f;
for (int a = 0; a < index_count; a += 3) {
BulletMesh.AddTriangle(vertices[indices[a]], vertices[indices[a + 1]], vertices[indices[a + 2]], true);
}
return BulletMesh;
}
-
- Posts: 144
- Joined: Fri Aug 01, 2008 6:36 am
- Location: Bonn, Germany
Re: TriangleMesh CollisionObject and RaycastVehicle not work
looks like vehicle's raytest doesn't see the shape... there are some thresholds and collision groups set in your code, check it..I can drive over BoxShapes and stuff like that just fine, just not this mesh.
And yes the chassis IS sitting on the level. That's the problem - the wheels are going right through it.
-
- Posts: 28
- Joined: Sun Jul 31, 2011 11:20 pm
Re: TriangleMesh CollisionObject and RaycastVehicle not work
I don't think my code is of use to you since it's irrlicht, but I believe there are examples targeting your environment. The only interesting thing might be that it uses the TriangleIndexVertexArray which corrected issues I had with my triangle mesh (just looked in my notes and I was also using a btTriangleMesh prior to changing to this). It was code Erwin generated as a tutorial somewhere, possibly on the irrlicht forum, don't remember where I got it. A search of this forum turned up nothing (too much actually) quickly enough, I was looking for the post I read that suggested using the TriangleIndexVertexArray. The only one I found was concerning the level not colliding, not a shape sinking in.
I could provide you the method I have, but it's not for Ogre and could easily be a red herring. I can say that the raycast and triangle mesh are working, so it seems likely it would be in the creation of your mesh.
Perhaps someone else has a more educated guess.
I could provide you the method I have, but it's not for Ogre and could easily be a red herring. I can say that the raycast and triangle mesh are working, so it seems likely it would be in the creation of your mesh.
Perhaps someone else has a more educated guess.
-
- Posts: 25
- Joined: Thu Aug 11, 2011 6:42 pm
Re: TriangleMesh CollisionObject and RaycastVehicle not work
The collision groups are the same as some other static BoxShapes and one of those infinite planes, and it's fine with those.mi076 wrote:looks like vehicle's raytest doesn't see the shape... there are some thresholds and collision groups set in your code, check it..I can drive over BoxShapes and stuff like that just fine, just not this mesh.
And yes the chassis IS sitting on the level. That's the problem - the wheels are going right through it.
I was just kinda playing around with different threshold numbers to see if they would do anything (which they didn't) but I'll try removing them and seeing what happens
There's a custom mesh strider someone wrote for ogre, but I completely failed at trying to rebuild bulletsharp with it added, and I have no idea how to rewrite reinterpret_cast<unsigned char*> in c#. Plus I can't make a subclass of btStridingMeshInterface anyway because of a problem with the wrapper.eagletree wrote:but I believe there are examples targeting your environment
The TriangleIndexVertexArray stuff looks a bit confusing though, especially with the wrapper, though I admit I only skimmed the docs a bit. I can try poking around with those.
You could try posting your code anyway, since the only part where ours should differ is just how we get vertex information from the graphics meshes I'd think.
-
- Posts: 25
- Joined: Thu Aug 11, 2011 6:42 pm
Re: TriangleMesh CollisionObject and RaycastVehicle not work
I think I found the problem, it's in btDefaultVehicleRaycaster -
Note how it casts rayCallback.m_collisionObject to a RigidBody, and it only does the rest if the cast is successful. Since my ground is not a rigidbody, this just keeps returning null for me so the wheels think they're floating in the air
I'm gonna see if I can edit this without breaking everything else
Code: Select all
void* btDefaultVehicleRaycaster::castRay(const btVector3& from,const btVector3& to, btVehicleRaycasterResult& result)
{
// RayResultCallback& resultCallback;
btCollisionWorld::ClosestRayResultCallback rayCallback(from,to);
m_dynamicsWorld->rayTest(from, to, rayCallback);
if (rayCallback.hasHit())
{
btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
if (body && body->hasContactResponse())
{
result.m_hitPointInWorld = rayCallback.m_hitPointWorld;
result.m_hitNormalInWorld = rayCallback.m_hitNormalWorld;
result.m_hitNormalInWorld.normalize();
result.m_distFraction = rayCallback.m_closestHitFraction;
return body;
}
}
return 0;
}
I'm gonna see if I can edit this without breaking everything else
-
- Posts: 28
- Joined: Sun Jul 31, 2011 11:20 pm
Re: TriangleMesh CollisionObject and RaycastVehicle not work
Well that is a difference. My working triangle mesh is a rigidbody.
-
- Posts: 25
- Joined: Thu Aug 11, 2011 6:42 pm
Re: TriangleMesh CollisionObject and RaycastVehicle not work
well
I have no idea what the hell just happened but I made it a rigid body again and now it doesn't spaz out at all
I guess this is solved?
I have no idea what the hell just happened but I made it a rigid body again and now it doesn't spaz out at all
I guess this is solved?