modulate collision sounds intensity with relative collision speed
parent
deb87e7890
commit
98a2c7bfee
|
@ -33,14 +33,24 @@ using OpenSim.Framework;
|
||||||
|
|
||||||
namespace OpenSim.Region.Framework.Scenes
|
namespace OpenSim.Region.Framework.Scenes
|
||||||
{
|
{
|
||||||
|
public struct CollisionForSoundInfo
|
||||||
|
{
|
||||||
|
public uint colliderID;
|
||||||
|
public Vector3 position;
|
||||||
|
public float relativeVel;
|
||||||
|
}
|
||||||
|
|
||||||
public static class CollisionSounds
|
public static class CollisionSounds
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// defines for cases
|
// defines for cases
|
||||||
// only know one UUID for now (woodflesh)
|
// only know one UUID for now (woodflesh)
|
||||||
|
|
||||||
private const int MaxMaterials = 7;
|
private const int MaxMaterials = 7;
|
||||||
// part part
|
// part part
|
||||||
private static UUID snd_StoneStone = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_StoneStone = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_StoneMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_StoneMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_StoneGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_StoneGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_StoneWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_StoneWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
|
@ -48,29 +58,29 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
private static UUID snd_StonePlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_StonePlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_StoneRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_StoneRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
|
|
||||||
private static UUID snd_MetalMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_MetalMetal = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_MetalGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_MetalGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_MetalWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_MetalWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_MetalFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_MetalFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_MetalPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_MetalPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_MetalRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_MetalRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
|
|
||||||
private static UUID snd_GlassGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_GlassGlass = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_GlassWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_GlassWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_GlassFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_GlassFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_GlassPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_GlassPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_GlassRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_GlassRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
|
|
||||||
private static UUID snd_WoodWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_WoodWood = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_WoodFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_WoodFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_WoodPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_WoodPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_WoodRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_WoodRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
|
|
||||||
private static UUID snd_FleshFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_FleshFlesh = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_FleshPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_FleshPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_FleshRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_FleshRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
|
|
||||||
private static UUID snd_PlasticPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_PlasticPlastic = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
private static UUID snd_PlasticRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_PlasticRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
|
|
||||||
private static UUID snd_RubberRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
private static UUID snd_RubberRubber = new UUID("c80260ba-41fd-8a46-768a-6bf236360e3a");
|
||||||
|
@ -107,7 +117,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
public static void PartCollisionSound(SceneObjectPart part,List<uint> Colliders)
|
public static void PartCollisionSound(SceneObjectPart part,List<uint> Colliders)
|
||||||
{
|
{
|
||||||
// temporary mute sounds
|
// temporary mute sounds
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
if(Colliders.Count == 0 || part == null)
|
if(Colliders.Count == 0 || part == null)
|
||||||
return;
|
return;
|
||||||
|
@ -178,28 +188,15 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* avatars get notification let them trigger the sound
|
|
||||||
else if (!doneownsound)
|
|
||||||
{
|
|
||||||
ScenePresence av = part.ParentGroup.Scene.GetScenePresence(Id);
|
|
||||||
if (av != null && (!av.IsChildAgent))
|
|
||||||
{
|
|
||||||
index = thisMatScaled + 4; // flesh
|
|
||||||
soundID = m_PartPart[index];
|
|
||||||
part.SendCollisionSound(soundID, 1.0);
|
|
||||||
doneownsound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AvatarCollisionSound(ScenePresence av, List<uint> Colliders)
|
public static void AvatarCollisionSound(ScenePresence av, List<CollisionForSoundInfo> collidersinfolist)
|
||||||
{
|
{
|
||||||
// temporary mute sounds
|
// temporary mute sounds
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
if (Colliders.Count == 0 || av == null)
|
if (collidersinfolist.Count == 0 || av == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UUID soundID;
|
UUID soundID;
|
||||||
|
@ -211,30 +208,43 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
int index;
|
int index;
|
||||||
// bool doneownsound = false;
|
// bool doneownsound = false;
|
||||||
|
|
||||||
Vector3 position = av.AbsolutePosition;
|
CollisionForSoundInfo colInfo;
|
||||||
|
uint id;
|
||||||
|
float volume;
|
||||||
|
|
||||||
foreach (uint Id in Colliders)
|
for(int i = 0; i< collidersinfolist.Count; i++)
|
||||||
{
|
{
|
||||||
if (Id == 0)
|
colInfo = collidersinfolist[i];
|
||||||
|
|
||||||
|
volume = Math.Abs(colInfo.relativeVel);
|
||||||
|
if(volume < 0.2f)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
id = colInfo.colliderID;
|
||||||
|
|
||||||
|
if (id == 0) // no terrain collision sounds for now
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SceneObjectPart otherPart = av.Scene.GetSceneObjectPart(Id);
|
SceneObjectPart otherPart = av.Scene.GetSceneObjectPart(id);
|
||||||
if (otherPart != null)
|
if (otherPart != null)
|
||||||
{
|
{
|
||||||
if (otherPart.CollisionSound == otherPart.invalidCollisionSoundUUID)
|
if (otherPart.CollisionSound == otherPart.invalidCollisionSoundUUID)
|
||||||
continue;
|
continue;
|
||||||
if (otherPart.CollisionSound != UUID.Zero)
|
if (otherPart.CollisionSound != UUID.Zero)
|
||||||
otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position);
|
otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, colInfo.position);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
volume *= volume * .0625f; // 4m/s == full volume
|
||||||
|
if (volume > 1.0f)
|
||||||
|
volume = 1.0f;
|
||||||
otherMaterial = (int)otherPart.Material;
|
otherMaterial = (int)otherPart.Material;
|
||||||
if (otherMaterial >= MaxMaterials)
|
if (otherMaterial >= MaxMaterials)
|
||||||
otherMaterial = 3;
|
otherMaterial = 3;
|
||||||
index = thisMatScaled + otherMaterial;
|
index = thisMatScaled + otherMaterial;
|
||||||
soundID = m_PartPart[index];
|
soundID = m_PartPart[index];
|
||||||
otherPart.SendCollisionSound(soundID, 1.0, position);
|
otherPart.SendCollisionSound(soundID, volume, colInfo.position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -4112,71 +4112,100 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
List<uint> thisHitColliders = new List<uint>();
|
List<uint> thisHitColliders = new List<uint>();
|
||||||
List<uint> endedColliders = new List<uint>();
|
List<uint> endedColliders = new List<uint>();
|
||||||
List<uint> startedColliders = new List<uint>();
|
List<uint> startedColliders = new List<uint>();
|
||||||
|
List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
|
||||||
|
CollisionForSoundInfo soundinfo;
|
||||||
|
ContactPoint curcontact;
|
||||||
|
|
||||||
foreach (uint localid in coldata.Keys)
|
if (coldata.Count == 0)
|
||||||
{
|
{
|
||||||
thisHitColliders.Add(localid);
|
if (m_lastColliders.Count == 0)
|
||||||
if (!m_lastColliders.Contains(localid))
|
return; // nothing to do
|
||||||
{
|
|
||||||
startedColliders.Add(localid);
|
foreach (uint localID in m_lastColliders)
|
||||||
}
|
|
||||||
//m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate things that ended colliding
|
|
||||||
foreach (uint localID in m_lastColliders)
|
|
||||||
{
|
|
||||||
if (!thisHitColliders.Contains(localID))
|
|
||||||
{
|
{
|
||||||
endedColliders.Add(localID);
|
endedColliders.Add(localID);
|
||||||
}
|
}
|
||||||
}
|
m_lastColliders.Clear();
|
||||||
//add the items that started colliding this time to the last colliders list.
|
|
||||||
foreach (uint localID in startedColliders)
|
|
||||||
{
|
|
||||||
m_lastColliders.Add(localID);
|
|
||||||
}
|
|
||||||
// remove things that ended colliding from the last colliders list
|
|
||||||
foreach (uint localID in endedColliders)
|
|
||||||
{
|
|
||||||
m_lastColliders.Remove(localID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// do event notification
|
else
|
||||||
if (startedColliders.Count > 0)
|
|
||||||
{
|
{
|
||||||
CollisionSounds.AvatarCollisionSound(this, startedColliders);
|
foreach (uint id in coldata.Keys)
|
||||||
|
|
||||||
ColliderArgs StartCollidingMessage = new ColliderArgs();
|
|
||||||
List<DetectedObject> colliding = new List<DetectedObject>();
|
|
||||||
foreach (uint localId in startedColliders)
|
|
||||||
{
|
{
|
||||||
if (localId == 0)
|
thisHitColliders.Add(id);
|
||||||
continue;
|
if (!m_lastColliders.Contains(id))
|
||||||
|
|
||||||
SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
|
|
||||||
string data = "";
|
|
||||||
if (obj != null)
|
|
||||||
{
|
{
|
||||||
DetectedObject detobj = new DetectedObject();
|
startedColliders.Add(id);
|
||||||
detobj.keyUUID = obj.UUID;
|
curcontact = coldata[id];
|
||||||
detobj.nameStr = obj.Name;
|
if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
|
||||||
detobj.ownerUUID = obj.OwnerID;
|
{
|
||||||
detobj.posVector = obj.AbsolutePosition;
|
soundinfo = new CollisionForSoundInfo();
|
||||||
detobj.rotQuat = obj.GetWorldRotation();
|
soundinfo.colliderID = id;
|
||||||
detobj.velVector = obj.Velocity;
|
soundinfo.position = curcontact.Position;
|
||||||
detobj.colliderType = 0;
|
soundinfo.relativeVel = curcontact.RelativeSpeed;
|
||||||
detobj.groupUUID = obj.GroupID;
|
soundinfolist.Add(soundinfo);
|
||||||
colliding.Add(detobj);
|
}
|
||||||
}
|
}
|
||||||
|
//m_log.Debug("[SCENE PRESENCE]: Collided with:" + localid.ToString() + " at depth of: " + collissionswith[localid].ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colliding.Count > 0)
|
// calculate things that ended colliding
|
||||||
|
foreach (uint localID in m_lastColliders)
|
||||||
{
|
{
|
||||||
StartCollidingMessage.Colliders = colliding;
|
if (!thisHitColliders.Contains(localID))
|
||||||
|
{
|
||||||
|
endedColliders.Add(localID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//add the items that started colliding this time to the last colliders list.
|
||||||
|
foreach (uint localID in startedColliders)
|
||||||
|
{
|
||||||
|
m_lastColliders.Add(localID);
|
||||||
|
}
|
||||||
|
// remove things that ended colliding from the last colliders list
|
||||||
|
foreach (uint localID in endedColliders)
|
||||||
|
{
|
||||||
|
m_lastColliders.Remove(localID);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (SceneObjectGroup att in GetAttachments())
|
if (soundinfolist.Count > 0)
|
||||||
Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
|
CollisionSounds.AvatarCollisionSound(this, soundinfolist);
|
||||||
|
|
||||||
|
// do event notification
|
||||||
|
if (startedColliders.Count > 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
ColliderArgs StartCollidingMessage = new ColliderArgs();
|
||||||
|
List<DetectedObject> colliding = new List<DetectedObject>();
|
||||||
|
foreach (uint localId in startedColliders)
|
||||||
|
{
|
||||||
|
if (localId == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
|
||||||
|
string data = "";
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
DetectedObject detobj = new DetectedObject();
|
||||||
|
detobj.keyUUID = obj.UUID;
|
||||||
|
detobj.nameStr = obj.Name;
|
||||||
|
detobj.ownerUUID = obj.OwnerID;
|
||||||
|
detobj.posVector = obj.AbsolutePosition;
|
||||||
|
detobj.rotQuat = obj.GetWorldRotation();
|
||||||
|
detobj.velVector = obj.Velocity;
|
||||||
|
detobj.colliderType = 0;
|
||||||
|
detobj.groupUUID = obj.GroupID;
|
||||||
|
colliding.Add(detobj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (colliding.Count > 0)
|
||||||
|
{
|
||||||
|
StartCollidingMessage.Colliders = colliding;
|
||||||
|
|
||||||
|
foreach (SceneObjectGroup att in GetAttachments())
|
||||||
|
Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue