1
0

HullClasses.cs 5.1 KB

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