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.
user_profiles
Melanie 2013-02-06 08:03:04 +00:00
parent 07a7ec4d1b
commit e5beb480ea
7 changed files with 264 additions and 21 deletions

View File

@ -52,7 +52,7 @@ namespace OpenSim.Data.MySQL
private string m_connectionString; private string m_connectionString;
private object m_dbLock = new object(); private object m_dbLock = new object();
protected virtual Assembly Assembly protected Assembly Assembly
{ {
get { return GetType().Assembly; } get { return GetType().Assembly; }
} }
@ -119,8 +119,10 @@ namespace OpenSim.Data.MySQL
// Eligibility check // Eligibility check
// //
if ((flags & (uint)PrimFlags.Temporary) != 0) // PrimFlags.Temporary is not used in OpenSim code and cannot
return; // be guaranteed to always be clear. Don't check it.
// if ((flags & (uint)PrimFlags.Temporary) != 0)
// return;
if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0) if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
return; return;
@ -171,8 +173,10 @@ namespace OpenSim.Data.MySQL
"ParticleSystem, ClickAction, Material, " + "ParticleSystem, ClickAction, Material, " +
"CollisionSound, CollisionSoundVolume, " + "CollisionSound, CollisionSoundVolume, " +
"PassTouches, " + "PassTouches, " +
"LinkNumber, MediaURL, DynAttrs) " + "LinkNumber, MediaURL, " +
"values (?UUID, " + "PhysicsShapeType, Density, GravityModifier, " +
"Friction, Restitution, DynAttrs " +
") values (" + "?UUID, " +
"?CreationDate, ?Name, ?Text, " + "?CreationDate, ?Name, ?Text, " +
"?Description, ?SitName, ?TouchName, " + "?Description, ?SitName, ?TouchName, " +
"?ObjectFlags, ?OwnerMask, ?NextOwnerMask, " + "?ObjectFlags, ?OwnerMask, ?NextOwnerMask, " +
@ -203,8 +207,10 @@ namespace OpenSim.Data.MySQL
"?SaleType, ?ColorR, ?ColorG, " + "?SaleType, ?ColorR, ?ColorG, " +
"?ColorB, ?ColorA, ?ParticleSystem, " + "?ColorB, ?ColorA, ?ParticleSystem, " +
"?ClickAction, ?Material, ?CollisionSound, " + "?ClickAction, ?Material, ?CollisionSound, " +
"?CollisionSoundVolume, ?PassTouches, ?LinkNumber, " + "?CollisionSoundVolume, ?PassTouches, " +
"?MediaURL, ?DynAttrs)"; "?LinkNumber, ?MediaURL, " +
"?PhysicsShapeType, ?Density, ?GravityModifier, " +
"?Friction, ?Restitution, ?DynAttrs)";
FillPrimCommand(cmd, prim, obj.UUID, regionUUID); FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
@ -741,7 +747,7 @@ namespace OpenSim.Data.MySQL
{ {
//No result, so store our default windlight profile and return it //No result, so store our default windlight profile and return it
nWP.regionID = regionUUID; nWP.regionID = regionUUID;
StoreRegionWindlightSettings(nWP); // StoreRegionWindlightSettings(nWP);
return nWP; return nWP;
} }
else else
@ -1097,7 +1103,8 @@ namespace OpenSim.Data.MySQL
"?SunPosition, ?Covenant, ?CovenantChangedDateTime, ?Sandbox, " + "?SunPosition, ?Covenant, ?CovenantChangedDateTime, ?Sandbox, " +
"?SunVectorX, ?SunVectorY, ?SunVectorZ, " + "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
"?LoadedCreationDateTime, ?LoadedCreationID, " + "?LoadedCreationDateTime, ?LoadedCreationID, " +
"?TerrainImageID, ?TelehubObject, ?ParcelImageID) "; "?TerrainImageID, " +
"?TelehubObject, ?ParcelImageID)";
FillRegionSettingsCommand(cmd, rs); FillRegionSettingsCommand(cmd, rs);
@ -1300,6 +1307,12 @@ namespace OpenSim.Data.MySQL
else else
prim.DynAttrs = new DAMap(); prim.DynAttrs = new DAMap();
prim.PhysicsShapeType = (byte)Convert.ToInt32(row["PhysicsShapeType"].ToString());
prim.Density = (float)(double)row["Density"];
prim.GravityModifier = (float)(double)row["GravityModifier"];
prim.Friction = (float)(double)row["Friction"];
prim.Bounciness = (float)(double)row["Restitution"];
return prim; return prim;
} }
@ -1499,7 +1512,7 @@ namespace OpenSim.Data.MySQL
for (int x = 0; x < (int)Constants.RegionSize; x++) for (int x = 0; x < (int)Constants.RegionSize; x++)
for (int y = 0; y < (int)Constants.RegionSize; y++) for (int y = 0; y < (int)Constants.RegionSize; y++)
{ {
double height = val[x, y]; double height = 20.0;
if (height == 0.0) if (height == 0.0)
height = double.Epsilon; height = double.Epsilon;
@ -1646,6 +1659,12 @@ namespace OpenSim.Data.MySQL
cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum); cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum);
cmd.Parameters.AddWithValue("MediaURL", prim.MediaUrl); cmd.Parameters.AddWithValue("MediaURL", prim.MediaUrl);
cmd.Parameters.AddWithValue("PhysicsShapeType", prim.PhysicsShapeType);
cmd.Parameters.AddWithValue("Density", (double)prim.Density);
cmd.Parameters.AddWithValue("GravityModifier", (double)prim.GravityModifier);
cmd.Parameters.AddWithValue("Friction", (double)prim.Friction);
cmd.Parameters.AddWithValue("Restitution", (double)prim.Bounciness);
if (prim.DynAttrs.Count > 0) if (prim.DynAttrs.Count > 0)
cmd.Parameters.AddWithValue("DynAttrs", prim.DynAttrs.ToXml()); cmd.Parameters.AddWithValue("DynAttrs", prim.DynAttrs.ToXml());
else else
@ -1728,6 +1747,7 @@ namespace OpenSim.Data.MySQL
cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime); cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime);
cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID); cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID);
cmd.Parameters.AddWithValue("TerrainImageID", settings.TerrainImageID); cmd.Parameters.AddWithValue("TerrainImageID", settings.TerrainImageID);
cmd.Parameters.AddWithValue("ParcelImageID", settings.ParcelImageID); cmd.Parameters.AddWithValue("ParcelImageID", settings.ParcelImageID);
cmd.Parameters.AddWithValue("TelehubObject", settings.TelehubObject); cmd.Parameters.AddWithValue("TelehubObject", settings.TelehubObject);
} }

