Beispiel #1
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);
     }
 }
Beispiel #2
0
        public static void InstantiateEquipment(GameObject parent, ResourceManager res, EquipmentType type, string hardpoint, Equipment equip)
        {
            var etype = equip.GetType();

            if (!handlers.TryGetValue(etype, out var handle))
            {
                FLLog.Error("Equipment", $"Cannot instantiate {etype}");
                return;
            }
            var obj = handle(parent, res, type, hardpoint, equip);

            //Do setup of child attachment, hardpoint, lod inheriting, static position etc.
            if (obj != null)
            {
                obj.Parent = parent;
                parent.Children.Add(obj);
                if (equip.LODRanges != null && obj.RenderComponent != null)
                {
                    obj.RenderComponent.LODRanges = equip.LODRanges;
                }
                if (equip.HPChild != null)
                {
                    Hardpoint hpChild = obj.GetHardpoint(equip.HPChild);
                    if (hpChild != null)
                    {
                        Matrix4x4.Invert(hpChild.Transform, out var invTr);
                        obj.SetLocalTransform(invTr);
                    }
                }
                var hp = parent.GetHardpoint(hardpoint);
                obj.Attachment = hp;
                if (obj.RenderComponent is ModelRenderer && parent.RenderComponent != null)
                {
                    if (parent.RenderComponent.LODRanges != null)
                    {
                        obj.RenderComponent.InheritCull = true;
                    }
                    else if (parent.RenderComponent is ModelRenderer)
                    {
                        var mr = (ModelRenderer)parent.RenderComponent;
                        //if (mr.Model.Mesh != null && mr.Model.Switch2 != null)
                        //  obj. 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)
                         *  obj.RenderComponent.InheritCull = true;*/
                        //}
                    }
                }
            }
        }
        public static void InstantiateEquipment(GameObject parent, ResourceManager res, bool draw, string hardpoint, Equipment equip)
        {
            var obj = handlers[equip.GetType()](parent, res, draw, hardpoint, equip);

            //Do setup of child attachment, hardpoint, lod inheriting, static position etc.
            if (obj != null)
            {
                obj.Parent = parent;
                parent.Children.Add(obj);
                if (equip.LODRanges != null && obj.RenderComponent != null)
                {
                    obj.RenderComponent.LODRanges = equip.LODRanges;
                }
                if (equip.HPChild != null)
                {
                    Hardpoint hpChild = obj.GetHardpoint(equip.HPChild);
                    if (hpChild != null)
                    {
                        Matrix4x4.Invert(hpChild.Transform, out var invTr);
                        obj.Transform = invTr;
                    }
                }
                var hp = parent.GetHardpoint(hardpoint);
                obj.Attachment = hp;
                if (obj.RenderComponent is ModelRenderer && parent.RenderComponent != null)
                {
                    if (parent.RenderComponent.LODRanges != null)
                    {
                        obj.RenderComponent.InheritCull = true;
                    }
                    else if (parent.RenderComponent is ModelRenderer)
                    {
                        var mr = (ModelRenderer)parent.RenderComponent;
                        //if (mr.Model.Mesh != null && mr.Model.Switch2 != null)
                        //  obj. 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)
                         *  obj.RenderComponent.InheritCull = true;*/
                        //}
                    }
                }
                //Optimisation: Don't re-calculate transforms every frame for static objects
                if (parent.IsStatic && (hp == null || hp.IsStatic))
                {
                    obj.Transform = obj.GetTransform();
                    obj.SetStatic(true);
                    obj.StaticPosition = Vector3.Transform(Vector3.Zero, obj.Transform);
                }
            }
        }
        public void Process(ThnEvent ev, Cutscene cs)
        {
            ThnObject objA;
            ThnObject objB;

            if (!cs.Objects.TryGetValue((string)ev.Targets[0], out objA))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[0]);
                return;
            }
            if (!cs.Objects.TryGetValue((string)ev.Targets[1], out objB))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[1]);
                return;
            }
            var     targetType = ThnEnum.Check <TargetTypes>(ev.Properties["target_type"]);
            var     flags      = AttachFlags.Position | AttachFlags.Orientation;
            Vector3 offset;
            object  tmp;

            if (ev.Properties.TryGetValue("flags", out tmp))
            {
                flags = ThnEnum.Check <AttachFlags>(tmp);
            }
            ev.Properties.TryGetVector3("offset", out offset);
            //Attach GameObjects to eachother
            GameObject part = null;
            string     tgt_part;

            ev.Properties.TryGetValue("target_part", out tmp);
            tgt_part = (tmp as string);
            if (targetType == TargetTypes.Hardpoint && !string.IsNullOrEmpty(tgt_part))
            {
                part            = new GameObject();
                part.Parent     = objB.Object;
                part.Attachment = objB.Object.GetHardpoint(ev.Properties["target_part"].ToString());
            }
            if (targetType == TargetTypes.Part && !string.IsNullOrEmpty(tgt_part))
            {
                var hp = new Hardpoint(null, objB.Object.CmpConstructs.Find(ev.Properties["target_part"].ToString())); //Create a dummy hardpoint to attach to
                part            = new GameObject();
                part.Parent     = objB.Object;
                part.Attachment = hp;
            }
            cs.Coroutines.Add(new AttachRoutine()
            {
                Duration    = ev.Duration,
                Child       = objA,
                Parent      = objB,
                Part        = part,
                Position    = ((flags & AttachFlags.Position) == AttachFlags.Position),
                Orientation = ((flags & AttachFlags.Orientation) == AttachFlags.Orientation),
                LookAt      = ((flags & AttachFlags.LookAt) == AttachFlags.LookAt)
            });
        }
