public void AddObject(ObjectRenderer render)
 {
     lock (objects)
     {
         objects.Add(render);
     }
 }
Пример #2
0
 public GameObject(Equipment equip, Hardpoint hp, GameObject parent)
 {
     Parent     = parent;
     Attachment = hp;
     if (equip is LightEquipment)
     {
         RenderComponent = new LightEquipRenderer((LightEquipment)equip);
     }
     if (equip is EffectEquipment)
     {
         RenderComponent = new ParticleEffectRenderer(((EffectEquipment)equip).Particles);
     }
     if (equip is ThrusterEquipment)
     {
         var th = (ThrusterEquipment)equip;
         InitWithDrawable(th.Model, parent.Resources, false);
         Components.Add(new ThrusterComponent(this, th));
     }
     //Optimisation: Don't re-calculate transforms every frame for static objects
     if (parent.isstatic && hp.IsStatic)
     {
         Transform      = GetTransform();
         isstatic       = true;
         StaticPosition = Transform.Transform(Vector3.Zero);
     }
 }
        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(Archetype arch, ResourceManager res, bool draw = true, bool staticpos = false)
 {
     isstatic = staticpos;
     if (arch is Archs.Sun)
     {
         RenderComponent = new SunRenderer((Archs.Sun)arch);
     }
     else
     {
         InitWithDrawable(arch.ModelFile.LoadFile(res), res, draw, staticpos);
     }
 }
 public GameObject(string name, RigidModel model, ResourceManager res)
 {
     RigidModel = model;
     Resources  = res;
     PopulateHardpoints();
     if (RigidModel != null)
     {
         RenderComponent = new ModelRenderer(RigidModel)
         {
             Name = name
         };
     }
 }
Пример #6
0
 public GameObject(Archetype arch, ResourceManager res, bool draw = true, bool staticpos = false)
 {
     isstatic = staticpos;
     if (arch is Archs.Sun)
     {
         RenderComponent = new SunRenderer((Archs.Sun)arch);
         //TODO: You can't collide with a sun
         //PhysicsComponent = new RigidBody(new SphereShape((((Archs.Sun)arch).Radius)));
         //PhysicsComponent.IsStatic = true;
         //PhysicsComponent.Tag = this;
     }
     else
     {
         InitWithDrawable(arch.Drawable, res, draw, staticpos);
     }
 }
Пример #7
0
        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 (dr is SphFile)
            {
                var radius = ((SphFile)dr).Radius;
                phys = new PhysicsComponent(this)
                {
                    SphereRadius = radius
                };
                name = ((SphFile)dr).SideMaterialNames[0];
            }
            else if (dr is ModelFile)
            {
                var mdl  = dr as ModelFile;
                var path = Path.ChangeExtension(mdl.Path, "sur");
                name = Path.GetFileNameWithoutExtension(mdl.Path);
                if (File.Exists(path))
                {
                    phys = new PhysicsComponent(this)
                    {
                        SurPath = path
                    }
                }
                ;
            }
            else if (dr is CmpFile)
            {
                isCmp = true;
                var cmp = dr as CmpFile;
                CmpParts      = new List <Part>();
                CmpConstructs = cmp.Constructs.CloneAll();
                foreach (var part in cmp.Parts)
                {
                    CmpParts.Add(part.Clone(CmpConstructs));
                }
                if (cmp.Animation != null)
                {
                    AnimationComponent = new AnimationComponent(this, cmp.Animation);
                    Components.Add(AnimationComponent);
                }
                var path = Path.ChangeExtension(cmp.Path, "sur");
                name = Path.GetFileNameWithoutExtension(cmp.Path);
                if (File.Exists(path))
                {
                    phys = new PhysicsComponent(this)
                    {
                        SurPath = path
                    }
                }
                ;
            }

            if (havePhys && phys != null)
            {
                PhysicsComponent = phys;
                Components.Add(phys);
            }
            PopulateHardpoints(dr);
            if (draw)
            {
                if (isCmp)
                {
                    RenderComponent = new ModelRenderer(CmpParts, (dr as CmpFile))
                    {
                        Name = name
                    }
                }
                ;
                else
                {
                    RenderComponent = new ModelRenderer(dr)
                    {
                        Name = name
                    }
                };
            }
        }
