diff options
author | Melanie | 2013-03-26 03:26:02 +0000 |
---|---|---|
committer | Melanie | 2013-03-26 03:26:02 +0000 |
commit | 95d0a7d4faffd94199f49e2bd0d658d2d8333189 (patch) | |
tree | 639471bf99034d3209ca6b8496668d9e0fbdbe84 /OpenSim/Region/Physics | |
parent | Merge branch 'master' into careminster (diff) | |
parent | BulletSim: new algorithm for vertical attraction which uses quaternion (diff) | |
download | opensim-SC-95d0a7d4faffd94199f49e2bd0d658d2d8333189.zip opensim-SC-95d0a7d4faffd94199f49e2bd0d658d2d8333189.tar.gz opensim-SC-95d0a7d4faffd94199f49e2bd0d658d2d8333189.tar.bz2 opensim-SC-95d0a7d4faffd94199f49e2bd0d658d2d8333189.tar.xz |
Merge branch 'master' into careminster
Conflicts:
OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 48 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | 54 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | 12 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 2 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | 74 |
5 files changed, 158 insertions, 32 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index 5549984..65df741 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -321,7 +321,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
321 | } | 321 | } |
322 | } | 322 | } |
323 | 323 | ||
324 | internal void ProcessTypeChange(Vehicle pType) | 324 | public void ProcessTypeChange(Vehicle pType) |
325 | { | 325 | { |
326 | VDetailLog("{0},ProcessTypeChange,type={1}", Prim.LocalID, pType); | 326 | VDetailLog("{0},ProcessTypeChange,type={1}", Prim.LocalID, pType); |
327 | // Set Defaults For Type | 327 | // Set Defaults For Type |
@@ -1301,14 +1301,52 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1301 | // efficiency of 1.0 will cause the spring to reach its equilibrium with exponential decay. | 1301 | // efficiency of 1.0 will cause the spring to reach its equilibrium with exponential decay. |
1302 | public void ComputeAngularVerticalAttraction() | 1302 | public void ComputeAngularVerticalAttraction() |
1303 | { | 1303 | { |
1304 | |||
1304 | // If vertical attaction timescale is reasonable | 1305 | // If vertical attaction timescale is reasonable |
1305 | if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) | 1306 | if (enableAngularVerticalAttraction && m_verticalAttractionTimescale < m_verticalAttractionCutoff) |
1306 | { | 1307 | { |
1308 | // Possible solution derived from a discussion at: | ||
1309 | // http://stackoverflow.com/questions/14939657/computing-vector-from-quaternion-works-computing-quaternion-from-vector-does-no | ||
1310 | |||
1311 | // Create a rotation that is only the vehicle's rotation around Z | ||
1312 | Vector3 currentEuler = Vector3.Zero; | ||
1313 | VehicleOrientation.GetEulerAngles(out currentEuler.X, out currentEuler.Y, out currentEuler.Z); | ||
1314 | Quaternion justZOrientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, currentEuler.Z); | ||
1315 | |||
1316 | // Create the axis that is perpendicular to the up vector and the rotated up vector. | ||
1317 | Vector3 differenceAxis = Vector3.Cross(Vector3.UnitZ * justZOrientation, Vector3.UnitZ * VehicleOrientation); | ||
1318 | // Compute the angle between those to vectors. | ||
1319 | double differenceAngle = Math.Acos((double)Vector3.Dot(Vector3.UnitZ, Vector3.Normalize(Vector3.UnitZ * VehicleOrientation))); | ||
1320 | // 'differenceAngle' is the angle to rotate and 'differenceAxis' is the plane to rotate in to get the vehicle vertical | ||
1321 | |||
1322 | // Reduce the change by the time period it is to change in. Timestep is handled when velocity is applied. | ||
1323 | // TODO: add 'efficiency'. | ||
1324 | differenceAngle /= m_verticalAttractionTimescale; | ||
1325 | |||
1326 | // Create the quaterian representing the correction angle | ||
1327 | Quaternion correctionRotation = Quaternion.CreateFromAxisAngle(differenceAxis, (float)differenceAngle); | ||
1328 | |||
1329 | // Turn that quaternion into Euler values to make it into velocities to apply. | ||
1330 | Vector3 vertContributionV = Vector3.Zero; | ||
1331 | correctionRotation.GetEulerAngles(out vertContributionV.X, out vertContributionV.Y, out vertContributionV.Z); | ||
1332 | vertContributionV *= -1f; | ||
1333 | |||
1334 | VehicleRotationalVelocity += vertContributionV; | ||
1335 | |||
1336 | VDetailLog("{0}, MoveAngular,verticalAttraction,diffAxis={1},diffAng={2},corrRot={3},contrib={4}", | ||
1337 | Prim.LocalID, | ||
1338 | differenceAxis, | ||
1339 | differenceAngle, | ||
1340 | correctionRotation, | ||
1341 | vertContributionV); | ||
1342 | |||
1343 | // =================================================================== | ||
1344 | /* | ||
1307 | Vector3 vertContributionV = Vector3.Zero; | 1345 | Vector3 vertContributionV = Vector3.Zero; |
1308 | Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG | 1346 | Vector3 origRotVelW = VehicleRotationalVelocity; // DEBUG DEBUG |
1309 | 1347 | ||
1310 | // Take a vector pointing up and convert it from world to vehicle relative coords. | 1348 | // Take a vector pointing up and convert it from world to vehicle relative coords. |
1311 | Vector3 verticalError = Vector3.UnitZ * VehicleOrientation; | 1349 | Vector3 verticalError = Vector3.Normalize(Vector3.UnitZ * VehicleOrientation); |
1312 | 1350 | ||
1313 | // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) | 1351 | // If vertical attraction correction is needed, the vector that was pointing up (UnitZ) |
1314 | // is now: | 1352 | // is now: |
@@ -1334,13 +1372,17 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
1334 | // 'vertContrbution' is now the necessary angular correction to correct tilt in one second. | 1372 | // 'vertContrbution' is now the necessary angular correction to correct tilt in one second. |
1335 | // Correction happens over a number of seconds. | 1373 | // Correction happens over a number of seconds. |
1336 | Vector3 unscaledContribVerticalErrorV = vertContributionV; // DEBUG DEBUG | 1374 | Vector3 unscaledContribVerticalErrorV = vertContributionV; // DEBUG DEBUG |
1375 | |||
1376 | // The correction happens over the user's time period | ||
1337 | vertContributionV /= m_verticalAttractionTimescale; | 1377 | vertContributionV /= m_verticalAttractionTimescale; |
1338 | 1378 | ||
1339 | VehicleRotationalVelocity += vertContributionV; | 1379 | // Rotate the vehicle rotation to the world coordinates. |
1380 | VehicleRotationalVelocity += (vertContributionV * VehicleOrientation); | ||
1340 | 1381 | ||
1341 | VDetailLog("{0}, MoveAngular,verticalAttraction,,origRotVW={1},vertError={2},unscaledV={3},eff={4},ts={5},vertContribV={6}", | 1382 | VDetailLog("{0}, MoveAngular,verticalAttraction,,origRotVW={1},vertError={2},unscaledV={3},eff={4},ts={5},vertContribV={6}", |
1342 | Prim.LocalID, origRotVelW, verticalError, unscaledContribVerticalErrorV, | 1383 | Prim.LocalID, origRotVelW, verticalError, unscaledContribVerticalErrorV, |
1343 | m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContributionV); | 1384 | m_verticalAttractionEfficiency, m_verticalAttractionTimescale, vertContributionV); |
1385 | */ | ||
1344 | } | 1386 | } |
1345 | } | 1387 | } |
1346 | 1388 | ||
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs index 4d89a88..f3454c8 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSParam.cs | |||
@@ -142,6 +142,14 @@ public static class BSParam | |||
142 | public static float VehicleAngularBankingTimescaleFudge { get; private set; } | 142 | public static float VehicleAngularBankingTimescaleFudge { get; private set; } |
143 | public static bool VehicleDebuggingEnabled { get; private set; } | 143 | public static bool VehicleDebuggingEnabled { get; private set; } |
144 | 144 | ||
145 | // Convex Hulls | ||
146 | public static int CSHullMaxDepthSplit { get; private set; } | ||
147 | public static int CSHullMaxDepthSplitForSimpleShapes { get; private set; } | ||
148 | public static float CSHullConcavityThresholdPercent { get; private set; } | ||
149 | public static float CSHullVolumeConservationThresholdPercent { get; private set; } | ||
150 | public static int CSHullMaxVertices { get; private set; } | ||
151 | public static float CSHullMaxSkinWidth { get; private set; } | ||
152 | |||
145 | // Linkset implementation parameters | 153 | // Linkset implementation parameters |
146 | public static float LinksetImplementation { get; private set; } | 154 | public static float LinksetImplementation { get; private set; } |
147 | public static bool LinkConstraintUseFrameOffset { get; private set; } | 155 | public static bool LinkConstraintUseFrameOffset { get; private set; } |
@@ -195,10 +203,10 @@ public static class BSParam | |||
195 | public delegate void PSetOnObject<T>(BSScene scene, BSPhysObject obj); | 203 | public delegate void PSetOnObject<T>(BSScene scene, BSPhysObject obj); |
196 | public sealed class ParameterDefn<T> : ParameterDefnBase | 204 | public sealed class ParameterDefn<T> : ParameterDefnBase |
197 | { | 205 | { |
198 | T defaultValue; | 206 | private T defaultValue; |
199 | PSetValue<T> setter; | 207 | private PSetValue<T> setter; |
200 | PGetValue<T> getter; | 208 | private PGetValue<T> getter; |
201 | PSetOnObject<T> objectSet; | 209 | private PSetOnObject<T> objectSet; |
202 | public ParameterDefn(string pName, string pDesc, T pDefault, PGetValue<T> pGetter, PSetValue<T> pSetter) | 210 | public ParameterDefn(string pName, string pDesc, T pDefault, PGetValue<T> pGetter, PSetValue<T> pSetter) |
203 | : base(pName, pDesc) | 211 | : base(pName, pDesc) |
204 | { | 212 | { |
@@ -215,13 +223,23 @@ public static class BSParam | |||
215 | getter = pGetter; | 223 | getter = pGetter; |
216 | objectSet = pObjSetter; | 224 | objectSet = pObjSetter; |
217 | } | 225 | } |
226 | /* Wish I could simplify using this definition but CLR doesn't store references so closure around delegates of references won't work | ||
227 | public ParameterDefn(string pName, string pDesc, T pDefault, ref T loc) | ||
228 | : base(pName, pDesc) | ||
229 | { | ||
230 | defaultValue = pDefault; | ||
231 | setter = (s, v) => { loc = v; }; | ||
232 | getter = (s) => { return loc; }; | ||
233 | objectSet = null; | ||
234 | } | ||
235 | */ | ||
218 | public override void AssignDefault(BSScene s) | 236 | public override void AssignDefault(BSScene s) |
219 | { | 237 | { |
220 | setter(s, defaultValue); | 238 | setter(s, defaultValue); |
221 | } | 239 | } |
222 | public override string GetValue(BSScene s) | 240 | public override string GetValue(BSScene s) |
223 | { | 241 | { |
224 | return String.Format("{0}", getter(s)); | 242 | return getter(s).ToString(); |
225 | } | 243 | } |
226 | public override void SetValue(BSScene s, string valAsString) | 244 | public override void SetValue(BSScene s, string valAsString) |
227 | { | 245 | { |
@@ -244,6 +262,7 @@ public static class BSParam | |||
244 | try | 262 | try |
245 | { | 263 | { |
246 | T setValue = (T)parser.Invoke(genericType, new Object[] { valAsString }); | 264 | T setValue = (T)parser.Invoke(genericType, new Object[] { valAsString }); |
265 | // Store the parsed value | ||
247 | setter(s, setValue); | 266 | setter(s, setValue); |
248 | // s.Logger.DebugFormat("{0} Parameter {1} = {2}", LogHeader, name, setValue); | 267 | // s.Logger.DebugFormat("{0} Parameter {1} = {2}", LogHeader, name, setValue); |
249 | } | 268 | } |
@@ -623,6 +642,31 @@ public static class BSParam | |||
623 | (s) => { return GlobalContactBreakingThreshold; }, | 642 | (s) => { return GlobalContactBreakingThreshold; }, |
624 | (s,v) => { GlobalContactBreakingThreshold = v; s.UnmanagedParams[0].globalContactBreakingThreshold = v; } ), | 643 | (s,v) => { GlobalContactBreakingThreshold = v; s.UnmanagedParams[0].globalContactBreakingThreshold = v; } ), |
625 | 644 | ||
645 | new ParameterDefn<int>("CSHullMaxDepthSplit", "CS impl: max depth to split for hull. 1-10 but > 7 is iffy", | ||
646 | 7, | ||
647 | (s) => { return CSHullMaxDepthSplit; }, | ||
648 | (s,v) => { CSHullMaxDepthSplit = v; } ), | ||
649 | new ParameterDefn<int>("CSHullMaxDepthSplitForSimpleShapes", "CS impl: max depth setting for simple prim shapes", | ||
650 | 2, | ||
651 | (s) => { return CSHullMaxDepthSplitForSimpleShapes; }, | ||
652 | (s,v) => { CSHullMaxDepthSplitForSimpleShapes = v; } ), | ||
653 | new ParameterDefn<float>("CSHullConcavityThresholdPercent", "CS impl: concavity threshold percent (0-20)", | ||
654 | 5f, | ||
655 | (s) => { return CSHullConcavityThresholdPercent; }, | ||
656 | (s,v) => { CSHullConcavityThresholdPercent = v; } ), | ||
657 | new ParameterDefn<float>("CSHullVolumeConservationThresholdPercent", "percent volume conservation to collapse hulls (0-30)", | ||
658 | 5f, | ||
659 | (s) => { return CSHullVolumeConservationThresholdPercent; }, | ||
660 | (s,v) => { CSHullVolumeConservationThresholdPercent = v; } ), | ||
661 | new ParameterDefn<int>("CSHullMaxVertices", "CS impl: maximum number of vertices in output hulls. Keep < 50.", | ||
662 | 32, | ||
663 | (s) => { return CSHullMaxVertices; }, | ||
664 | (s,v) => { CSHullMaxVertices = v; } ), | ||
665 | new ParameterDefn<float>("CSHullMaxSkinWidth", "CS impl: skin width to apply to output hulls.", | ||
666 | 0, | ||
667 | (s) => { return CSHullMaxSkinWidth; }, | ||
668 | (s,v) => { CSHullMaxSkinWidth = v; } ), | ||
669 | |||
626 | new ParameterDefn<float>("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)", | 670 | new ParameterDefn<float>("LinksetImplementation", "Type of linkset implementation (0=Constraint, 1=Compound, 2=Manual)", |
627 | (float)BSLinkset.LinksetImplementation.Compound, | 671 | (float)BSLinkset.LinksetImplementation.Compound, |
628 | (s) => { return LinksetImplementation; }, | 672 | (s) => { return LinksetImplementation; }, |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs index f953c1e..6bb88c7 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPhysObject.cs | |||
@@ -86,7 +86,7 @@ public abstract class BSPhysObject : PhysicsActor | |||
86 | PhysBody = new BulletBody(localID); | 86 | PhysBody = new BulletBody(localID); |
87 | PhysShape = new BulletShape(); | 87 | PhysShape = new BulletShape(); |
88 | 88 | ||
89 | LastAssetBuildFailed = false; | 89 | PrimAssetState = PrimAssetCondition.Unknown; |
90 | 90 | ||
91 | // Default material type. Also sets Friction, Restitution and Density. | 91 | // Default material type. Also sets Friction, Restitution and Density. |
92 | SetMaterial((int)MaterialAttributes.Material.Wood); | 92 | SetMaterial((int)MaterialAttributes.Material.Wood); |
@@ -133,9 +133,13 @@ public abstract class BSPhysObject : PhysicsActor | |||
133 | // Reference to the physical shape (btCollisionShape) of this object | 133 | // Reference to the physical shape (btCollisionShape) of this object |
134 | public BulletShape PhysShape; | 134 | public BulletShape PhysShape; |
135 | 135 | ||
136 | // 'true' if the mesh's underlying asset failed to build. | 136 | // The physical representation of the prim might require an asset fetch. |
137 | // This will keep us from looping after the first time the build failed. | 137 | // The asset state is first 'Unknown' then 'Waiting' then either 'Failed' or 'Fetched'. |
138 | public bool LastAssetBuildFailed { get; set; } | 138 | public enum PrimAssetCondition |
139 | { | ||
140 | Unknown, Waiting, Failed, Fetched | ||
141 | } | ||
142 | public PrimAssetCondition PrimAssetState { get; set; } | ||
139 | 143 | ||
140 | // The objects base shape information. Null if not a prim type shape. | 144 | // The objects base shape information. Null if not a prim type shape. |
141 | public PrimitiveBaseShape BaseShape { get; protected set; } | 145 | public PrimitiveBaseShape BaseShape { get; protected set; } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 2cbbe9a..6a5461a 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | |||
@@ -155,7 +155,7 @@ public class BSPrim : BSPhysObject | |||
155 | public override PrimitiveBaseShape Shape { | 155 | public override PrimitiveBaseShape Shape { |
156 | set { | 156 | set { |
157 | BaseShape = value; | 157 | BaseShape = value; |
158 | LastAssetBuildFailed = false; | 158 | PrimAssetState = PrimAssetCondition.Unknown; |
159 | ForceBodyShapeRebuild(false); | 159 | ForceBodyShapeRebuild(false); |
160 | } | 160 | } |
161 | } | 161 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs index 05c147d..7609578 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSShapeCollection.cs | |||
@@ -447,17 +447,10 @@ public sealed class BSShapeCollection : IDisposable | |||
447 | 447 | ||
448 | // If the prim attributes are simple, this could be a simple Bullet native shape | 448 | // If the prim attributes are simple, this could be a simple Bullet native shape |
449 | if (!haveShape | 449 | if (!haveShape |
450 | && nativeShapePossible | ||
450 | && pbs != null | 451 | && pbs != null |
451 | && !pbs.SculptEntry | 452 | && !pbs.SculptEntry |
452 | && nativeShapePossible | 453 | && ((pbs.SculptEntry && !BSParam.ShouldMeshSculptedPrim) || PrimHasNoCuts(pbs)) ) |
453 | && ((pbs.SculptEntry && !BSParam.ShouldMeshSculptedPrim) | ||
454 | || (pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0 | ||
455 | && pbs.ProfileHollow == 0 | ||
456 | && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0 | ||
457 | && pbs.PathBegin == 0 && pbs.PathEnd == 0 | ||
458 | && pbs.PathTaperX == 0 && pbs.PathTaperY == 0 | ||
459 | && pbs.PathScaleX == 100 && pbs.PathScaleY == 100 | ||
460 | && pbs.PathShearX == 0 && pbs.PathShearY == 0) ) ) | ||
461 | { | 454 | { |
462 | // Get the scale of any existing shape so we can see if the new shape is same native type and same size. | 455 | // Get the scale of any existing shape so we can see if the new shape is same native type and same size. |
463 | OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero; | 456 | OMV.Vector3 scaleOfExistingShape = OMV.Vector3.Zero; |
@@ -508,6 +501,18 @@ public sealed class BSShapeCollection : IDisposable | |||
508 | return ret; | 501 | return ret; |
509 | } | 502 | } |
510 | 503 | ||
504 | // return 'true' if this shape description does not include any cutting or twisting. | ||
505 | private bool PrimHasNoCuts(PrimitiveBaseShape pbs) | ||
506 | { | ||
507 | return pbs.ProfileBegin == 0 && pbs.ProfileEnd == 0 | ||
508 | && pbs.ProfileHollow == 0 | ||
509 | && pbs.PathTwist == 0 && pbs.PathTwistBegin == 0 | ||
510 | && pbs.PathBegin == 0 && pbs.PathEnd == 0 | ||
511 | && pbs.PathTaperX == 0 && pbs.PathTaperY == 0 | ||
512 | && pbs.PathScaleX == 100 && pbs.PathScaleY == 100 | ||
513 | && pbs.PathShearX == 0 && pbs.PathShearY == 0; | ||
514 | } | ||
515 | |||
511 | // return 'true' if the prim's shape was changed. | 516 | // return 'true' if the prim's shape was changed. |
512 | public bool CreateGeomMeshOrHull(BSPhysObject prim, ShapeDestructionCallback shapeCallback) | 517 | public bool CreateGeomMeshOrHull(BSPhysObject prim, ShapeDestructionCallback shapeCallback) |
513 | { | 518 | { |
@@ -518,7 +523,7 @@ public sealed class BSShapeCollection : IDisposable | |||
518 | if (prim.IsPhysical && BSParam.ShouldUseHullsForPhysicalObjects) | 523 | if (prim.IsPhysical && BSParam.ShouldUseHullsForPhysicalObjects) |
519 | { | 524 | { |
520 | // Update prim.BSShape to reference a hull of this shape. | 525 | // Update prim.BSShape to reference a hull of this shape. |
521 | ret = GetReferenceToHull(prim,shapeCallback); | 526 | ret = GetReferenceToHull(prim, shapeCallback); |
522 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1},key={2}", | 527 | if (DDetail) DetailLog("{0},BSShapeCollection.CreateGeom,hull,shape={1},key={2}", |
523 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); | 528 | prim.LocalID, prim.PhysShape, prim.PhysShape.shapeKey.ToString("X")); |
524 | } | 529 | } |
@@ -699,6 +704,7 @@ public sealed class BSShapeCollection : IDisposable | |||
699 | 704 | ||
700 | // See that hull shape exists in the physical world and update prim.BSShape. | 705 | // See that hull shape exists in the physical world and update prim.BSShape. |
701 | // We could be creating the hull because scale changed or whatever. | 706 | // We could be creating the hull because scale changed or whatever. |
707 | // Return 'true' if a new hull was built. Otherwise, returning a shared hull instance. | ||
702 | private bool GetReferenceToHull(BSPhysObject prim, ShapeDestructionCallback shapeCallback) | 708 | private bool GetReferenceToHull(BSPhysObject prim, ShapeDestructionCallback shapeCallback) |
703 | { | 709 | { |
704 | BulletShape newShape; | 710 | BulletShape newShape; |
@@ -717,6 +723,7 @@ public sealed class BSShapeCollection : IDisposable | |||
717 | DereferenceShape(prim.PhysShape, shapeCallback); | 723 | DereferenceShape(prim.PhysShape, shapeCallback); |
718 | 724 | ||
719 | newShape = CreatePhysicalHull(prim.PhysObjectName, newHullKey, prim.BaseShape, prim.Size, lod); | 725 | newShape = CreatePhysicalHull(prim.PhysObjectName, newHullKey, prim.BaseShape, prim.Size, lod); |
726 | // It might not have been created if we're waiting for an asset. | ||
720 | newShape = VerifyMeshCreated(newShape, prim); | 727 | newShape = VerifyMeshCreated(newShape, prim); |
721 | 728 | ||
722 | ReferenceShape(newShape); | 729 | ReferenceShape(newShape); |
@@ -735,13 +742,13 @@ public sealed class BSShapeCollection : IDisposable | |||
735 | HullDesc hullDesc; | 742 | HullDesc hullDesc; |
736 | if (Hulls.TryGetValue(newHullKey, out hullDesc)) | 743 | if (Hulls.TryGetValue(newHullKey, out hullDesc)) |
737 | { | 744 | { |
738 | // If the hull shape already is created, just use it. | 745 | // If the hull shape already has been created, just use the one shared instance. |
739 | newShape = hullDesc.shape.Clone(); | 746 | newShape = hullDesc.shape.Clone(); |
740 | } | 747 | } |
741 | else | 748 | else |
742 | { | 749 | { |
743 | // Build a new hull in the physical world | 750 | // Build a new hull in the physical world. |
744 | // Pass true for physicalness as this creates some sort of bounding box which we don't need | 751 | // Pass true for physicalness as this prevents the creation of bounding box which is not needed |
745 | IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false, false, false); | 752 | IMesh meshData = PhysicsScene.mesher.CreateMesh(objName, pbs, size, lod, true, false, false, false); |
746 | if (meshData != null) | 753 | if (meshData != null) |
747 | { | 754 | { |
@@ -761,15 +768,35 @@ public sealed class BSShapeCollection : IDisposable | |||
761 | convVertices.Add(new float3(vv.X, vv.Y, vv.Z)); | 768 | convVertices.Add(new float3(vv.X, vv.Y, vv.Z)); |
762 | } | 769 | } |
763 | 770 | ||
771 | uint maxDepthSplit = (uint)BSParam.CSHullMaxDepthSplit; | ||
772 | if (BSParam.CSHullMaxDepthSplit != BSParam.CSHullMaxDepthSplitForSimpleShapes) | ||
773 | { | ||
774 | // Simple primitive shapes we know are convex so they are better implemented with | ||
775 | // fewer hulls. | ||
776 | // Check for simple shape (prim without cuts) and reduce split parameter if so. | ||
777 | if (PrimHasNoCuts(pbs)) | ||
778 | { | ||
779 | maxDepthSplit = (uint)BSParam.CSHullMaxDepthSplitForSimpleShapes; | ||
780 | } | ||
781 | } | ||
782 | |||
764 | // setup and do convex hull conversion | 783 | // setup and do convex hull conversion |
765 | m_hulls = new List<ConvexResult>(); | 784 | m_hulls = new List<ConvexResult>(); |
766 | DecompDesc dcomp = new DecompDesc(); | 785 | DecompDesc dcomp = new DecompDesc(); |
767 | dcomp.mIndices = convIndices; | 786 | dcomp.mIndices = convIndices; |
768 | dcomp.mVertices = convVertices; | 787 | dcomp.mVertices = convVertices; |
788 | dcomp.mDepth = maxDepthSplit; | ||
789 | dcomp.mCpercent = BSParam.CSHullConcavityThresholdPercent; | ||
790 | dcomp.mPpercent = BSParam.CSHullVolumeConservationThresholdPercent; | ||
791 | dcomp.mMaxVertices = (uint)BSParam.CSHullMaxVertices; | ||
792 | dcomp.mSkinWidth = BSParam.CSHullMaxSkinWidth; | ||
769 | ConvexBuilder convexBuilder = new ConvexBuilder(HullReturn); | 793 | ConvexBuilder convexBuilder = new ConvexBuilder(HullReturn); |
770 | // create the hull into the _hulls variable | 794 | // create the hull into the _hulls variable |
771 | convexBuilder.process(dcomp); | 795 | convexBuilder.process(dcomp); |
772 | 796 | ||
797 | DetailLog("{0},BSShapeCollection.CreatePhysicalHull,key={1},inVert={2},inInd={3},split={4},hulls={5}", | ||
798 | BSScene.DetailLogZero, newHullKey, indices.GetLength(0), vertices.Count, maxDepthSplit, m_hulls.Count); | ||
799 | |||
773 | // Convert the vertices and indices for passing to unmanaged. | 800 | // Convert the vertices and indices for passing to unmanaged. |
774 | // The hull information is passed as a large floating point array. | 801 | // The hull information is passed as a large floating point array. |
775 | // The format is: | 802 | // The format is: |
@@ -905,11 +932,15 @@ public sealed class BSShapeCollection : IDisposable | |||
905 | return newShape; | 932 | return newShape; |
906 | 933 | ||
907 | // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset | 934 | // If this mesh has an underlying asset and we have not failed getting it before, fetch the asset |
908 | if (prim.BaseShape.SculptEntry && !prim.LastAssetBuildFailed && prim.BaseShape.SculptTexture != OMV.UUID.Zero) | 935 | if (prim.BaseShape.SculptEntry |
936 | && prim.PrimAssetState != BSPhysObject.PrimAssetCondition.Failed | ||
937 | && prim.PrimAssetState != BSPhysObject.PrimAssetCondition.Waiting | ||
938 | && prim.BaseShape.SculptTexture != OMV.UUID.Zero | ||
939 | ) | ||
909 | { | 940 | { |
910 | DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset,lastFailed={1}", prim.LocalID, prim.LastAssetBuildFailed); | 941 | DetailLog("{0},BSShapeCollection.VerifyMeshCreated,fetchAsset", prim.LocalID); |
911 | // This will prevent looping through this code as we keep trying to get the failed shape | 942 | // Multiple requestors will know we're waiting for this asset |
912 | prim.LastAssetBuildFailed = true; | 943 | prim.PrimAssetState = BSPhysObject.PrimAssetCondition.Waiting; |
913 | 944 | ||
914 | BSPhysObject xprim = prim; | 945 | BSPhysObject xprim = prim; |
915 | Util.FireAndForget(delegate | 946 | Util.FireAndForget(delegate |
@@ -920,7 +951,7 @@ public sealed class BSShapeCollection : IDisposable | |||
920 | BSPhysObject yprim = xprim; // probably not necessary, but, just in case. | 951 | BSPhysObject yprim = xprim; // probably not necessary, but, just in case. |
921 | assetProvider(yprim.BaseShape.SculptTexture, delegate(AssetBase asset) | 952 | assetProvider(yprim.BaseShape.SculptTexture, delegate(AssetBase asset) |
922 | { | 953 | { |
923 | bool assetFound = false; // DEBUG DEBUG | 954 | bool assetFound = false; |
924 | string mismatchIDs = String.Empty; // DEBUG DEBUG | 955 | string mismatchIDs = String.Empty; // DEBUG DEBUG |
925 | if (asset != null && yprim.BaseShape.SculptEntry) | 956 | if (asset != null && yprim.BaseShape.SculptEntry) |
926 | { | 957 | { |
@@ -938,6 +969,10 @@ public sealed class BSShapeCollection : IDisposable | |||
938 | mismatchIDs = yprim.BaseShape.SculptTexture.ToString() + "/" + asset.ID; | 969 | mismatchIDs = yprim.BaseShape.SculptTexture.ToString() + "/" + asset.ID; |
939 | } | 970 | } |
940 | } | 971 | } |
972 | if (assetFound) | ||
973 | yprim.PrimAssetState = BSPhysObject.PrimAssetCondition.Fetched; | ||
974 | else | ||
975 | yprim.PrimAssetState = BSPhysObject.PrimAssetCondition.Failed; | ||
941 | DetailLog("{0},BSShapeCollection,fetchAssetCallback,found={1},isSculpt={2},ids={3}", | 976 | DetailLog("{0},BSShapeCollection,fetchAssetCallback,found={1},isSculpt={2},ids={3}", |
942 | yprim.LocalID, assetFound, yprim.BaseShape.SculptEntry, mismatchIDs ); | 977 | yprim.LocalID, assetFound, yprim.BaseShape.SculptEntry, mismatchIDs ); |
943 | 978 | ||
@@ -945,6 +980,7 @@ public sealed class BSShapeCollection : IDisposable | |||
945 | } | 980 | } |
946 | else | 981 | else |
947 | { | 982 | { |
983 | xprim.PrimAssetState = BSPhysObject.PrimAssetCondition.Failed; | ||
948 | PhysicsScene.Logger.ErrorFormat("{0} Physical object requires asset but no asset provider. Name={1}", | 984 | PhysicsScene.Logger.ErrorFormat("{0} Physical object requires asset but no asset provider. Name={1}", |
949 | LogHeader, PhysicsScene.Name); | 985 | LogHeader, PhysicsScene.Name); |
950 | } | 986 | } |
@@ -952,7 +988,7 @@ public sealed class BSShapeCollection : IDisposable | |||
952 | } | 988 | } |
953 | else | 989 | else |
954 | { | 990 | { |
955 | if (prim.LastAssetBuildFailed) | 991 | if (prim.PrimAssetState == BSPhysObject.PrimAssetCondition.Failed) |
956 | { | 992 | { |
957 | PhysicsScene.Logger.ErrorFormat("{0} Mesh failed to fetch asset. lID={1}, texture={2}", | 993 | PhysicsScene.Logger.ErrorFormat("{0} Mesh failed to fetch asset. lID={1}, texture={2}", |
958 | LogHeader, prim.LocalID, prim.BaseShape.SculptTexture); | 994 | LogHeader, prim.LocalID, prim.BaseShape.SculptTexture); |