diff options
author | UbitUmarov | 2017-07-21 14:11:03 +0100 |
---|---|---|
committer | UbitUmarov | 2017-07-21 14:11:03 +0100 |
commit | 66a5b4d1205058cb66a7dc2d02f52a93175bcc57 (patch) | |
tree | e9a148c96063abc8d1c06339d9267d16c047bdcd /OpenSim/Region | |
parent | fix object updates throttle for scripts doing motion by direct change of posi... (diff) | |
download | opensim-SC-66a5b4d1205058cb66a7dc2d02f52a93175bcc57.zip opensim-SC-66a5b4d1205058cb66a7dc2d02f52a93175bcc57.tar.gz opensim-SC-66a5b4d1205058cb66a7dc2d02f52a93175bcc57.tar.bz2 opensim-SC-66a5b4d1205058cb66a7dc2d02f52a93175bcc57.tar.xz |
ubOde suport convex shapes on all normal prims and sculpts. Since code is experimental this is controled by options ConvexPrims and ConvexSculpts, on section Mesh, that can be set to false in case of problems
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs | 133 |
1 files changed, 115 insertions, 18 deletions
diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs index 0117800..c14abd0 100644 --- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs +++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs | |||
@@ -43,8 +43,6 @@ using log4net; | |||
43 | using Nini.Config; | 43 | using Nini.Config; |
44 | using System.Reflection; | 44 | using System.Reflection; |
45 | using System.IO; | 45 | using System.IO; |
46 | using System.Runtime.Serialization; | ||
47 | using System.Runtime.Serialization.Formatters.Binary; | ||
48 | 46 | ||
49 | using Mono.Addins; | 47 | using Mono.Addins; |
50 | 48 | ||
@@ -72,6 +70,8 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing | |||
72 | private const string baseDir = null; //"rawFiles"; | 70 | private const string baseDir = null; //"rawFiles"; |
73 | 71 | ||
74 | private bool useMeshiesPhysicsMesh = false; | 72 | private bool useMeshiesPhysicsMesh = false; |
73 | private bool doConvexPrims = true; | ||
74 | private bool doConvexSculpts = true; | ||
75 | 75 | ||
76 | private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh | 76 | private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh |
77 | 77 | ||
@@ -103,18 +103,14 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing | |||
103 | if (mesh_config != null) | 103 | if (mesh_config != null) |
104 | { | 104 | { |
105 | useMeshiesPhysicsMesh = mesh_config.GetBoolean("UseMeshiesPhysicsMesh", useMeshiesPhysicsMesh); | 105 | useMeshiesPhysicsMesh = mesh_config.GetBoolean("UseMeshiesPhysicsMesh", useMeshiesPhysicsMesh); |
106 | if (useMeshiesPhysicsMesh) | 106 | |
107 | { | 107 | doConvexPrims = mesh_config.GetBoolean("ConvexPrims",doConvexPrims); |
108 | doMeshFileCache = mesh_config.GetBoolean("MeshFileCache", doMeshFileCache); | 108 | doConvexSculpts = mesh_config.GetBoolean("ConvexSculpts",doConvexPrims); |
109 | cachePath = mesh_config.GetString("MeshFileCachePath", cachePath); | 109 | |
110 | fcache = mesh_config.GetFloat("MeshFileCacheExpireHours", fcache); | 110 | doMeshFileCache = mesh_config.GetBoolean("MeshFileCache", doMeshFileCache); |
111 | doCacheExpire = mesh_config.GetBoolean("MeshFileCacheDoExpire", doCacheExpire); | 111 | cachePath = mesh_config.GetString("MeshFileCachePath", cachePath); |
112 | } | 112 | fcache = mesh_config.GetFloat("MeshFileCacheExpireHours", fcache); |
113 | else | 113 | doCacheExpire = mesh_config.GetBoolean("MeshFileCacheDoExpire", doCacheExpire); |
114 | { | ||
115 | doMeshFileCache = false; | ||
116 | doCacheExpire = false; | ||
117 | } | ||
118 | 114 | ||
119 | m_Enabled = true; | 115 | m_Enabled = true; |
120 | } | 116 | } |
@@ -330,6 +326,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing | |||
330 | 326 | ||
331 | List<Coord> coords; | 327 | List<Coord> coords; |
332 | List<Face> faces; | 328 | List<Face> faces; |
329 | bool needsConvexProcessing = convex; | ||
333 | 330 | ||
334 | if (primShape.SculptEntry) | 331 | if (primShape.SculptEntry) |
335 | { | 332 | { |
@@ -340,23 +337,49 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing | |||
340 | 337 | ||
341 | if (!GenerateCoordsAndFacesFromPrimMeshData(primName, primShape, out coords, out faces, convex)) | 338 | if (!GenerateCoordsAndFacesFromPrimMeshData(primName, primShape, out coords, out faces, convex)) |
342 | return null; | 339 | return null; |
340 | needsConvexProcessing = false; | ||
343 | } | 341 | } |
344 | else | 342 | else |
345 | { | 343 | { |
346 | if (!GenerateCoordsAndFacesFromPrimSculptData(primName, primShape, lod, out coords, out faces)) | 344 | if (!GenerateCoordsAndFacesFromPrimSculptData(primName, primShape, lod, out coords, out faces)) |
347 | return null; | 345 | return null; |
346 | needsConvexProcessing &= doConvexSculpts; | ||
348 | } | 347 | } |
349 | } | 348 | } |
350 | else | 349 | else |
351 | { | 350 | { |
352 | if (!GenerateCoordsAndFacesFromPrimShapeData(primName, primShape, lod, convex, out coords, out faces)) | 351 | if (!GenerateCoordsAndFacesFromPrimShapeData(primName, primShape, lod, convex, out coords, out faces)) |
353 | return null; | 352 | return null; |
353 | needsConvexProcessing &= doConvexPrims; | ||
354 | } | 354 | } |
355 | 355 | ||
356 | |||
357 | int numCoords = coords.Count; | 356 | int numCoords = coords.Count; |
358 | int numFaces = faces.Count; | 357 | int numFaces = faces.Count; |
359 | 358 | ||
359 | if(numCoords < 3 || (!needsConvexProcessing && numFaces < 1)) | ||
360 | { | ||
361 | m_log.ErrorFormat("[MESH]: invalid degenerated mesh for prim {0} ignored", primName); | ||
362 | return null; | ||
363 | } | ||
364 | |||
365 | if(needsConvexProcessing) | ||
366 | { | ||
367 | List<Coord> convexcoords; | ||
368 | List<Face> convexfaces; | ||
369 | if(CreateHull(coords, out convexcoords, out convexfaces) && convexcoords != null && convexfaces != null) | ||
370 | { | ||
371 | coords.Clear(); | ||
372 | coords = convexcoords; | ||
373 | numCoords = coords.Count; | ||
374 | |||
375 | faces.Clear(); | ||
376 | faces = convexfaces; | ||
377 | numFaces = faces.Count; | ||
378 | } | ||
379 | else | ||
380 | m_log.ErrorFormat("[ubMESH]: failed to create convex for {0} using normal mesh", primName); | ||
381 | } | ||
382 | |||
360 | Mesh mesh = new Mesh(true); | 383 | Mesh mesh = new Mesh(true); |
361 | // Add the corresponding triangles to the mesh | 384 | // Add the corresponding triangles to the mesh |
362 | for (int i = 0; i < numFaces; i++) | 385 | for (int i = 0; i < numFaces; i++) |
@@ -371,10 +394,10 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing | |||
371 | faces.Clear(); | 394 | faces.Clear(); |
372 | 395 | ||
373 | if(mesh.numberVertices() < 3 || mesh.numberTriangles() < 1) | 396 | if(mesh.numberVertices() < 3 || mesh.numberTriangles() < 1) |
374 | { | 397 | { |
375 | m_log.ErrorFormat("[MESH]: invalid degenerated mesh for prim " + primName + " ignored"); | 398 | m_log.ErrorFormat("[MESH]: invalid degenerated mesh for prim {0} ignored", primName); |
376 | return null; | 399 | return null; |
377 | } | 400 | } |
378 | 401 | ||
379 | primShape.SculptData = Utils.EmptyBytes; | 402 | primShape.SculptData = Utils.EmptyBytes; |
380 | 403 | ||
@@ -1583,5 +1606,79 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing | |||
1583 | catch { } | 1606 | catch { } |
1584 | } | 1607 | } |
1585 | } | 1608 | } |
1609 | |||
1610 | public bool CreateHull(List<Coord> inputVertices, out List<Coord> convexcoords, out List<Face> newfaces) | ||
1611 | { | ||
1612 | convexcoords = null; | ||
1613 | newfaces = null; | ||
1614 | HullDesc desc = new HullDesc(); | ||
1615 | HullResult result = new HullResult(); | ||
1616 | |||
1617 | int nInputVerts = inputVertices.Count; | ||
1618 | int i; | ||
1619 | |||
1620 | List<float3> vs = new List<float3>(nInputVerts); | ||
1621 | float3 f3; | ||
1622 | |||
1623 | //useless copy | ||
1624 | for(i = 0 ; i < nInputVerts; i++) | ||
1625 | { | ||
1626 | f3 = new float3(inputVertices[i].X, inputVertices[i].Y, inputVertices[i].Z); | ||
1627 | vs.Add(f3); | ||
1628 | } | ||
1629 | |||
1630 | desc.Vertices = vs; | ||
1631 | desc.Flags = HullFlag.QF_TRIANGLES; | ||
1632 | desc.MaxVertices = 256; | ||
1633 | |||
1634 | try | ||
1635 | { | ||
1636 | HullError ret = HullUtils.CreateConvexHull(desc, ref result); | ||
1637 | if (ret != HullError.QE_OK) | ||
1638 | return false; | ||
1639 | int nverts = result.OutputVertices.Count; | ||
1640 | int nindx = result.Indices.Count; | ||
1641 | if(nverts < 3 || nindx< 3) | ||
1642 | return false; | ||
1643 | if(nindx % 3 != 0) | ||
1644 | return false; | ||
1645 | |||
1646 | convexcoords = new List<Coord>(nverts); | ||
1647 | Coord c; | ||
1648 | vs = result.OutputVertices; | ||
1649 | |||
1650 | for(i = 0 ; i < nverts; i++) | ||
1651 | { | ||
1652 | c = new Coord(vs[i].x, vs[i].y, vs[i].z); | ||
1653 | convexcoords.Add(c); | ||
1654 | } | ||
1655 | |||
1656 | newfaces = new List<Face>(nindx / 3); | ||
1657 | List<int> indxs = result.Indices; | ||
1658 | int k, l, m; | ||
1659 | Face f; | ||
1660 | for(i = 0 ; i < nindx;) | ||
1661 | { | ||
1662 | k = indxs[i++]; | ||
1663 | l = indxs[i++]; | ||
1664 | m = indxs[i++]; | ||
1665 | if(k > nInputVerts) | ||
1666 | continue; | ||
1667 | if(l > nInputVerts) | ||
1668 | continue; | ||
1669 | if(m > nInputVerts) | ||
1670 | continue; | ||
1671 | f = new Face(k,l,m); | ||
1672 | newfaces.Add(f); | ||
1673 | } | ||
1674 | return true; | ||
1675 | } | ||
1676 | catch | ||
1677 | { | ||
1678 | |||
1679 | return false; | ||
1680 | } | ||
1681 | return false; | ||
1682 | } | ||
1586 | } | 1683 | } |
1587 | } | 1684 | } |