Пример #8
0
 public GameObject(Equipment equip, Hardpoint hp, GameObject parent)
 {
     Parent     = parent;
     Attachment = hp;
     if (equip is LightEquipment)
     {
         RenderComponent = new LightEquipRenderer((LightEquipment)equip);
     }
     if (equip is EffectEquipment)
     {
         RenderComponent = new ParticleEffectRenderer(((EffectEquipment)equip).Particles);
         Components.Add(new UpdateSParamComponent(this));
     }
     if (equip is ThrusterEquipment)
     {
         var th = (ThrusterEquipment)equip;
         InitWithDrawable(th.Model, parent.Resources, false, false);
         Components.Add(new ThrusterComponent(this, th));
     }
     if (equip is GunEquipment)
     {
         var gn = (GunEquipment)equip;
         InitWithDrawable(gn.Model, parent.Resources, false, false);
         Components.Add(new WeaponComponent(this, gn));
     }
     if (equip.LODRanges != null && RenderComponent != null)
     {
         RenderComponent.LODRanges = equip.LODRanges;
     }
     if (equip.HPChild != null)
     {
         if (hardpoints.TryGetValue(equip.HPChild, out Hardpoint hpchild))
         {
             Transform = hpchild.Transform.Inverted();
         }
     }
     if (RenderComponent is ModelRenderer &&
         parent.RenderComponent != null
         )
     {
         if (parent.RenderComponent.LODRanges != null)
         {
             RenderComponent.InheritCull = true;
         }
         else if (parent.RenderComponent is ModelRenderer)
         {
             var mr = (ModelRenderer)parent.RenderComponent;
             if (mr.Model != null && mr.Model.Switch2 != null)
             {
                 RenderComponent.InheritCull = true;
             }
             if (mr.CmpParts != null)
             {
                 Part parentPart = null;
                 if (hp.parent != null)
                 {
                     parentPart = mr.CmpParts.Find((o) => o.ObjectName == hp.parent.ChildName);
                 }
                 else
                 {
                     parentPart = mr.CmpParts.Find((o) => o.ObjectName == "Root");
                 }
                 if (parentPart.Model.Switch2 != null)
                 {
                     RenderComponent.InheritCull = true;
                 }
             }
         }
     }
     //Optimisation: Don't re-calculate transforms every frame for static objects
     if (parent.isstatic && (hp == null || hp.IsStatic))
     {
         Transform      = GetTransform();
         isstatic       = true;
         StaticPosition = Transform.Transform(Vector3.Zero);
     }
 }
Пример #9
0
        void InitWithDrawable(IDrawable drawable, ResourceManager res, bool staticpos, bool havePhys = true)
        {
            Resources = res;
            dr        = drawable;
            PhysicsComponent phys  = null;
            bool             isCmp = false;
            string           name  = "";

            if (dr is SphFile)
            {
                var radius = ((SphFile)dr).Radius;
                phys = new PhysicsComponent(this)
                {
                    SphereRadius = radius
                };
                name = ((SphFile)dr).SideMaterialNames[0];
            }
            else if (dr is ModelFile)
            {
                var mdl  = dr as ModelFile;
                var path = Path.ChangeExtension(mdl.Path, "sur");
                name = Path.GetFileNameWithoutExtension(mdl.Path);
                if (File.Exists(path))
                {
                    phys = new PhysicsComponent(this)
                    {
                        SurPath = path
                    }
                }
                ;
            }
            else if (dr is CmpFile)
            {
                isCmp = true;
                var cmp = dr as CmpFile;
                CmpParts      = new List <Part>();
                CmpConstructs = cmp.Constructs.CloneAll();
                foreach (var part in cmp.Parts)
                {
                    CmpParts.Add(part.Clone(CmpConstructs));
                }
                if (cmp.Animation != null)
                {
                    AnimationComponent = new AnimationComponent(this, cmp.Animation);
                    Components.Add(AnimationComponent);
                }
                var path = Path.ChangeExtension(cmp.Path, "sur");
                name = Path.GetFileNameWithoutExtension(cmp.Path);
                if (File.Exists(path))
                {
                    phys = new PhysicsComponent(this)
                    {
                        SurPath = path
                    }
                }
                ;

                /*if (File.Exists(path))
                 *              {
                 *                      SurFile sur = res.GetSur(path);
                 *                      var shapes = new List<CompoundSurShape.TransformedShape>();
                 *                      foreach (var part in CmpParts)
                 *                      {
                 *                              var crc = CrcTool.FLModelCrc(part.ObjectName);
                 *                              if (!sur.HasShape(crc))
                 *                              {
                 *                                      FLLog.Warning("Sur", "No hitbox for " + part.ObjectName);
                 *                                      continue;
                 *                              }
                 *                              var colshape = sur.GetShape(crc);
                 *                              if (part.Construct == null)
                 *                              {
                 *                                      foreach (var s in colshape)
                 *                                              shapes.Add(new CompoundSurShape.TransformedShape(s, Matrix3.Identity, Vector3.Zero));						}
                 *                              else
                 *                              {
                 *                                      var tr = part.Construct.Transform;
                 *                                      var pos = tr.ExtractTranslation();
                 *                                      var q = tr.ExtractRotation(true);
                 *                                      var rot = Matrix3.CreateFromQuaternion(q);
                 *                                      foreach (var s in colshape)
                 *                                              shapes.Add(new CompoundSurShape.TransformedShape(s, rot, pos) { Tag = part.Construct });
                 *                              }
                 *                      }
                 *                      collisionShape = new CompoundSurShape(shapes);
                 *              }*/
            }

            if (havePhys && phys != null)
            {
                PhysicsComponent = phys;
                Components.Add(phys);
            }
            PopulateHardpoints(dr);
            if (isCmp)
            {
                RenderComponent = new ModelRenderer(CmpParts, (dr as CmpFile))
                {
                    Name = name
                }
            }
            ;
            else
            {
                RenderComponent = new ModelRenderer(dr)
                {
                    Name = name
                }
            };
        }
