diff options
Diffstat (limited to 'OpenSim/Region/Physics/Meshing/Extruder.cs')
-rw-r--r-- | OpenSim/Region/Physics/Meshing/Extruder.cs | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/Meshing/Extruder.cs b/OpenSim/Region/Physics/Meshing/Extruder.cs new file mode 100644 index 0000000..63d727f --- /dev/null +++ b/OpenSim/Region/Physics/Meshing/Extruder.cs | |||
@@ -0,0 +1,83 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Region.Physics.Meshing | ||
6 | { | ||
7 | class Extruder | ||
8 | { | ||
9 | public float startParameter; | ||
10 | public float stopParameter; | ||
11 | public Manager.PhysicsVector size; | ||
12 | |||
13 | public Mesh Extrude(Mesh m) | ||
14 | { | ||
15 | // Currently only works for iSteps=1; | ||
16 | Mesh result = new Mesh(); | ||
17 | |||
18 | Mesh workingPlus = m.Clone(); | ||
19 | Mesh workingMinus = m.Clone(); | ||
20 | |||
21 | foreach (Vertex v in workingPlus.vertices) | ||
22 | { | ||
23 | if (v == null) | ||
24 | continue; | ||
25 | |||
26 | v.Z = +.5f; | ||
27 | v.X *= size.X; | ||
28 | v.Y *= size.Y; | ||
29 | v.Z *= size.Z; | ||
30 | } | ||
31 | |||
32 | foreach (Vertex v in workingMinus.vertices) | ||
33 | { | ||
34 | if (v == null) | ||
35 | continue; | ||
36 | |||
37 | v.Z = -.5f; | ||
38 | v.X *= size.X; | ||
39 | v.Y *= size.Y; | ||
40 | v.Z *= size.Z; | ||
41 | } | ||
42 | |||
43 | foreach (Triangle t in workingMinus.triangles) | ||
44 | { | ||
45 | t.invertNormal(); | ||
46 | } | ||
47 | |||
48 | result.Append(workingMinus); | ||
49 | result.Append(workingPlus); | ||
50 | |||
51 | int iLastNull = 0; | ||
52 | for (int i = 0; i < workingPlus.vertices.Count; i++) | ||
53 | { | ||
54 | int iNext = (i + 1); | ||
55 | |||
56 | if (workingPlus.vertices[i] == null) // Can't make a simplex here | ||
57 | { | ||
58 | iLastNull = i+1; | ||
59 | continue; | ||
60 | } | ||
61 | |||
62 | if (i == workingPlus.vertices.Count-1) // End of list | ||
63 | { | ||
64 | iNext = iLastNull; | ||
65 | } | ||
66 | |||
67 | if (workingPlus.vertices[iNext] == null) // Null means wrap to begin of last segment | ||
68 | { | ||
69 | iNext = iLastNull; | ||
70 | } | ||
71 | |||
72 | Triangle tSide; | ||
73 | tSide = new Triangle(workingPlus.vertices[i], workingMinus.vertices[i], workingPlus.vertices[iNext]); | ||
74 | result.Add(tSide); | ||
75 | |||
76 | tSide = new Triangle(workingPlus.vertices[iNext], workingMinus.vertices[i], workingMinus.vertices[iNext]); | ||
77 | result.Add(tSide); | ||
78 | } | ||
79 | |||
80 | return result; | ||
81 | } | ||
82 | } | ||
83 | } | ||