diff options
Diffstat (limited to 'OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs')
-rw-r--r-- | OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs | 1029 |
1 files changed, 1029 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs new file mode 100644 index 0000000..7667e91 --- /dev/null +++ b/OpenSim/Region/Physics/UbitMeshing/Meshmerizer.cs | |||
@@ -0,0 +1,1029 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | //#define SPAM | ||
28 | |||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Region.Physics.Manager; | ||
33 | using OpenMetaverse; | ||
34 | using OpenMetaverse.StructuredData; | ||
35 | using System.Drawing; | ||
36 | using System.Drawing.Imaging; | ||
37 | using System.IO.Compression; | ||
38 | using PrimMesher; | ||
39 | using log4net; | ||
40 | using Nini.Config; | ||
41 | using System.Reflection; | ||
42 | using System.IO; | ||
43 | using ComponentAce.Compression.Libs.zlib; | ||
44 | using OpenSim.Region.Physics.ConvexDecompositionDotNet; | ||
45 | |||
46 | namespace OpenSim.Region.Physics.Meshing | ||
47 | { | ||
48 | public class MeshmerizerPlugin : IMeshingPlugin | ||
49 | { | ||
50 | public MeshmerizerPlugin() | ||
51 | { | ||
52 | } | ||
53 | |||
54 | public string GetName() | ||
55 | { | ||
56 | return "UbitMeshmerizer"; | ||
57 | } | ||
58 | |||
59 | public IMesher GetMesher(IConfigSource config) | ||
60 | { | ||
61 | return new Meshmerizer(config); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | public class Meshmerizer : IMesher | ||
66 | { | ||
67 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
68 | |||
69 | // Setting baseDir to a path will enable the dumping of raw files | ||
70 | // raw files can be imported by blender so a visual inspection of the results can be done | ||
71 | #if SPAM | ||
72 | const string baseDir = "rawFiles"; | ||
73 | #else | ||
74 | private const string baseDir = null; //"rawFiles"; | ||
75 | #endif | ||
76 | |||
77 | private bool cacheSculptMaps = true; | ||
78 | private bool cacheSculptAlphaMaps = true; | ||
79 | |||
80 | private string decodedSculptMapPath = null; | ||
81 | private bool useMeshiesPhysicsMesh = false; | ||
82 | |||
83 | private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh | ||
84 | |||
85 | private Dictionary<ulong, Mesh> m_uniqueMeshes = new Dictionary<ulong, Mesh>(); | ||
86 | |||
87 | public Meshmerizer(IConfigSource config) | ||
88 | { | ||
89 | IConfig start_config = config.Configs["Startup"]; | ||
90 | IConfig mesh_config = config.Configs["Mesh"]; | ||
91 | |||
92 | decodedSculptMapPath = start_config.GetString("DecodedSculptMapPath","j2kDecodeCache"); | ||
93 | |||
94 | cacheSculptMaps = start_config.GetBoolean("CacheSculptMaps", cacheSculptMaps); | ||
95 | |||
96 | if (Environment.OSVersion.Platform == PlatformID.Unix) | ||
97 | { | ||
98 | cacheSculptAlphaMaps = false; | ||
99 | } | ||
100 | else | ||
101 | cacheSculptAlphaMaps = cacheSculptMaps; | ||
102 | |||
103 | if(mesh_config != null) | ||
104 | useMeshiesPhysicsMesh = mesh_config.GetBoolean("UseMeshiesPhysicsMesh", useMeshiesPhysicsMesh); | ||
105 | |||
106 | try | ||
107 | { | ||
108 | if (!Directory.Exists(decodedSculptMapPath)) | ||
109 | Directory.CreateDirectory(decodedSculptMapPath); | ||
110 | } | ||
111 | catch (Exception e) | ||
112 | { | ||
113 | m_log.WarnFormat("[SCULPT]: Unable to create {0} directory: ", decodedSculptMapPath, e.Message); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | /// <summary> | ||
118 | /// creates a simple box mesh of the specified size. This mesh is of very low vertex count and may | ||
119 | /// be useful as a backup proxy when level of detail is not needed or when more complex meshes fail | ||
120 | /// for some reason | ||
121 | /// </summary> | ||
122 | /// <param name="minX"></param> | ||
123 | /// <param name="maxX"></param> | ||
124 | /// <param name="minY"></param> | ||
125 | /// <param name="maxY"></param> | ||
126 | /// <param name="minZ"></param> | ||
127 | /// <param name="maxZ"></param> | ||
128 | /// <returns></returns> | ||
129 | private static Mesh CreateSimpleBoxMesh(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) | ||
130 | { | ||
131 | Mesh box = new Mesh(); | ||
132 | List<Vertex> vertices = new List<Vertex>(); | ||
133 | // bottom | ||
134 | |||
135 | vertices.Add(new Vertex(minX, maxY, minZ)); | ||
136 | vertices.Add(new Vertex(maxX, maxY, minZ)); | ||
137 | vertices.Add(new Vertex(maxX, minY, minZ)); | ||
138 | vertices.Add(new Vertex(minX, minY, minZ)); | ||
139 | |||
140 | box.Add(new Triangle(vertices[0], vertices[1], vertices[2])); | ||
141 | box.Add(new Triangle(vertices[0], vertices[2], vertices[3])); | ||
142 | |||
143 | // top | ||
144 | |||
145 | vertices.Add(new Vertex(maxX, maxY, maxZ)); | ||
146 | vertices.Add(new Vertex(minX, maxY, maxZ)); | ||
147 | vertices.Add(new Vertex(minX, minY, maxZ)); | ||
148 | vertices.Add(new Vertex(maxX, minY, maxZ)); | ||
149 | |||
150 | box.Add(new Triangle(vertices[4], vertices[5], vertices[6])); | ||
151 | box.Add(new Triangle(vertices[4], vertices[6], vertices[7])); | ||
152 | |||
153 | // sides | ||
154 | |||
155 | box.Add(new Triangle(vertices[5], vertices[0], vertices[3])); | ||
156 | box.Add(new Triangle(vertices[5], vertices[3], vertices[6])); | ||
157 | |||
158 | box.Add(new Triangle(vertices[1], vertices[0], vertices[5])); | ||
159 | box.Add(new Triangle(vertices[1], vertices[5], vertices[4])); | ||
160 | |||
161 | box.Add(new Triangle(vertices[7], vertices[1], vertices[4])); | ||
162 | box.Add(new Triangle(vertices[7], vertices[2], vertices[1])); | ||
163 | |||
164 | box.Add(new Triangle(vertices[3], vertices[2], vertices[7])); | ||
165 | box.Add(new Triangle(vertices[3], vertices[7], vertices[6])); | ||
166 | |||
167 | return box; | ||
168 | } | ||
169 | |||
170 | /// <summary> | ||
171 | /// Creates a simple bounding box mesh for a complex input mesh | ||
172 | /// </summary> | ||
173 | /// <param name="meshIn"></param> | ||
174 | /// <returns></returns> | ||
175 | private static Mesh CreateBoundingBoxMesh(Mesh meshIn) | ||
176 | { | ||
177 | float minX = float.MaxValue; | ||
178 | float maxX = float.MinValue; | ||
179 | float minY = float.MaxValue; | ||
180 | float maxY = float.MinValue; | ||
181 | float minZ = float.MaxValue; | ||
182 | float maxZ = float.MinValue; | ||
183 | |||
184 | foreach (Vector3 v in meshIn.getVertexList()) | ||
185 | { | ||
186 | if (v.X < minX) minX = v.X; | ||
187 | if (v.Y < minY) minY = v.Y; | ||
188 | if (v.Z < minZ) minZ = v.Z; | ||
189 | |||
190 | if (v.X > maxX) maxX = v.X; | ||
191 | if (v.Y > maxY) maxY = v.Y; | ||
192 | if (v.Z > maxZ) maxZ = v.Z; | ||
193 | } | ||
194 | |||
195 | return CreateSimpleBoxMesh(minX, maxX, minY, maxY, minZ, maxZ); | ||
196 | } | ||
197 | |||
198 | private void ReportPrimError(string message, string primName, PrimMesh primMesh) | ||
199 | { | ||
200 | m_log.Error(message); | ||
201 | m_log.Error("\nPrim Name: " + primName); | ||
202 | m_log.Error("****** PrimMesh Parameters ******\n" + primMesh.ParamsToDisplayString()); | ||
203 | } | ||
204 | |||
205 | /// <summary> | ||
206 | /// Add a submesh to an existing list of coords and faces. | ||
207 | /// </summary> | ||
208 | /// <param name="subMeshData"></param> | ||
209 | /// <param name="size">Size of entire object</param> | ||
210 | /// <param name="coords"></param> | ||
211 | /// <param name="faces"></param> | ||
212 | private void AddSubMesh(OSDMap subMeshData, Vector3 size, List<Coord> coords, List<Face> faces) | ||
213 | { | ||
214 | // Console.WriteLine("subMeshMap for {0} - {1}", primName, Util.GetFormattedXml((OSD)subMeshMap)); | ||
215 | |||
216 | // As per http://wiki.secondlife.com/wiki/Mesh/Mesh_Asset_Format, some Mesh Level | ||
217 | // of Detail Blocks (maps) contain just a NoGeometry key to signal there is no | ||
218 | // geometry for this submesh. | ||
219 | if (subMeshData.ContainsKey("NoGeometry") && ((OSDBoolean)subMeshData["NoGeometry"])) | ||
220 | return; | ||
221 | |||
222 | OpenMetaverse.Vector3 posMax = ((OSDMap)subMeshData["PositionDomain"])["Max"].AsVector3(); | ||
223 | OpenMetaverse.Vector3 posMin = ((OSDMap)subMeshData["PositionDomain"])["Min"].AsVector3(); | ||
224 | ushort faceIndexOffset = (ushort)coords.Count; | ||
225 | |||
226 | byte[] posBytes = subMeshData["Position"].AsBinary(); | ||
227 | for (int i = 0; i < posBytes.Length; i += 6) | ||
228 | { | ||
229 | ushort uX = Utils.BytesToUInt16(posBytes, i); | ||
230 | ushort uY = Utils.BytesToUInt16(posBytes, i + 2); | ||
231 | ushort uZ = Utils.BytesToUInt16(posBytes, i + 4); | ||
232 | |||
233 | Coord c = new Coord( | ||
234 | Utils.UInt16ToFloat(uX, posMin.X, posMax.X) * size.X, | ||
235 | Utils.UInt16ToFloat(uY, posMin.Y, posMax.Y) * size.Y, | ||
236 | Utils.UInt16ToFloat(uZ, posMin.Z, posMax.Z) * size.Z); | ||
237 | |||
238 | coords.Add(c); | ||
239 | } | ||
240 | |||
241 | byte[] triangleBytes = subMeshData["TriangleList"].AsBinary(); | ||
242 | for (int i = 0; i < triangleBytes.Length; i += 6) | ||
243 | { | ||
244 | ushort v1 = (ushort)(Utils.BytesToUInt16(triangleBytes, i) + faceIndexOffset); | ||
245 | ushort v2 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 2) + faceIndexOffset); | ||
246 | ushort v3 = (ushort)(Utils.BytesToUInt16(triangleBytes, i + 4) + faceIndexOffset); | ||
247 | Face f = new Face(v1, v2, v3); | ||
248 | faces.Add(f); | ||
249 | } | ||
250 | } | ||
251 | |||
252 | /// <summary> | ||
253 | /// Create a physics mesh from data that comes with the prim. The actual data used depends on the prim type. | ||
254 | /// </summary> | ||
255 | /// <param name="primName"></param> | ||
256 | /// <param name="primShape"></param> | ||
257 | /// <param name="size"></param> | ||
258 | /// <param name="lod"></param> | ||
259 | /// <returns></returns> | ||
260 | private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool convex) | ||
261 | { | ||
262 | // m_log.DebugFormat( | ||
263 | // "[MESH]: Creating physics proxy for {0}, shape {1}", | ||
264 | // primName, (OpenMetaverse.SculptType)primShape.SculptType); | ||
265 | |||
266 | List<Coord> coords; | ||
267 | List<Face> faces; | ||
268 | |||
269 | if (primShape.SculptEntry) | ||
270 | { | ||
271 | if (((OpenMetaverse.SculptType)primShape.SculptType) == SculptType.Mesh) | ||
272 | { | ||
273 | if (!useMeshiesPhysicsMesh) | ||
274 | return null; | ||
275 | |||
276 | if (!GenerateCoordsAndFacesFromPrimMeshData(primName, primShape, size, out coords, out faces, convex)) | ||
277 | return null; | ||
278 | } | ||
279 | else | ||
280 | { | ||
281 | if (!GenerateCoordsAndFacesFromPrimSculptData(primName, primShape, size, lod, out coords, out faces)) | ||
282 | return null; | ||
283 | // Remove the reference to any JPEG2000 sculpt data so it can be GCed | ||
284 | // don't loose it | ||
285 | // primShape.SculptData = Utils.EmptyBytes; | ||
286 | } | ||
287 | // primShape.SculptDataLoaded = true; | ||
288 | } | ||
289 | else | ||
290 | { | ||
291 | if (!GenerateCoordsAndFacesFromPrimShapeData(primName, primShape, size, lod, out coords, out faces)) | ||
292 | return null; | ||
293 | } | ||
294 | // keep compatible | ||
295 | primShape.SculptData = Utils.EmptyBytes; | ||
296 | |||
297 | int numCoords = coords.Count; | ||
298 | int numFaces = faces.Count; | ||
299 | |||
300 | Mesh mesh = new Mesh(); | ||
301 | // Add the corresponding triangles to the mesh | ||
302 | for (int i = 0; i < numFaces; i++) | ||
303 | { | ||
304 | Face f = faces[i]; | ||
305 | mesh.Add(new Triangle(coords[f.v1].X, coords[f.v1].Y, coords[f.v1].Z, | ||
306 | coords[f.v2].X, coords[f.v2].Y, coords[f.v2].Z, | ||
307 | coords[f.v3].X, coords[f.v3].Y, coords[f.v3].Z)); | ||
308 | } | ||
309 | |||
310 | |||
311 | // mesh.DumpRaw("c:\\lixo", "lixo", "lixo"); | ||
312 | mesh.DumpRaw(".", "lixo", "lixo"); | ||
313 | |||
314 | return mesh; | ||
315 | } | ||
316 | |||
317 | /// <summary> | ||
318 | /// Generate the co-ords and faces necessary to construct a mesh from the mesh data the accompanies a prim. | ||
319 | /// </summary> | ||
320 | /// <param name="primName"></param> | ||
321 | /// <param name="primShape"></param> | ||
322 | /// <param name="size"></param> | ||
323 | /// <param name="coords">Coords are added to this list by the method.</param> | ||
324 | /// <param name="faces">Faces are added to this list by the method.</param> | ||
325 | /// <returns>true if coords and faces were successfully generated, false if not</returns> | ||
326 | private bool GenerateCoordsAndFacesFromPrimMeshData( | ||
327 | string primName, PrimitiveBaseShape primShape, Vector3 size, out List<Coord> coords, out List<Face> faces, bool convex) | ||
328 | { | ||
329 | // m_log.DebugFormat("[MESH]: experimental mesh proxy generation for {0}", primName); | ||
330 | |||
331 | bool usemesh = false; | ||
332 | |||
333 | coords = new List<Coord>(); | ||
334 | faces = new List<Face>(); | ||
335 | OSD meshOsd = null; | ||
336 | |||
337 | if (primShape.SculptData.Length <= 0) | ||
338 | { | ||
339 | m_log.ErrorFormat("[MESH]: asset data for {0} is zero length", primName); | ||
340 | return false; | ||
341 | } | ||
342 | |||
343 | long start = 0; | ||
344 | using (MemoryStream data = new MemoryStream(primShape.SculptData)) | ||
345 | { | ||
346 | try | ||
347 | { | ||
348 | OSD osd = OSDParser.DeserializeLLSDBinary(data); | ||
349 | if (osd is OSDMap) | ||
350 | meshOsd = (OSDMap)osd; | ||
351 | else | ||
352 | { | ||
353 | m_log.Warn("[Mesh}: unable to cast mesh asset to OSDMap"); | ||
354 | return false; | ||
355 | } | ||
356 | } | ||
357 | catch (Exception e) | ||
358 | { | ||
359 | m_log.Error("[MESH]: Exception deserializing mesh asset header:" + e.ToString()); | ||
360 | } | ||
361 | |||
362 | start = data.Position; | ||
363 | } | ||
364 | |||
365 | if (meshOsd is OSDMap) | ||
366 | { | ||
367 | OSDMap physicsParms = null; | ||
368 | OSDMap map = (OSDMap)meshOsd; | ||
369 | |||
370 | if (!convex) | ||
371 | { | ||
372 | if (map.ContainsKey("physics_shape")) | ||
373 | physicsParms = (OSDMap)map["physics_shape"]; // old asset format | ||
374 | else if (map.ContainsKey("physics_mesh")) | ||
375 | physicsParms = (OSDMap)map["physics_mesh"]; // new asset format | ||
376 | |||
377 | if (physicsParms != null) | ||
378 | usemesh = true; | ||
379 | } | ||
380 | |||
381 | if(!usemesh && (map.ContainsKey("physics_convex"))) | ||
382 | physicsParms = (OSDMap)map["physics_convex"]; | ||
383 | |||
384 | |||
385 | if (physicsParms == null) | ||
386 | { | ||
387 | m_log.Warn("[MESH]: unknown mesh type"); | ||
388 | return false; | ||
389 | } | ||
390 | |||
391 | int physOffset = physicsParms["offset"].AsInteger() + (int)start; | ||
392 | int physSize = physicsParms["size"].AsInteger(); | ||
393 | |||
394 | if (physOffset < 0 || physSize == 0) | ||
395 | return false; // no mesh data in asset | ||
396 | |||
397 | OSD decodedMeshOsd = new OSD(); | ||
398 | byte[] meshBytes = new byte[physSize]; | ||
399 | System.Buffer.BlockCopy(primShape.SculptData, physOffset, meshBytes, 0, physSize); | ||
400 | // byte[] decompressed = new byte[physSize * 5]; | ||
401 | try | ||
402 | { | ||
403 | using (MemoryStream inMs = new MemoryStream(meshBytes)) | ||
404 | { | ||
405 | using (MemoryStream outMs = new MemoryStream()) | ||
406 | { | ||
407 | using (ZOutputStream zOut = new ZOutputStream(outMs)) | ||
408 | { | ||
409 | byte[] readBuffer = new byte[2048]; | ||
410 | int readLen = 0; | ||
411 | while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0) | ||
412 | { | ||
413 | zOut.Write(readBuffer, 0, readLen); | ||
414 | } | ||
415 | zOut.Flush(); | ||
416 | outMs.Seek(0, SeekOrigin.Begin); | ||
417 | |||
418 | byte[] decompressedBuf = outMs.GetBuffer(); | ||
419 | |||
420 | decodedMeshOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf); | ||
421 | } | ||
422 | } | ||
423 | } | ||
424 | } | ||
425 | catch (Exception e) | ||
426 | { | ||
427 | m_log.Error("[MESH]: exception decoding physical mesh: " + e.ToString()); | ||
428 | return false; | ||
429 | } | ||
430 | |||
431 | if (usemesh) | ||
432 | { | ||
433 | OSDArray decodedMeshOsdArray = null; | ||
434 | |||
435 | // physics_shape is an array of OSDMaps, one for each submesh | ||
436 | if (decodedMeshOsd is OSDArray) | ||
437 | { | ||
438 | // Console.WriteLine("decodedMeshOsd for {0} - {1}", primName, Util.GetFormattedXml(decodedMeshOsd)); | ||
439 | |||
440 | decodedMeshOsdArray = (OSDArray)decodedMeshOsd; | ||
441 | foreach (OSD subMeshOsd in decodedMeshOsdArray) | ||
442 | { | ||
443 | if (subMeshOsd is OSDMap) | ||
444 | AddSubMesh(subMeshOsd as OSDMap, size, coords, faces); | ||
445 | } | ||
446 | } | ||
447 | } | ||
448 | else | ||
449 | { | ||
450 | OSDMap cmap = (OSDMap)decodedMeshOsd; | ||
451 | if (cmap == null) | ||
452 | return false; | ||
453 | |||
454 | byte[] data; | ||
455 | const float invMaxU16 = 1.0f / 65535f; | ||
456 | int t1; | ||
457 | int t2; | ||
458 | int t3; | ||
459 | int i; | ||
460 | |||
461 | List<float3> vs = new List<float3>(); | ||
462 | |||
463 | float3 f3; | ||
464 | PHullResult hullr = new PHullResult(); | ||
465 | |||
466 | Coord c; | ||
467 | Face f; | ||
468 | |||
469 | Vector3 range; | ||
470 | Vector3 min; | ||
471 | int nverts; | ||
472 | int nindexs; | ||
473 | |||
474 | if (cmap.ContainsKey("Max")) | ||
475 | range = cmap["Max"].AsVector3(); | ||
476 | else | ||
477 | range = new Vector3(0.5f, 0.5f, 0.5f); | ||
478 | |||
479 | if (cmap.ContainsKey("Min")) | ||
480 | min = cmap["Min"].AsVector3(); | ||
481 | else | ||
482 | min = new Vector3(-0.5f, -0.5f, -0.5f); | ||
483 | |||
484 | range = range - min; | ||
485 | range *= invMaxU16; | ||
486 | |||
487 | if (!convex && cmap.ContainsKey("HullList") && cmap.ContainsKey("Positions")) | ||
488 | { | ||
489 | List<int> hsizes = new List<int>(); | ||
490 | int totalpoints = 0; | ||
491 | data = cmap["HullList"].AsBinary(); | ||
492 | for (i = 0; i < data.Length; i++) | ||
493 | { | ||
494 | t1 = data[i]; | ||
495 | if (t1 == 0) | ||
496 | t1 = 256; | ||
497 | totalpoints += t1; | ||
498 | hsizes.Add(t1); | ||
499 | } | ||
500 | |||
501 | data = cmap["Positions"].AsBinary(); | ||
502 | int ptr = 0; | ||
503 | int vertsoffset = 0; | ||
504 | |||
505 | if (totalpoints == data.Length / 6) // 2 bytes per coord, 3 coords per point | ||
506 | { | ||
507 | foreach (int hullsize in hsizes) | ||
508 | { | ||
509 | for (i = 0; i < hullsize; i++ ) | ||
510 | { | ||
511 | t1 = data[ptr++]; | ||
512 | t1 += data[ptr++] << 8; | ||
513 | t2 = data[ptr++]; | ||
514 | t2 += data[ptr++] << 8; | ||
515 | t3 = data[ptr++]; | ||
516 | t3 += data[ptr++] << 8; | ||
517 | |||
518 | f3 = new float3((t1 * range.X + min.X) * size.X, | ||
519 | (t2 * range.Y + min.Y) * size.Y, | ||
520 | (t3 * range.Z + min.Z) * size.Z); | ||
521 | vs.Add(f3); | ||
522 | } | ||
523 | |||
524 | if(hullsize <3) | ||
525 | { | ||
526 | vs.Clear(); | ||
527 | continue; | ||
528 | } | ||
529 | |||
530 | if (hullsize <5) | ||
531 | { | ||
532 | foreach (float3 point in vs) | ||
533 | { | ||
534 | c.X = point.x; | ||
535 | c.Y = point.y; | ||
536 | c.Z = point.z; | ||
537 | coords.Add(c); | ||
538 | } | ||
539 | f = new Face(vertsoffset, vertsoffset + 1, vertsoffset + 2); | ||
540 | faces.Add(f); | ||
541 | |||
542 | if (hullsize == 4) | ||
543 | { | ||
544 | // not sure about orientation.. | ||
545 | f = new Face(vertsoffset, vertsoffset + 2, vertsoffset + 3); | ||
546 | faces.Add(f); | ||
547 | f = new Face(vertsoffset, vertsoffset + 3, vertsoffset + 1); | ||
548 | faces.Add(f); | ||
549 | f = new Face(vertsoffset + 3, vertsoffset + 2, vertsoffset + 1); | ||
550 | faces.Add(f); | ||
551 | } | ||
552 | vertsoffset += vs.Count; | ||
553 | vs.Clear(); | ||
554 | continue; | ||
555 | } | ||
556 | |||
557 | if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f)) | ||
558 | { | ||
559 | vs.Clear(); | ||
560 | continue; | ||
561 | } | ||
562 | |||
563 | nverts = hullr.Vertices.Count; | ||
564 | nindexs = hullr.Indices.Count; | ||
565 | |||
566 | if (nindexs % 3 != 0) | ||
567 | { | ||
568 | vs.Clear(); | ||
569 | continue; | ||
570 | } | ||
571 | |||
572 | for (i = 0; i < nverts; i++) | ||
573 | { | ||
574 | c.X = hullr.Vertices[i].x; | ||
575 | c.Y = hullr.Vertices[i].y; | ||
576 | c.Z = hullr.Vertices[i].z; | ||
577 | coords.Add(c); | ||
578 | } | ||
579 | |||
580 | |||
581 | for (i = 0; i < nindexs; i += 3) | ||
582 | { | ||
583 | t1 = hullr.Indices[i]; | ||
584 | if (t1 > nverts) | ||
585 | break; | ||
586 | t2 = hullr.Indices[i + 1]; | ||
587 | if (t2 > nverts) | ||
588 | break; | ||
589 | t3 = hullr.Indices[i + 2]; | ||
590 | if (t3 > nverts) | ||
591 | break; | ||
592 | f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3); | ||
593 | faces.Add(f); | ||
594 | } | ||
595 | vertsoffset += nverts; | ||
596 | vs.Clear(); | ||
597 | } | ||
598 | } | ||
599 | if (coords.Count > 0 && faces.Count > 0) | ||
600 | return true; | ||
601 | |||
602 | } | ||
603 | |||
604 | vs.Clear(); | ||
605 | |||
606 | if (cmap.ContainsKey("BoundingVerts")) | ||
607 | { | ||
608 | data = cmap["BoundingVerts"].AsBinary(); | ||
609 | |||
610 | for (i = 0; i < data.Length; ) | ||
611 | { | ||
612 | t1 = data[i++]; | ||
613 | t1 += data[i++] << 8; | ||
614 | t2 = data[i++]; | ||
615 | t2 += data[i++] << 8; | ||
616 | t3 = data[i++]; | ||
617 | t3 += data[i++] << 8; | ||
618 | |||
619 | f3 = new float3((t1 * range.X + min.X) * size.X, | ||
620 | (t2 * range.Y + min.Y) * size.Y, | ||
621 | (t3 * range.Z + min.Z) * size.Z); | ||
622 | vs.Add(f3); | ||
623 | } | ||
624 | |||
625 | if (vs.Count < 3) | ||
626 | { | ||
627 | vs.Clear(); | ||
628 | return false; | ||
629 | } | ||
630 | |||
631 | if (vs.Count < 5) | ||
632 | { | ||
633 | foreach (float3 point in vs) | ||
634 | { | ||
635 | c.X = point.x; | ||
636 | c.Y = point.y; | ||
637 | c.Z = point.z; | ||
638 | coords.Add(c); | ||
639 | } | ||
640 | f = new Face(0, 1, 2); | ||
641 | faces.Add(f); | ||
642 | |||
643 | if (vs.Count == 4) | ||
644 | { | ||
645 | // not sure about orientation.. | ||
646 | f = new Face(0, 2, 3); | ||
647 | faces.Add(f); | ||
648 | f = new Face(0, 3, 1); | ||
649 | faces.Add(f); | ||
650 | f = new Face( 3, 2, 1); | ||
651 | faces.Add(f); | ||
652 | } | ||
653 | vs.Clear(); | ||
654 | return true; | ||
655 | } | ||
656 | |||
657 | if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f)) | ||
658 | return false; | ||
659 | |||
660 | nverts = hullr.Vertices.Count; | ||
661 | nindexs = hullr.Indices.Count; | ||
662 | |||
663 | if (nindexs % 3 != 0) | ||
664 | return false; | ||
665 | |||
666 | for (i = 0; i < nverts; i++) | ||
667 | { | ||
668 | c.X = hullr.Vertices[i].x; | ||
669 | c.Y = hullr.Vertices[i].y; | ||
670 | c.Z = hullr.Vertices[i].z; | ||
671 | coords.Add(c); | ||
672 | } | ||
673 | for (i = 0; i < nindexs; i += 3) | ||
674 | { | ||
675 | t1 = hullr.Indices[i]; | ||
676 | if (t1 > nverts) | ||
677 | break; | ||
678 | t2 = hullr.Indices[i + 1]; | ||
679 | if (t2 > nverts) | ||
680 | break; | ||
681 | t3 = hullr.Indices[i + 2]; | ||
682 | if (t3 > nverts) | ||
683 | break; | ||
684 | f = new Face(t1, t2, t3); | ||
685 | faces.Add(f); | ||
686 | } | ||
687 | |||
688 | if (coords.Count > 0 && faces.Count > 0) | ||
689 | return true; | ||
690 | } | ||
691 | else | ||
692 | return false; | ||
693 | |||
694 | } | ||
695 | } | ||
696 | |||
697 | return true; | ||
698 | } | ||
699 | |||
700 | /// <summary> | ||
701 | /// Generate the co-ords and faces necessary to construct a mesh from the sculpt data the accompanies a prim. | ||
702 | /// </summary> | ||
703 | /// <param name="primName"></param> | ||
704 | /// <param name="primShape"></param> | ||
705 | /// <param name="size"></param> | ||
706 | /// <param name="lod"></param> | ||
707 | /// <param name="coords">Coords are added to this list by the method.</param> | ||
708 | /// <param name="faces">Faces are added to this list by the method.</param> | ||
709 | /// <returns>true if coords and faces were successfully generated, false if not</returns> | ||
710 | private bool GenerateCoordsAndFacesFromPrimSculptData( | ||
711 | string primName, PrimitiveBaseShape primShape, Vector3 size, float lod, out List<Coord> coords, out List<Face> faces) | ||
712 | { | ||
713 | coords = new List<Coord>(); | ||
714 | faces = new List<Face>(); | ||
715 | PrimMesher.SculptMesh sculptMesh; | ||
716 | Image idata = null; | ||
717 | string decodedSculptFileName = ""; | ||
718 | |||
719 | if (cacheSculptMaps && primShape.SculptTexture != UUID.Zero) | ||
720 | { | ||
721 | decodedSculptFileName = System.IO.Path.Combine(decodedSculptMapPath, "smap_" + primShape.SculptTexture.ToString()); | ||
722 | try | ||
723 | { | ||
724 | if (File.Exists(decodedSculptFileName)) | ||
725 | { | ||
726 | idata = Image.FromFile(decodedSculptFileName); | ||
727 | } | ||
728 | } | ||
729 | catch (Exception e) | ||
730 | { | ||
731 | m_log.Error("[SCULPT]: unable to load cached sculpt map " + decodedSculptFileName + " " + e.Message); | ||
732 | |||
733 | } | ||
734 | //if (idata != null) | ||
735 | // m_log.Debug("[SCULPT]: loaded cached map asset for map ID: " + primShape.SculptTexture.ToString()); | ||
736 | } | ||
737 | |||
738 | if (idata == null) | ||
739 | { | ||
740 | if (primShape.SculptData == null || primShape.SculptData.Length == 0) | ||
741 | return false; | ||
742 | |||
743 | try | ||
744 | { | ||
745 | OpenMetaverse.Imaging.ManagedImage unusedData; | ||
746 | OpenMetaverse.Imaging.OpenJPEG.DecodeToImage(primShape.SculptData, out unusedData, out idata); | ||
747 | |||
748 | if (idata == null) | ||
749 | { | ||
750 | // In some cases it seems that the decode can return a null bitmap without throwing | ||
751 | // an exception | ||
752 | m_log.WarnFormat("[PHYSICS]: OpenJPEG decoded sculpt data for {0} to a null bitmap. Ignoring.", primName); | ||
753 | |||
754 | return false; | ||
755 | } | ||
756 | |||
757 | unusedData = null; | ||
758 | |||
759 | //idata = CSJ2K.J2kImage.FromBytes(primShape.SculptData); | ||
760 | |||
761 | if (cacheSculptMaps && (cacheSculptAlphaMaps || (((ImageFlags)(idata.Flags) & ImageFlags.HasAlpha) ==0))) | ||
762 | // don't cache images with alpha channel in linux since mono can't load them correctly) | ||
763 | { | ||
764 | try { idata.Save(decodedSculptFileName, ImageFormat.MemoryBmp); } | ||
765 | catch (Exception e) { m_log.Error("[SCULPT]: unable to cache sculpt map " + decodedSculptFileName + " " + e.Message); } | ||
766 | } | ||
767 | } | ||
768 | catch (DllNotFoundException) | ||
769 | { | ||
770 | m_log.Error("[PHYSICS]: OpenJpeg is not installed correctly on this system. Physics Proxy generation failed. Often times this is because of an old version of GLIBC. You must have version 2.4 or above!"); | ||
771 | return false; | ||
772 | } | ||
773 | catch (IndexOutOfRangeException) | ||
774 | { | ||
775 | m_log.Error("[PHYSICS]: OpenJpeg was unable to decode this. Physics Proxy generation failed"); | ||
776 | return false; | ||
777 | } | ||
778 | catch (Exception ex) | ||
779 | { | ||
780 | m_log.Error("[PHYSICS]: Unable to generate a Sculpty physics proxy. Sculpty texture decode failed: " + ex.Message); | ||
781 | return false; | ||
782 | } | ||
783 | } | ||
784 | |||
785 | PrimMesher.SculptMesh.SculptType sculptType; | ||
786 | switch ((OpenMetaverse.SculptType)primShape.SculptType) | ||
787 | { | ||
788 | case OpenMetaverse.SculptType.Cylinder: | ||
789 | sculptType = PrimMesher.SculptMesh.SculptType.cylinder; | ||
790 | break; | ||
791 | case OpenMetaverse.SculptType.Plane: | ||
792 | sculptType = PrimMesher.SculptMesh.SculptType.plane; | ||
793 | break; | ||
794 | case OpenMetaverse.SculptType.Torus: | ||
795 | sculptType = PrimMesher.SculptMesh.SculptType.torus; | ||
796 | break; | ||
797 | case OpenMetaverse.SculptType.Sphere: | ||
798 | sculptType = PrimMesher.SculptMesh.SculptType.sphere; | ||
799 | break; | ||
800 | default: | ||
801 | sculptType = PrimMesher.SculptMesh.SculptType.plane; | ||
802 | break; | ||
803 | } | ||
804 | |||
805 | bool mirror = ((primShape.SculptType & 128) != 0); | ||
806 | bool invert = ((primShape.SculptType & 64) != 0); | ||
807 | |||
808 | sculptMesh = new PrimMesher.SculptMesh((Bitmap)idata, sculptType, (int)lod, false, mirror, invert); | ||
809 | |||
810 | idata.Dispose(); | ||
811 | |||
812 | sculptMesh.DumpRaw(baseDir, primName, "primMesh"); | ||
813 | |||
814 | sculptMesh.Scale(size.X, size.Y, size.Z); | ||
815 | |||
816 | coords = sculptMesh.coords; | ||
817 | faces = sculptMesh.faces; | ||
818 | |||
819 | return true; | ||
820 | } | ||
821 | |||
822 | /// <summary> | ||
823 | /// Generate the co-ords and faces necessary to construct a mesh from the shape data the accompanies a prim. | ||
824 | /// </summary> | ||
825 | /// <param name="primName"></param> | ||
826 | /// <param name="primShape"></param> | ||
827 | /// <param name="size"></param> | ||
828 | /// <param name="coords">Coords are added to this list by the method.</param> | ||
829 | /// <param name="faces">Faces are added to this list by the method.</param> | ||
830 | /// <returns>true if coords and faces were successfully generated, false if not</returns> | ||
831 | private bool GenerateCoordsAndFacesFromPrimShapeData( | ||
832 | string primName, PrimitiveBaseShape primShape, Vector3 size, float lod, out List<Coord> coords, out List<Face> faces) | ||
833 | { | ||
834 | PrimMesh primMesh; | ||
835 | coords = new List<Coord>(); | ||
836 | faces = new List<Face>(); | ||
837 | |||
838 | float pathShearX = primShape.PathShearX < 128 ? (float)primShape.PathShearX * 0.01f : (float)(primShape.PathShearX - 256) * 0.01f; | ||
839 | float pathShearY = primShape.PathShearY < 128 ? (float)primShape.PathShearY * 0.01f : (float)(primShape.PathShearY - 256) * 0.01f; | ||
840 | float pathBegin = (float)primShape.PathBegin * 2.0e-5f; | ||
841 | float pathEnd = 1.0f - (float)primShape.PathEnd * 2.0e-5f; | ||
842 | float pathScaleX = (float)(primShape.PathScaleX - 100) * 0.01f; | ||
843 | float pathScaleY = (float)(primShape.PathScaleY - 100) * 0.01f; | ||
844 | |||
845 | float profileBegin = (float)primShape.ProfileBegin * 2.0e-5f; | ||
846 | float profileEnd = 1.0f - (float)primShape.ProfileEnd * 2.0e-5f; | ||
847 | float profileHollow = (float)primShape.ProfileHollow * 2.0e-5f; | ||
848 | if (profileHollow > 0.95f) | ||
849 | profileHollow = 0.95f; | ||
850 | |||
851 | int sides = 4; | ||
852 | LevelOfDetail iLOD = (LevelOfDetail)lod; | ||
853 | if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.EquilateralTriangle) | ||
854 | sides = 3; | ||
855 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.Circle) | ||
856 | { | ||
857 | switch (iLOD) | ||
858 | { | ||
859 | case LevelOfDetail.High: sides = 24; break; | ||
860 | case LevelOfDetail.Medium: sides = 12; break; | ||
861 | case LevelOfDetail.Low: sides = 6; break; | ||
862 | case LevelOfDetail.VeryLow: sides = 3; break; | ||
863 | default: sides = 24; break; | ||
864 | } | ||
865 | } | ||
866 | else if ((primShape.ProfileCurve & 0x07) == (byte)ProfileShape.HalfCircle) | ||
867 | { // half circle, prim is a sphere | ||
868 | switch (iLOD) | ||
869 | { | ||
870 | case LevelOfDetail.High: sides = 24; break; | ||
871 | case LevelOfDetail.Medium: sides = 12; break; | ||
872 | case LevelOfDetail.Low: sides = 6; break; | ||
873 | case LevelOfDetail.VeryLow: sides = 3; break; | ||
874 | default: sides = 24; break; | ||
875 | } | ||
876 | |||
877 | profileBegin = 0.5f * profileBegin + 0.5f; | ||
878 | profileEnd = 0.5f * profileEnd + 0.5f; | ||
879 | } | ||
880 | |||
881 | int hollowSides = sides; | ||
882 | if (primShape.HollowShape == HollowShape.Circle) | ||
883 | { | ||
884 | switch (iLOD) | ||
885 | { | ||
886 | case LevelOfDetail.High: hollowSides = 24; break; | ||
887 | case LevelOfDetail.Medium: hollowSides = 12; break; | ||
888 | case LevelOfDetail.Low: hollowSides = 6; break; | ||
889 | case LevelOfDetail.VeryLow: hollowSides = 3; break; | ||
890 | default: hollowSides = 24; break; | ||
891 | } | ||
892 | } | ||
893 | else if (primShape.HollowShape == HollowShape.Square) | ||
894 | hollowSides = 4; | ||
895 | else if (primShape.HollowShape == HollowShape.Triangle) | ||
896 | hollowSides = 3; | ||
897 | |||
898 | primMesh = new PrimMesh(sides, profileBegin, profileEnd, profileHollow, hollowSides); | ||
899 | |||
900 | if (primMesh.errorMessage != null) | ||
901 | if (primMesh.errorMessage.Length > 0) | ||
902 | m_log.Error("[ERROR] " + primMesh.errorMessage); | ||
903 | |||
904 | primMesh.topShearX = pathShearX; | ||
905 | primMesh.topShearY = pathShearY; | ||
906 | primMesh.pathCutBegin = pathBegin; | ||
907 | primMesh.pathCutEnd = pathEnd; | ||
908 | |||
909 | if (primShape.PathCurve == (byte)Extrusion.Straight || primShape.PathCurve == (byte) Extrusion.Flexible) | ||
910 | { | ||
911 | primMesh.twistBegin = primShape.PathTwistBegin * 18 / 10; | ||
912 | primMesh.twistEnd = primShape.PathTwist * 18 / 10; | ||
913 | primMesh.taperX = pathScaleX; | ||
914 | primMesh.taperY = pathScaleY; | ||
915 | |||
916 | if (profileBegin < 0.0f || profileBegin >= profileEnd || profileEnd > 1.0f) | ||
917 | { | ||
918 | ReportPrimError("*** CORRUPT PRIM!! ***", primName, primMesh); | ||
919 | if (profileBegin < 0.0f) profileBegin = 0.0f; | ||
920 | if (profileEnd > 1.0f) profileEnd = 1.0f; | ||
921 | } | ||
922 | #if SPAM | ||
923 | m_log.Debug("****** PrimMesh Parameters (Linear) ******\n" + primMesh.ParamsToDisplayString()); | ||
924 | #endif | ||
925 | try | ||
926 | { | ||
927 | primMesh.ExtrudeLinear(); | ||
928 | } | ||
929 | catch (Exception ex) | ||
930 | { | ||
931 | ReportPrimError("Extrusion failure: exception: " + ex.ToString(), primName, primMesh); | ||
932 | return false; | ||
933 | } | ||
934 | } | ||
935 | else | ||
936 | { | ||
937 | primMesh.holeSizeX = (200 - primShape.PathScaleX) * 0.01f; | ||
938 | primMesh.holeSizeY = (200 - primShape.PathScaleY) * 0.01f; | ||
939 | primMesh.radius = 0.01f * primShape.PathRadiusOffset; | ||
940 | primMesh.revolutions = 1.0f + 0.015f * primShape.PathRevolutions; | ||
941 | primMesh.skew = 0.01f * primShape.PathSkew; | ||
942 | primMesh.twistBegin = primShape.PathTwistBegin * 36 / 10; | ||
943 | primMesh.twistEnd = primShape.PathTwist * 36 / 10; | ||
944 | primMesh.taperX = primShape.PathTaperX * 0.01f; | ||
945 | primMesh.taperY = primShape.PathTaperY * 0.01f; | ||
946 | |||
947 | if (profileBegin < 0.0f || profileBegin >= profileEnd || profileEnd > 1.0f) | ||
948 | { | ||
949 | ReportPrimError("*** CORRUPT PRIM!! ***", primName, primMesh); | ||
950 | if (profileBegin < 0.0f) profileBegin = 0.0f; | ||
951 | if (profileEnd > 1.0f) profileEnd = 1.0f; | ||
952 | } | ||
953 | #if SPAM | ||
954 | m_log.Debug("****** PrimMesh Parameters (Circular) ******\n" + primMesh.ParamsToDisplayString()); | ||
955 | #endif | ||
956 | try | ||
957 | { | ||
958 | primMesh.ExtrudeCircular(); | ||
959 | } | ||
960 | catch (Exception ex) | ||
961 | { | ||
962 | ReportPrimError("Extrusion failure: exception: " + ex.ToString(), primName, primMesh); | ||
963 | return false; | ||
964 | } | ||
965 | } | ||
966 | |||
967 | primMesh.DumpRaw(baseDir, primName, "primMesh"); | ||
968 | |||
969 | primMesh.Scale(size.X, size.Y, size.Z); | ||
970 | |||
971 | coords = primMesh.coords; | ||
972 | faces = primMesh.faces; | ||
973 | |||
974 | return true; | ||
975 | } | ||
976 | |||
977 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod) | ||
978 | { | ||
979 | return CreateMesh(primName, primShape, size, lod, false,false); | ||
980 | } | ||
981 | |||
982 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical) | ||
983 | { | ||
984 | return CreateMesh(primName, primShape, size, lod, false,false); | ||
985 | } | ||
986 | |||
987 | public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, Vector3 size, float lod, bool isPhysical, bool convex) | ||
988 | { | ||
989 | #if SPAM | ||
990 | m_log.DebugFormat("[MESH]: Creating mesh for {0}", primName); | ||
991 | #endif | ||
992 | |||
993 | Mesh mesh = null; | ||
994 | ulong key = 0; | ||
995 | |||
996 | // If this mesh has been created already, return it instead of creating another copy | ||
997 | // For large regions with 100k+ prims and hundreds of copies of each, this can save a GB or more of memory | ||
998 | key = primShape.GetMeshKey(size, lod); | ||
999 | if (m_uniqueMeshes.TryGetValue(key, out mesh)) | ||
1000 | return mesh; | ||
1001 | |||
1002 | if (size.X < 0.01f) size.X = 0.01f; | ||
1003 | if (size.Y < 0.01f) size.Y = 0.01f; | ||
1004 | if (size.Z < 0.01f) size.Z = 0.01f; | ||
1005 | |||
1006 | mesh = CreateMeshFromPrimMesher(primName, primShape, size, lod,convex); | ||
1007 | |||
1008 | if (mesh != null) | ||
1009 | { | ||
1010 | if ((!isPhysical) && size.X < minSizeForComplexMesh && size.Y < minSizeForComplexMesh && size.Z < minSizeForComplexMesh) | ||
1011 | { | ||
1012 | #if SPAM | ||
1013 | m_log.Debug("Meshmerizer: prim " + primName + " has a size of " + size.ToString() + " which is below threshold of " + | ||
1014 | minSizeForComplexMesh.ToString() + " - creating simple bounding box"); | ||
1015 | #endif | ||
1016 | mesh = CreateBoundingBoxMesh(mesh); | ||
1017 | mesh.DumpRaw(baseDir, primName, "Z extruded"); | ||
1018 | } | ||
1019 | |||
1020 | // trim the vertex and triangle lists to free up memory | ||
1021 | mesh.TrimExcess(); | ||
1022 | |||
1023 | m_uniqueMeshes.Add(key, mesh); | ||
1024 | } | ||
1025 | |||
1026 | return mesh; | ||
1027 | } | ||
1028 | } | ||
1029 | } | ||