modulate collision sounds intensity with relative collision speed
parent
deb87e7890
commit
98a2c7bfee
|
@ -33,14 +33,24 @@ using OpenSim.Framework;
|
|||
|
||||
namespace OpenSim.Region.Framework.Scenes
|
||||
{
|
||||
public struct CollisionForSoundInfo
|
||||
{
|
||||
public uint colliderID;
|
||||
public Vector3 position;
|
||||
public float relativeVel;
|
||||
}
|
||||
|
||||
public static class CollisionSounds
|
||||
{
|
||||
|
||||
|
||||
|
||||
// defines for cases
|
||||
// only know one UUID for now (woodflesh)
|
||||
|
||||
private const int MaxMaterials = 7;
|
||||
// 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_StoneGlass = 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_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_MetalWood = 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_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_GlassFlesh = 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_WoodWood = 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_WoodRubber = 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_WoodPlastic = 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_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_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)
|
||||
{
|
||||
// temporary mute sounds
|
||||
return;
|
||||
// return;
|
||||
|
||||
if(Colliders.Count == 0 || part == null)
|
||||
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
|
||||
return;
|
||||
// return;
|
||||
|
||||
if (Colliders.Count == 0 || av == null)
|
||||
if (collidersinfolist.Count == 0 || av == null)
|
||||
return;
|
||||
|
||||
UUID soundID;
|
||||
|
@ -211,30 +208,43 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
int index;
|
||||
// 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;
|
||||
}
|
||||
|
||||
SceneObjectPart otherPart = av.Scene.GetSceneObjectPart(Id);
|
||||
SceneObjectPart otherPart = av.Scene.GetSceneObjectPart(id);
|
||||
if (otherPart != null)
|
||||
{
|
||||
if (otherPart.CollisionSound == otherPart.invalidCollisionSoundUUID)
|
||||
continue;
|
||||
if (otherPart.CollisionSound != UUID.Zero)
|
||||
otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position);
|
||||
otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, colInfo.position);
|
||||
else
|
||||
{
|
||||
volume *= volume * .0625f; // 4m/s == full volume
|
||||
if (volume > 1.0f)
|
||||
volume = 1.0f;
|
||||
otherMaterial = (int)otherPart.Material;
|
||||
if (otherMaterial >= MaxMaterials)
|
||||
otherMaterial = 3;
|
||||
index = thisMatScaled + otherMaterial;
|
||||
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> endedColliders = 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.Contains(localid))
|
||||
{
|
||||
startedColliders.Add(localid);
|
||||
}
|
||||
//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))
|
||||
if (m_lastColliders.Count == 0)
|
||||
return; // nothing to do
|
||||
|
||||
foreach (uint localID in m_lastColliders)
|
||||
{
|
||||
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);
|
||||
m_lastColliders.Clear();
|
||||
}
|
||||
|
||||
// do event notification
|
||||
if (startedColliders.Count > 0)
|
||||
else
|
||||
{
|
||||
CollisionSounds.AvatarCollisionSound(this, startedColliders);
|
||||
|
||||
ColliderArgs StartCollidingMessage = new ColliderArgs();
|
||||
List<DetectedObject> colliding = new List<DetectedObject>();
|
||||
foreach (uint localId in startedColliders)
|
||||
foreach (uint id in coldata.Keys)
|
||||
{
|
||||
if (localId == 0)
|
||||
continue;
|
||||
|
||||
SceneObjectPart obj = Scene.GetSceneObjectPart(localId);
|
||||
string data = "";
|
||||
if (obj != null)
|
||||
thisHitColliders.Add(id);
|
||||
if (!m_lastColliders.Contains(id))
|
||||
{
|
||||
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);
|
||||
startedColliders.Add(id);
|
||||
curcontact = coldata[id];
|
||||
if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
|
||||
{
|
||||
soundinfo = new CollisionForSoundInfo();
|
||||
soundinfo.colliderID = id;
|
||||
soundinfo.position = curcontact.Position;
|
||||
soundinfo.relativeVel = curcontact.RelativeSpeed;
|
||||
soundinfolist.Add(soundinfo);
|
||||
}
|
||||
}
|
||||
//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())
|
||||
Scene.EventManager.TriggerScriptCollidingStart(att.LocalId, StartCollidingMessage);
|
||||
if (soundinfolist.Count > 0)
|
||||
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