Exemplo n.º 1
0
    private void LoadModel()
    {
        if (!SetPath())
        {
            return;
        }
        errorString = "";

        if (loadedModel != null)
        {
            GameObject.DestroyImmediate(loadedModel);
            animPlayer  = null;
            loadedModel = null;
        }

        var gen = new ModelGenerator();

        loadedModel = gen.LoadObject(Path.Combine("models", modelName), null);

        if (loadedModel == null)
        {
            Debug.Log("Model name is incorrect!");
            errorString = string.Format("Model name: {0} is incorrect, model not found!", modelName);
            return;
        }

        loadedModel.transform.parent = transform;
        orbitCam.target = loadedModel.transform;
    }
Exemplo n.º 2
0
    private void PlayAnim()
    {
        if (!SetPath())
        {
            return;
        }
        if (loadedModel == null)
        {
            return;
        }

        if (animPlayer == null)
        {
            animPlayer = loadedModel.AddComponent <ModelAnimationPlayer>();
        }

        if (animPlayer.LoadAndSetAnimation(Path.Combine("anims", animName)) == null)
        {
            Debug.Log("Anim name is incorrect!");
            errorString = string.Format("Animation name: {0} is incorrect, animation not found!", animName);
            return;
        }

        animPlayer.isPlaying = true;
    }
Exemplo n.º 3
0
 public AnimationPlayed(AnimationState animationState, ModelAnimationPlayer modelAnimationPlayer, float fadeLenght = 0, float elapsedTime = 0)
 {
     AnimationState       = animationState;
     ModelAnimationPlayer = modelAnimationPlayer;
     FadeLenght           = fadeLenght;
     ElapsedTime          = elapsedTime;
 }
Exemplo n.º 4
0
        public static void TransformAnimatedModel(Model model, Microsoft.Xna.Framework.Game game, Matrix world)
        {
            SkinningData skinningData = (SkinningData)model.Tag;

            renderTarget = GfxComponent.CreateCustomRenderTarget(game.GraphicsDevice, 1, SurfaceFormat.Color, MultiSampleType.None, (int)TextureSize.X, (int)TextureSize.Y);
            depthBuffer  = GfxComponent.CreateDepthStencil(renderTarget);
            Texture2D tex;

            Color[] reverseTexture  = new Color[(int)(TextureSize.X * TextureSize.Y)];
            Color[] originalTexture = new Color[(int)(TextureSize.X * TextureSize.Y)];

            Vertices vertices;

            ModelAnimationPlayer player = new ModelAnimationPlayer(skinningData);

            foreach (AnimationClip clip in skinningData.AnimationClips.Values)
            {
                clip.vertices = new Dictionary <int, Vertices>[] { new Dictionary <int, Vertices>(), new Dictionary <int, Vertices>() };

                player.SetClip(clip);

                bool hasGoneThrough = false;
                int  lastKeyFrame   = 0;
                while (!hasGoneThrough)
                {
                    RenderToTarget(model, player, game, world, out tex);
                    vertices = GetVertices(tex, model);

                    if (vertices.Count != 1)
                    {
                        clip.vertices[(int)ModelDirection.Right][player.CurrentKeyframe] = vertices;

                        // flip the texture and the vertices
                        tex.GetData <Color>(originalTexture);
                        int left = 0;
                        for (int right = (int)TextureSize.X - 1; right >= 0; right--, left++)
                        {
                            for (int j = 0; j < TextureSize.Y; j++)
                            {
                                reverseTexture[left + j * (int)TextureSize.X] = originalTexture[right + j * (int)TextureSize.X];
                            }
                        }

                        tex.SetData <Color>(reverseTexture);
                        clip.vertices[(int)ModelDirection.Left][player.CurrentKeyframe] = GetVertices(tex, model);
                    }
                    lastKeyFrame = player.CurrentKeyframe;
                    player.StepClip();
                    hasGoneThrough = (player.CurrentKeyframe - lastKeyFrame < 1);
                }
            }
        }
Exemplo n.º 5
0
    public PawnController(ModelAnimationPlayer pawn, Transform rootObject)
    {
        this.pawn       = pawn;
        this.rootObject = rootObject;

        animationSets = new MafiaAnimationSet[8];

        for (int i = 0; i < 8; i++)
        {
            animationSets[i] = new MafiaAnimationSet(i + 1, pawn);
        }

        pawn.isPlaying    = true;
        pawn.playbackMode = ModelAnimationPlayer.AnimationPlaybackMode.Repeat;
        pawn.SetAnimation(animationSets[(int)stanceMode].idleAnimations[0]);
    }