Пример #10
0
        void InitWithDrawable(IDrawable drawable, ResourceManager res, bool staticpos)
        {
            Resources = res;
            dr        = drawable;
            Shape collisionShape = null;
            bool  isCmp          = false;

            if (dr is SphFile)
            {
                var radius = ((SphFile)dr).Radius;
                collisionShape = new SphereShape(radius);
            }
            else if (dr is ModelFile)
            {
                var mdl  = dr as ModelFile;
                var path = Path.ChangeExtension(mdl.Path, "sur");
                if (File.Exists(path))
                {
                    SurFile sur = res.GetSur(path);
                    var     shs = new List <CompoundSurShape.TransformedShape>();
                    foreach (var s in sur.GetShape(0))
                    {
                        shs.Add(new CompoundSurShape.TransformedShape(s, Matrix3.Identity, Vector3.Zero));
                    }
                    collisionShape = new CompoundSurShape(shs);
                }
            }
            else if (dr is CmpFile)
            {
                isCmp = true;
                var cmp = dr as CmpFile;
                CmpParts      = new List <Part>();
                CmpConstructs = cmp.Constructs.CloneAll();
                foreach (var part in cmp.Parts.Values)
                {
                    CmpParts.Add(part.Clone(CmpConstructs));
                }
                if (cmp.Animation != null)
                {
                    AnimationComponent = new AnimationComponent(this, cmp.Animation);
                    Components.Add(AnimationComponent);
                }
                var path = Path.ChangeExtension(cmp.Path, "sur");
                if (File.Exists(path))
                {
                    SurFile sur    = res.GetSur(path);
                    var     shapes = new List <CompoundSurShape.TransformedShape>();
                    foreach (var part in CmpParts)
                    {
                        var crc = CrcTool.FLModelCrc(part.ObjectName);
                        if (!sur.HasShape(crc))
                        {
                            FLLog.Warning("Sur", "No hitbox for " + part.ObjectName);
                            continue;
                        }
                        var colshape = sur.GetShape(crc);
                        if (part.Construct == null)
                        {
                            foreach (var s in colshape)
                            {
                                shapes.Add(new CompoundSurShape.TransformedShape(s, Matrix3.Identity, Vector3.Zero));
                            }
                        }
                        else
                        {
                            var tr  = part.Construct.Transform;
                            var pos = tr.ExtractTranslation();
                            var q   = tr.ExtractRotation(true);
                            var rot = Matrix3.CreateFromQuaternion(q);
                            foreach (var s in colshape)
                            {
                                shapes.Add(new CompoundSurShape.TransformedShape(s, rot, pos)
                                {
                                    Tag = part.Construct
                                });
                            }
                        }
                    }
                    collisionShape = new CompoundSurShape(shapes);
                }
            }
            if (collisionShape != null)
            {
                PhysicsComponent          = new RigidBody(collisionShape);
                PhysicsComponent.Tag      = this;
                PhysicsComponent.IsStatic = staticpos;
                if (staticpos)
                {
                    PhysicsComponent.Material.Restitution = 1;
                }
            }
            PopulateHardpoints(dr);
            if (isCmp)
            {
                RenderComponent = new ModelRenderer(CmpParts, (dr as CmpFile));
            }
            else
            {
                RenderComponent = new ModelRenderer(dr);
            }
        }