diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BulletXPlugin/TriangleIndexVertexArray.cs | 161 |
1 files changed, 161 insertions, 0 deletions
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 | */ | ||
35 | using System; | ||
36 | using System.Collections.Generic; | ||
37 | using System.Text; | ||
38 | using MonoXnaCompactMaths; | ||
39 | |||
40 | namespace 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 | } | ||