public void SpawnDebris(string archetype, string part, Matrix4x4 transform, float mass, Vector3 initialForce) { actions.Enqueue(() => { var arch = Server.GameData.GetSolarArchetype(archetype); var mdl = ((IRigidModelFile)arch.ModelFile.LoadFile(Server.Resources)).CreateRigidModel(false); var newpart = mdl.Parts[part].Clone(); var newmodel = new RigidModel() { Root = newpart, AllParts = new[] { newpart }, MaterialAnims = mdl.MaterialAnims, Path = mdl.Path, }; var id = GenerateID(); var go = new GameObject($"debris{id}", newmodel, Server.Resources, part, mass, false); go.NetID = id; go.Transform = transform; GameWorld.Objects.Add(go); updatingObjects.Add(go); go.Register(GameWorld.Physics); go.PhysicsComponent.Body.Impulse(initialForce); //Spawn debris foreach (Player p in Players.Keys) { p.SpawnDebris(go.NetID, archetype, part, transform, mass); } }); }
public GameObject(string name, RigidModel model, ResourceManager res, string partName, float mass, bool draw) { RigidModel = model; Resources = res; PopulateHardpoints(); if (draw && RigidModel != null) { RenderComponent = new ModelRenderer(RigidModel) { Name = name }; } var path = Path.ChangeExtension(RigidModel.Path, "sur"); name = Path.GetFileNameWithoutExtension(RigidModel.Path); uint plainCrc = 0; if (!string.IsNullOrEmpty(partName)) { plainCrc = CrcTool.FLModelCrc(partName); } if (File.Exists(path)) { PhysicsComponent = new PhysicsComponent(this) { SurPath = path, Mass = mass, PlainCrc = plainCrc }; Components.Add(PhysicsComponent); } }
void InitWithDrawable(IDrawable drawable, ResourceManager res, bool draw, bool staticpos, bool havePhys = true) { Resources = res; dr = drawable; PhysicsComponent phys = null; bool isCmp = false; string name = ""; if (draw) { drawable?.Initialize(res); } if (dr is SphFile) { var radius = ((SphFile)dr).Radius; phys = new PhysicsComponent(this) { SphereRadius = radius }; name = ((SphFile)dr).SideMaterialNames[0]; RigidModel = ((SphFile)dr).CreateRigidModel(draw); } else if (dr is IRigidModelFile mdl) { //var mdl = dr as ModelFile; RigidModel = mdl.CreateRigidModel(draw); var path = Path.ChangeExtension(RigidModel.Path, "sur"); name = Path.GetFileNameWithoutExtension(RigidModel.Path); if (File.Exists(path)) { phys = new PhysicsComponent(this) { SurPath = path } } ; if (RigidModel.Animation != null) { AnimationComponent = new AnimationComponent(this, RigidModel.Animation); Components.Add(AnimationComponent); } } if (havePhys && phys != null) { PhysicsComponent = phys; Components.Add(phys); } PopulateHardpoints(); if (draw && RigidModel != null) { RenderComponent = new ModelRenderer(RigidModel) { Name = name }; } }
public GameObject(string name, RigidModel model, ResourceManager res) { RigidModel = model; Resources = res; PopulateHardpoints(); if (RigidModel != null) { RenderComponent = new ModelRenderer(RigidModel) { Name = name }; } }
public GameObject SpawnDebris(string part) { if (RigidModel != null && RigidModel.Parts.TryGetValue(part, out var srcpart)) { var newpart = srcpart.Clone(); var newmodel = new RigidModel() { Root = newpart, AllParts = new[] { newpart }, MaterialAnims = RigidModel.MaterialAnims, Path = newpart.Path, }; srcpart.Active = false; var tr = srcpart.LocalTransform * GetTransform(); var obj = new GameObject($"{Name}$debris-{part}", newmodel, Resources); obj.Transform = tr; obj.World = World; obj.World.Objects.Add(obj); var pos0 = Vector3.Transform(Vector3.Zero, GetTransform()); var pos1 = Vector3.Transform(Vector3.Zero, tr); var vec = (pos1 - pos0).Normalized(); var initialforce = 100f; var mass = 50f; if (CollisionGroups != null) { var cg = CollisionGroups.FirstOrDefault(x => x.obj.Equals(part, StringComparison.OrdinalIgnoreCase)); if (cg != null) { mass = cg.Mass; initialforce = cg.ChildImpulse; } } PhysicsComponent.ChildDebris(obj, srcpart, mass, vec * initialforce); } return(null); }
public AnimationComponent(RigidModel rm, AnmFile animation) : base(null) { this.rm = rm; anm = animation; }
public void HandlePacket(IPacket pkt) { if (!(pkt is ObjectUpdatePacket)) { FLLog.Debug("Client", "Got packet of type " + pkt.GetType()); } switch (pkt) { case CallThornPacket ct: RunSync(() => { var thn = new ThnScript(Game.GameData.ResolveDataPath(ct.Thorn)); gp.Thn = new Cutscene(new ThnScript[] { thn }, gp); }); break; case UpdateRTCPacket rtc: AddRTC(rtc.RTCs); break; case MsnDialogPacket msndlg: RunSync(() => { RunDialog(msndlg.Lines); }); break; case PlaySoundPacket psnd: PlaySound(psnd.Sound); break; case PlayMusicPacket mus: PlayMusic(mus.Music); break; case SpawnPlayerPacket p: PlayerBase = null; PlayerSystem = p.System; PlayerPosition = p.Position; PlayerOrientation = Matrix4x4.CreateFromQuaternion(p.Orientation); SetSelfLoadout(p.Ship); SceneChangeRequired(); break; case BaseEnterPacket b: PlayerBase = b.Base; SetSelfLoadout(b.Ship); SceneChangeRequired(); AddRTC(b.RTCs); break; case SpawnSolarPacket solar: RunSync(() => { foreach (var si in solar.Solars) { if (!objects.ContainsKey(si.ID)) { var arch = Game.GameData.GetSolarArchetype(si.Archetype); var go = new GameObject(arch, Game.ResourceManager, true); go.StaticPosition = si.Position; go.Transform = Matrix4x4.CreateFromQuaternion(si.Orientation) * Matrix4x4.CreateTranslation(si.Position); go.Nickname = $"$Solar{si.ID}"; go.World = gp.world; go.Register(go.World.Physics); go.CollisionGroups = arch.CollisionGroups; FLLog.Debug("Client", $"Spawning object {si.ID}"); gp.world.Objects.Add(go); objects.Add(si.ID, go); } } }); break; case DestroyPartPacket p: RunSync(() => { objects[p.ID].DisableCmpPart(p.PartName); }); break; case SpawnDebrisPacket p: RunSync(() => { var arch = Game.GameData.GetSolarArchetype(p.Archetype); var mdl = ((IRigidModelFile)arch.ModelFile.LoadFile(Game.ResourceManager)).CreateRigidModel(true); var newpart = mdl.Parts[p.Part].Clone(); var newmodel = new RigidModel() { Root = newpart, AllParts = new[] { newpart }, MaterialAnims = mdl.MaterialAnims, Path = mdl.Path, }; var go = new GameObject($"debris{p.ID}", newmodel, Game.ResourceManager, p.Part, p.Mass, true); go.Transform = Matrix4x4.CreateFromQuaternion(p.Orientation) * Matrix4x4.CreateTranslation(p.Position); go.World = gp.world; go.Register(go.World.Physics); gp.world.Objects.Add(go); objects.Add(p.ID, go); }); break; case SpawnObjectPacket p: RunSync(() => { var shp = Game.GameData.GetShip((int)p.Loadout.ShipCRC); //Set up player object + camera var newobj = new GameObject(shp, Game.ResourceManager); newobj.Name = "NetPlayer " + p.ID; newobj.Transform = Matrix4x4.CreateFromQuaternion(p.Orientation) * Matrix4x4.CreateTranslation(p.Position); if (connection is GameNetClient) { newobj.Components.Add(new CNetPositionComponent(newobj)); } objects.Add(p.ID, newobj); gp.world.Objects.Add(newobj); }); break; case ObjectUpdatePacket p: RunSync(() => { foreach (var update in p.Updates) { UpdateObject(p.Tick, update); } }); break; case DespawnObjectPacket p: RunSync(() => { var despawn = objects[p.ID]; gp.world.Objects.Remove(despawn); objects.Remove(p.ID); }); break; default: if (ExtraPackets != null) { ExtraPackets(pkt); } else { FLLog.Error("Network", "Unknown packet type " + pkt.GetType().ToString()); } break; } }
public ModelRenderer(RigidModel model) { Model = model; }