Merge branch 'ubitwork'

avinationmerge
Melanie 2012-03-13 20:21:26 +01:00
commit f53c322b7e
8 changed files with 361 additions and 34 deletions

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

@ -124,7 +124,7 @@ namespace OpenSim.Framework
public delegate void ObjectDrop(uint localID, IClientAPI remoteClient);
public delegate void UpdatePrimFlags(
uint localID, bool UsePhysics, bool IsTemporary, bool IsPhantom, IClientAPI remoteClient);
uint localID, bool UsePhysics, bool IsTemporary, bool IsPhantom,ExtraPhysicsData PhysData, IClientAPI remoteClient);
public delegate void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient);

View File

@ -7006,10 +7006,31 @@ namespace OpenSim.Region.ClientStack.LindenUDP
// 46,47,48 are special positions within the packet
// This may change so perhaps we need a better way
// of storing this (OMV.FlagUpdatePacket.UsePhysics,etc?)
bool UsePhysics = (data[46] != 0) ? true : false;
bool IsTemporary = (data[47] != 0) ? true : false;
bool IsPhantom = (data[48] != 0) ? true : false;
handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, this);
/*
bool UsePhysics = (data[46] != 0) ? true : false;
bool IsTemporary = (data[47] != 0) ? true : false;
bool IsPhantom = (data[48] != 0) ? true : false;
handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, this);
*/
bool UsePhysics = flags.AgentData.UsePhysics;
bool IsPhantom = flags.AgentData.IsPhantom;
bool IsTemporary = flags.AgentData.IsTemporary;
ObjectFlagUpdatePacket.ExtraPhysicsBlock[] blocks = flags.ExtraPhysics;
ExtraPhysicsData physdata = new ExtraPhysicsData();
if (blocks == null || blocks.Length == 0)
{
physdata.PhysShapeType = PhysShapeType.invalid;
}
else
{
ObjectFlagUpdatePacket.ExtraPhysicsBlock phsblock = blocks[0];
physdata.PhysShapeType = (PhysShapeType)phsblock.PhysicsShapeType;
physdata.Bounce = phsblock.Restitution;
physdata.Density = phsblock.Density;
physdata.Friction = phsblock.Friction;
}
handlerUpdatePrimFlags(flags.AgentData.ObjectLocalID, UsePhysics, IsTemporary, IsPhantom, physdata, this);
}
return true;
}

View File

