From a0a25bb8ca846c87b3e8e0de74d4fbcc985ae456 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 22 Aug 2010 13:42:29 +0200 Subject: A stab at making a better bounding box calculation --- .../Shared/Api/Implementation/LSL_Api.cs | 105 +++++++++++++++------ 1 file changed, 74 insertions(+), 31 deletions(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 9615d08..d856464 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -7829,55 +7829,98 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); UUID objID = UUID.Zero; LSL_List result = new LSL_List(); + + // If the ID is not valid, return null result if (!UUID.TryParse(obj, out objID)) { result.Add(new LSL_Vector()); result.Add(new LSL_Vector()); return result; } + + // Check if this is an attached prim. If so, replace + // the UUID with the avatar UUID and report it's bounding box + SceneObjectPart part = World.GetSceneObjectPart(objID); + if (part != null && part.ParentGroup.IsAttachment) + objID = part.ParentGroup.RootPart.AttachedAvatar; + + // Find out if this is an avatar ID. If so, return it's box ScenePresence presence = World.GetScenePresence(objID); if (presence != null) { - if (presence.ParentID == 0) // not sat on an object + // As per LSL Wiki, there is no difference between sitting + // and standing avatar since server 1.36 + LSL_Vector lower; + LSL_Vector upper; + if (presence.Animator.Animations.DefaultAnimation.AnimID + == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) { - LSL_Vector lower; - LSL_Vector upper; - if (presence.Animator.Animations.DefaultAnimation.AnimID - == AnimationSet.Animations.AnimsUUID["SIT_GROUND_CONSTRAINED"]) - { - // This is for ground sitting avatars - float height = presence.Appearance.AvatarHeight / 2.66666667f; - lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f); - upper = new LSL_Vector(0.3375f, 0.45f, 0.0f); - } - else - { - // This is for standing/flying avatars - float height = presence.Appearance.AvatarHeight / 2.0f; - lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f); - upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f); - } - result.Add(lower); - result.Add(upper); - return result; + // This is for ground sitting avatars + float height = presence.Appearance.AvatarHeight / 2.66666667f; + lower = new LSL_Vector(-0.3375f, -0.45f, height * -1.0f); + upper = new LSL_Vector(0.3375f, 0.45f, 0.0f); } else { - // sitting on an object so we need the bounding box of that - // which should include the avatar so set the UUID to the - // UUID of the object the avatar is sat on and allow it to fall through - // to processing an object - SceneObjectPart p = World.GetSceneObjectPart(presence.ParentID); - objID = p.UUID; + // This is for standing/flying avatars + float height = presence.Appearance.AvatarHeight / 2.0f; + lower = new LSL_Vector(-0.225f, -0.3f, height * -1.0f); + upper = new LSL_Vector(0.225f, 0.3f, height + 0.05f); } + + // Adjust to the documented error offsets (see LSL Wiki) + lower += new LSL_Vector(0.05f, 0.05f, 0.05f); + upper -= new LSL_Vector(0.05f, 0.05f, 0.05f); + + if (lower.x > upper.x) + lower.x = upper.x; + if (lower.y > upper.y) + lower.y = upper.y; + if (lower.z > upper.z) + lower.z = upper.z; + + result.Add(lower); + result.Add(upper); + return result; } - SceneObjectPart part = World.GetSceneObjectPart(objID); + + part = World.GetSceneObjectPart(objID); // Currently only works for single prims without a sitting avatar if (part != null) { - Vector3 halfSize = part.Scale / 2.0f; - LSL_Vector lower = new LSL_Vector(halfSize.X * -1.0f, halfSize.Y * -1.0f, halfSize.Z * -1.0f); - LSL_Vector upper = new LSL_Vector(halfSize.X, halfSize.Y, halfSize.Z); + float minX; + float maxX; + float minY; + float maxY; + float minZ; + float maxZ; + + // This BBox is in sim coordinates, with the offset being + // a contained point. + Vector3[] offsets = World.GetCombinedBoundingBox(new List { part.ParentGroup }, + out minX, out maxX, out minY, out maxY, out minZ, out maxZ); + + minX -= offsets[0].X; + maxX -= offsets[0].X; + minY -= offsets[0].Y; + maxY -= offsets[0].Y; + minZ -= offsets[0].Z; + maxZ -= offsets[0].Z; + + LSL_Vector lower; + LSL_Vector upper; + + // Adjust to the documented error offsets (see LSL Wiki) + lower = new LSL_Vector(minX + 0.05f, minY + 0.05f, minZ + 0.05f); + upper = new LSL_Vector(maxX - 0.05f, maxY - 0.05f, maxZ - 0.05f); + + if (lower.x > upper.x) + lower.x = upper.x; + if (lower.y > upper.y) + lower.y = upper.y; + if (lower.z > upper.z) + lower.z = upper.z; + result.Add(lower); result.Add(upper); return result; -- cgit v1.1 From 98b2d3a7f2f95ee26de76147d0d43468d8c5ad71 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 22 Aug 2010 15:55:23 +0200 Subject: Revert "Fix a typecasting issue in llList2Float. This addresses mantis #262" This reverts commit 810840b8624886a615f303baf74f7b72fb1ca66a. This breaks llList2Float in horrible ways. 12 hours 14 minutes becomes 1214.0 and 023.145 becomes 23145.0 Could just add the dot to fix the latter issue but that would not help the first part. Another solution is needed. --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index d856464..5caade6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -5123,7 +5123,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api else if (src.Data[index] is LSL_Float) return Convert.ToDouble(((LSL_Float) src.Data[index]).value); else if (src.Data[index] is LSL_String) - return Convert.ToDouble(Regex.Replace(((LSL_String)src.Data[index]).m_string, "[^0-9]", "")); + return Convert.ToDouble(((LSL_String) src.Data[index]).m_string); return Convert.ToDouble(src.Data[index]); } catch (FormatException) -- cgit v1.1 From 0ca771c1850780d0be87b5f16f282b46f9bd4936 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 22 Aug 2010 16:23:36 +0200 Subject: Provide a better implementation of llList2Float --- .../ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 5caade6..ca09705 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -5123,7 +5123,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api else if (src.Data[index] is LSL_Float) return Convert.ToDouble(((LSL_Float) src.Data[index]).value); else if (src.Data[index] is LSL_String) - return Convert.ToDouble(((LSL_String) src.Data[index]).m_string); + { + string str = ((LSL_String) src.Data[index]).m_string; + Match m = Regex.Match(str, "^\\s*(-?+?[0-9,]+\\.?[0-9]*)"); + if (m != Match.Empty) + { + str = m.Value; + double d = 0.0; + if (!Double.TryParse(str, out d)) + return 0.0; + + return d; + } + return 0.0; + } return Convert.ToDouble(src.Data[index]); } catch (FormatException) -- cgit v1.1 From 5c368c8d380e623185f74d32505b841f8496e510 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 22 Aug 2010 16:44:22 +0200 Subject: Refix the fix --- OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation') diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index ca09705..5717086 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -5125,7 +5125,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api else if (src.Data[index] is LSL_String) { string str = ((LSL_String) src.Data[index]).m_string; - Match m = Regex.Match(str, "^\\s*(-?+?[0-9,]+\\.?[0-9]*)"); + Match m = Regex.Match(str, "^\\s*(-?\\+?[,0-9]+\\.?[0-9]*)"); if (m != Match.Empty) { str = m.Value; -- cgit v1.1