View File

@ -910,3 +910,16 @@ BEGIN;
ALTER TABLE prims ADD COLUMN DynAttrs TEXT; ALTER TABLE prims ADD COLUMN DynAttrs TEXT;
COMMIT; COMMIT;
:VERSION 47 #---------------- Extra prim params
BEGIN;
ALTER TABLE prims ADD COLUMN `PhysicsShapeType` tinyint(4) NOT NULL default '0';
ALTER TABLE prims ADD COLUMN `Density` double NOT NULL default '1000';
ALTER TABLE prims ADD COLUMN `GravityModifier` double NOT NULL default '1';
ALTER TABLE prims ADD COLUMN `Friction` double NOT NULL default '0.6';
ALTER TABLE prims ADD COLUMN `Restitution` double NOT NULL default '0.5';
COMMIT;

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using OpenMetaverse;
namespace OpenSim.Framework
{
public enum PhysShapeType : byte
{
prim = 0,
none = 1,
convex = 2,
invalid = 255 // use to mark invalid data in ExtraPhysicsData
}
public struct ExtraPhysicsData
{
public float Density;
public float GravitationModifier;
public float Friction;
public float Bounce;
public PhysShapeType PhysShapeType;
}
}

View File

@ -303,6 +303,13 @@ namespace OpenSim.Region.Framework.Scenes
protected Vector3 m_lastAngularVelocity; protected Vector3 m_lastAngularVelocity;
protected int m_lastTerseSent; 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
/// <summary> /// <summary>
/// Stores media texture data /// Stores media texture data
/// </summary> /// </summary>
@ -1322,6 +1329,69 @@ namespace OpenSim.Region.Framework.Scenes
set { m_collisionSoundVolume = value; } 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 #endregion Public Properties with only Get
private uint ApplyMask(uint val, bool set, uint mask) private uint ApplyMask(uint val, bool set, uint mask)
@ -1523,9 +1593,8 @@ namespace OpenSim.Region.Framework.Scenes
if (!ParentGroup.Scene.CollidablePrims) if (!ParentGroup.Scene.CollidablePrims)
return; return;
// m_log.DebugFormat( if (PhysicsShapeType == (byte)PhysShapeType.none)
// "[SCENE OBJECT PART]: Applying physics to {0} {1}, m_physicalPrim {2}", return;
// Name, LocalId, UUID, m_physicalPrim);
bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0; bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0;
bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 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;
}
/// <summary> /// <summary>
/// Update the flags on this prim. This covers properties such as phantom, physics and temporary. /// Update the flags on this prim. This covers properties such as phantom, physics and temporary.
/// </summary> /// </summary>
@ -3949,6 +4038,7 @@ namespace OpenSim.Region.Framework.Scenes
if (SetPhantom if (SetPhantom
|| ParentGroup.IsAttachment || ParentGroup.IsAttachment
|| PhysicsShapeType == (byte)PhysShapeType.none
|| (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints
{ {
AddFlag(PrimFlags.Phantom); AddFlag(PrimFlags.Phantom);

View File

@ -367,6 +367,13 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2); m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2);
m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3); m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3);
m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4); 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 #endregion
#region TaskInventoryXmlProcessors initialization #region TaskInventoryXmlProcessors initialization
@ -594,6 +601,31 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
obj.ClickAction = (byte)reader.ReadElementContentAsInt("ClickAction", String.Empty); 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) private static void ProcessShape(SceneObjectPart obj, XmlTextReader reader)
{ {
List<string> errorNodeNames; List<string> errorNodeNames;
@ -1257,6 +1289,17 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString()); writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString());
writer.WriteElementString("PayPrice4", sop.PayPrice[4].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(); writer.WriteEndElement();
} }

