From cc7bbfcf7edfca7a6ba4a0334a6bb915ba326a4e Mon Sep 17 00:00:00 2001 From: gmriggs Date: Tue, 25 May 2021 01:33:56 -0400 Subject: [PATCH] fixing portals, further updates to ParticleViewer (#23) --- ACViewer/Model/Setup.cs | 11 ++++++-- ACViewer/Model/SetupInstance.cs | 2 +- ACViewer/ModelViewer.cs | 37 ++++++-------------------- ACViewer/ParticleViewer.cs | 9 ++++--- ACViewer/Physics/Common/Position.cs | 5 ++++ ACViewer/Physics/PartArray.cs | 10 +++---- ACViewer/Physics/Particles/Particle.cs | 2 +- ACViewer/Physics/PhysicsObj.cs | 2 +- ACViewer/ViewObject.cs | 3 +++ 9 files changed, 37 insertions(+), 44 deletions(-) diff --git a/ACViewer/Model/Setup.cs b/ACViewer/Model/Setup.cs index 7faa07b..346cc7f 100644 --- a/ACViewer/Model/Setup.cs +++ b/ACViewer/Model/Setup.cs @@ -4,6 +4,7 @@ using Microsoft.Xna.Framework; using ACE.DatLoader; using ACE.DatLoader.FileTypes; +using ACE.Entity.Enum; namespace ACViewer.Model { @@ -38,7 +39,10 @@ public Setup(uint setupID) PlacementFrames = new List(); - 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(); @@ -86,7 +90,10 @@ public Setup(uint setupID, FileTypes.ObjDesc objDesc, Dictionary cust PlacementFrames = new List(); - 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(); diff --git a/ACViewer/Model/SetupInstance.cs b/ACViewer/Model/SetupInstance.cs index 4659833..c67ef31 100644 --- a/ACViewer/Model/SetupInstance.cs +++ b/ACViewer/Model/SetupInstance.cs @@ -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; diff --git a/ACViewer/ModelViewer.cs b/ACViewer/ModelViewer.cs index 2231ce2..0d10d04 100644 --- a/ACViewer/ModelViewer.cs +++ b/ACViewer/ModelViewer.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -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; @@ -16,8 +16,6 @@ using ACViewer.Render; using ACViewer.View; -using Frame = ACE.DatLoader.Entity.Frame; - namespace ACViewer { public enum ModelType @@ -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; @@ -51,8 +49,6 @@ public class ModelViewer public ModelType ModelType; - public List CreateParticleHooks; - public static GameView GameView => GameView.Instance; public static Player Player => GameView.Player; @@ -157,24 +153,11 @@ 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); } } @@ -182,10 +165,6 @@ 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); } @@ -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() diff --git a/ACViewer/ParticleViewer.cs b/ACViewer/ParticleViewer.cs index 4dbe1f5..6020b52 100644 --- a/ACViewer/ParticleViewer.cs +++ b/ACViewer/ParticleViewer.cs @@ -136,10 +136,10 @@ 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; @@ -147,7 +147,7 @@ public void DrawParticles() rs.FillMode = FillMode.Solid; GraphicsDevice.RasterizerState = rs; - var particleManager = Player.PhysicsObj.ParticleManager; + var particleManager = obj.ParticleManager; if (particleManager == null || particleManager.ParticleTable.Count == 0) return; @@ -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); @@ -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); diff --git a/ACViewer/Physics/Common/Position.cs b/ACViewer/Physics/Common/Position.cs index 36073d7..57377e4 100644 --- a/ACViewer/Physics/Common/Position.cs +++ b/ACViewer/Physics/Common/Position.cs @@ -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}"; + } } } diff --git a/ACViewer/Physics/PartArray.cs b/ACViewer/Physics/PartArray.cs index 6946770..2a88c5b 100644 --- a/ACViewer/Physics/PartArray.cs +++ b/ACViewer/Physics/PartArray.cs @@ -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); } diff --git a/ACViewer/Physics/Particles/Particle.cs b/ACViewer/Physics/Particles/Particle.cs index 167c00b..25ff77b 100644 --- a/ACViewer/Physics/Particles/Particle.cs +++ b/ACViewer/Physics/Particles/Particle.cs @@ -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; } diff --git a/ACViewer/Physics/PhysicsObj.cs b/ACViewer/Physics/PhysicsObj.cs index 46715b3..336f128 100644 --- a/ACViewer/Physics/PhysicsObj.cs +++ b/ACViewer/Physics/PhysicsObj.cs @@ -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; } diff --git a/ACViewer/ViewObject.cs b/ACViewer/ViewObject.cs index bb609b6..001a036 100644 --- a/ACViewer/ViewObject.cs +++ b/ACViewer/ViewObject.cs @@ -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");