Hi
I am building collisiondetection model in contentpipeline and storing it in the tag-field of Model -class (just like in your example). This is due to the fact that calculating the collision model is expensive timewise and it is best done at build time. In the game the collision model works great. Now I just want to modify the combined collision model (which is stored in tag) a bit for gameplay reasons (e.g. you can drive through tree branches and plants)
I thought that this is best to do in the contentPipeline, where I read one single world 3D model (.x) and I just modify meshes a bit to make them more simple for collision detection purposes (I know which meshes need to be replaced with certain type of objects, here just cylinders.) So i plan to replace certain meshes with more simper object e.g. with a cylinder. I just need to position the cylinder in the same world position as the original object. Somehow the below code do not work, that well. (I have simplified the below code a bit)
01.foreach (var mesh in meshes)
02.{
03. Matrix transform = mesh.AbsoluteTransform;
04. for (int i = 0; i < mesh.Positions.Count; i++)
05. mesh.Positions[i] = Vector3.Transform(mesh.Positions[i], transform);
06.
07. // Here is the tricky stuff!
08. CylinderShape tempShape = new CylinderShape(1f,100);
09. TriangleMesh d = tempShape .GetMesh(0.1f, 100);
10. d.Transform(Matrix44F.FromXna(transform));
11. triangleMesh.Add(d, false);
12.}
13........
14.
15.triangleMesh.WeldVertices();
16.CompressedAabbTree s = new CompressedAabbTree();
17.TriangleMeshShape triangleMeshShape = new TriangleMeshShape(triangleMesh, true, s);