Skip to content

Commit

Permalink
fixing portals, further updates to ParticleViewer (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmriggs committed May 25, 2021
1 parent 9ef173a commit cc7bbfc
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 44 deletions.
11 changes: 9 additions & 2 deletions ACViewer/Model/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Xna.Framework;
using ACE.DatLoader;
using ACE.DatLoader.FileTypes;
using ACE.Entity.Enum;

namespace ACViewer.Model
{
Expand Down Expand Up @@ -38,7 +39,10 @@ public Setup(uint setupID)

PlacementFrames = new List<Matrix>();

foreach (var placementFrame in _setup.PlacementFrames[0].AnimFrame.Frames)
if (!_setup.PlacementFrames.TryGetValue((int)Placement.Resting, out var placementFrames))
_setup.PlacementFrames.TryGetValue((int)Placement.Default, out placementFrames);

foreach (var placementFrame in placementFrames.AnimFrame.Frames)
PlacementFrames.Add(placementFrame.ToXna());

BuildBoundingBox();
Expand Down Expand Up @@ -86,7 +90,10 @@ public Setup(uint setupID, FileTypes.ObjDesc objDesc, Dictionary<int, uint> cust

PlacementFrames = new List<Matrix>();

foreach (var placementFrame in _setup.PlacementFrames[0].AnimFrame.Frames)
if (!_setup.PlacementFrames.TryGetValue((int)Placement.Resting, out var placementFrames))
_setup.PlacementFrames.TryGetValue((int)Placement.Default, out placementFrames);

foreach (var placementFrame in placementFrames.AnimFrame.Frames)
PlacementFrames.Add(placementFrame.ToXna());

BuildBoundingBox();
Expand Down
2 changes: 1 addition & 1 deletion ACViewer/Model/SetupInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void Draw(int polyIdx = -1)
var curPolyIdx = 0;
for (var i = 0; i < Setup.Parts.Count; i++)
{
var placementFrame = Setup.PlacementFrames[i];
//var placementFrame = Setup.PlacementFrames[i];
var part = Setup.Parts[i];

var partFrame = physParts[i].Pos.Frame;
Expand Down
37 changes: 8 additions & 29 deletions ACViewer/ModelViewer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
Expand All @@ -7,7 +8,6 @@
using MonoGame.Framework.WpfInterop.Input;

using ACE.DatLoader;
using ACE.DatLoader.Entity.AnimationHooks;
using ACE.DatLoader.FileTypes;
using ACE.Entity.Enum;
using ACE.Server.Physics.Animation;
Expand All @@ -16,8 +16,6 @@
using ACViewer.Render;
using ACViewer.View;

using Frame = ACE.DatLoader.Entity.Frame;

namespace ACViewer
{
public enum ModelType
Expand All @@ -42,7 +40,7 @@ public class ModelViewer
public static Effect Effect { get => ACViewer.Render.Render.Effect; }
public static Camera Camera { get => GameView.Camera; }

public ViewObject ViewObject;
public ViewObject ViewObject { get; set; }

public bool GfxObjMode = false;

Expand All @@ -51,8 +49,6 @@ public class ModelViewer

public ModelType ModelType;

public List<CreateParticleHook> CreateParticleHooks;

public static GameView GameView => GameView.Instance;

public static Player Player => GameView.Player;
Expand Down Expand Up @@ -157,35 +153,18 @@ public void LoadEnvCell(uint envCellID)

public void LoadScript(uint scriptID)
{
CreateParticleHooks = ParticleViewer.Instance.GetCreateParticleHooks(scriptID, 0.0f);
var createParticleHooks = ParticleViewer.Instance.GetCreateParticleHooks(scriptID, 1.0f);

foreach (var createParticleHook in CreateParticleHooks)
foreach (var createParticleHook in createParticleHooks)
{
// passing partIndex to create_particle_emitter doesn't seem to affect the renderer atm,
// so linking the partFrame to the emitterOffset here

var partFrame = new AFrame();

if (Setup.Setup._setup.PlacementFrames.TryGetValue((int)Placement.Resting, out var placementType) || Setup.Setup._setup.PlacementFrames.TryGetValue((int)Placement.Default, out placementType))
{
if (placementType.AnimFrame.Frames.Count > 0 && createParticleHook.PartIndex < placementType.AnimFrame.Frames.Count)
partFrame = new AFrame(placementType.AnimFrame.Frames[(int)createParticleHook.PartIndex]);
}

var emitterOffset = AFrame.Combine(partFrame, new AFrame(createParticleHook.Offset));

Player.PhysicsObj.create_particle_emitter(createParticleHook.EmitterInfoId, (int)createParticleHook.PartIndex, emitterOffset, (int)createParticleHook.EmitterId);
ViewObject.PhysicsObj.create_particle_emitter(createParticleHook.EmitterInfoId, (int)createParticleHook.PartIndex, new AFrame(createParticleHook.Offset), (int)createParticleHook.EmitterId);
}
}

public void InitObject(uint setupID)
{
ViewObject = new ViewObject(setupID);

Player.PhysicsObj.ParticleManager.ParticleTable.Clear();

CreateParticleHooks = null;

if (Setup.Setup._setup.DefaultScript != 0)
LoadScript(Setup.Setup._setup.DefaultScript);
}
Expand Down Expand Up @@ -241,8 +220,8 @@ public void DrawModel()

Setup.Draw(PolyIdx);

if (CreateParticleHooks != null)
ParticleViewer.Instance.DrawParticles();
if (ViewObject.PhysicsObj.ParticleManager != null)
ParticleViewer.Instance.DrawParticles(ViewObject.PhysicsObj);
}

public void DrawEnvironment()
Expand Down
9 changes: 5 additions & 4 deletions ACViewer/ParticleViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,18 @@ public void Draw(GameTime gameTime)
Effect.Parameters["xView"].SetValue(Camera.ViewMatrix);
Effect.Parameters["xProjection"].SetValue(Camera.ProjectionMatrix);

DrawParticles();
DrawParticles(Player.PhysicsObj);
}

public void DrawParticles()
public void DrawParticles(PhysicsObj obj)
{
var rs = new RasterizerState();
//rs.CullMode = Microsoft.Xna.Framework.Graphics.CullMode.CullClockwiseFace;
rs.CullMode = Microsoft.Xna.Framework.Graphics.CullMode.None;
rs.FillMode = FillMode.Solid;
GraphicsDevice.RasterizerState = rs;

var particleManager = Player.PhysicsObj.ParticleManager;
var particleManager = obj.ParticleManager;

if (particleManager == null || particleManager.ParticleTable.Count == 0)
return;
Expand Down Expand Up @@ -175,7 +175,7 @@ public void DrawPointSprite(GfxObj gfxObj, PhysicsPart part, Texture2D texture)
GraphicsDevice.SetVertexBuffer(Billboard.VertexBuffer);
GraphicsDevice.Indices = Billboard.IndexBuffer;

var translateWorld = Matrix.CreateTranslation(part.Pos.Frame.Origin.ToXna()) * Matrix.CreateFromQuaternion(part.Pos.Frame.Orientation.ToXna());
var translateWorld = Matrix.CreateFromQuaternion(part.Pos.Frame.Orientation.ToXna()) * Matrix.CreateTranslation(part.Pos.Frame.Origin.ToXna());

Effect.CurrentTechnique = Effect.Techniques["PointSprite"];
Effect.Parameters["xWorld"].SetValue(translateWorld);
Expand All @@ -192,6 +192,7 @@ public void DrawPointSprite(GfxObj gfxObj, PhysicsPart part, Texture2D texture)
GraphicsDevice.BlendState = BlendState.Additive;
else
GraphicsDevice.BlendState = BlendState.NonPremultiplied;

pass.Apply();

GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, 2);
Expand Down
5 changes: 5 additions & 0 deletions ACViewer/Physics/Common/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,10 @@ public bool Equals(Position pos)
{
return ObjCellID == pos.ObjCellID && Frame.Equals(pos.Frame);
}

public override string ToString()
{
return $"{ObjCellID:X8} [{Frame.Origin}] {Frame.Orientation}";
}
}
}
10 changes: 4 additions & 6 deletions ACViewer/Physics/PartArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,13 +594,11 @@ public void Update(double quantum, ref AFrame offsetFrame)
public void UpdateParts(AFrame frame)
{
var curFrame = Sequence.GetCurrAnimFrame();
if (curFrame == null)
{
if (Parts.Count == 1)
Parts[0].Pos = Owner.Position;
return;
}

if (curFrame == null) return;

var numParts = Math.Min(NumParts, curFrame.Frames.Count);

for (var i = 0; i < numParts; i++)
Parts[i].Pos.Frame.Combine(frame, new AFrame(curFrame.Frames[i]), Scale);
}
Expand Down
2 changes: 1 addition & 1 deletion ACViewer/Physics/Particles/Particle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public bool Init(ParticleEmitterInfo info, PhysicsObj parent, int partIdx, AFram
part.GfxObjScale = new Vector3(StartScale, StartScale, StartScale);
part.SetTranslucency(StartTrans);

Update(info.ParticleType, persistent, part, pFrame);
Update(info.ParticleType, persistent, part, StartFrame);

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion ACViewer/Physics/PhysicsObj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2589,7 +2589,7 @@ public static PhysicsObj makeObject(uint dataDID, uint objectIID, bool dynamic)
public static PhysicsObj makeParticleObject(int numParts, Sphere sortingSphere)
{
var particle = new PhysicsObj();
particle.State = PhysicsState.Static | PhysicsState.ReportCollisions;
particle.State = PhysicsState.Static | PhysicsState.ParticleEmitter;
particle.PartArray = PartArray.CreateParticle(particle, numParts, sortingSphere);
return particle;
}
Expand Down
3 changes: 3 additions & 0 deletions ACViewer/ViewObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public void UpdatePhysics(GameTime time)
// update anim only?
PhysicsObj.update_animation();

if (PhysicsObj.ParticleManager != null)
PhysicsObj.ParticleManager.UpdateParticles();

var minterp = PhysicsObj.get_minterp();
//if (minterp.motions_pending())
//Console.WriteLine("Motions pending");
Expand Down

0 comments on commit cc7bbfc

Please sign in to comment.