Render and select sphere audio zones and static emitters

This commit is contained in:
dexyfex 2017-12-22 11:25:19 +11:00
parent d8fd82c350
commit 9fd0a7d7a9
2 changed files with 174 additions and 36 deletions

View File

@ -121,6 +121,8 @@ namespace CodeWalker.World
public class AudioPlacement public class AudioPlacement
{ {
public string Name { get; set; }
public MetaHash NameHash { get; set; }
public RelFile RelFile { get; set; } public RelFile RelFile { get; set; }
public Dat151Unk37 AudioZone { get; set; } public Dat151Unk37 AudioZone { get; set; }
public Dat151Unk38 AudioEmitter { get; set; } public Dat151Unk38 AudioEmitter { get; set; }
@ -153,6 +155,8 @@ namespace CodeWalker.World
Shape = zone.Shape; Shape = zone.Shape;
ShortTypeName = "AudioZone"; ShortTypeName = "AudioZone";
FullTypeName = "Audio Zone"; FullTypeName = "Audio Zone";
Name = zone.Name;
NameHash = zone.NameHash;
float deg2rad = (float)(Math.PI / 180.0); float deg2rad = (float)(Math.PI / 180.0);
@ -165,6 +169,10 @@ namespace CodeWalker.World
InnerOri = Quaternion.RotationAxis(Vector3.UnitZ, zone.InnerAngle * deg2rad); InnerOri = Quaternion.RotationAxis(Vector3.UnitZ, zone.InnerAngle * deg2rad);
break; break;
case Dat151ZoneShape.Sphere: case Dat151ZoneShape.Sphere:
InnerPos = zone.InnerPos;
InnerOri = Quaternion.Identity;
InnerRad = zone.InnerSize.X;
OuterRad = zone.OuterSize.X;
break; break;
case Dat151ZoneShape.Line: case Dat151ZoneShape.Line:
InnerPos = zone.InnerPos; InnerPos = zone.InnerPos;
@ -180,11 +188,18 @@ namespace CodeWalker.World
OuterOri = Quaternion.RotationAxis(Vector3.UnitZ, zone.OuterAngle * deg2rad); OuterOri = Quaternion.RotationAxis(Vector3.UnitZ, zone.OuterAngle * deg2rad);
bool useouter = ((InnerMax.X == 0) || (InnerMax.Y == 0) || (InnerMax.Z == 0)); bool useouter = ((InnerMax.X == 0) || (InnerMax.Y == 0) || (InnerMax.Z == 0));
if (useouter && (zone.Shape != Dat151ZoneShape.Sphere))
{ } //not sure what these are yet!
HitboxPos = useouter ? OuterPos : InnerPos; HitboxPos = useouter ? OuterPos : InnerPos;
HitboxMax = useouter ? OuterMax : InnerMax; HitboxMax = useouter ? OuterMax : InnerMax;
HitboxMin = useouter ? OuterMin : InnerMin; HitboxMin = useouter ? OuterMin : InnerMin;
HitboxOri = useouter ? OuterOri : InnerOri; HitboxOri = useouter ? OuterOri : InnerOri;
HitboxOriInv = Quaternion.Invert(HitboxOri); HitboxOriInv = Quaternion.Invert(HitboxOri);
HitSphereRad = InnerRad;
if (zone.Shape == Dat151ZoneShape.Sphere)
{
HitboxPos = InnerPos;
}
} }
public AudioPlacement(RelFile rel, Dat151Unk38 emitter) public AudioPlacement(RelFile rel, Dat151Unk38 emitter)
{ {
@ -193,16 +208,23 @@ namespace CodeWalker.World
Shape = Dat151ZoneShape.Sphere; Shape = Dat151ZoneShape.Sphere;
ShortTypeName = "AudioEmitter"; ShortTypeName = "AudioEmitter";
FullTypeName = "Audio Emitter"; FullTypeName = "Audio Emitter";
Name = emitter.Name;
NameHash = emitter.NameHash;
HitboxOri = Quaternion.Identity; HitboxOri = Quaternion.Identity;
HitboxOriInv = Quaternion.Identity; HitboxOriInv = Quaternion.Identity;
InnerPos = emitter.Position; InnerPos = emitter.Position;
OuterPos = InnerPos;
InnerRad = emitter.InnerRad; InnerRad = emitter.InnerRad;
OuterRad = emitter.OuterRad; OuterRad = emitter.OuterRad;
bool useouter = (InnerRad == 0); bool useouter = (InnerRad == 0);
if (useouter)
{
InnerRad = 1;
}
HitboxPos = InnerPos; HitboxPos = InnerPos;
HitSphereRad = useouter ? OuterRad : InnerRad; HitSphereRad = InnerRad;// useouter ? OuterRad : InnerRad;
} }