@ -0,0 +1,95 @@
/*
* 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 OpenSim.Framework;
namespace OpenSim.Region.Framework.Scenes
{
public static class SOPMaterialData
{
public enum SopMaterial : int // redundante and not in use for now
{
Stone = 0,
Metal = 1,
Glass = 2,
Wood = 3,
Flesh = 4,
Plastic = 5,
Rubber = 6,
light = 7 // compatibility with old viewers
}
private struct MaterialData
{
public float friction;
public float bounce;
public MaterialData(float f, float b)
{
friction = f;
bounce = b;
}
}
private static MaterialData[] m_materialdata = {
new MaterialData(0.8f,0.4f), // Stone
new MaterialData(0.3f,0.4f), // Metal
new MaterialData(0.2f,0.7f), // Glass
new MaterialData(0.6f,0.5f), // Wood
new MaterialData(0.9f,0.3f), // Flesh
new MaterialData(0.4f,0.7f), // Plastic
new MaterialData(0.9f,0.95f), // Rubber
new MaterialData(0.0f,0.0f) // light ??
};
public static Material MaxMaterial
{
get { return (Material)(m_materialdata.Length - 1); }
}
public static float friction(Material material)
{
int indx = (int)material;
if (indx < m_materialdata.Length)
return (m_materialdata[indx].friction);
else
return 0;
}
public static float bounce(Material material)
{
int indx = (int)material;
if (indx < m_materialdata.Length)
return (m_materialdata[indx].bounce);
else
return 0;
}
}
}

View File

@ -1536,7 +1536,7 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="SetPhantom"></param>
/// <param name="remoteClient"></param>
protected internal void UpdatePrimFlags(
uint localID, bool UsePhysics, bool SetTemporary, bool SetPhantom, IClientAPI remoteClient)
uint localID, bool UsePhysics, bool SetTemporary, bool SetPhantom, ExtraPhysicsData PhysData, IClientAPI remoteClient)
{
SceneObjectGroup group = GetGroupByPrim(localID);
if (group != null)
@ -1544,7 +1544,14 @@ namespace OpenSim.Region.Framework.Scenes
if (m_parentScene.Permissions.CanEditObject(group.UUID, remoteClient.AgentId))
{
// VolumeDetect can't be set via UI and will always be off when a change is made there
group.UpdatePrimFlags(localID, UsePhysics, SetTemporary, SetPhantom, false);
if (PhysData.PhysShapeType == PhysShapeType.invalid)
group.UpdatePrimFlags(localID, UsePhysics, SetTemporary, SetPhantom, false);
else
{
SceneObjectPart part = GetSceneObjectPart(localID);
if (part != null)
part.UpdateExtraPhysics(PhysData);
}
}
}
}

View File

@ -2556,7 +2556,7 @@ namespace OpenSim.Region.Framework.Scenes
linkPart.CreateSelected = true;
// let physics know preserve part volume dtc messy since UpdatePrimFlags doesn't look to parent changes for now
linkPart.UpdatePrimFlags(grpusephys, grptemporary, IsPhantom || ((linkPart.Flags & PrimFlags.Phantom) != null), linkPart.VolumeDetectActive, true);
linkPart.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (linkPart.Flags & PrimFlags.Phantom) != 0), linkPart.VolumeDetectActive, true);
if (linkPart.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
{
linkPart.PhysActor.link(m_rootPart.PhysActor);
@ -2578,7 +2578,7 @@ namespace OpenSim.Region.Framework.Scenes
{
LinkNonRootPart(part, oldGroupPosition, oldRootRotation, linkNum++);
// let physics know
part.UpdatePrimFlags(grpusephys, grptemporary, IsPhantom || ((part.Flags & PrimFlags.Phantom) != null), part.VolumeDetectActive, true);
part.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (part.Flags & PrimFlags.Phantom) != 0), part.VolumeDetectActive, true);
if (part.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical)
{
part.PhysActor.link(m_rootPart.PhysActor);

View File

@ -295,7 +295,13 @@ namespace OpenSim.Region.Framework.Scenes
protected float m_buoyancy = 0.0f;
protected Vector3 m_force;
protected Vector3 m_torque;
protected byte m_physicsShapeType = (byte)PhysShapeType.prim;
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
/// </summary>
@ -556,19 +562,6 @@ namespace OpenSim.Region.Framework.Scenes
}
}
public byte Material
{
get { return (byte) m_material; }
set
{
m_material = (Material)value;
if (PhysActor != null)
{
PhysActor.SetMaterial((int)value);
}
}
}
public bool PassTouches
{
get { return m_passTouches; }
@ -1377,6 +1370,87 @@ namespace OpenSim.Region.Framework.Scenes
}
}
public byte Material
{
get { return (byte)m_material; }
set
{
if (value >= 0 && value <= (byte)SOPMaterialData.MaxMaterial)
{
m_material = (Material)value;
m_friction = SOPMaterialData.friction(m_material);
m_bounce = SOPMaterialData.bounce(m_material);
if (PhysActor != null)
{
PhysActor.SetMaterial((int)value);
}
}
}
}
public byte PhysicsShapeType
{
get { return m_physicsShapeType; }
set
{
if (value < 0 || value >= (byte)PhysShapeType.convex)
value = (byte)PhysShapeType.prim; //convex not supported ?
else if (value == (byte)PhysShapeType.none)
{
if (ParentGroup == null || ParentGroup.RootPart == this)
value = (byte)PhysShapeType.prim;
}
m_physicsShapeType = value;
}
}
public float Density // in kg/m^3
{
get { return m_density; }
set
{
if (value >=1 && value <= 22587.0)
{
m_density = value;
}
}
}
public float GravityModifier
{
get { return m_gravitymod; }
set
{ if( value >= -1 && value <=28.0f)
m_gravitymod = value;
}
}
public float Friction
{
get { return m_friction; }
set
{
if (value >= 0 && value <= 255.0f)
{
m_friction = value;
}
}
}
public float Bounciness
{
get { return m_bounce; }
set
{
if (value >= 0 && value <= 1.0f)
{
m_bounce = value;
}
}
}
#endregion Public Properties with only Get
private uint ApplyMask(uint val, bool set, uint mask)
@ -1583,9 +1657,13 @@ namespace OpenSim.Region.Framework.Scenes
if (!ParentGroup.Scene.CollidablePrims)
return;
if (PhysicsShapeType == (byte)PhysShapeType.none)
return;
bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0;
bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0;
if (IsJoint())
{
DoPhysicsPropertyUpdate(isPhysical, true);
@ -1942,6 +2020,7 @@ namespace OpenSim.Region.Framework.Scenes
if (PhysActor.Phantom != phan)
PhysActor.Phantom = phan;
// If this part is a sculpt then delay the physics update until we've asynchronously loaded the
// mesh data.
if (Shape.SculptEntry)
@ -4334,6 +4413,41 @@ 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 (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, false);
}
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>
@ -4362,9 +4476,10 @@ namespace OpenSim.Region.Framework.Scenes
// ... if VD is changed, all others are not.
// ... if one of the others is changed, VD is not.
/*
if (SetVD) // VD is active, special logic applies
/* volume detection is now independent of phantom in sl
volume detection is now independent of phantom in sl
{
// State machine logic for VolumeDetect
@ -4385,9 +4500,8 @@ namespace OpenSim.Region.Framework.Scenes
// If volumedetect is active we don't want phantom to be applied.
// If this is a new call to VD out of the state "phantom"
// this will also cause the prim to be visible to physics
*/
SetPhantom = false;
/* }
}
}
else if (wasVD)
{
@ -4434,10 +4548,10 @@ namespace OpenSim.Region.Framework.Scenes
else
RemFlag(PrimFlags.Phantom);
if ((SetPhantom && !UsePhysics) || ParentGroup.IsAttachment
if ((SetPhantom && !UsePhysics) || 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);
// AddFlag(PrimFlags.Phantom);
Velocity = new Vector3(0, 0, 0);
Acceleration = new Vector3(0, 0, 0);

View File

@ -359,9 +359,14 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
m_SOPXmlProcessors.Add("Torque", ProcessTorque);
m_SOPXmlProcessors.Add("VolumeDetectActive", ProcessVolumeDetectActive);
//Ubit comented until proper testing
m_SOPXmlProcessors.Add("Vehicle", ProcessVehicle);
m_SOPXmlProcessors.Add("Vehicle", ProcessVehicle);
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
@ -390,7 +395,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
m_TaskInventoryXmlProcessors.Add("PermsMask", ProcessTIPermsMask);
m_TaskInventoryXmlProcessors.Add("Type", ProcessTIType);
m_TaskInventoryXmlProcessors.Add("OwnerChanged", ProcessTIOwnerChanged);
#endregion
#region ShapeXmlProcessors initialization
@ -585,6 +590,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 = (byte)reader.ReadElementContentAsInt("Density", String.Empty);
}
private static void ProcessFriction(SceneObjectPart obj, XmlTextReader reader)
{
obj.Friction = (byte)reader.ReadElementContentAsInt("Friction", String.Empty);
}
private static void ProcessBounce(SceneObjectPart obj, XmlTextReader reader)
{
obj.Bounciness = (byte)reader.ReadElementContentAsInt("Bounce", String.Empty);
}
private static void ProcessGravityModifier(SceneObjectPart obj, XmlTextReader reader)
{
obj.GravityModifier = (byte)reader.ReadElementContentAsInt("GravityModifier", String.Empty);
}
private static void ProcessVehicle(SceneObjectPart obj, XmlTextReader reader)
{
bool errors = false;
@ -1288,9 +1318,19 @@ namespace OpenSim.Region.Framework.Scenes.Serialization
writer.WriteElementString("VolumeDetectActive", sop.VolumeDetectActive.ToString().ToLower());
//Ubit comented until proper testing
if (sop.sopVehicle != null)
sop.sopVehicle.ToXml2(writer);
if (sop.sopVehicle != null)
sop.sopVehicle.ToXml2(writer);
if(sop.PhysicsShapeType != (byte)PhysShapeType.prim)
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();
}