1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
/* The MIT License
*
* Copyright (c) 2010 Intel Corporation.
* All rights reserved.
*
* Based on the convexdecomposition library from
* <http://codesuppository.googlecode.com> by John W. Ratcliff and Stan Melax.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
using System;
using System.Collections.Generic;
namespace OpenSim.Region.PhysicsModule.ConvexDecompositionDotNet
{
public class HullResult
{
public bool Polygons = true; // true if indices represents polygons, false indices are triangles
public List<float3> OutputVertices = new List<float3>();
public List<int> Indices;
// If triangles, then indices are array indexes into the vertex list.
// If polygons, indices are in the form (number of points in face) (p1, p2, p3, ..) etc..
}
public class PHullResult
{
public List<float3> Vertices = new List<float3>();
public List<int> Indices = new List<int>();
}
[Flags]
public enum HullFlag : int
{
QF_DEFAULT = 0,
QF_TRIANGLES = (1 << 0), // report results as triangles, not polygons.
QF_SKIN_WIDTH = (1 << 2) // extrude hull based on this skin width
}
public enum HullError : int
{
QE_OK, // success!
QE_FAIL // failed.
}
public class HullDesc
{
public HullFlag Flags; // flags to use when generating the convex hull.
public List<float3> Vertices;
public float NormalEpsilon; // the epsilon for removing duplicates. This is a normalized value, if normalized bit is on.
public float SkinWidth;
public uint MaxVertices; // maximum number of vertices to be considered for the hull!
public uint MaxFaces;
public HullDesc()
{
Flags = HullFlag.QF_DEFAULT;
Vertices = new List<float3>();
NormalEpsilon = 0.001f;
MaxVertices = 4096;
MaxFaces = 4096;
SkinWidth = 0.01f;
}
public HullDesc(HullFlag flags, List<float3> vertices)
{
Flags = flags;
Vertices = new List<float3>(vertices);
NormalEpsilon = 0.001f;
MaxVertices = 4096;
MaxFaces = 4096;
SkinWidth = 0.01f;
}
public bool HasHullFlag(HullFlag flag)
{
return (Flags & flag) != 0;
}
public void SetHullFlag(HullFlag flag)
{
Flags |= flag;
}
public void ClearHullFlag(HullFlag flag)
{
Flags &= ~flag;
}
}
public class ConvexH
{
public struct HalfEdge
{
public short ea; // the other half of the edge (index into edges list)
public byte v; // the vertex at the start of this edge (index into vertices list)
public byte p; // the facet on which this edge lies (index into facets list)
public HalfEdge(short _ea, byte _v, byte _p)
{
ea = _ea;
v = _v;
p = _p;
}
public HalfEdge(HalfEdge e)
{
ea = e.ea;
v = e.v;
p = e.p;
}
}
public List<float3> vertices = new List<float3>();
public List<HalfEdge> edges = new List<HalfEdge>();
public List<Plane> facets = new List<Plane>();
public ConvexH(int vertices_size, int edges_size, int facets_size)
{
vertices = new List<float3>(vertices_size);
edges = new List<HalfEdge>(edges_size);
facets = new List<Plane>(facets_size);
}
}
public class VertFlag
{
public byte planetest;
public byte junk;
public byte undermap;
public byte overmap;
}
public class EdgeFlag
{
public byte planetest;
public byte fixes;
public short undermap;
public short overmap;
}
public class PlaneFlag
{
public byte undermap;
public byte overmap;
}
public class Coplanar
{
public ushort ea;
public byte v0;
public byte v1;
}
}
|