From 0e7e2eba14cd9a5302f6f14e57b7247a5199a65e Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 5 Mar 2009 00:16:06 +0000 Subject: * Implements a number of members on SOGObject for use with the MRM Script Engine API. * It's lag-tacular! :D --- .../Scripting/Minimodule/IObject.cs | 18 +-- .../Scripting/Minimodule/SOPObject.cs | 163 ++++++++++++++++++++- 2 files changed, 166 insertions(+), 15 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs index 3456258..ef442d4 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs @@ -66,15 +66,15 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule public enum PrimType { - NotPrimitive, - Box, - Cylinder, - Prism, - Sphere, - Torus, - Tube, - Ring, - Sculpt + NotPrimitive = 255, + Box = 0, + Cylinder = 1, + Prism = 2, + Sphere = 3, + Torus = 4, + Tube = 5, + Ring = 6, + Sculpt = 7 } public enum TextureMapping diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs index 55b9767..cf59cba 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs @@ -1,7 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; using OpenMetaverse; +using OpenSim.Framework; using OpenSim.Region.Framework.Scenes; namespace OpenSim.Region.OptionalModules.Scripting.Minimodule @@ -17,6 +16,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule m_localID = localID; } + /// + /// This needs to run very, very quickly. + /// It is utilized in nearly every property and method. + /// + /// private SceneObjectPart GetSOP() { if (m_rootScene.Entities.ContainsKey(m_localID)) @@ -42,7 +46,21 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule public IObject[] Children { - get { throw new System.NotImplementedException(); } + get + { + SceneObjectPart my = GetSOP(); + int total = my.ParentGroup.Children.Count; + + IObject[] rets = new IObject[total]; + + int i = 0; + foreach (KeyValuePair pair in my.ParentGroup.Children) + { + rets[i++] = new SOPObject(m_rootScene, pair.Value.LocalId); + } + + return rets; + } } public IObject Root @@ -52,7 +70,18 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule public IObjectFace[] Faces { - get { throw new System.NotImplementedException(); } + get + { + SceneObjectPart sop = GetSOP(); + IObjectFace[] rets = new IObjectFace[getNumberOfSides(sop)]; + + for (int i = 0; i < rets.Length;i++ ) + { + //rets[i] = new ObjectFace + } + + return rets; + } } public Vector3 Scale @@ -153,7 +182,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule public PrimType PrimShape { - get { throw new System.NotImplementedException(); } + get { return (PrimType) getScriptPrimType(GetSOP().Shape); } set { throw new System.NotImplementedException(); } } @@ -162,5 +191,127 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule get { throw new System.NotImplementedException(); } set { throw new System.NotImplementedException(); } } + + + #region Supporting Functions + + // Helper functions to understand if object has cut, hollow, dimple, and other affecting number of faces + private static void hasCutHollowDimpleProfileCut(int primType, PrimitiveBaseShape shape, out bool hasCut, out bool hasHollow, + out bool hasDimple, out bool hasProfileCut) + { + if (primType == (int)PrimType.Box + || + primType == (int)PrimType.Cylinder + || + primType == (int)PrimType.Prism) + + hasCut = (shape.ProfileBegin > 0) || (shape.ProfileEnd > 0); + else + hasCut = (shape.PathBegin > 0) || (shape.PathEnd > 0); + + hasHollow = shape.ProfileHollow > 0; + hasDimple = (shape.ProfileBegin > 0) || (shape.ProfileEnd > 0); // taken from llSetPrimitiveParms + hasProfileCut = hasDimple; // is it the same thing? + + } + + private static int getScriptPrimType(PrimitiveBaseShape primShape) + { + if (primShape.SculptEntry) + return (int) PrimType.Sculpt; + if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.Square) + { + if (primShape.PathCurve == (byte) Extrusion.Straight) + return (int) PrimType.Box; + if (primShape.PathCurve == (byte) Extrusion.Curve1) + return (int) PrimType.Tube; + } + else if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.Circle) + { + if (primShape.PathCurve == (byte) Extrusion.Straight) + return (int) PrimType.Cylinder; + if (primShape.PathCurve == (byte) Extrusion.Curve1) + return (int) PrimType.Torus; + } + else if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.HalfCircle) + { + if (primShape.PathCurve == (byte) Extrusion.Curve1 || primShape.PathCurve == (byte) Extrusion.Curve2) + return (int) PrimType.Sphere; + } + else if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.EquilateralTriangle) + { + if (primShape.PathCurve == (byte) Extrusion.Straight) + return (int) PrimType.Prism; + if (primShape.PathCurve == (byte) Extrusion.Curve1) + return (int) PrimType.Ring; + } + return (int) PrimType.NotPrimitive; + } + + private static int getNumberOfSides(SceneObjectPart part) + { + int ret; + bool hasCut; + bool hasHollow; + bool hasDimple; + bool hasProfileCut; + + int primType = getScriptPrimType(part.Shape); + hasCutHollowDimpleProfileCut(primType, part.Shape, out hasCut, out hasHollow, out hasDimple, out hasProfileCut); + + switch (primType) + { + default: + case (int) PrimType.Box: + ret = 6; + if (hasCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Cylinder: + ret = 3; + if (hasCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Prism: + ret = 5; + if (hasCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Sphere: + ret = 1; + if (hasCut) ret += 2; + if (hasDimple) ret += 2; + if (hasHollow) + ret += 1; // GOTCHA: LSL shows 2 additional sides here. + // This has been fixed, but may cause porting issues. + break; + case (int) PrimType.Torus: + ret = 1; + if (hasCut) ret += 2; + if (hasProfileCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Tube: + ret = 4; + if (hasCut) ret += 2; + if (hasProfileCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Ring: + ret = 3; + if (hasCut) ret += 2; + if (hasProfileCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Sculpt: + ret = 1; + break; + } + return ret; + } + + + #endregion + } } -- cgit v1.1