Skip to content

Commit

Permalink
add SDFX and templates
Browse files Browse the repository at this point in the history
  • Loading branch information
igorseabra4 committed Apr 30, 2020
1 parent 5f2b50e commit c84cbdb
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 309 deletions.
2 changes: 1 addition & 1 deletion IndustrialPark/ArchiveEditor/ArchiveEditorFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ private void AddAssetToDictionary(Section_AHDR AHDR, bool fast, bool skipTexture
case AssetType.RWTX:
newAsset = skipTexturesAndModels ? new Asset(AHDR, game, platform) : new AssetRWTX(AHDR, game, platform); break;
case AssetType.SCRP: newAsset = new AssetSCRP(AHDR, game, platform); break;
case AssetType.SDFX: newAsset = new AssetSDFX(AHDR, game, platform); break;
case AssetType.SFX: newAsset = new AssetSFX(AHDR, game, platform); break;
case AssetType.SGRP: newAsset = new AssetSGRP(AHDR, game, platform); break;
case AssetType.SIMP: newAsset = new AssetSIMP(AHDR, game, platform); break;
Expand Down Expand Up @@ -478,7 +479,6 @@ private void AddAssetToDictionary(Section_AHDR AHDR, bool fast, bool skipTexture
case AssetType.NGMS:
case AssetType.PGRS:
case AssetType.RANM:
case AssetType.SDFX:
case AssetType.SLID:
case AssetType.SPLN:
case AssetType.SSET:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,11 @@ public void ApplyScale(Vector3 factor)
SFX.OuterRadius *= singleFactor;
SFX.InnerRadius *= singleFactor;
}
else if (a is AssetSGRP SGRP)
{
SGRP.OuterRadius *= singleFactor;
SGRP.InnerRadius *= singleFactor;
}
else if (a is PlaceableAsset placeable && !(a is AssetPLYR || a is AssetPKUP || a is AssetUI || a is AssetUIFT || a is AssetVIL || (a is AssetDYNA DYNA && DYNA.Type_BFBB == DynaType_BFBB.game_object__Teleport)))
{
placeable.ScaleX *= factor.X;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static void PopulateTemplateMenusAt(ToolStripMenuItem menu, EventHandler
new ToolStripMenuItem(AssetTemplate.Group.ToString()),
new ToolStripMenuItem(AssetTemplate.Portal.ToString()),
new ToolStripMenuItem(AssetTemplate.Script.ToString()),
new ToolStripMenuItem(AssetTemplate.SoundGroup.ToString()),
new ToolStripMenuItem(AssetTemplate.Text.ToString()),
new ToolStripMenuItem(AssetTemplate.Timer.ToString()),
new ToolStripSeparator(),
Expand Down Expand Up @@ -240,9 +241,10 @@ public static void PopulateTemplateMenusAt(ToolStripMenuItem menu, EventHandler
new ToolStripMenuItem(AssetTemplate.Player_Generic.ToString()),
new ToolStripMenuItem(AssetTemplate.SIMP_Generic.ToString()),
new ToolStripMenuItem(AssetTemplate.VIL_Generic.ToString()),
new ToolStripSeparator(),
new ToolStripMenuItem(AssetTemplate.UI_Generic.ToString()),
new ToolStripMenuItem(AssetTemplate.UIFT_Generic.ToString()),
new ToolStripSeparator(),
new ToolStripMenuItem(AssetTemplate.SDFX.ToString()),
new ToolStripMenuItem(AssetTemplate.LightEmitter_Generic.ToString()),
});
foreach (ToolStripItem i in placeable.DropDownItems)
Expand Down Expand Up @@ -589,11 +591,19 @@ public uint PlaceTemplate(Vector3 position, int layerIndex, out bool success, re
dataSize = 0x14;
newAssetType = AssetType.SCRP;
break;
case AssetTemplate.SoundGroup:
dataSize = 0x20;
newAssetType = AssetType.SGRP;
break;
case AssetTemplate.SFX_OnEvent:
case AssetTemplate.SFX_OnRadius:
dataSize = 0x30;
newAssetType = AssetType.SFX;
break;
case AssetTemplate.SDFX:
dataSize = 0x20;
newAssetType = AssetType.SDFX;
break;
case AssetTemplate.ShadowTable:
dataSize = 4;
newAssetType = AssetType.SHDW;
Expand Down Expand Up @@ -859,7 +869,6 @@ public uint PlaceTemplate(Vector3 position, int layerIndex, out bool success, re
case AssetTemplate.Platform_Generic:
((AssetPLAT)asset).AssetType = ObjectAssetType.PLAT;
((AssetPLAT)asset).PlatformType = PlatType.Mechanism;
((AssetPLAT)asset).PlatformSubtype = PlatTypeSpecific.Mechanism;
((AssetPLAT)asset).PlatFlags = 4;
((AssetPLAT)asset).PlatSpecific = new PlatSpecific_Generic((AssetPLAT)asset);
((AssetPLAT)asset).Motion = new Motion_Mechanism((AssetPLAT)asset);
Expand All @@ -886,6 +895,15 @@ public uint PlaceTemplate(Vector3 position, int layerIndex, out bool success, re
((AssetSCRP)asset).AssetType = ObjectAssetType.SCRP;
((AssetSCRP)asset).UnknownFloat08 = 1f;
break;
case AssetTemplate.SoundGroup:
((AssetSGRP)asset).AssetType = ObjectAssetType.SGRP;
((AssetSGRP)asset).UnknownByte0E = 0x30;
((AssetSGRP)asset).UnknownByte0F = 0x80;
((AssetSGRP)asset).UnknownByte13 = 0x42;
((AssetSGRP)asset).InnerRadius = 8f;
((AssetSGRP)asset).OuterRadius = 25f;
((AssetSGRP)asset).SGRP_Entries = new EntrySGRP[] { new EntrySGRP() };
break;
case AssetTemplate.SoundInfo:
if (asset is AssetSNDI_GCN_V1 sndi)
sndi.Padding = 0xCDCDCDCD;
Expand Down Expand Up @@ -925,6 +943,12 @@ public uint PlaceTemplate(Vector3 position, int layerIndex, out bool success, re
((AssetSFX)asset).InnerRadius = 5f;
((AssetSFX)asset).OuterRadius = 10f;
break;
case AssetTemplate.SDFX:
((AssetSDFX)asset).AssetType = ObjectAssetType.SDFX;
((AssetSDFX)asset).PositionX = position.X;
((AssetSDFX)asset).PositionY = position.Y;
((AssetSDFX)asset).PositionZ = position.Z;
break;
case AssetTemplate.Shiny_Red:
((AssetPKUP)asset).StateIsPersistent = persistentShinies;
((AssetPKUP)asset).Shape = 0x3E;
Expand Down Expand Up @@ -1635,7 +1659,6 @@ public uint PlaceTemplate(Vector3 position, int layerIndex, out bool success, re
((AssetPLAT)asset).Model_AssetID = 0x55E9EAB5;
((AssetPLAT)asset).Animation_AssetID = 0x7AAA99BB;
((AssetPLAT)asset).PlatformType = PlatType.Springboard;
((AssetPLAT)asset).PlatformSubtype = PlatTypeSpecific.Springboard;
((AssetPLAT)asset).PlatFlags = 4;
((AssetPLAT)asset).PlatSpecific = new PlatSpecific_Springboard((AssetPLAT)asset)
{
Expand All @@ -1654,7 +1677,6 @@ public uint PlaceTemplate(Vector3 position, int layerIndex, out bool success, re
((AssetPLAT)asset).Model_AssetID = 0x335EE0C8;
((AssetPLAT)asset).Animation_AssetID = 0x730847B6;
((AssetPLAT)asset).PlatformType = PlatType.Mechanism;
((AssetPLAT)asset).PlatformSubtype = PlatTypeSpecific.Mechanism;
((AssetPLAT)asset).PlatFlags = 4;
((AssetPLAT)asset).Motion = new Motion_Mechanism((AssetPLAT)asset) {
Type = MotionType.Other,
Expand Down
2 changes: 2 additions & 0 deletions IndustrialPark/ArchiveEditor/Other/AssetTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum AssetTemplate
Group,
Portal,
Script,
SoundGroup,
Text,
Timer,
CamTweak,
Expand Down Expand Up @@ -169,6 +170,7 @@ public enum AssetTemplate
UIFT_Generic,
SFX_OnEvent,
SFX_OnRadius,
SDFX,
LightEmitter_Generic,

// Other
Expand Down
12 changes: 12 additions & 0 deletions IndustrialPark/ArchiveEditor/Other/EndianConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ private Section_AHDR GetReversedEndian(Section_AHDR AHDR)
ReversePRJT(ref bytes); break;
case AssetType.SCRP:
ReverseSCRP(ref bytes); break;
case AssetType.SDFX:
ReverseSDFX(ref bytes); break;
case AssetType.SFX:
ReverseSFX(ref bytes); break;
case AssetType.SGRP:
Expand Down Expand Up @@ -774,6 +776,16 @@ private void ReverseSCRP(ref List<byte> bytes)
ReverseLinks(ref bytes, bytes[5]);
}

private void ReverseSDFX(ref List<byte> bytes)
{
ReverseObject(ref bytes);

for (int i = 0; i < 6; i++)
bytes.AddRange(Reverse(reader.ReadInt32()));

ReverseLinks(ref bytes, bytes[5]);
}

private void ReverseSFX(ref List<byte> bytes)
{
ReverseObject(ref bytes);
Expand Down
5 changes: 3 additions & 2 deletions IndustrialPark/Assets/ObjectAssets/AssetSGRP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class EntrySGRP
public EntrySGRP()
{
Sound_AssetID = 0;
UnknownFloat04 = 0.8f;
}

public static int SizeOfEntry => 0x10;
Expand Down Expand Up @@ -114,14 +115,14 @@ public byte UnknownByte13
}

[Category("Sound Group"), TypeConverter(typeof(FloatTypeConverter))]
public float UnknownFloat14
public float InnerRadius
{
get => ReadFloat(0x14);
set => Write(0x14, value);
}

[Category("Sound Group"), TypeConverter(typeof(FloatTypeConverter))]
public float UnknownFloat18
public float OuterRadius
{
get => ReadFloat(0x18);
set => Write(0x18, value);
Expand Down
208 changes: 208 additions & 0 deletions IndustrialPark/Assets/ObjectAssets/ClickableAssets/AssetSDFX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
using HipHopFile;
using SharpDX;
using System.Collections.Generic;
using System.ComponentModel;
using IndustrialPark.Models;

namespace IndustrialPark
{
public class AssetSDFX : ObjectAsset, IRenderableAsset, IClickableAsset
{
private Matrix world;
private Matrix world2;
private BoundingBox boundingBox;

public static bool dontRender = false;

protected override int EventStartOffset => 0x20;

public AssetSDFX(Section_AHDR AHDR, Game game, Platform platform) : base(AHDR, game, platform)
{
_position = new Vector3(ReadFloat(0x10), ReadFloat(0x14), ReadFloat(0x18));

CreateTransformMatrix();

if (!ArchiveEditorFunctions.renderableAssetSetTrans.Contains(this))
ArchiveEditorFunctions.renderableAssetSetTrans.Add(this);
}

public override bool HasReference(uint assetID) =>
SoundGroup_AssetID == assetID ||
Emitter_AssetID == assetID ||
base.HasReference(assetID);

public override void Verify(ref List<string> result)
{
base.Verify(ref result);

if (SoundGroup_AssetID == 0)
result.Add("SDFX with SoundGroup_AssetID set to 0");
Verify(SoundGroup_AssetID, ref result);
Verify(Emitter_AssetID, ref result);
}

public void CreateTransformMatrix()
{
world = Matrix.Scaling(_radius * 2f) * Matrix.Translation(_position);
world2 = Matrix.Scaling(_radius2 * 2f) * Matrix.Translation(_position);

CreateBoundingBox();
}

public BoundingSphere boundingSphere;

protected void CreateBoundingBox()
{
boundingSphere = new BoundingSphere(_position, _radius);
boundingBox = BoundingBox.FromSphere(boundingSphere);
}

public float? IntersectsWith(Ray ray)
{
if (dontRender || isInvisible)
return null;

if (ray.Intersects(ref boundingSphere))
return TriangleIntersection(ray, SharpRenderer.sphereTriangles, SharpRenderer.sphereVertices);
return null;
}

private float? TriangleIntersection(Ray r, List<Triangle> triangles, List<Vector3> vertices)
{
bool hasIntersected = false;
float smallestDistance = 1000f;

foreach (Triangle t in triangles)
{
Vector3 v1 = (Vector3)Vector3.Transform(vertices[t.vertex1], world);
Vector3 v2 = (Vector3)Vector3.Transform(vertices[t.vertex2], world);
Vector3 v3 = (Vector3)Vector3.Transform(vertices[t.vertex3], world);

if (r.Intersects(ref v1, ref v2, ref v3, out float distance))
{
hasIntersected = true;

if (distance < smallestDistance)
smallestDistance = distance;
}
}

if (hasIntersected)
return smallestDistance;
else return null;
}

public void Draw(SharpRenderer renderer)
{
if (!isSelected && (dontRender || isInvisible))
return;

renderer.DrawSphere(world, isSelected, renderer.sfxColor);

if (isSelected)
renderer.DrawSphere(world2, false, renderer.sfxColor);
}

public BoundingBox GetBoundingBox()
{
return boundingBox;
}

public float GetDistance(Vector3 cameraPosition)
{
return Vector3.Distance(cameraPosition, _position) - _radius;
}

private AssetSGRP soundGroup
{
get
{
foreach (var ae in Program.MainForm.archiveEditors)
if (ae.archive.ContainsAsset(SoundGroup_AssetID))
if (ae.archive.GetFromAssetID(SoundGroup_AssetID) is AssetSGRP sgrp)
return sgrp;
return null;
}
}

private float _radius
{
get
{
if (soundGroup != null)
return soundGroup.InnerRadius;
return 1f;
}
}

private float _radius2
{
get
{
if (soundGroup != null)
return soundGroup.OuterRadius;
return 1f;
}
}

private const string categoryName = "Sound Effect";

[Category(categoryName)]
public AssetID SoundGroup_AssetID
{
get => ReadUInt(0x8);
set { Write(0x8, value); CreateTransformMatrix(); }
}

[Category(categoryName)]
public AssetID Emitter_AssetID
{
get => ReadUInt(0xC);
set => Write(0xC, value);
}

private Vector3 _position;
[Category(categoryName), TypeConverter(typeof(FloatTypeConverter))]
public float PositionX
{
get { return _position.X; }
set
{
_position.X = value;
Write(0x10, _position.X);
CreateTransformMatrix();
}
}

[Category(categoryName), TypeConverter(typeof(FloatTypeConverter))]
public float PositionY
{
get { return _position.Y; }
set
{
_position.Y = value;
Write(0x14, _position.Y);
CreateTransformMatrix();
}
}

[Category(categoryName), TypeConverter(typeof(FloatTypeConverter))]
public float PositionZ
{
get { return _position.Z; }
set
{
_position.Z = value;
Write(0x18, _position.Z);
CreateTransformMatrix();
}
}

[Category(categoryName), Description("0 = Normal\n4 = Play from Entity")]
public int SoundEffectFlags
{
get => ReadInt(0x1C);
set => Write(0x1C, value);
}
}
}
Loading

0 comments on commit c84cbdb

Please sign in to comment.