Exemplo n.º 6
0
        public MafiaAnimationSet(int slot, ModelAnimationPlayer pawn)
        {
            walkAnimations = new MafiaAnimation[Enum.GetNames(typeof(AnimationSlots)).Length];
            runAnimations  = new MafiaAnimation[Enum.GetNames(typeof(AnimationSlots)).Length];
            turnAnimations = new MafiaAnimation[Enum.GetNames(typeof(AnimationSlots)).Length];
            jumpAnimations = new MafiaAnimation[Enum.GetNames(typeof(AnimationSlots)).Length];

            walkAnimations[(int)AnimationSlots.Forward]  = pawn.LoadAnimation("anims/walk" + slot + ".5ds");
            walkAnimations[(int)AnimationSlots.Backward] = pawn.LoadAnimation("anims/back" + slot + ".5ds");

            walkAnimations[(int)AnimationSlots.ForwardLeft]  = pawn.LoadAnimation("anims/walkL" + slot + ".5ds");
            walkAnimations[(int)AnimationSlots.ForwardRight] = pawn.LoadAnimation("anims/walkR" + slot + ".5ds");

            walkAnimations[(int)AnimationSlots.BackwardLeft]  = pawn.LoadAnimation("anims/backL" + slot + ".5ds");
            walkAnimations[(int)AnimationSlots.BackwardRight] = pawn.LoadAnimation("anims/backR" + slot + ".5ds");

            walkAnimations[(int)AnimationSlots.Left]  = pawn.LoadAnimation("anims/strafL" + slot + ".5ds");
            walkAnimations[(int)AnimationSlots.Right] = pawn.LoadAnimation("anims/strafR" + slot + ".5ds");

            runAnimations[(int)AnimationSlots.Forward]  = pawn.LoadAnimation("anims/run" + slot + ".5ds");
            runAnimations[(int)AnimationSlots.Backward] = pawn.LoadAnimation("anims/back" + slot + ".5ds");

            runAnimations[(int)AnimationSlots.ForwardLeft]  = pawn.LoadAnimation("anims/runL" + slot + ".5ds");
            runAnimations[(int)AnimationSlots.ForwardRight] = pawn.LoadAnimation("anims/runR" + slot + ".5ds");

            runAnimations[(int)AnimationSlots.BackwardLeft]  = pawn.LoadAnimation("anims/backL" + slot + ".5ds");
            runAnimations[(int)AnimationSlots.BackwardRight] = pawn.LoadAnimation("anims/backR" + slot + ".5ds");

            runAnimations[(int)AnimationSlots.Left]  = pawn.LoadAnimation("anims/strafL" + slot + ".5ds");
            runAnimations[(int)AnimationSlots.Right] = pawn.LoadAnimation("anims/strafR" + slot + ".5ds");

            turnAnimations[(int)AnimationSlots.Left]  = pawn.LoadAnimation("anims/left" + slot + ".5ds", 0, 1);
            turnAnimations[(int)AnimationSlots.Right] = pawn.LoadAnimation("anims/left" + slot + ".5ds", 0, 1); // temp fix

            jumpAnimations[(int)AnimationSlots.Left]  = pawn.LoadAnimation("anims/jumpL1.5ds");
            jumpAnimations[(int)AnimationSlots.Right] = pawn.LoadAnimation("anims/jumpR1.5ds");

            idleAnimations = new MafiaAnimation[] { pawn.LoadAnimation("anims/breath0" + slot + "a.5ds"),
                                                    pawn.LoadAnimation("anims/breath0" + slot + "b.5ds"),
                                                    pawn.LoadAnimation("anims/breath0" + slot + "c.5ds"),
                                                    pawn.LoadAnimation("anims/breath0" + slot + "d.5ds") };
        }
Exemplo n.º 7
0
        private static Texture2D RenderToTarget(Model model, ModelAnimationPlayer player, Microsoft.Xna.Framework.Game game, Matrix world, out Texture2D Sillouette)
        {
            DepthStencilBuffer old = ShadowMapManager.SetupShadowMap(game.GraphicsDevice, ref renderTarget, ref depthBuffer);

            BoundingSphere bs = new BoundingSphere();

            bool first = true;

            foreach (ModelMesh mesh in model.Meshes)
            {
                if (first)
                {
                    bs    = mesh.BoundingSphere;
                    first = false;
                }
                else
                {
                    bs = BoundingSphere.CreateMerged(bs, mesh.BoundingSphere);
                }
            }

            bs.Center.X = bs.Center.Z;
            bs.Radius  *= 1.5f;

            ShaderManager.AddEffect(ShaderManager.EFFECT_ID.PHYSICS, "PhysicsRenderer", game);
            ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.PHYSICS);
            ShaderManager.SetValue("World", world);

            Matrix m = Matrix.Identity;

            m.M33 = 0;
            m.M43 = 0.5f;
            ShaderManager.SetValue("Projection", m);


            Matrix view;

            view = Matrix.CreateTranslation(-bs.Center) * Matrix.CreateScale(1 / bs.Radius, 1 / bs.Radius, 1);

            ShaderManager.SetValue("Projection", m);
            ShaderManager.SetValue("View", view);
            ShaderManager.SetValue("usingBones", player != null);

            if (player != null)
            {
                ShaderManager.SetValue("Bones", player.GetSkinTransforms());
            }

            ShaderManager.CommitChanges();
            List <Effect> effects = new List <Effect>();

            game.GraphicsDevice.Clear(Color.Black);

            foreach (ModelMesh mesh in model.Meshes)
            {
                effects.Clear();

                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    effects.Add(part.Effect);
                    part.Effect = ShaderManager.GetCurrentEffect();
                }
                mesh.Draw();
                for (int i = 0; i < mesh.MeshParts.Count; i++)
                {
                    mesh.MeshParts[i].Effect = effects[i];
                }
            }

            ShadowMapManager.ResetGraphicsDevice(game.GraphicsDevice, old);

            Color[] textureColors = new Color[(int)(TextureSize.X * TextureSize.Y)];
            renderTarget.GetTexture().GetData <Color>(textureColors);

            Sillouette = new Texture2D(game.GraphicsDevice, (int)TextureSize.X, (int)TextureSize.Y);
            Sillouette.SetData <Color>(textureColors);
            return(renderTarget.GetTexture());
        }