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 object m_dbLock = new object();
protected virtual Assembly Assembly
protected Assembly Assembly
{
get { return GetType().Assembly; }
}
@ -119,8 +119,10 @@ namespace OpenSim.Data.MySQL
// Eligibility check
//
if ((flags & (uint)PrimFlags.Temporary) != 0)
return;
// PrimFlags.Temporary is not used in OpenSim code and cannot
// be guaranteed to always be clear. Don't check it.
// if ((flags & (uint)PrimFlags.Temporary) != 0)
// return;
if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
return;
@ -135,7 +137,7 @@ namespace OpenSim.Data.MySQL
foreach (SceneObjectPart prim in obj.Parts)
{
cmd.Parameters.Clear();
cmd.CommandText = "replace into prims (" +
"UUID, CreationDate, " +
"Name, Text, Description, " +
@ -171,8 +173,10 @@ namespace OpenSim.Data.MySQL
"ParticleSystem, ClickAction, Material, " +
"CollisionSound, CollisionSoundVolume, " +
"PassTouches, " +
"LinkNumber, MediaURL, DynAttrs) " +
"values (?UUID, " +
"LinkNumber, MediaURL, " +
"PhysicsShapeType, Density, GravityModifier, " +
"Friction, Restitution, DynAttrs " +
") values (" + "?UUID, " +
"?CreationDate, ?Name, ?Text, " +
"?Description, ?SitName, ?TouchName, " +
"?ObjectFlags, ?OwnerMask, ?NextOwnerMask, " +
@ -203,15 +207,17 @@ namespace OpenSim.Data.MySQL
"?SaleType, ?ColorR, ?ColorG, " +
"?ColorB, ?ColorA, ?ParticleSystem, " +
"?ClickAction, ?Material, ?CollisionSound, " +
"?CollisionSoundVolume, ?PassTouches, ?LinkNumber, " +
"?MediaURL, ?DynAttrs)";
"?CollisionSoundVolume, ?PassTouches, " +
"?LinkNumber, ?MediaURL, " +
"?PhysicsShapeType, ?Density, ?GravityModifier, " +
"?Friction, ?Restitution, ?DynAttrs)";
FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
ExecuteNonQuery(cmd);
cmd.Parameters.Clear();
cmd.CommandText = "replace into primshapes (" +
"UUID, Shape, ScaleX, ScaleY, " +
"ScaleZ, PCode, PathBegin, PathEnd, " +
@ -234,9 +240,9 @@ namespace OpenSim.Data.MySQL
"?ProfileEnd, ?ProfileCurve, " +
"?ProfileHollow, ?Texture, ?ExtraParams, " +
"?State, ?Media)";
FillShapeCommand(cmd, prim);
ExecuteNonQuery(cmd);
}
}
@ -582,7 +588,7 @@ namespace OpenSim.Data.MySQL
cmd.CommandText = "insert into terrain (RegionUUID, " +
"Revision, Heightfield) values (?RegionUUID, " +
"1, ?Heightfield)";
cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter));
ExecuteNonQuery(cmd);
@ -741,7 +747,7 @@ namespace OpenSim.Data.MySQL
{
//No result, so store our default windlight profile and return it
nWP.regionID = regionUUID;
StoreRegionWindlightSettings(nWP);
// StoreRegionWindlightSettings(nWP);
return nWP;
}
else
@ -1097,7 +1103,8 @@ namespace OpenSim.Data.MySQL
"?SunPosition, ?Covenant, ?CovenantChangedDateTime, ?Sandbox, " +
"?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
"?LoadedCreationDateTime, ?LoadedCreationID, " +
"?TerrainImageID, ?TelehubObject, ?ParcelImageID) ";
"?TerrainImageID, " +
"?TelehubObject, ?ParcelImageID)";
FillRegionSettingsCommand(cmd, rs);
@ -1300,6 +1307,12 @@ namespace OpenSim.Data.MySQL
else
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;
}
@ -1499,7 +1512,7 @@ namespace OpenSim.Data.MySQL
for (int x = 0; x < (int)Constants.RegionSize; x++)
for (int y = 0; y < (int)Constants.RegionSize; y++)
{
double height = val[x, y];
double height = 20.0;
if (height == 0.0)
height = double.Epsilon;
@ -1646,6 +1659,12 @@ namespace OpenSim.Data.MySQL
cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum);
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)
cmd.Parameters.AddWithValue("DynAttrs", prim.DynAttrs.ToXml());
else
@ -1728,6 +1747,7 @@ namespace OpenSim.Data.MySQL
cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime);
cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID);
cmd.Parameters.AddWithValue("TerrainImageID", settings.TerrainImageID);
cmd.Parameters.AddWithValue("ParcelImageID", settings.ParcelImageID);
cmd.Parameters.AddWithValue("TelehubObject", settings.TelehubObject);
}

View File

@ -910,3 +910,16 @@ BEGIN;
ALTER TABLE prims ADD COLUMN DynAttrs TEXT;
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

@ -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
/// <summary>
/// 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;
}
/// <summary>
/// Update the flags on this prim. This covers properties such as phantom, physics and temporary.
/// </summary>
@ -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);

View File

@ -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<string> 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();
}

View File

@ -7594,6 +7594,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
part.ScriptSetPhysicsStatus(physics);
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:
if (remain < 1)
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_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
public static readonly LSLInteger LSL_STATUS_OK = new LSLInteger(0);
public static readonly LSLInteger LSL_STATUS_MALFORMED_PARAMS = new LSLInteger(1000);