Exemplo n.º 1
0
 public MNPC(MSceneObject parent, string inname = "") : base(EType.NPCPlayer, inname)
 {
     OriginalRotation             = parent.transform.Rotation;
     OriginalPosition             = parent.transform.Position;
     model                        = (MAnimatedModel)parent;
     _physics                     = (MPhysicsObject)model.FindModuleByType(EType.PhysicsObject);
     _physics._rigidBody.Friction = 0.4;
 }
Exemplo n.º 2
0
        public static MAnimatedModel SpawnAnimatedModel(MObject parent, string TemplateID, string OwnerID, string sName, Vector3d pos)
        {
            MAnimatedModel mo = (MAnimatedModel)MScene.TemplateRoot.FindModuleByInstanceID(TemplateID);
            //MMesh sm = (MMesh)mo.FindModuleByType(MObject.EType.Mesh);

            MAnimatedModel m = new MAnimatedModel(MObject.EType.AnimatedModel, sName);

            m.OwnerID            = OwnerID;
            m.transform.Position = pos;
            mo.CopyTo(m);
            parent.Add(m);

            for (int i = 0; i < mo.Modules.Count; i++)
            {
                if (mo.Modules[i].Type != MObject.EType.BoneMesh)
                {
                    continue;
                }

                MAnimatedMesh mr = (MAnimatedMesh)mo.Modules[i];
                // m.Add(mr);
                MAnimatedMesh mesh = new MAnimatedMesh(sName);
                mesh.OwnerID = mr.OwnerID;
                mr.transform.CopyTo(mesh);
                m.Add(mesh);
                mesh.VBO            = mr.VBO;
                mesh.VAO            = mr.VAO;
                mesh.EBO            = mr.EBO;
                mesh.Indices        = mr.Indices;
                mesh.IndicesLength  = mr.IndicesLength;
                mesh.Vertices       = mr.Vertices;
                mesh.VerticesLength = mr.VerticesLength;
                mesh.Normals        = mr.Normals;
                mesh.material       = mo.material;
                m.material          = mo.material;
                //parent.Add(m);
            }


            return(m);
        }
Exemplo n.º 3
0
        public static MAnimatedModel CreateAnimatedModel(MObject parent, string sName, string Filename, Vector3d pos)
        {
            if (parent == null)
            {
                parent = MScene.ModelRoot;
            }
            MAnimatedModel m = new MAnimatedModel(MObject.EType.AnimatedModel, sName);

            m.transform.Position = pos;

            try
            {
                m.Load(Filename);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + " --- Helper.CreateAnimatedModel: Failed to load model:" + sName + " :" + Filename);
            }
            parent.Add(m);
            return(m);
        }
Exemplo n.º 4
0
        void DoIdle()
        {
            accum += Time.DeltaTime * direction * speed;
            if (accum > 1)
            {
                direction = -direction;
                accum     = 1;
            }
            if (accum <= -1)
            {
                accum     = -1;
                direction = -direction;
            }
            MSceneObject msoParent = (MSceneObject)Parent;

            msoParent.SetRotation(OriginalRotation * Quaterniond.FromEulerAngles(0, accum, 0));

            if (Parent is MAnimatedModel)
            {
                MAnimatedModel m = (MAnimatedModel)Parent;
                m._animationController.PlayAnimation("idle", 1);
            }
        }
Exemplo n.º 5
0
        void SyncAnimationToState()
        {
            MAnimatedModel ma = (MAnimatedModel)Target;

            if (CurrentSpeed == 0)
            {
                MoveState = eMoveState.Idle;
            }
            //CurrentSpeed = 1;
            switch (MoveState)
            {
            case eMoveState.Idle:
                ma._animationController.PlayAnimation("idle", CurrentSpeed);
                break;

            case eMoveState.Walk:
                ma._animationController.PlayAnimation("walk", CurrentSpeed);
                break;

            case eMoveState.Run:
                ma._animationController.PlayAnimation("run", CurrentSpeed * 0.5f);
                break;
            }
        }
Exemplo n.º 6
0
        public static MSceneObject LoadTemplate(string TemplateID)
        {
            MBuildingBlock bb = MBuildParts.GetBlock(TemplateID);

            if (bb == null)
            {
                Console.WriteLine("WARNING: MSpawnHandler.LoadTemplate " + TemplateID + " not found in blocks");
                return(null);
            }

            MSceneObject o = null;

            if (bb.Type == MBuildParts.MAnimatedModel)
            {
                o = Helper.CreateAnimatedModel(MScene.TemplateRoot, TemplateID, bb.Model, Vector3d.Zero);
                MAnimatedModel man = (MAnimatedModel)o;
                man.BoneOffset = MassiveTools.VectorFromArray(bb.BoneOffset);
            }

            if (bb.Type == MBuildParts.MModel)
            {
                o = Helper.CreateModel(MScene.TemplateRoot, TemplateID, bb.Model, Vector3d.Zero);
            }

            MMaterial mat = (MMaterial)MScene.MaterialRoot.FindModuleByName(bb.MaterialID);

            if (mat == null)
            {
                Console.WriteLine("MSpawnHandler.LoadTemplate " + bb.MaterialID + " was null");
            }
            o.SetMaterial(mat);

            Vector3d size = MassiveTools.VectorFromArray(bb.Size);

            MPhysicsObject.EShape shape = GetShape(bb.PhysicsShape);
            if (shape != MPhysicsObject.EShape.NULL)
            {
                MPhysicsObject mpo = new MPhysicsObject(o, TemplateID + "_physics", bb.Weight, shape,
                                                        true, size);
                mpo.SetSleep(5);
                mpo.SetFriction(0.5);
                if (shape != MPhysicsObject.EShape.Sphere)
                {
                    mpo.SetAngularFactor(0.0, 0.0, 0.0);
                    mpo.SetDamping(0.5, 0.5);
                    mpo.SetRestitution(0.5);
                }
                else
                {
                    mpo.SetDamping(0.1, 0.1);
                    mpo.SetRestitution(0.8);
                }
            }

            o.TemplateID               = TemplateID;
            o.InstanceID               = TemplateID;
            o.IsTransparent            = bb.IsTransparent;
            o.transform.RotationOffset = Quaterniond.FromEulerAngles(MassiveTools.VectorFromArray(bb.RotationOffset));
            o.Setup();

            AddSubmodules(bb, o);

            return(o);
        }