using System.Numerics; using System.Text.Json; using GamePort.Assets; using GamePort.Game; namespace GamePort.Application; /// Original Strato, HIDRIVE, HIROCK and additive FireStrato resources. /// Uses source local pivots/transforms without standing-sole correction. public sealed class RocketshipVisuals { private sealed record Clip(MorphAnimation Animation,int Offset,MeshDraw Draw); private readonly Clip ship,rider,dog,fire; public Mesh Mesh { get; } public RocketshipVisuals(Mesh combined,string preparedRoot) { var root=Path.Combine(preparedRoot,"rocketship"); using var doc=JsonDocument.Parse(File.ReadAllText(Path.Combine(root,"rocketship.json"))); if(doc.RootElement.GetProperty("schema").GetInt32()!=1)throw new InvalidDataException("Unknown Rocketship resource schema"); Clip Load(string name) { var animation=new MorphAnimation(Path.Combine(root,name,"animation.json")); var offset=combined.Vertices.Length; var id=int.MinValue;while(combined.Textures.ContainsKey(id))id++; combined=animation.AppendTo(combined,id); var draw=combined.Draws[^1];draw.Visible=false; return new(animation,offset,draw); } ship=Load("strato");rider=Load("jimdrive");dog=Load("godrocket");fire=Load("firestrato"); fire.Draw.Blend=MeshBlend.Additive;fire.Draw.Opacity=1; Mesh=combined; } public void Update(Mesh mesh,Rocketship vehicle,double time,PlayerAppearance appearance) { var ordinary=RocketOrientation.Model(vehicle.Rotation,vehicle.Root,Vector3.One); Draw(ship,RocketOrientation.Model(vehicle.Rotation,vehicle.Root,vehicle.ShapeScale),vehicle.Mounted); Draw(rider,ordinary,vehicle.Mounted); Draw(dog,RocketOrientation.Model(vehicle.Rotation,vehicle.CompanionRoot,Vector3.One),vehicle.Mounted); Draw(fire,ordinary,vehicle.Mounted&&vehicle.FireVisible); PlayerGadgetMaterial.Apply(rider.Draw,appearance); var color=appearance.Color; for(var i=0;i