modulate collision sound intensity with collision relative velocity for parts also
parent
98a2c7bfee
commit
9ecdef2686
|
@ -114,12 +114,9 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
snd_StoneRubber, snd_MetalRubber, snd_GlassRubber, snd_WoodRubber, snd_FleshRubber, snd_PlasticRubber, snd_RubberRubber
|
snd_StoneRubber, snd_MetalRubber, snd_GlassRubber, snd_WoodRubber, snd_FleshRubber, snd_PlasticRubber, snd_RubberRubber
|
||||||
};
|
};
|
||||||
|
|
||||||
public static void PartCollisionSound(SceneObjectPart part,List<uint> Colliders)
|
public static void PartCollisionSound(SceneObjectPart part, List<CollisionForSoundInfo> collidersinfolist)
|
||||||
{
|
{
|
||||||
// temporary mute sounds
|
if (collidersinfolist.Count == 0 || part == null)
|
||||||
// return;
|
|
||||||
|
|
||||||
if(Colliders.Count == 0 || part == null)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (part.VolumeDetectActive || (part.Flags & PrimFlags.Physics) == 0)
|
if (part.VolumeDetectActive || (part.Flags & PrimFlags.Physics) == 0)
|
||||||
|
@ -128,19 +125,20 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
if (part.ParentGroup == null)
|
if (part.ParentGroup == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (part.CollisionSound == part.invalidCollisionSoundUUID)
|
UUID soundID = part.CollisionSound;
|
||||||
|
if (soundID == part.invalidCollisionSoundUUID)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
UUID soundID;
|
float volume = 0.0f;
|
||||||
int otherMaterial;
|
int otherMaterial;
|
||||||
|
bool HaveSound = false;
|
||||||
|
|
||||||
Vector3 position = part.AbsolutePosition;
|
if (soundID != UUID.Zero)
|
||||||
|
|
||||||
if (part.CollisionSound != UUID.Zero)
|
|
||||||
{
|
{
|
||||||
if (part.CollisionSoundVolume > 0.0f)
|
volume = part.CollisionSoundVolume;
|
||||||
part.SendCollisionSound(part.CollisionSound, part.CollisionSoundVolume, position);
|
if (volume == 0.0f)
|
||||||
return;
|
return;
|
||||||
|
HaveSound = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int thisMaterial = (int) part.Material;
|
int thisMaterial = (int) part.Material;
|
||||||
|
@ -152,44 +150,76 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
|
|
||||||
bool doneownsound = false;
|
bool doneownsound = false;
|
||||||
|
|
||||||
foreach (uint Id in Colliders)
|
CollisionForSoundInfo colInfo;
|
||||||
|
uint id;
|
||||||
|
|
||||||
|
for(int i = 0; i< collidersinfolist.Count; i++)
|
||||||
{
|
{
|
||||||
if (Id == 0)
|
colInfo = collidersinfolist[i];
|
||||||
|
|
||||||
|
if (!HaveSound)
|
||||||
|
{
|
||||||
|
volume = Math.Abs(colInfo.relativeVel);
|
||||||
|
if (volume < 0.2f)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = colInfo.colliderID;
|
||||||
|
if (id == 0)
|
||||||
{
|
{
|
||||||
if (!doneownsound)
|
if (!doneownsound)
|
||||||
{
|
{
|
||||||
|
if (!HaveSound)
|
||||||
|
{
|
||||||
|
volume *= volume * .0625f; // 4m/s == full volume
|
||||||
|
if (volume > 1.0f)
|
||||||
|
volume = 1.0f;
|
||||||
soundID = m_TerrainPart[thisMaterial];
|
soundID = m_TerrainPart[thisMaterial];
|
||||||
part.SendCollisionSound(soundID, 1.0, position);
|
}
|
||||||
|
part.SendCollisionSound(soundID, volume, colInfo.position);
|
||||||
doneownsound = true;
|
doneownsound = true;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SceneObjectPart otherPart = part.ParentGroup.Scene.GetSceneObjectPart(Id);
|
SceneObjectPart otherPart = part.ParentGroup.Scene.GetSceneObjectPart(id);
|
||||||
if (otherPart != null)
|
if (otherPart != null)
|
||||||
{
|
{
|
||||||
if (otherPart.CollisionSound == part.invalidCollisionSoundUUID || otherPart.VolumeDetectActive)
|
if (otherPart.CollisionSound == part.invalidCollisionSoundUUID || otherPart.VolumeDetectActive)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (!HaveSound)
|
||||||
|
{
|
||||||
if (otherPart.CollisionSound != UUID.Zero)
|
if (otherPart.CollisionSound != UUID.Zero)
|
||||||
otherPart.SendCollisionSound(otherPart.CollisionSound, otherPart.CollisionSoundVolume, position);
|
{
|
||||||
|
soundID = otherPart.CollisionSound;
|
||||||
|
volume = otherPart.CollisionSoundVolume;
|
||||||
|
if (volume == 0.0f)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (doneownsound)
|
if (doneownsound)
|
||||||
otherPart.SendCollisionSound(soundID, 1.0, position);
|
otherPart.SendCollisionSound(soundID, volume, colInfo.position);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
part.SendCollisionSound(soundID, 1.0, position);
|
part.SendCollisionSound(soundID, volume, colInfo.position);
|
||||||
doneownsound = true;
|
doneownsound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void AvatarCollisionSound(ScenePresence av, List<CollisionForSoundInfo> collidersinfolist)
|
public static void AvatarCollisionSound(ScenePresence av, List<CollisionForSoundInfo> collidersinfolist)
|
||||||
{
|
{
|
||||||
|
|
|
@ -333,7 +333,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
private UUID m_collisionSound;
|
private UUID m_collisionSound;
|
||||||
private float m_collisionSoundVolume;
|
private float m_collisionSoundVolume;
|
||||||
|
|
||||||
private DateTime LastColSoundSentTime;
|
private int LastColSoundSentTime;
|
||||||
|
|
||||||
|
|
||||||
private SOPVehicle m_vehicle = null;
|
private SOPVehicle m_vehicle = null;
|
||||||
|
@ -374,7 +374,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
// this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
|
// this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
|
||||||
// the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
|
// the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
|
||||||
m_inventory = new SceneObjectPartInventory(this);
|
m_inventory = new SceneObjectPartInventory(this);
|
||||||
LastColSoundSentTime = DateTime.UtcNow;
|
LastColSoundSentTime = Util.EnvironmentTickCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -2632,13 +2632,29 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
|
||||||
|
CollisionForSoundInfo soundinfo;
|
||||||
|
ContactPoint curcontact;
|
||||||
|
|
||||||
// calculate things that started colliding this time
|
// calculate things that started colliding this time
|
||||||
// and build up list of colliders this time
|
// and build up list of colliders this time
|
||||||
foreach (uint localid in collissionswith.Keys)
|
foreach (uint id in collissionswith.Keys)
|
||||||
{
|
{
|
||||||
thisHitColliders.Add(localid);
|
thisHitColliders.Add(id);
|
||||||
if (!m_lastColliders.Contains(localid))
|
if (!m_lastColliders.Contains(id))
|
||||||
startedColliders.Add(localid);
|
{
|
||||||
|
startedColliders.Add(id);
|
||||||
|
|
||||||
|
curcontact = collissionswith[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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate things that ended colliding
|
// calculate things that ended colliding
|
||||||
|
@ -2655,17 +2671,14 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
// remove things that ended colliding from the last colliders list
|
// remove things that ended colliding from the last colliders list
|
||||||
foreach (uint localID in endedColliders)
|
foreach (uint localID in endedColliders)
|
||||||
m_lastColliders.Remove(localID);
|
m_lastColliders.Remove(localID);
|
||||||
|
|
||||||
|
// play sounds.
|
||||||
|
if (soundinfolist.Count > 0 && !VolumeDetectActive && CollisionSound != invalidCollisionSoundUUID)
|
||||||
|
CollisionSounds.PartCollisionSound(this, soundinfolist);
|
||||||
}
|
}
|
||||||
|
|
||||||
// play the sound.
|
|
||||||
|
|
||||||
bool IsNotVolumeDtc = !VolumeDetectActive;
|
|
||||||
|
|
||||||
if (IsNotVolumeDtc && startedColliders.Count > 0 && CollisionSound != invalidCollisionSoundUUID)
|
|
||||||
CollisionSounds.PartCollisionSound(this, startedColliders);
|
|
||||||
|
|
||||||
SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart);
|
SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart);
|
||||||
if (IsNotVolumeDtc)
|
if (!VolumeDetectActive)
|
||||||
SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding);
|
SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding);
|
||||||
SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd);
|
SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd);
|
||||||
|
|
||||||
|
@ -3210,8 +3223,8 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
if (volume < 0)
|
if (volume < 0)
|
||||||
volume = 0;
|
volume = 0;
|
||||||
|
|
||||||
DateTime now = DateTime.UtcNow;
|
int now = Util.EnvironmentTickCount();
|
||||||
if((now - LastColSoundSentTime).Milliseconds < 200) // reduce rate to 5 per sec per part ??
|
if(Util.EnvironmentTickCountSubtract(now,LastColSoundSentTime) <200)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LastColSoundSentTime = now;
|
LastColSoundSentTime = now;
|
||||||
|
|
Loading…
Reference in New Issue