store the physics inertia override in Mysql and add it to serializer. run prebuild is required

httptests
UbitUmarov 2017-04-01 17:49:17 +01:00
parent 24b7903cd0
commit 443fc60cdf
8 changed files with 336 additions and 38 deletions

View File

@ -187,7 +187,7 @@ namespace OpenSim.Data.MySQL
"LinkNumber, MediaURL, KeyframeMotion, AttachedPosX, " +
"AttachedPosY, AttachedPosZ, " +
"PhysicsShapeType, Density, GravityModifier, " +
"Friction, Restitution, Vehicle, DynAttrs, " +
"Friction, Restitution, Vehicle, PhysInertia, DynAttrs, " +
"RotationAxisLocks" +
") values (" + "?UUID, " +
"?CreationDate, ?Name, ?Text, " +
@ -224,7 +224,7 @@ namespace OpenSim.Data.MySQL
"?LinkNumber, ?MediaURL, ?KeyframeMotion, ?AttachedPosX, " +
"?AttachedPosY, ?AttachedPosZ, " +
"?PhysicsShapeType, ?Density, ?GravityModifier, " +
"?Friction, ?Restitution, ?Vehicle, ?DynAttrs," +
"?Friction, ?Restitution, ?Vehicle, ?PhysInertia, ?DynAttrs," +
"?RotationAxisLocks)";
FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
@ -1452,6 +1452,14 @@ namespace OpenSim.Data.MySQL
prim.VehicleParams = vehicle;
}
PhysicsInertiaData pdata;
if (row["PhysInertia"].ToString() != String.Empty)
{
pdata = PhysicsInertiaData.FromXml2(row["PhysInertia"].ToString());
if (pdata != null)
prim.PhysicsInertia = pdata;
}
return prim;
}
@ -1810,6 +1818,11 @@ namespace OpenSim.Data.MySQL
else
cmd.Parameters.AddWithValue("KeyframeMotion", new Byte[0]);
if (prim.PhysicsInertia != null)
cmd.Parameters.AddWithValue("PhysInertia", prim.PhysicsInertia.ToXml2());
else
cmd.Parameters.AddWithValue("PhysInertia", String.Empty);
if (prim.VehicleParams != null)
cmd.Parameters.AddWithValue("Vehicle", prim.VehicleParams.ToXml2());
else

View File

@ -461,3 +461,9 @@ BEGIN;
ALTER TABLE `prims` ADD COLUMN `RezzerID` char(36) DEFAULT NULL;
COMMIT;
:VERSION 57 #----- Add physics inertia data
BEGIN;
ALTER TABLE `prims` ADD COLUMN `PhysInertia` TEXT default NULL;
COMMIT;

View File

