From e5beb480eaf23fa7454728724de80b2a67ded1e8 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 6 Feb 2013 08:03:04 +0000 Subject: Partial port of Avination's support for the new physics parameters. Implements the parameters as properties, the serialization and database storage (MySQL only). Implements llSetPrimitiveParams for prim physics shape and the other 4 extra params. Only the prim shape type "None" is currently functional. No support for the Viewer UI (yet), that will be ported in due course. Lots more to port, this is a large-ish changeset. --- OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 96 +++++++++++++++++++++- .../Scenes/Serialization/SceneObjectSerializer.cs | 43 ++++++++++ 2 files changed, 136 insertions(+), 3 deletions(-) (limited to 'OpenSim/Region/Framework/Scenes') diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 19e6d37..55b5462 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -302,6 +302,13 @@ namespace OpenSim.Region.Framework.Scenes protected Vector3 m_lastAcceleration; protected Vector3 m_lastAngularVelocity; protected int m_lastTerseSent; + + protected byte m_physicsShapeType = (byte)PhysShapeType.prim; + // TODO: Implement these + //protected float m_density = 1000.0f; // in kg/m^3 + //protected float m_gravitymod = 1.0f; + //protected float m_friction = 0.6f; // wood + //protected float m_bounce = 0.5f; // wood /// /// Stores media texture data @@ -1322,6 +1329,69 @@ namespace OpenSim.Region.Framework.Scenes set { m_collisionSoundVolume = value; } } + public byte DefaultPhysicsShapeType() + { + byte type; + + if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh)) + type = (byte)PhysShapeType.convex; + else + type = (byte)PhysShapeType.prim; + + return type; + } + + public byte PhysicsShapeType + { + get { return m_physicsShapeType; } + set + { + byte oldv = m_physicsShapeType; + + if (value >= 0 && value <= (byte)PhysShapeType.convex) + { + if (value == (byte)PhysShapeType.none && ParentGroup != null && ParentGroup.RootPart == this) + m_physicsShapeType = DefaultPhysicsShapeType(); + else + m_physicsShapeType = value; + } + else + m_physicsShapeType = DefaultPhysicsShapeType(); + + if (m_physicsShapeType != oldv && ParentGroup != null) + { + if (m_physicsShapeType == (byte)PhysShapeType.none) + { + if (PhysActor != null) + { + Velocity = new Vector3(0, 0, 0); + Acceleration = new Vector3(0, 0, 0); + if (ParentGroup.RootPart == this) + AngularVelocity = new Vector3(0, 0, 0); + ParentGroup.Scene.RemovePhysicalPrim(1); + RemoveFromPhysics(); + } + } + else if (PhysActor == null) + { + ApplyPhysics((uint)Flags, VolumeDetectActive); + } + else + { + // TODO: Update physics actor + } + + if (ParentGroup != null) + ParentGroup.HasGroupChanged = true; + } + } + } + + public float Density { get; set; } + public float GravityModifier { get; set; } + public float Friction { get; set; } + public float Bounciness { get; set; } + #endregion Public Properties with only Get private uint ApplyMask(uint val, bool set, uint mask) @@ -1523,9 +1593,8 @@ namespace OpenSim.Region.Framework.Scenes if (!ParentGroup.Scene.CollidablePrims) return; -// m_log.DebugFormat( -// "[SCENE OBJECT PART]: Applying physics to {0} {1}, m_physicalPrim {2}", -// Name, LocalId, UUID, m_physicalPrim); + if (PhysicsShapeType == (byte)PhysShapeType.none) + return; bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0; bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0; @@ -3878,6 +3947,26 @@ namespace OpenSim.Region.Framework.Scenes } } + public void UpdateExtraPhysics(ExtraPhysicsData physdata) + { + if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null) + return; + + if (PhysicsShapeType != (byte)physdata.PhysShapeType) + { + PhysicsShapeType = (byte)physdata.PhysShapeType; + + } + + if(Density != physdata.Density) + Density = physdata.Density; + if(GravityModifier != physdata.GravitationModifier) + GravityModifier = physdata.GravitationModifier; + if(Friction != physdata.Friction) + Friction = physdata.Friction; + if(Bounciness != physdata.Bounce) + Bounciness = physdata.Bounce; + } /// /// Update the flags on this prim. This covers properties such as phantom, physics and temporary. /// @@ -3949,6 +4038,7 @@ namespace OpenSim.Region.Framework.Scenes if (SetPhantom || ParentGroup.IsAttachment + || PhysicsShapeType == (byte)PhysShapeType.none || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints { AddFlag(PrimFlags.Phantom); diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index 4a2a47e..78229fe 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs @@ -367,6 +367,13 @@ namespace OpenSim.Region.Framework.Scenes.Serialization m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2); m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3); m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4); + + m_SOPXmlProcessors.Add("PhysicsShapeType", ProcessPhysicsShapeType); + m_SOPXmlProcessors.Add("Density", ProcessDensity); + m_SOPXmlProcessors.Add("Friction", ProcessFriction); + m_SOPXmlProcessors.Add("Bounce", ProcessBounce); + m_SOPXmlProcessors.Add("GravityModifier", ProcessGravityModifier); + #endregion #region TaskInventoryXmlProcessors initialization @@ -594,6 +601,31 @@ namespace OpenSim.Region.Framework.Scenes.Serialization obj.ClickAction = (byte)reader.ReadElementContentAsInt("ClickAction", String.Empty); } + private static void ProcessPhysicsShapeType(SceneObjectPart obj, XmlTextReader reader) + { + obj.PhysicsShapeType = (byte)reader.ReadElementContentAsInt("PhysicsShapeType", String.Empty); + } + + private static void ProcessDensity(SceneObjectPart obj, XmlTextReader reader) + { + obj.Density = reader.ReadElementContentAsFloat("Density", String.Empty); + } + + private static void ProcessFriction(SceneObjectPart obj, XmlTextReader reader) + { + obj.Friction = reader.ReadElementContentAsFloat("Friction", String.Empty); + } + + private static void ProcessBounce(SceneObjectPart obj, XmlTextReader reader) + { + obj.Bounciness = reader.ReadElementContentAsFloat("Bounce", String.Empty); + } + + private static void ProcessGravityModifier(SceneObjectPart obj, XmlTextReader reader) + { + obj.GravityModifier = reader.ReadElementContentAsFloat("GravityModifier", String.Empty); + } + private static void ProcessShape(SceneObjectPart obj, XmlTextReader reader) { List errorNodeNames; @@ -1257,6 +1289,17 @@ namespace OpenSim.Region.Framework.Scenes.Serialization writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString()); writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString()); + if(sop.PhysicsShapeType != sop.DefaultPhysicsShapeType()) + writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower()); + if (sop.Density != 1000.0f) + writer.WriteElementString("Density", sop.Density.ToString().ToLower()); + if (sop.Friction != 0.6f) + writer.WriteElementString("Friction", sop.Friction.ToString().ToLower()); + if (sop.Bounciness != 0.5f) + writer.WriteElementString("Bounce", sop.Bounciness.ToString().ToLower()); + if (sop.GravityModifier != 1.0f) + writer.WriteElementString("GravityModifier", sop.GravityModifier.ToString().ToLower()); + writer.WriteEndElement(); } -- cgit v1.1