View File

@ -135,9 +135,12 @@ namespace CodeWalker
float renderboundsmaxdist = 10000.0f; float renderboundsmaxdist = 10000.0f;
List<MapBox> BoundingBoxes = new List<MapBox>(); List<MapBox> BoundingBoxes = new List<MapBox>();
List<MapSphere> BoundingSpheres = new List<MapSphere>(); List<MapSphere> BoundingSpheres = new List<MapSphere>();
List<MapSphere> HilightSpheres = new List<MapSphere>();
List<MapBox> HilightBoxes = new List<MapBox>(); List<MapBox> HilightBoxes = new List<MapBox>();
List<MapBox> SelectionBoxes = new List<MapBox>(); List<MapBox> SelectionBoxes = new List<MapBox>();
List<MapBox> WhiteBoxes = new List<MapBox>(); List<MapBox> WhiteBoxes = new List<MapBox>();
List<MapSphere> SelectionSpheres = new List<MapSphere>();
List<MapSphere> WhiteSpheres = new List<MapSphere>();
bool controllightdir = false; //if not, use timecycle bool controllightdir = false; //if not, use timecycle
@ -570,8 +573,11 @@ namespace CodeWalker
UpdateWidgets(); UpdateWidgets();
WhiteBoxes.Clear(); WhiteBoxes.Clear();
WhiteSpheres.Clear();
SelectionBoxes.Clear(); SelectionBoxes.Clear();
SelectionSpheres.Clear();
HilightBoxes.Clear(); HilightBoxes.Clear();
HilightSpheres.Clear();
BoundingBoxes.Clear(); BoundingBoxes.Clear();
BoundingSpheres.Clear(); BoundingSpheres.Clear();
BeginMouseHitTest(); BeginMouseHitTest();
@ -859,6 +865,14 @@ namespace CodeWalker
{ {
Vector3 movevec = Vector3.Zero; Vector3 movevec = Vector3.Zero;
if (ShiftPressed)
{
moveSpeed *= 5.0f;
}
if (CtrlPressed)
{
moveSpeed *= 0.2f;
}
if (MapViewEnabled) if (MapViewEnabled)
{ {
@ -2095,13 +2109,16 @@ namespace CodeWalker
BoundingBox bbox = new BoundingBox(); BoundingBox bbox = new BoundingBox();
BoundingSphere bsph = new BoundingSphere();
Ray mray = new Ray(); Ray mray = new Ray();
mray.Position = camera.MouseRay.Position + camera.Position; mray.Position = camera.MouseRay.Position + camera.Position;
mray.Direction = camera.MouseRay.Direction; mray.Direction = camera.MouseRay.Direction;
float hitdist = float.MaxValue; float hitdist = float.MaxValue;
MapBox lastHitOuterBox = new MapBox(); MapBox lastHitOuterBox = new MapBox();
MapSphere lastHitOuterSphere = new MapSphere();
MapBox mb = new MapBox(); MapBox mb = new MapBox();
MapSphere ms = new MapSphere();
for (int i = 0; i < audiozones.AllItems.Count; i++) for (int i = 0; i < audiozones.AllItems.Count; i++)
{ {
@ -2141,6 +2158,33 @@ namespace CodeWalker
} }
break; break;
case Dat151ZoneShape.Sphere: case Dat151ZoneShape.Sphere:
if ((placement.InnerPos != Vector3.Zero) && (placement.OuterPos != Vector3.Zero))
{
ms.CamRelPos = placement.InnerPos - camera.Position;
ms.Radius = placement.InnerRad;
HilightSpheres.Add(ms);
ms.CamRelPos = placement.OuterPos - camera.Position;
ms.Radius = placement.OuterRad;
BoundingSpheres.Add(ms);
bsph.Center = placement.HitboxPos;
bsph.Radius = placement.HitSphereRad;
if (mray.Intersects(ref bsph, out hitdist) && (hitdist < CurMouseHit.HitDist) && (hitdist > 0))
{
CurMouseHit.Audio = placement;
CurMouseHit.HitDist = hitdist;
CurMouseHit.CamRel = placement.HitboxPos - camera.Position;
CurMouseHit.AABB = new BoundingBox(); //no box here
CurMouseHit.BSphere = bsph;
lastHitOuterSphere = ms; //highlight the outer sphere
}
}
else
{ }
break; break;
default: default:
break;//shouldn't get here break;//shouldn't get here
@ -2157,7 +2201,7 @@ namespace CodeWalker
HilightBoxes.Add(lastHitOuterBox); HilightBoxes.Add(lastHitOuterBox);
break; break;
case Dat151ZoneShape.Sphere: case Dat151ZoneShape.Sphere:
//HilightSpheres.Add(lastHitOuterSphere); HilightSpheres.Add(lastHitOuterSphere);
break; break;
} }
} }
@ -3005,7 +3049,7 @@ namespace CodeWalker
} }
} }
if (BoundingSpheres.Count > 0) if ((BoundingSpheres.Count > 0) || (HilightSpheres.Count > 0))
{ {
shader.SetMode(BoundsShaderMode.Sphere); shader.SetMode(BoundsShaderMode.Sphere);
shader.SetShader(context); shader.SetShader(context);
@ -3019,6 +3063,13 @@ namespace CodeWalker
shader.SetSphereVars(context, ms.CamRelPos, ms.Radius); shader.SetSphereVars(context, ms.CamRelPos, ms.Radius);
shader.DrawSphere(context); shader.DrawSphere(context);
} }
shader.SetColourVars(context, new Vector4(colourhi, 1));
for (int i = 0; i < HilightSpheres.Count; i++)
{
MapSphere ms = HilightSpheres[i];
shader.SetSphereVars(context, ms.CamRelPos, ms.Radius);
shader.DrawSphere(context);
}
} }
@ -3109,6 +3160,8 @@ namespace CodeWalker
bool clip = renderboundsclip; bool clip = renderboundsclip;
BoundsShaderMode mode = BoundsShaderMode.Box;
float bsphrad = CurMouseHit.BSphere.Radius;
Vector3 bbmin = CurMouseHit.AABB.Minimum; Vector3 bbmin = CurMouseHit.AABB.Minimum;
Vector3 bbmax = CurMouseHit.AABB.Maximum; Vector3 bbmax = CurMouseHit.AABB.Maximum;
Vector3 camrel = CurMouseHit.CamRel; Vector3 camrel = CurMouseHit.CamRel;
@ -3155,6 +3208,10 @@ namespace CodeWalker
if (CurMouseHit.Audio != null) if (CurMouseHit.Audio != null)
{ {
ori = CurMouseHit.Audio.HitboxOri; ori = CurMouseHit.Audio.HitboxOri;
if (CurMouseHit.Audio.Shape == Dat151ZoneShape.Sphere)
{
mode = BoundsShaderMode.Sphere;
}
} }
@ -3162,14 +3219,22 @@ namespace CodeWalker
//render moused object box. //render moused object box.
var shader = shaders.Bounds; var shader = shaders.Bounds;
shader.SetMode(BoundsShaderMode.Box); shader.SetMode(mode);
shader.SetShader(context); shader.SetShader(context);
shader.SetInputLayout(context, VertexType.Default); shader.SetInputLayout(context, VertexType.Default);
shader.SetSceneVars(context, camera, null, globalLights); shader.SetSceneVars(context, camera, null, globalLights);
shader.SetColourVars(context, new Vector4(colour, 1)); //white box shader.SetColourVars(context, new Vector4(colour, 1)); //white box
if (mode == BoundsShaderMode.Box)
{
shader.SetBoxVars(context, camrel, bbmin, bbmax, ori, scale); shader.SetBoxVars(context, camrel, bbmin, bbmax, ori, scale);
shader.DrawBox(context); shader.DrawBox(context);
}
else if (mode == BoundsShaderMode.Sphere)
{
shader.SetSphereVars(context, camrel, bsphrad);
shader.DrawSphere(context);
}
shader.UnbindResources(context); shader.UnbindResources(context);
@ -3220,6 +3285,8 @@ namespace CodeWalker
bool clip = renderboundsclip; bool clip = renderboundsclip;
BoundsShaderMode mode = BoundsShaderMode.Box;
float bsphrad = selectionItem.BSphere.Radius;
Vector3 bbmin = selectionItem.AABB.Minimum; Vector3 bbmin = selectionItem.AABB.Minimum;
Vector3 bbmax = selectionItem.AABB.Maximum; Vector3 bbmax = selectionItem.AABB.Maximum;
Vector3 camrel = -camera.Position; Vector3 camrel = -camera.Position;
@ -3350,6 +3417,16 @@ namespace CodeWalker
bbmin = au.HitboxMin; bbmin = au.HitboxMin;
bbmax = au.HitboxMax; bbmax = au.HitboxMax;
if (selectionItem.Audio.Shape == Dat151ZoneShape.Sphere)
{
mode = BoundsShaderMode.Sphere;
MapSphere wsph = new MapSphere();
wsph.CamRelPos = au.OuterPos - camera.Position;
wsph.Radius = au.OuterRad;
WhiteSpheres.Add(wsph);
}
else
{
MapBox wbox = new MapBox(); MapBox wbox = new MapBox();
wbox.CamRelPos = au.OuterPos - camera.Position; wbox.CamRelPos = au.OuterPos - camera.Position;
wbox.BBMin = au.OuterMin; wbox.BBMin = au.OuterMin;
@ -3358,9 +3435,11 @@ namespace CodeWalker
wbox.Scale = scale; wbox.Scale = scale;
WhiteBoxes.Add(wbox); WhiteBoxes.Add(wbox);
} }
}
if (mode == BoundsShaderMode.Box)
{
MapBox box = new MapBox(); MapBox box = new MapBox();
box.CamRelPos = camrel; box.CamRelPos = camrel;
box.BBMin = bbmin; box.BBMin = bbmin;
@ -3368,6 +3447,14 @@ namespace CodeWalker
box.Orientation = ori; box.Orientation = ori;
box.Scale = scale; box.Scale = scale;
SelectionBoxes.Add(box); SelectionBoxes.Add(box);
}
else if (mode == BoundsShaderMode.Sphere)
{
MapSphere sph = new MapSphere();
sph.CamRelPos = camrel;
sph.Radius = bsphrad;
SelectionSpheres.Add(sph);
}
} }
@ -3541,6 +3628,9 @@ namespace CodeWalker
Vector3 coloursel = new Vector3(0, 1, 0) * globalLights.HdrIntensity * 5.0f; Vector3 coloursel = new Vector3(0, 1, 0) * globalLights.HdrIntensity * 5.0f;
Vector3 colourwht = new Vector3(1, 1, 1) * globalLights.HdrIntensity * 10.0f; Vector3 colourwht = new Vector3(1, 1, 1) * globalLights.HdrIntensity * 10.0f;
var shader = shaders.Bounds; var shader = shaders.Bounds;
if ((WhiteBoxes.Count > 0) || (SelectionBoxes.Count > 0))
{
shader.SetMode(BoundsShaderMode.Box); shader.SetMode(BoundsShaderMode.Box);
shader.SetShader(context); shader.SetShader(context);
shader.SetInputLayout(context, VertexType.Default); shader.SetInputLayout(context, VertexType.Default);
@ -3560,6 +3650,31 @@ namespace CodeWalker
shader.DrawBox(context); shader.DrawBox(context);
} }
shader.UnbindResources(context); shader.UnbindResources(context);
}
if ((WhiteSpheres.Count > 0) || (SelectionSpheres.Count > 0))
{
shader.SetMode(BoundsShaderMode.Sphere);
shader.SetShader(context);
shader.SetInputLayout(context, VertexType.Default);
shader.SetSceneVars(context, camera, null, globalLights);
shader.SetColourVars(context, new Vector4(colourwht, 1));
for (int i = 0; i < WhiteSpheres.Count; i++)
{
MapSphere ms = WhiteSpheres[i];
shader.SetSphereVars(context, ms.CamRelPos, ms.Radius);
shader.DrawSphere(context);
}
shader.SetColourVars(context, new Vector4(coloursel, 1));
for (int i = 0; i < SelectionSpheres.Count; i++)
{
MapSphere ms = SelectionSpheres[i];
shader.SetSphereVars(context, ms.CamRelPos, ms.Radius);
shader.DrawSphere(context);
}
shader.UnbindResources(context);
}
} }
@ -9439,6 +9554,7 @@ namespace CodeWalker
public Vector3 MultipleSelectionCenter { get; set; } public Vector3 MultipleSelectionCenter { get; set; }
public BoundingBox AABB { get; set; } public BoundingBox AABB { get; set; }
public BoundingSphere BSphere { get; set; }
public int GeometryIndex { get; set; } public int GeometryIndex { get; set; }
public Vector3 CamRel { get; set; } public Vector3 CamRel { get; set; }
public float HitDist { get; set; } public float HitDist { get; set; }