Example #1
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
                    }
                };
            }
        }
Example #2
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
                }
            };
        }