Beispiel #5
0
        void ProcessAttachEntity(ThnEvent ev)
        {
            object tmp;

            if (!Objects.ContainsKey((string)ev.Targets[0]))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[0]);
                return;
            }
            var     objA       = Objects[(string)ev.Targets[0]];
            var     objB       = Objects[(string)ev.Targets[1]];
            var     targetType = ThnEnum.Check <TargetTypes>(ev.Properties["target_type"]);
            var     flags      = AttachFlags.Position | AttachFlags.Orientation;
            Vector3 offset;

            if (ev.Properties.TryGetValue("flags", out tmp))
            {
                flags = ThnEnum.Check <AttachFlags>(tmp);
            }
            ev.Properties.TryGetVector3("offset", out offset);
            //Attach GameObjects to eachother
            if (objA.Object != null && objB.Object != null)
            {
                if (targetType == TargetTypes.Hardpoint)
                {
                    var targetHp = ev.Properties["target_part"].ToString();
                    if (!objB.Object.HardpointExists(targetHp))
                    {
                        FLLog.Error("Thn", "object " + objB.Name + " does not have hardpoint " + targetHp);
                        return;
                    }
                    var hp = objB.Object.GetHardpoint(targetHp);
                    objA.Object.Attachment = hp;
                    objA.Object.Parent     = objB.Object;
                    objA.Object.Transform  = Matrix4.CreateTranslation(offset);
                }
                else if (targetType == TargetTypes.Root)
                {
                    objA.Object.Transform = Matrix4.CreateTranslation(offset);
                    objA.Object.Parent    = objB.Object;
                }
            }
            //Attach GameObjects and Cameras to eachother
            if (objA.Object != null && objB.Camera != null)
            {
            }
            if (objA.Camera != null && objB.Object != null)
            {
                if ((flags & AttachFlags.LookAt) == AttachFlags.LookAt)
                {
                    objA.Camera.LookAt = objB.Object;
                }
                GameObject part = null;
                if (targetType == TargetTypes.Hardpoint)
                {
                    part            = new GameObject();
                    part.Parent     = objB.Object;
                    part.Attachment = objB.Object.GetHardpoint(ev.Properties["target_part"].ToString());
                }
                if (targetType == TargetTypes.Part)
                {
                    var hp = new Hardpoint(null, part.CmpConstructs.Find(ev.Properties["target_part"].ToString()));                     //Create a dummy hardpoint to attach to
                    part            = new GameObject();
                    part.Parent     = objB.Object;
                    part.Attachment = hp;
                }
                coroutines.Add(new AttachCameraToObject()
                {
                    Duration    = ev.Duration,
                    Camera      = objA.Camera,
                    Object      = objB.Object,
                    Part        = part,
                    Position    = ((flags & AttachFlags.Position) == AttachFlags.Position),
                    Orientation = ((flags & AttachFlags.Orientation) == AttachFlags.Orientation),
                    LookAt      = ((flags & AttachFlags.LookAt) == AttachFlags.LookAt)
                });
            }
        }
