Skip to content

Commit

Permalink
add support for DefaultScript to ModelViewer (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmriggs committed May 24, 2021
1 parent e39f8de commit f079484
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
45 changes: 41 additions & 4 deletions ACViewer/ModelViewer.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using Microsoft.Xna.Framework;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using MonoGame.Framework.WpfInterop.Input;

using ACE.DatLoader;
using ACE.DatLoader.FileTypes;
using ACE.Entity.Enum;
using ACE.Server.Physics.Animation;

using ACViewer.Model;
using ACViewer.Render;
using ACViewer.View;
using System.Collections.Generic;

namespace ACViewer
{
Expand Down Expand Up @@ -43,6 +48,12 @@ public class ModelViewer

public ModelType ModelType;

public List<uint> EmitterInfoIDs;

public static GameView GameView => GameView.Instance;

public static Player Player => GameView.Player;

public ModelViewer()
{
Instance = this;
Expand All @@ -62,6 +73,7 @@ public void LoadModel(uint id)

ModelType = ModelType.Setup;
}

public void LoadModel(uint id, ClothingTable clothingBase, uint palTemplate, float shade)
{
// can be either a gfxobj or setup id
Expand Down Expand Up @@ -140,9 +152,30 @@ public void LoadEnvCell(uint envCellID)
ModelType = ModelType.EnvCell;
}

public void LoadScript(uint scriptID)
{
EmitterInfoIDs = ParticleViewer.Instance.GetEmitterInfoIDs(scriptID, 1.0f);

foreach (var emitterInfoID in EmitterInfoIDs)
{
var emitterInfo = DatManager.PortalDat.ReadFromDat<ParticleEmitterInfo>(emitterInfoID);

// link to object frame?
var frame = new AFrame();
Player.PhysicsObj.create_particle_emitter(emitterInfoID, 0, frame, 0);
}
}

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

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

EmitterInfoIDs = null;

if (Setup.Setup._setup.DefaultScript != 0)
LoadScript(Setup.Setup._setup.DefaultScript);
}

public void DoStance(MotionStance stance)
Expand Down Expand Up @@ -192,8 +225,12 @@ public void Draw(GameTime time)

public void DrawModel()
{
if (Setup != null)
Setup.Draw(PolyIdx);
if (Setup == null) return;

Setup.Draw(PolyIdx);

if (EmitterInfoIDs != null)
ParticleViewer.Instance.DrawParticles();
}

public void DrawEnvironment()
Expand Down
6 changes: 6 additions & 0 deletions ACViewer/Render/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ public void InitModel(Model.BoundingBox box)
//var box = setup.BoundingBox;
var size = box.Size;

if (float.IsInfinity(size.X))
{
InitParticle();
return;
}

var facing = box.GetTargetFace();
var face = box.Faces[(int)facing];
var center = face.Center;
Expand Down

0 comments on commit f079484

Please sign in to comment.