View File

@ -7594,6 +7594,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
part.ScriptSetPhysicsStatus(physics); part.ScriptSetPhysicsStatus(physics);
break; break;
case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
if (remain < 1)
return null;
int shape_type = rules.GetLSLIntegerItem(idx++);
ExtraPhysicsData physdata = new ExtraPhysicsData();
physdata.Density = part.Density;
physdata.Bounce = part.Bounciness;
physdata.GravitationModifier = part.GravityModifier;
physdata.PhysShapeType = (PhysShapeType)shape_type;
part.UpdateExtraPhysics(physdata);
break;
case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ: case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
if (remain < 1) if (remain < 1)
return null; return null;

View File

@ -661,6 +661,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
public const int PRIM_MEDIA_PERM_GROUP = 2; public const int PRIM_MEDIA_PERM_GROUP = 2;
public const int PRIM_MEDIA_PERM_ANYONE = 4; public const int PRIM_MEDIA_PERM_ANYONE = 4;
public const int PRIM_PHYSICS_SHAPE_TYPE = 30;
public const int PRIM_PHYSICS_SHAPE_PRIM = 0;
public const int PRIM_PHYSICS_SHAPE_CONVEX = 2;
public const int PRIM_PHYSICS_SHAPE_NONE = 1;
public const int PRIM_PHYSICS_MATERIAL = 31;
public const int DENSITY = 1;
public const int FRICTION = 2;
public const int RESTITUTION = 4;
public const int GRAVITY_MULTIPLIER = 8;
// extra constants for llSetPrimMediaParams // extra constants for llSetPrimMediaParams
public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0); public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0);
public static readonly LSLInteger LSL_STATUS_MALFORMED_PARAMS = new LSLInteger(1000); public static readonly LSLInteger LSL_STATUS_MALFORMED_PARAMS = new LSLInteger(1000);