aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs
diff options
context:
space:
mode:
authorUbitUmarov2012-10-03 19:33:28 +0100
committerUbitUmarov2012-10-03 19:33:28 +0100
commit7137b234b4e99d8d19e83dfb5268674c72f46479 (patch)
tree7c9a899940be65e1fcda108af16207dcebf489ca /OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs
parentAttempt to fix Mantis #6311. Honor a destination folder if one is given (diff)
downloadopensim-SC-7137b234b4e99d8d19e83dfb5268674c72f46479.zip
opensim-SC-7137b234b4e99d8d19e83dfb5268674c72f46479.tar.gz
opensim-SC-7137b234b4e99d8d19e83dfb5268674c72f46479.tar.bz2
opensim-SC-7137b234b4e99d8d19e83dfb5268674c72f46479.tar.xz
introduce a ODEMeshWorker class, should be pure cosmetic changes for now
Diffstat (limited to 'OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs')
-rw-r--r--OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs199
1 files changed, 199 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs b/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs
new file mode 100644
index 0000000..81d59a6
--- /dev/null
+++ b/OpenSim/Region/Physics/UbitOdePlugin/ODEMeshWorker.cs
@@ -0,0 +1,199 @@
1/*
2 * AJLDuarte 2012
3 */
4
5using System;
6using System.Threading;
7using System.Collections.Generic;
8using System.Reflection;
9using System.Runtime.InteropServices;
10using System.Text;
11using OpenSim.Framework;
12using OpenSim.Region.Physics.Manager;
13using OdeAPI;
14using log4net;
15using Nini.Config;
16using OpenMetaverse;
17
18namespace OpenSim.Region.Physics.OdePlugin
19{
20 public class ODEMeshWorker
21 {
22 private ILog m_log;
23 private OdeScene m_scene;
24 private IMesher m_mesher;
25
26 public bool meshSculptedPrim = true;
27 public bool forceSimplePrimMeshing = false;
28 public float meshSculptLOD = 32;
29 public float MeshSculptphysicalLOD = 32;
30
31
32 public ODEMeshWorker(OdeScene pScene, ILog pLog, IMesher pMesher, IConfig pConfig)
33 {
34 m_scene = pScene;
35 m_log = pLog;
36 m_mesher = pMesher;
37
38 if (pConfig != null)
39 {
40 forceSimplePrimMeshing = pConfig.GetBoolean("force_simple_prim_meshing", forceSimplePrimMeshing);
41 meshSculptedPrim = pConfig.GetBoolean("mesh_sculpted_prim", meshSculptedPrim);
42 meshSculptLOD = pConfig.GetFloat("mesh_lod", meshSculptLOD);
43 MeshSculptphysicalLOD = pConfig.GetFloat("mesh_physical_lod", MeshSculptphysicalLOD);
44 }
45 }
46
47
48
49 /// <summary>
50 /// Routine to figure out if we need to mesh this prim with our mesher
51 /// </summary>
52 /// <param name="pbs"></param>
53 /// <returns></returns>
54 public bool needsMeshing(PrimitiveBaseShape pbs)
55 {
56 // check sculpts or meshs
57 if (pbs.SculptEntry)
58 {
59 if (meshSculptedPrim)
60 return true;
61
62 if (pbs.SculptType == (byte)SculptType.Mesh) // always do meshs
63 return true;
64
65 return false;
66 }
67
68 if (forceSimplePrimMeshing)
69 return true;
70
71 // if it's a standard box or sphere with no cuts, hollows, twist or top shear, return false since ODE can use an internal representation for the prim
72
73 if ((pbs.ProfileShape == ProfileShape.Square && pbs.PathCurve == (byte)Extrusion.Straight)
74 || (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1
75 && pbs.Scale.X == pbs.Scale.Y && pbs.Scale.Y == pbs.Scale.Z))
76 {
77
78 if (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0
79 && pbs.ProfileHollow == 0
80 && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0
81 && pbs.PathBegin == 0 && pbs.PathEnd == 0
82 && pbs.PathTaperX == 0 && pbs.PathTaperY == 0
83 && pbs.PathScaleX == 100 && pbs.PathScaleY == 100
84 && pbs.PathShearX == 0 && pbs.PathShearY == 0)
85 {
86 return false;
87 }
88 }
89
90 // following code doesn't give meshs to boxes and spheres ever
91 // and it's odd.. so for now just return true if asked to force meshs
92 // hopefully mesher will fail if doesn't suport so things still get basic boxes
93
94 int iPropertiesNotSupportedDefault = 0;
95
96 if (pbs.ProfileHollow != 0)
97 iPropertiesNotSupportedDefault++;
98
99 if ((pbs.PathBegin != 0) || pbs.PathEnd != 0)
100 iPropertiesNotSupportedDefault++;
101
102 if ((pbs.PathTwistBegin != 0) || (pbs.PathTwist != 0))
103 iPropertiesNotSupportedDefault++;
104
105 if ((pbs.ProfileBegin != 0) || pbs.ProfileEnd != 0)
106 iPropertiesNotSupportedDefault++;
107
108 if ((pbs.PathScaleX != 100) || (pbs.PathScaleY != 100))
109 iPropertiesNotSupportedDefault++;
110
111 if ((pbs.PathShearX != 0) || (pbs.PathShearY != 0))
112 iPropertiesNotSupportedDefault++;
113
114 if (pbs.ProfileShape == ProfileShape.Circle && pbs.PathCurve == (byte)Extrusion.Straight)
115 iPropertiesNotSupportedDefault++;
116
117 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1 && (pbs.Scale.X != pbs.Scale.Y || pbs.Scale.Y != pbs.Scale.Z || pbs.Scale.Z != pbs.Scale.X))
118 iPropertiesNotSupportedDefault++;
119
120 if (pbs.ProfileShape == ProfileShape.HalfCircle && pbs.PathCurve == (byte)Extrusion.Curve1)
121 iPropertiesNotSupportedDefault++;
122
123 // test for torus
124 if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Square)
125 {
126 if (pbs.PathCurve == (byte)Extrusion.Curve1)
127 {
128 iPropertiesNotSupportedDefault++;
129 }
130 }
131 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.Circle)
132 {
133 if (pbs.PathCurve == (byte)Extrusion.Straight)
134 {
135 iPropertiesNotSupportedDefault++;
136 }
137
138 // ProfileCurve seems to combine hole shape and profile curve so we need to only compare against the lower 3 bits
139 else if (pbs.PathCurve == (byte)Extrusion.Curve1)
140 {
141 iPropertiesNotSupportedDefault++;
142 }
143 }
144 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle)
145 {
146 if (pbs.PathCurve == (byte)Extrusion.Curve1 || pbs.PathCurve == (byte)Extrusion.Curve2)
147 {
148 iPropertiesNotSupportedDefault++;
149 }
150 }
151 else if ((pbs.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle)
152 {
153 if (pbs.PathCurve == (byte)Extrusion.Straight)
154 {
155 iPropertiesNotSupportedDefault++;
156 }
157 else if (pbs.PathCurve == (byte)Extrusion.Curve1)
158 {
159 iPropertiesNotSupportedDefault++;
160 }
161 }
162
163 if (iPropertiesNotSupportedDefault == 0)
164 {
165 return false;
166 }
167 return true;
168 }
169
170 public IMesh getMesh(PhysicsActor actor, PrimitiveBaseShape ppbs, Vector3 psize, byte pshapetype)
171 {
172 if (!(actor is OdePrim))
173 return null;
174
175 IMesh mesh = null;
176 PrimitiveBaseShape pbs = ppbs;
177 Vector3 size = psize;
178 byte shapetype = pshapetype;
179
180 if (needsMeshing(pbs) && (pbs.SculptData.Length > 0))
181 {
182 bool convex;
183 int clod = (int)LevelOfDetail.High;
184 if (shapetype == 0)
185 convex = false;
186 else
187 {
188 convex = true;
189 if (pbs.SculptType != (byte)SculptType.Mesh)
190 clod = (int)LevelOfDetail.Low;
191 }
192 mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex);
193 if(mesh == null)
194 mesh = m_mesher.CreateMesh(actor.Name, pbs, size, clod, true, convex);
195 }
196 return mesh;
197 }
198 }
199} \ No newline at end of file