Beispiel #6
0
        public void Process(ThnEvent ev, Cutscene cs)
        {
            ThnObject objA;
            ThnObject objB;

            if (!cs.Objects.TryGetValue((string)ev.Targets[0], out objA))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[0]);
                return;
            }
            if (!cs.Objects.TryGetValue((string)ev.Targets[1], out objB))
            {
                FLLog.Error("Thn", "Object doesn't exist " + (string)ev.Targets[1]);
                return;
            }
            var    targetType = ThnEnum.Check <TargetTypes>(ev.Properties["target_type"]);
            var    flags      = AttachFlags.Position | AttachFlags.Orientation;
            object tmp;

            if (ev.Properties.TryGetValue("flags", out tmp))
            {
                flags = ThnEnum.Check <AttachFlags>(tmp);
            }
            //Attach GameObjects to eachother
            GameObject part = null;
            string     tgt_part;

            ev.Properties.TryGetValue("target_part", out tmp);
            tgt_part = (tmp as string);
            if (targetType == TargetTypes.Hardpoint && !string.IsNullOrEmpty(tgt_part))
            {
                if (objB.Object == null)
                {
                    FLLog.Error("Thn", "Could not get hardpoints on " + objB.Name);
                }
                else
                {
                    part            = new GameObject();
                    part.Parent     = objB.Object;
                    part.Attachment = objB.Object.GetHardpoint(ev.Properties["target_part"].ToString());
                }
            }
            if (targetType == TargetTypes.Part && !string.IsNullOrEmpty(tgt_part))
            {
                if (objB.Object == null || objB.Object.RigidModel == null || objB.Object.RigidModel.Parts == null)
                {
                    FLLog.Error("Thn", "Could not get parts on " + objB.Name);
                }
                else
                {
                    if (objB.Object.RigidModel.Parts.TryGetValue((string)ev.Properties["target_part"], out var tgtpart))
                    {
                        var hp = new Hardpoint(null, tgtpart);
                        part            = new GameObject();
                        part.Parent     = objB.Object;
                        part.Attachment = hp;
                    }
                }
            }
            Vector3 offset = Vector3.Zero;

            if (ev.Properties.TryGetValue("offset", out tmp))
            {
                offset = ((LuaTable)tmp).ToVector3();
            }
            Quaternion lastRotate = Quaternion.Identity;

            if ((flags & AttachFlags.Orientation) == AttachFlags.Orientation &&
                (flags & AttachFlags.OrientationRelative) == AttachFlags.OrientationRelative)
            {
                if (part != null)
                {
                    lastRotate = part.GetTransform().ExtractRotation();
                }
                else
                {
                    lastRotate = objB.Rotate.ExtractRotation();
                }
            }
            cs.Coroutines.Add(new AttachRoutine()
            {
                Duration            = ev.Duration,
                Child               = objA,
                Parent              = objB,
                Part                = part,
                Position            = ((flags & AttachFlags.Position) == AttachFlags.Position),
                Orientation         = ((flags & AttachFlags.Orientation) == AttachFlags.Orientation),
                OrientationRelative = ((flags & AttachFlags.OrientationRelative) == AttachFlags.OrientationRelative),
                EntityRelative      = ((flags & AttachFlags.EntityRelative) == AttachFlags.EntityRelative),
                LookAt              = ((flags & AttachFlags.LookAt) == AttachFlags.LookAt),
                LastRotate          = lastRotate,
                Offset              = offset
            });
        }
Beispiel #7
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);
     }
 }
Beispiel #8
0
 public AttachedEffect(Hardpoint attachment, ParticleEffectRenderer fx)
 {
     Attachment    = attachment;
     Effect        = fx;
     Effect.SParam = 0.9f;
 }