aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletXPlugin
diff options
context:
space:
mode:
authorTeravus Ovares2007-11-10 19:13:52 +0000
committerTeravus Ovares2007-11-10 19:13:52 +0000
commitcb07ba0d68eeb57bae1cb60f387483ff720cc29d (patch)
treea46f7b6b50e70a9f5f56a89396ba8a3f1078c19e /OpenSim/Region/Physics/BulletXPlugin
parent* ODE Fixed annoying bug where resizing causes there to be a 'ghost' prim lef... (diff)
downloadopensim-SC_OLD-cb07ba0d68eeb57bae1cb60f387483ff720cc29d.zip
opensim-SC_OLD-cb07ba0d68eeb57bae1cb60f387483ff720cc29d.tar.gz
opensim-SC_OLD-cb07ba0d68eeb57bae1cb60f387483ff720cc29d.tar.bz2
opensim-SC_OLD-cb07ba0d68eeb57bae1cb60f387483ff720cc29d.tar.xz
* Moves the Meshmerizer to a separate plugin
* Experimental. Linux Prebuild needs testing. * One more update after this to remove the ODEMeshing directory....
Diffstat (limited to 'OpenSim/Region/Physics/BulletXPlugin')
-rw-r--r--OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs145
-rw-r--r--OpenSim/Region/Physics/BulletXPlugin/TriangleIndexVertexArray.cs161
2 files changed, 275 insertions, 31 deletions
diff --git a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs
index c733adb..2db7a54 100644
--- a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs
+++ b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs
@@ -64,6 +64,7 @@ using System;
64using System.Collections.Generic; 64using System.Collections.Generic;
65using MonoXnaCompactMaths; 65using MonoXnaCompactMaths;
66using OpenSim.Framework; 66using OpenSim.Framework;
67using OpenSim.Framework.Console;
67using OpenSim.Region.Physics.Manager; 68using OpenSim.Region.Physics.Manager;
68using XnaDevRu.BulletX; 69using XnaDevRu.BulletX;
69using XnaDevRu.BulletX.Dynamics; 70using XnaDevRu.BulletX.Dynamics;
@@ -74,15 +75,6 @@ using BoxShape=XnaDevRu.BulletX.BoxShape;
74 75
75namespace OpenSim.Region.Physics.BulletXPlugin 76namespace OpenSim.Region.Physics.BulletXPlugin
76{ 77{
77 /// <summary>
78 /// This class is only here for compilations reasons
79 /// </summary>
80 public class Mesh
81 {
82 public Mesh()
83 {
84 }
85 }
86 78
87 /// <summary> 79 /// <summary>
88 /// BulletXConversions are called now BulletXMaths 80 /// BulletXConversions are called now BulletXMaths
@@ -268,6 +260,65 @@ namespace OpenSim.Region.Physics.BulletXPlugin
268 } 260 }
269 } 261 }
270 262
263
264 // Class to detect and debug collisions
265 // Mainly used for debugging purposes
266 class CollisionDispatcherLocal : CollisionDispatcher
267 {
268
269 BulletXScene relatedScene;
270
271 public CollisionDispatcherLocal(BulletXScene s)
272 : base()
273 {
274 relatedScene=s;
275 }
276
277 public override bool NeedsCollision(CollisionObject bodyA, CollisionObject bodyB)
278 {
279 RigidBody rb;
280 BulletXCharacter bxcA=null;
281 BulletXPrim bxpA = null;
282 Type t = bodyA.GetType();
283 if (t==typeof(RigidBody)) {
284 rb = (RigidBody)bodyA;
285 relatedScene._characters.TryGetValue(rb, out bxcA);
286 relatedScene._prims.TryGetValue(rb, out bxpA);
287 }
288 String nameA;
289 if (bxcA != null)
290 nameA = bxcA._name;
291 else if (bxpA != null)
292 nameA = bxpA._name;
293 else
294 nameA = "null";
295
296 BulletXCharacter bxcB = null;
297 BulletXPrim bxpB = null;
298 t = bodyB.GetType();
299 if (t == typeof(RigidBody))
300 {
301 rb = (RigidBody)bodyB;
302 relatedScene._characters.TryGetValue(rb, out bxcB);
303 relatedScene._prims.TryGetValue(rb, out bxpB);
304 }
305 String nameB;
306 if (bxcB != null)
307 nameB = bxcB._name;
308 else if (bxpB != null)
309 nameB = bxpB._name;
310 else
311 nameB = "null";
312
313 bool needsCollision=base.NeedsCollision(bodyA, bodyB);
314
315 MainLog.Instance.Debug("BulletX", "A collision was detected between {0} and {1} --> {2}", nameA, nameB, needsCollision);
316
317
318 return needsCollision;
319 }
320 }
321
271 /// <summary> 322 /// <summary>
272 /// PhysicsScene Class for BulletX 323 /// PhysicsScene Class for BulletX
273 /// </summary> 324 /// </summary>
@@ -294,8 +345,11 @@ namespace OpenSim.Region.Physics.BulletXPlugin
294 private const int simulationSubSteps = 10; 345 private const int simulationSubSteps = 10;
295 //private float[] _heightmap; 346 //private float[] _heightmap;
296 private BulletXPlanet _simFlatPlanet; 347 private BulletXPlanet _simFlatPlanet;
297 private List<BulletXCharacter> _characters = new List<BulletXCharacter>(); 348 internal Dictionary<RigidBody, BulletXCharacter> _characters = new Dictionary<RigidBody, BulletXCharacter>();
298 private List<BulletXPrim> _prims = new List<BulletXPrim>(); 349 internal Dictionary<RigidBody, BulletXPrim> _prims = new Dictionary<RigidBody, BulletXPrim>();
350
351 public IMesher mesher;
352
299 353
300 public static float Gravity 354 public static float Gravity
301 { 355 {
@@ -334,7 +388,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
334 388
335 public BulletXScene() 389 public BulletXScene()
336 { 390 {
337 cDispatcher = new CollisionDispatcher(); 391 cDispatcher = new CollisionDispatcherLocal(this);
338 Vector3 worldMinDim = new Vector3((float) minXY, (float) minXY, (float) minZ); 392 Vector3 worldMinDim = new Vector3((float) minXY, (float) minXY, (float) minZ);
339 Vector3 worldMaxDim = new Vector3((float) maxXY, (float) maxXY, (float) maxZ); 393 Vector3 worldMaxDim = new Vector3((float) maxXY, (float) maxXY, (float) maxZ);
340 opCache = new AxisSweep3(worldMinDim, worldMaxDim, maxHandles); 394 opCache = new AxisSweep3(worldMinDim, worldMaxDim, maxHandles);
@@ -348,6 +402,12 @@ namespace OpenSim.Region.Physics.BulletXPlugin
348 //this._heightmap = new float[65536]; 402 //this._heightmap = new float[65536];
349 } 403 }
350 404
405 public override void Initialise(IMesher meshmerizer)
406 {
407 mesher = meshmerizer;
408 }
409
410
351 public override PhysicsActor AddAvatar(string avName, PhysicsVector position) 411 public override PhysicsActor AddAvatar(string avName, PhysicsVector position)
352 { 412 {
353 PhysicsVector pos = new PhysicsVector(); 413 PhysicsVector pos = new PhysicsVector();
@@ -358,7 +418,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
358 lock (BulletXLock) 418 lock (BulletXLock)
359 { 419 {
360 newAv = new BulletXCharacter(avName, this, pos); 420 newAv = new BulletXCharacter(avName, this, pos);
361 _characters.Add(newAv); 421 _characters.Add(newAv.RigidBody, newAv);
362 } 422 }
363 return newAv; 423 return newAv;
364 } 424 }
@@ -379,7 +439,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
379 ((BulletXCharacter) actor).RigidBody.ActivationState = ActivationState.DisableSimulation; 439 ((BulletXCharacter) actor).RigidBody.ActivationState = ActivationState.DisableSimulation;
380 AddForgottenRigidBody(((BulletXCharacter) actor).RigidBody); 440 AddForgottenRigidBody(((BulletXCharacter) actor).RigidBody);
381 } 441 }
382 _characters.Remove((BulletXCharacter) actor); 442 _characters.Remove(((BulletXCharacter)actor).RigidBody);
383 } 443 }
384 GC.Collect(); 444 GC.Collect();
385 } 445 }
@@ -405,7 +465,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
405 } 465 }
406 else 466 else
407 { 467 {
408 Mesh mesh = null; 468 IMesh mesh = mesher.CreateMesh(primName, pbs, size);
409 result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical); 469 result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical);
410 } 470 }
411 break; 471 break;
@@ -419,13 +479,13 @@ namespace OpenSim.Region.Physics.BulletXPlugin
419 } 479 }
420 480
421 public PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation, 481 public PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation,
422 Mesh mesh, PrimitiveBaseShape pbs, bool isPhysical) 482 IMesh mesh, PrimitiveBaseShape pbs, bool isPhysical)
423 { 483 {
424 BulletXPrim newPrim = null; 484 BulletXPrim newPrim = null;
425 lock (BulletXLock) 485 lock (BulletXLock)
426 { 486 {
427 newPrim = new BulletXPrim(name, this, position, size, rotation, mesh, pbs, isPhysical); 487 newPrim = new BulletXPrim(name, this, position, size, rotation, mesh, pbs, isPhysical);
428 _prims.Add(newPrim); 488 _prims.Add(newPrim.RigidBody, newPrim);
429 } 489 }
430 return newPrim; 490 return newPrim;
431 } 491 }
@@ -446,7 +506,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
446 ((BulletXPrim) prim).RigidBody.ActivationState = ActivationState.DisableSimulation; 506 ((BulletXPrim) prim).RigidBody.ActivationState = ActivationState.DisableSimulation;
447 AddForgottenRigidBody(((BulletXPrim) prim).RigidBody); 507 AddForgottenRigidBody(((BulletXPrim) prim).RigidBody);
448 } 508 }
449 _prims.Remove((BulletXPrim) prim); 509 _prims.Remove(((BulletXPrim) prim).RigidBody);
450 } 510 }
451 GC.Collect(); 511 GC.Collect();
452 } 512 }
@@ -470,11 +530,11 @@ namespace OpenSim.Region.Physics.BulletXPlugin
470 530
471 private void MoveAllObjects(float timeStep) 531 private void MoveAllObjects(float timeStep)
472 { 532 {
473 foreach (BulletXCharacter actor in _characters) 533 foreach (BulletXCharacter actor in _characters.Values)
474 { 534 {
475 actor.Move(timeStep); 535 actor.Move(timeStep);
476 } 536 }
477 foreach (BulletXPrim prim in _prims) 537 foreach (BulletXPrim prim in _prims.Values)
478 { 538 {
479 } 539 }
480 } 540 }
@@ -482,14 +542,14 @@ namespace OpenSim.Region.Physics.BulletXPlugin
482 private void ValidateHeightForAll() 542 private void ValidateHeightForAll()
483 { 543 {
484 float _height; 544 float _height;
485 foreach (BulletXCharacter actor in _characters) 545 foreach (BulletXCharacter actor in _characters.Values)
486 { 546 {
487 //_height = HeightValue(actor.RigidBodyPosition); 547 //_height = HeightValue(actor.RigidBodyPosition);
488 _height = _simFlatPlanet.HeightValue(actor.RigidBodyPosition); 548 _height = _simFlatPlanet.HeightValue(actor.RigidBodyPosition);
489 actor.ValidateHeight(_height); 549 actor.ValidateHeight(_height);
490 //if (_simFlatPlanet.heightIsNotValid(actor.RigidBodyPosition, out _height)) actor.ValidateHeight(_height); 550 //if (_simFlatPlanet.heightIsNotValid(actor.RigidBodyPosition, out _height)) actor.ValidateHeight(_height);
491 } 551 }
492 foreach (BulletXPrim prim in _prims) 552 foreach (BulletXPrim prim in _prims.Values)
493 { 553 {
494 //_height = HeightValue(prim.RigidBodyPosition); 554 //_height = HeightValue(prim.RigidBodyPosition);
495 _height = _simFlatPlanet.HeightValue(prim.RigidBodyPosition); 555 _height = _simFlatPlanet.HeightValue(prim.RigidBodyPosition);
@@ -510,11 +570,11 @@ namespace OpenSim.Region.Physics.BulletXPlugin
510 { 570 {
511 //UpdatePosition > UpdateKinetics. 571 //UpdatePosition > UpdateKinetics.
512 //Not only position will be updated, also velocity cause acceleration. 572 //Not only position will be updated, also velocity cause acceleration.
513 foreach (BulletXCharacter actor in _characters) 573 foreach (BulletXCharacter actor in _characters.Values)
514 { 574 {
515 actor.UpdateKinetics(); 575 actor.UpdateKinetics();
516 } 576 }
517 foreach (BulletXPrim prim in _prims) 577 foreach (BulletXPrim prim in _prims.Values)
518 { 578 {
519 prim.UpdateKinetics(); 579 prim.UpdateKinetics();
520 } 580 }
@@ -646,9 +706,11 @@ namespace OpenSim.Region.Physics.BulletXPlugin
646 protected PhysicsVector m_rotationalVelocity = PhysicsVector.Zero; 706 protected PhysicsVector m_rotationalVelocity = PhysicsVector.Zero;
647 protected RigidBody rigidBody; 707 protected RigidBody rigidBody;
648 private Boolean iscolliding = false; 708 private Boolean iscolliding = false;
709 internal string _name;
649 710
650 public BulletXActor() 711 public BulletXActor(String name)
651 { 712 {
713 _name = name;
652 } 714 }
653 715
654 public override PhysicsVector Position 716 public override PhysicsVector Position
@@ -847,6 +909,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
847 } 909 }
848 public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, 910 public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity,
849 PhysicsVector size, PhysicsVector acceleration, AxiomQuaternion orientation) 911 PhysicsVector size, PhysicsVector acceleration, AxiomQuaternion orientation)
912 : base(avName)
850 { 913 {
851 //This fields will be removed. They're temporal 914 //This fields will be removed. They're temporal
852 float _sizeX = 0.5f; 915 float _sizeX = 0.5f;
@@ -1016,14 +1079,15 @@ namespace OpenSim.Region.Physics.BulletXPlugin
1016 private bool m_lastUpdateSent = false; 1079 private bool m_lastUpdateSent = false;
1017 1080
1018 public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, 1081 public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size,
1019 AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs, bool isPhysical) 1082 AxiomQuaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool isPhysical)
1020 : this(primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs, isPhysical) 1083 : this(primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs, isPhysical)
1021 { 1084 {
1022 } 1085 }
1023 public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, 1086 public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity,
1024 PhysicsVector size, 1087 PhysicsVector size,
1025 PhysicsVector acceleration, AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs, 1088 PhysicsVector acceleration, AxiomQuaternion rotation, IMesh mesh, PrimitiveBaseShape pbs,
1026 bool isPhysical) 1089 bool isPhysical)
1090 : base(primName)
1027 { 1091 {
1028 if ((size.X == 0) || (size.Y == 0) || (size.Z == 0)) throw new Exception("Size 0"); 1092 if ((size.X == 0) || (size.Y == 0) || (size.Z == 0)) throw new Exception("Size 0");
1029 if (rotation.Norm == 0f) rotation = AxiomQuaternion.Identity; 1093 if (rotation.Norm == 0f) rotation = AxiomQuaternion.Identity;
@@ -1037,7 +1101,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
1037 1101
1038 _parent_scene = parent_scene; 1102 _parent_scene = parent_scene;
1039 1103
1040 CreateRigidBody(parent_scene, pos, size); 1104 CreateRigidBody(parent_scene, mesh, pos, size);
1041 } 1105 }
1042 1106
1043 public override PhysicsVector Position 1107 public override PhysicsVector Position
@@ -1191,7 +1255,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
1191 } 1255 }
1192 1256
1193 #region Methods for updating values of RigidBody 1257 #region Methods for updating values of RigidBody
1194 internal protected void CreateRigidBody(BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size) 1258 internal protected void CreateRigidBody(BulletXScene parent_scene, IMesh mesh, PhysicsVector pos, PhysicsVector size)
1195 { 1259 {
1196 //For RigidBody Constructor. The next values might change 1260 //For RigidBody Constructor. The next values might change
1197 float _linearDamping = 0.0f; 1261 float _linearDamping = 0.0f;
@@ -1204,7 +1268,26 @@ namespace OpenSim.Region.Physics.BulletXPlugin
1204 { 1268 {
1205 _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(pos); 1269 _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(pos);
1206 //For now all prims are boxes 1270 //For now all prims are boxes
1207 CollisionShape _collisionShape = new XnaDevRu.BulletX.BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(size) / 2.0f); 1271 CollisionShape _collisionShape;
1272 if (mesh == null)
1273 {
1274 _collisionShape = new XnaDevRu.BulletX.BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(size) / 2.0f);
1275 } else {
1276 int iVertexCount = mesh.getVertexList().Count;
1277 int[] indices = mesh.getIndexListAsInt();
1278 Vector3[] v3Vertices = new Vector3[iVertexCount];
1279 for (int i = 0; i < iVertexCount; i++)
1280 {
1281 PhysicsVector v=mesh.getVertexList()[i];
1282 if (v != null) // Note, null has special meaning. See meshing code for details
1283 v3Vertices[i] = BulletXMaths.PhysicsVectorToXnaVector3(v);
1284 else
1285 v3Vertices[i] = MonoXnaCompactMaths.Vector3.Zero;
1286 }
1287 TriangleIndexVertexArray triMesh = new TriangleIndexVertexArray(indices, v3Vertices);
1288
1289 _collisionShape = new XnaDevRu.BulletX.TriangleMeshShape(triMesh);
1290 }
1208 DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); 1291 DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset);
1209 Vector3 _localInertia = new Vector3(); 1292 Vector3 _localInertia = new Vector3();
1210 if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0 1293 if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0
@@ -1231,7 +1314,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
1231 rigidBody.ActivationState = ActivationState.DisableSimulation; 1314 rigidBody.ActivationState = ActivationState.DisableSimulation;
1232 this._parent_scene.AddForgottenRigidBody(rigidBody); 1315 this._parent_scene.AddForgottenRigidBody(rigidBody);
1233 } 1316 }
1234 CreateRigidBody(this._parent_scene, this._position, size); 1317 CreateRigidBody(this._parent_scene, null, this._position, size); // Note, null for the meshing definitely is wrong. It's here for the moment to apease the compiler
1235 if (_physical) Speed();//Static objects don't have linear velocity 1318 if (_physical) Speed();//Static objects don't have linear velocity
1236 ReOrient(); 1319 ReOrient();
1237 GC.Collect(); 1320 GC.Collect();
diff --git a/OpenSim/Region/Physics/BulletXPlugin/TriangleIndexVertexArray.cs b/OpenSim/Region/Physics/BulletXPlugin/TriangleIndexVertexArray.cs
new file mode 100644
index 0000000..fb30296
--- /dev/null
+++ b/OpenSim/Region/Physics/BulletXPlugin/TriangleIndexVertexArray.cs
@@ -0,0 +1,161 @@
1/*
2 Bullet for XNA Copyright (c) 2003-2007 Vsevolod Klementjev http://www.codeplex.com/xnadevru
3 Bullet original C++ version Copyright (c) 2003-2007 Erwin Coumans http://bulletphysics.com
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/*
23
24 This file contains a class TriangleIndexVertexArray. I tried using the class with the same name
25 from the BulletX implementation and found it unusable for the purpose of using triangle meshes
26 within BulletX as the implementation was painfully incomplete.
27 The attempt to derive from the original class failed as viable members were hidden.
28 Fiddling around with BulletX itself was not my intention.
29 So I copied the class to the BulletX-plugin and modified it.
30 If you want to fiddle around with it it's up to you to move all this to BulletX.
31 If someone someday implements the missing functionality in BulletX, feel free to remove this class.
32 It's just an ugly hack.
33
34 */
35using System;
36using System.Collections.Generic;
37using System.Text;
38using MonoXnaCompactMaths;
39
40namespace OpenSim.Region.Physics.BulletXPlugin
41{
42 /// <summary>
43 /// IndexedMesh indexes into existing vertex and index arrays, in a similar way OpenGL glDrawElements
44 /// instead of the number of indices, we pass the number of triangles
45 /// </summary>
46 public struct IndexedMesh
47 {
48 private int _numTriangles;
49 private int[] _triangleIndexBase;
50 private int _triangleIndexStride;
51 private int _numVertices;
52 private Vector3[] _vertexBase;
53 private int _vertexStride;
54
55 public IndexedMesh(int numTriangleIndices, int[] triangleIndexBase, int triangleIndexStride, int numVertices, Vector3[] vertexBase, int vertexStride)
56 {
57 _numTriangles = numTriangleIndices;
58 _triangleIndexBase = triangleIndexBase;
59 _triangleIndexStride = triangleIndexStride;
60 _vertexBase = vertexBase;
61 _numVertices = numVertices;
62 _vertexStride = vertexStride;
63 }
64
65 public IndexedMesh(int[] triangleIndexBase, Vector3[] vertexBase)
66 {
67 _numTriangles = triangleIndexBase.Length;
68 _triangleIndexBase = triangleIndexBase;
69 _triangleIndexStride = 32;
70 _vertexBase = vertexBase;
71 _numVertices = vertexBase.Length;
72 _vertexStride = 24;
73 }
74
75 public int TriangleCount { get { return _numTriangles; } set { _numTriangles = value; } }
76 public int[] TriangleIndexBase { get { return _triangleIndexBase; } set { _triangleIndexBase = value; } }
77 public int TriangleIndexStride { get { return _triangleIndexStride; } set { _triangleIndexStride = value; } }
78 public int VertexCount { get { return _numVertices; } set { _numVertices = value; } }
79 public Vector3[] VertexBase { get { return _vertexBase; } set { _vertexBase = value; } }
80 public int VertexStride { get { return _vertexStride; } set { _vertexStride = value; } }
81 }
82
83 /// <summary>
84 /// TriangleIndexVertexArray allows to use multiple meshes, by indexing into existing triangle/index arrays.
85 /// Additional meshes can be added using addIndexedMesh
86 /// </summary>
87 public class TriangleIndexVertexArray : XnaDevRu.BulletX.StridingMeshInterface
88 {
89 List<IndexedMesh> _indexedMeshes = new List<IndexedMesh>();
90
91 public TriangleIndexVertexArray() { }
92
93 public TriangleIndexVertexArray(int numTriangleIndices, int[] triangleIndexBase, int triangleIndexStride, int numVertices, Vector3[] vertexBase, int vertexStride)
94 {
95 IndexedMesh mesh = new IndexedMesh();
96 mesh.TriangleCount = numTriangleIndices;
97 mesh.TriangleIndexBase = triangleIndexBase;
98 mesh.TriangleIndexStride = triangleIndexStride;
99 mesh.VertexBase = vertexBase;
100 mesh.VertexCount = numVertices;
101 mesh.VertexStride = vertexStride;
102
103 AddIndexedMesh(mesh);
104 }
105
106 public TriangleIndexVertexArray(int[] triangleIndexBase, Vector3[] vertexBase)
107 : this(triangleIndexBase.Length, triangleIndexBase, 32, vertexBase.Length, vertexBase, 24) { }
108
109 public void AddIndexedMesh(IndexedMesh indexedMesh)
110 {
111 _indexedMeshes.Add(indexedMesh);
112 }
113
114 public override void GetLockedVertexIndexBase(out List<Vector3> verts, out List<int> indicies, out int numfaces, int subpart)
115 {
116 throw new Exception("The method or operation is not implemented.");
117 }
118
119 public override void GetLockedReadOnlyVertexIndexBase(out List<Vector3> verts, out List<int> indicies, out int numfaces, int subpart)
120 {
121 IndexedMesh m = _indexedMeshes[0];
122 Vector3[] vertexBase = m.VertexBase;
123 verts = new List<Vector3>();
124 foreach (Vector3 v in vertexBase)
125 {
126 verts.Add(v);
127 }
128 int[] indexBase = m.TriangleIndexBase;
129 indicies = new List<int>();
130 foreach (int i in indexBase)
131 {
132 indicies.Add(i);
133 }
134 numfaces = vertexBase.GetLength(0);
135 }
136
137 public override void UnLockVertexBase(int subpart)
138 {
139 throw new Exception("The method or operation is not implemented.");
140 }
141
142 public override void UnLockReadOnlyVertexBase(int subpart)
143 {
144 }
145
146 public override int SubPartsCount()
147 {
148 return _indexedMeshes.Count;
149 }
150
151 public override void PreallocateVertices(int numverts)
152 {
153 throw new Exception("The method or operation is not implemented.");
154 }
155
156 public override void PreallocateIndices(int numindices)
157 {
158 throw new Exception("The method or operation is not implemented.");
159 }
160 }
161}