@ -0,0 +1,262 @@
/*
* 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 System;
using System.Collections.Generic;
using OpenMetaverse;
using System.Text;
using System.IO;
using System.Xml;
namespace OpenSim.Framework
{
public class PhysicsInertiaData
{
public float TotalMass; // the total mass of a linkset
public Vector3 CenterOfMass; // the center of mass position relative to root part position
public Vector3 Inertia; // (Ixx, Iyy, Izz) moment of inertia relative to center of mass and principal axis in local coords
public Vector4 InertiaRotation; // if principal axis don't match local axis, the principal axis rotation
// or the upper triangle of the inertia tensor
// Ixy (= Iyx), Ixz (= Izx), Iyz (= Izy))
public PhysicsInertiaData()
{
}
public PhysicsInertiaData(PhysicsInertiaData source)
{
TotalMass = source.TotalMass;
CenterOfMass = source.CenterOfMass;
Inertia = source.Inertia;
InertiaRotation = source.InertiaRotation;
}
private XmlTextWriter writer;
private void XWint(string name, int i)
{
writer.WriteElementString(name, i.ToString());
}
private void XWfloat(string name, float f)
{
writer.WriteElementString(name, f.ToString(Utils.EnUsCulture));
}
private void XWVector(string name, Vector3 vec)
{
writer.WriteStartElement(name);
writer.WriteElementString("X", vec.X.ToString(Utils.EnUsCulture));
writer.WriteElementString("Y", vec.Y.ToString(Utils.EnUsCulture));
writer.WriteElementString("Z", vec.Z.ToString(Utils.EnUsCulture));
writer.WriteEndElement();
}
private void XWVector4(string name, Vector4 quat)
{
writer.WriteStartElement(name);
writer.WriteElementString("X", quat.X.ToString(Utils.EnUsCulture));
writer.WriteElementString("Y", quat.Y.ToString(Utils.EnUsCulture));
writer.WriteElementString("Z", quat.Z.ToString(Utils.EnUsCulture));
writer.WriteElementString("W", quat.W.ToString(Utils.EnUsCulture));
writer.WriteEndElement();
}
public void ToXml2(XmlTextWriter twriter)
{
writer = twriter;
writer.WriteStartElement("PhysicsInertia");
XWfloat("MASS", TotalMass);
XWVector("CM", CenterOfMass);
XWVector("INERTIA", Inertia);
XWVector4("IROT", InertiaRotation);
writer.WriteEndElement();
writer = null;
}
XmlReader reader;
private int XRint()
{
return reader.ReadElementContentAsInt();
}
private float XRfloat()
{
return reader.ReadElementContentAsFloat();
}
public Vector3 XRvector()
{
Vector3 vec;
reader.ReadStartElement();
vec.X = reader.ReadElementContentAsFloat();
vec.Y = reader.ReadElementContentAsFloat();
vec.Z = reader.ReadElementContentAsFloat();
reader.ReadEndElement();
return vec;
}
public Vector4 XRVector4()
{
Vector4 q;
reader.ReadStartElement();
q.X = reader.ReadElementContentAsFloat();
q.Y = reader.ReadElementContentAsFloat();
q.Z = reader.ReadElementContentAsFloat();
q.W = reader.ReadElementContentAsFloat();
reader.ReadEndElement();
return q;
}
public static bool EReadProcessors(
Dictionary<string, Action> processors,
XmlReader xtr)
{
bool errors = false;
string nodeName = string.Empty;
while (xtr.NodeType != XmlNodeType.EndElement)
{
nodeName = xtr.Name;
Action p = null;
if (processors.TryGetValue(xtr.Name, out p))
{
try
{
p();
}
catch
{
errors = true;
if (xtr.NodeType == XmlNodeType.EndElement)
xtr.Read();
}
}
else
{
xtr.ReadOuterXml(); // ignore
}
}
return errors;
}
public string ToXml2()
{
using (StringWriter sw = new StringWriter())
{
using (XmlTextWriter xwriter = new XmlTextWriter(sw))
{
ToXml2(xwriter);
}
return sw.ToString();
}
}
public static PhysicsInertiaData FromXml2(string text)
{
if (text == String.Empty)
return null;
UTF8Encoding enc = new UTF8Encoding();
MemoryStream ms = new MemoryStream(enc.GetBytes(text));
XmlTextReader xreader = new XmlTextReader(ms);
PhysicsInertiaData v = new PhysicsInertiaData();
bool error;
v.FromXml2(xreader, out error);
xreader.Close();
if (error)
return null;
return v;
}
public static PhysicsInertiaData FromXml2(XmlReader reader)
{
PhysicsInertiaData data = new PhysicsInertiaData();
bool errors = false;
data.FromXml2(reader, out errors);
if (errors)
return null;
return data;
}
private void FromXml2(XmlReader _reader, out bool errors)
{
errors = false;
reader = _reader;
Dictionary<string, Action> m_XmlProcessors = new Dictionary<string, Action>();
m_XmlProcessors.Add("MASS", ProcessXR_Mass);
m_XmlProcessors.Add("CM", ProcessXR_CM);
m_XmlProcessors.Add("INERTIA", ProcessXR_Inertia);
m_XmlProcessors.Add("IROT", ProcessXR_InertiaRotation);
reader.ReadStartElement("PhysicsInertia", String.Empty);
errors = EReadProcessors(
m_XmlProcessors,
reader);
reader.ReadEndElement();
reader = null;
}
private void ProcessXR_Mass()
{
TotalMass = XRfloat();
}
private void ProcessXR_CM()
{
CenterOfMass = XRvector();
}
private void ProcessXR_Inertia()
{
Inertia = XRvector();
}
private void ProcessXR_InertiaRotation()
{
InertiaRotation = XRVector4();
}
}
}

View File

@ -5037,20 +5037,22 @@ namespace OpenSim.Region.Framework.Scenes
public void SetInertiaData(float TotalMass, Vector3 CenterOfMass, Vector3 Inertia, Vector4 aux )
{
PhysicsInertiaData inertia = new PhysicsInertiaData();
inertia.TotalMass = TotalMass;
inertia.CenterOfMass = CenterOfMass;
inertia.Inertia = Inertia;
inertia.InertiaRotation = aux;
if(TotalMass < 0)
RootPart.PhysicsInertia = null;
else
RootPart.PhysicsInertia = new PhysicsInertiaData(inertia);
PhysicsActor pa = RootPart.PhysActor;
if(pa !=null)
{
PhysicsInertiaData inertia = new PhysicsInertiaData();
inertia.TotalMass = TotalMass;
inertia.CenterOfMass = CenterOfMass;
inertia.Inertia = Inertia;
inertia.InertiaRotation = aux;
pa.SetInertiaData(inertia);
}
}
/// <summary>
/// Set the user group to which this scene object belongs.
/// </summary>

View File

@ -406,6 +406,8 @@ namespace OpenSim.Region.Framework.Scenes
private SOPVehicle m_vehicleParams = null;
private PhysicsInertiaData m_physicsInertia;
public KeyframeMotion KeyframeMotion
{
get; set;
@ -3548,6 +3550,18 @@ SendFullUpdateToClient(remoteClient, Position) ignores position parameter
Force = force;
}
public PhysicsInertiaData PhysicsInertia
{
get
{
return m_physicsInertia;
}
set
{
m_physicsInertia = value;
}
}
public SOPVehicle VehicleParams
{
get
@ -4749,7 +4763,12 @@ SendFullUpdateToClient(remoteClient, Position) ignores position parameter
if (VolumeDetectActive) // change if not the default only
pa.SetVolumeDetect(1);
if (m_vehicleParams != null && m_localId == ParentGroup.RootPart.LocalId)
bool isroot = (m_localId == ParentGroup.RootPart.LocalId);
if(isroot && m_physicsInertia != null)
pa.SetInertiaData(m_physicsInertia);
if (isroot && m_vehicleParams != null )
{
m_vehicleParams.SetVehicle(pa);
if(isPhysical && !isPhantom && m_vehicleParams.CameraDecoupled)

View File

@ -453,9 +453,10 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
m_SOPXmlProcessors.Add("Torque", ProcessTorque);
m_SOPXmlProcessors.Add("VolumeDetectActive", ProcessVolumeDetectActive);
m_SOPXmlProcessors.Add("Vehicle", ProcessVehicle);
m_SOPXmlProcessors.Add("PhysicsInertia", ProcessPhysicsInertia);
m_SOPXmlProcessors.Add("RotationAxisLocks", ProcessRotationAxisLocks);
m_SOPXmlProcessors.Add("PhysicsShapeType", ProcessPhysicsShapeType);
m_SOPXmlProcessors.Add("Density", ProcessDensity);
@ -781,6 +782,23 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
}
}
private static void ProcessPhysicsInertia(SceneObjectPart obj, XmlReader reader)
{
PhysicsInertiaData pdata = PhysicsInertiaData.FromXml2(reader);
if (pdata == null)
{
obj.PhysicsInertia = null;
m_log.DebugFormat(
"[SceneObjectSerializer]: Parsing PhysicsInertiaData for object part {0} {1} encountered errors. Please see earlier log entries.",
obj.Name, obj.UUID);
}
else
{
obj.PhysicsInertia = pdata;
}
}
private static void ProcessShape(SceneObjectPart obj, XmlReader reader)
{
List<string> errorNodeNames;
@ -1498,6 +1516,9 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
if (sop.VehicleParams != null)
sop.VehicleParams.ToXml2(writer);
if (sop.PhysicsInertia != null)
sop.PhysicsInertia.ToXml2(writer);
if(sop.RotationAxisLocks != 0)
writer.WriteElementString("RotationAxisLocks", sop.RotationAxisLocks.ToString().ToLower());
writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower());

View File

@ -55,28 +55,6 @@ namespace OpenSim.Region.PhysicsModules.SharedBase
Absolute
}
public class PhysicsInertiaData
{
public float TotalMass; // the total mass of a linkset
public Vector3 CenterOfMass; // the center of mass position relative to root part position
public Vector3 Inertia; // (Ixx, Iyy, Izz) moment of inertia relative to center of mass and principal axis in local coords
public Vector4 InertiaRotation; // if principal axis don't match local axis, the principal axis rotation
// or the upper triangle of the inertia tensor
// Ixy (= Iyx), Ixz (= Izx), Iyz (= Izy))
public PhysicsInertiaData()
{
}
public PhysicsInertiaData(PhysicsInertiaData source)
{
TotalMass = source.TotalMass;
CenterOfMass = source.CenterOfMass;
Inertia = source.Inertia;
InertiaRotation = source.InertiaRotation;
}
}
public struct CameraData
{
public Quaternion CameraRotation;

View File

@ -568,9 +568,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
{
get
{
if(!childPrim && m_fakeInertiaOverride != null)
return m_fakeInertiaOverride.CenterOfMass;
lock (_parent_scene.OdeLock)
{
d.AllocateODEDataForThread(0);