示例#1
0
        public Animation(string AnimationFile)
        {
            skeletonRenderer = new SkeletonRenderer();

            String name = AnimationFile;

            Atlas        atlas = new Atlas("Data/" + name + ".atlas", new GLImpTextureLoader());
            SkeletonJson json  = new SkeletonJson(atlas);

            skeleton = new Skeleton(json.ReadSkeletonData("Data/" + name + ".json"));
            skeleton.SetSlotsToSetupPose();

            // Define mixing between animations.
            stateData = new AnimationStateData(skeleton.Data);
            state     = new AnimationState(stateData);
            //state.SetAnimation("idle", true);

            skeleton.X = 0;
            skeleton.Y = 0.1f;
            skeleton.UpdateWorldTransform();

            drawtime = new Stopwatch();
            drawtime.Start();

            Program.MiddleDrawQueue += Draw;
        }
示例#2
0
        static void SomeF()
        {
            string folder       = "models/coin/export/";
            string files        = folder + "coin";
            string skelFile     = files + "-pro.skel";
            string atlasFile    = files + ".atlas";
            string jsonSkelFile = files + "-pro.json";


            TexLoader textureLoader = new TexLoader();
            Atlas     atlas         = new Atlas(atlasFile, textureLoader);

            var skeletonBinary     = new SkeletonBinary(new Atlas[] { atlas });
            var skeletonBinaryData = skeletonBinary.ReadSkeletonData(skelFile);
            var jsonSkeletonBinary = JsonConvert.SerializeObject(skeletonBinaryData);

            File.WriteAllText(skelFile + ".json", jsonSkeletonBinary);

            var skeletonJson     = new SkeletonJson(new Atlas[] { atlas });
            var skeletonJsonData = skeletonJson.ReadSkeletonData(jsonSkelFile);
            var jsonSkeletonJson = JsonConvert.SerializeObject(skeletonJsonData);

            File.WriteAllText(jsonSkelFile + ".json", jsonSkeletonJson);
            //Console.WriteLine(json);
        }
示例#3
0
        private static SkeletonData loadSkeletonData(string skeletonPath, GraphicsDevice graphicsDevice)
        {
            Atlas        atlas        = new Atlas(skeletonPath + ".atlas", new XnaTextureLoader(graphicsDevice));
            SkeletonJson skeletonJson = new SkeletonJson(atlas);

            return(skeletonJson.ReadSkeletonData(skeletonPath + ".json"));
        }
        public void LoadAnimation(GraphicsDevice graphicsDevice, ContentManager contentManager, string folderPath, string fileName, string animationName = "animation", bool loop = true)
        {
            // Skeleton
            this.filesName = @contentManager.RootDirectory + "\\" + folderPath + fileName;

            this.atlas = new Atlas(this.filesName + ".atlas", new XnaTextureLoader(graphicsDevice));

            this.json = new SkeletonJson(atlas);

            SkeletonData skeletonData;

            skeletonData = json.ReadSkeletonData(this.filesName + ".json");

            this.skeleton = new Skeleton(skeletonData);

            // Animation
            AnimationStateData animationStateData = new AnimationStateData(skeleton.Data);

            this.animationState = new AnimationState(animationStateData);

            this.animationName = animationName;
            this.animationState.SetAnimation(0, this.animationName, loop);

            this.Position = Vector2.Zero;
            this.skeleton.UpdateWorldTransform();

            this.loop = loop;
        }
示例#5
0
        public GloveModel()
        {
            gc = GloveController.GetSingleton(ModelType.HandOnly);
            //            var mLogger = Logger.GetInstance(mw.txt_log);
            //            gc.RegisterLogger(mLogger);

            //if (!gc.IsConnected((int)handType)) //接入手套
            //{
            //    gc.Connect(chuankou, 0);       //连接手套和串口
            //}
            rhb             = Rehabilitation.GetSingleton();
            dh              = DataWarehouse.GetSingleton();
            sc              = SkeletonCalculator.GetSingleton("");
            handinformation = HandInf.GetSingleton();

            OptimizedData = HandInf.GetSingleton();

            fram       = new SkeletonJson();
            Mychuankou = "COM3";


            //pullDataTimer = new Timer(500);
            //pullDataTimer.Elapsed += pullDataTimer_Tick;
            //pullDataTimer.Start();
        }
示例#6
0
        private void Frame_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (e.Delta > 0)
            {
                App.GV.Scale += 0.02f;
            }
            else
            {
                if (App.GV.Scale > 0.04f)
                {
                    App.GV.Scale -= 0.02f;
                }
            }
            atlas = new Atlas(App.GV.SelectFile, new XnaTextureLoader(_graphicsDevice));
            if (Common.IsBinaryData(App.GV.SelectFile))
            {
                binary       = new SkeletonBinary(atlas);
                binary.Scale = App.GV.Scale;
                skeletonData = binary.ReadSkeletonData(Common.GetSkelPath(App.GV.SelectFile));
            }
            else
            {
                json         = new SkeletonJson(atlas);
                json.Scale   = App.GV.Scale;
                skeletonData = json.ReadSkeletonData(Common.GetJsonPath(App.GV.SelectFile));
            }

            skeleton = new Skeleton(skeletonData);
        }
示例#7
0
    public SkeletonData GetSkeletonData(bool quiet)
    {
        if (atlasAsset == null)
        {
            if (!quiet)
            {
                Debug.LogWarning("Atlas not set for skeleton data asset: " + name, this);
            }
            Clear();
            return(null);
        }

        if (skeletonJSON == null)
        {
            if (!quiet)
            {
                Debug.LogWarning("Skeleton JSON file not set for skeleton data asset: " + name, this);
            }
            Clear();
            return(null);
        }

        Atlas atlas = atlasAsset.GetAtlas();

        if (atlas == null)
        {
            Clear();
            return(null);
        }

        if (skeletonData != null)
        {
            return(skeletonData);
        }

        SkeletonJson json = new SkeletonJson(atlas);

        json.Scale = scale;
        try {
            skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
        } catch (Exception ex) {
            if (!quiet)
            {
                Debug.Log("Error reading skeleton JSON file for skeleton data asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
            }
            return(null);
        }

        stateData = new AnimationStateData(skeletonData);
        for (int i = 0, n = fromAnimation.Length; i < n; i++)
        {
            if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0)
            {
                continue;
            }
            stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);
        }

        return(skeletonData);
    }
示例#8
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="animationFolder">The folder the animation, skeleton, and spritesheet data are found in.</param>
        /// <param name="skin">An optional skin to use in the animation, if supported.</param>
        public SpineAnimation(string animationFolder, string skin = null)
        {
            animationFolder.TrimEnd('/');
            var atlas        = new Atlas(new StringReader(Library.GetText(string.Format("{0}/skeleton.atlas", animationFolder))), ".", new PunkTextureLoader(animationFolder));
            var json         = new SkeletonJson(atlas);
            var skeletonData = json.ReadSkeletonData(string.Format("{0}/skeleton.json", animationFolder));

            var stateData = new AnimationStateData(skeletonData);

            Rate   = 1;
            Active = true;

            _vertexArray = new VertexArray(PrimitiveType.Quads, (uint)skeletonData.Bones.Count * 4);

            _skeleton = new Skeleton(skeletonData);
            _state    = new AnimationState(stateData);

            if (!string.IsNullOrEmpty(skin))
            {
                _skeleton.SetSkin(skin);
            }

            _skeleton.SetSlotsToSetupPose();
            _skeleton.SetToSetupPose();
            _skeleton.UpdateWorldTransform();

            _vertexPositions = new float[8];                    //	cache this for performance
            _transform       = new Transformable();
        }
    // this actually loads the spine json file into a skeletondata object, then adds it to the dictionary
    public static void LoadSpine(string name, string jsonPath)
    {
        if (!DoesContainSkeleton(name))
        {
            TextAsset dataAsset = Resources.Load(jsonPath + Futile.resourceSuffix, typeof(TextAsset)) as TextAsset;
            if (dataAsset == null)
            {
                Debug.Log("Could not load Skeleton, file " + jsonPath + Futile.resourceSuffix + " not found.");
                return;
            }

            SkeletonJson json         = new SkeletonJson(_attachmentLoader);
            TextReader   reader       = new StringReader(dataAsset.text);
            SkeletonData skeletonData = json.ReadSkeletonData(reader);

            if (skeletonData != null)
            {
                _skeletons.Add(name, skeletonData);
            }
            else
            {
                Debug.Log("Could not load Skeleton Data");
            }
        }
        else
        {
            Debug.Log("Skeleton already exists for name [" + name + "]");
        }
    }
示例#10
0
 public SpineData(string pSkeletonName, SpineDataSettings pSettings)
 {
     Initialize();
     settings = pSettings;
     atlas    = new Atlas(EngineSettings.DefaultPathSpine + "\\" + pSkeletonName + ".atlas", EngineSettings.TextureLoader);
     json     = new SkeletonJson(atlas);
 }
示例#11
0
            public SpineAnimationSet(string folderName)
            {
                try
                {
                    atlas = atlasDataLib[spineAnimationDirectory + folderName + "/parts.atlas"];
                }
                catch (Exception)
                {
                    atlas = new Atlas(spineAnimationDirectory + folderName + "/parts.atlas", textureLoader);
                    atlasDataLib.Add(spineAnimationDirectory + folderName + "/parts.atlas", atlas);
                }

                SkeletonData skeletonData;

                try
                {
                    skeletonData = skeletonDataLib[spineAnimationDirectory + folderName + "/anims.json"];
                }
                catch (Exception)
                {
                    SkeletonJson json = new SkeletonJson(atlas);
                    skeletonData = json.ReadSkeletonData(spineAnimationDirectory + folderName + "/anims.json");
                    skeletonDataLib.Add(spineAnimationDirectory + folderName + "/anims.json", skeletonData);
                }

                skeleton = new Skeleton(skeletonData);

                animation = skeleton.Data.FindAnimation("run");
            }
示例#12
0
        public void LoadContent(ContentManager content, GraphicsDevice graphicsDevice)
        {
            blankTex = content.Load <Texture2D>("blank");

            skeletonRenderer = new SkeletonRenderer(graphicsDevice);
            Atlas        atlas = new Atlas(graphicsDevice, Path.Combine(content.RootDirectory, "spinegirl.atlas"));
            SkeletonJson json  = new SkeletonJson(atlas);

            skeleton = new Skeleton(json.readSkeletonData("spinegirl", File.ReadAllText(Path.Combine(content.RootDirectory, "spinegirl.json"))));
            skeleton.SetSkin("default");
            skeleton.SetSlotsToBindPose();
            Animations.Add("walk", skeleton.Data.FindAnimation("walk"));
            Animations.Add("jump", skeleton.Data.FindAnimation("jump"));
            Animations.Add("crawl", skeleton.Data.FindAnimation("crawl"));
            Animations.Add("fall", skeleton.Data.FindAnimation("fall"));
            Animations.Add("grab", skeleton.Data.FindAnimation("grab"));
            Animations.Add("climb", skeleton.Data.FindAnimation("climb"));
            Animations.Add("turnvalve", skeleton.Data.FindAnimation("turnvalve"));

            skeleton.RootBone.X      = Position.X;
            skeleton.RootBone.Y      = Position.Y;
            skeleton.RootBone.ScaleX = Scale;
            skeleton.RootBone.ScaleY = Scale;

            skeleton.UpdateWorldTransform();
        }
    private void MakeSkeletonAndAnimationData()
    {
        if (spritesData == null)
        {
            Debug.LogWarning("Sprite collection not set for skeleton data asset: " + name, this);
            return;
        }

        if (skeletonJSON == null)
        {
            Debug.LogWarning("Skeleton JSON file not set for skeleton data asset: " + name, this);
            return;
        }

        SkeletonJson json = new SkeletonJson(new tk2dSpineAttachmentLoader(spritesData));

        json.Scale = scale;

        try {
            skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
        } catch (Exception ex) {
            Debug.Log("Error reading skeleton JSON file for skeleton data asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
            return;
        }

        stateData = new AnimationStateData(skeletonData);
        for (int i = 0, n = fromAnimation.Length; i < n; i++)
        {
            if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0)
            {
                continue;
            }
            stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);
        }
    }
示例#14
0
        private static bool TryLoadSkeletonJson(Wz_Node atlasNode, Atlas atlas, out SkeletonData data)
        {
            data = null;

            if (atlasNode == null || atlasNode.ParentNode == null || atlas == null)
            {
                return(false);
            }

            var m = Regex.Match(atlasNode.Text, @"^(.+)\.atlas$", RegexOptions.IgnoreCase);

            if (!m.Success)
            {
                return(false);
            }
            var skeletonSource = atlasNode.ParentNode.FindNodeByPath(m.Result("$1") + ".json").GetValueEx <string>(null);

            if (string.IsNullOrEmpty(skeletonSource))
            {
                return(false);
            }

            StringReader skeletonReader = new StringReader(skeletonSource);
            SkeletonJson json           = new SkeletonJson(atlas);

            data = json.ReadSkeletonData(skeletonReader);
            return(true);
        }
示例#15
0
        public Skeleton Load(string assetName)
        {
            var Atlas    = new Atlas(RootDirectory + "/" + assetName + ".atlas", this);
            var Json     = new SkeletonJson(Atlas);
            var Skeleton = new Skeleton(Json.ReadSkeletonData(RootDirectory + "/" + assetName + ".json"));

            return(Skeleton);
        }
示例#16
0
 private static void loadSpineJSon(string animationName)
 {
     if (!skeletonDataLib.ContainsKey(spineAnimationDirectory + animationName + "/anims.json"))
     {
         SkeletonJson json         = new SkeletonJson(atlasDataLib[spineAnimationDirectory + animationName + "/parts.atlas"]);
         SkeletonData skeletonData = json.ReadSkeletonData(spineAnimationDirectory + animationName + "/anims.json");
         skeletonDataLib.Add(spineAnimationDirectory + animationName + "/anims.json", skeletonData);
     }
 }
        public CCSkeleton(string skeletonDataFile, Atlas atlas, float scale = 0)
        {
            var json = new SkeletonJson(atlas);

            json.Scale = scale == 0 ? 1 : scale;
            SkeletonData skeletonData = json.ReadSkeletonData(skeletonDataFile);

            SetSkeletonData(skeletonData, true);
        }
 private void CreateSkeletonIfPossible()
 {
     if (_atlas.IsAvailable && _atlas.Res.Atlas != null && _skeletonData.IsAvailable && !string.IsNullOrEmpty(_skeletonData.Res.Content))
     {
         _skeletonJson = new SkeletonJson(_atlas.Res.Atlas);
         _skeleton     = new Skeleton(_skeletonJson.ReadSkeletonData(new StringReader(_skeletonData.Res.Content)));
         _state        = new AnimationState(new AnimationStateData(_skeleton.Data));
     }
 }
示例#19
0
        public CCSkeleton(string skeletonDataFile, Atlas atlas, float scale = 0)
        {
            var json = new SkeletonJson(atlas);

            json.Scale = scale == 0 ? (1 / Director.ContentScaleFactor) : scale;
            SkeletonData skeletonData = json.ReadSkeletonData(skeletonDataFile);

            SetSkeletonData(skeletonData, true);
        }
示例#20
0
        internal static SkeletonData ReadSkeletonData(string text, AttachmentLoader attachmentLoader, float scale)
        {
            StringReader reader       = new StringReader(text);
            SkeletonJson skeletonJson = new SkeletonJson(attachmentLoader);

            skeletonJson.Scale = scale;
            SkeletonJson skeletonJson2 = skeletonJson;

            return(skeletonJson2.ReadSkeletonData(reader));
        }
    public void update_data(SkeletonJson result)
    {
        Mutex = true;
        if (result != null)
        {
            data_right = result;
        }

        Mutex = false;
    }
        internal static SkeletonData ReadSkeletonData(string text, AttachmentLoader attachmentLoader, float scale)
        {
            var input = new StringReader(text);
            var json  = new SkeletonJson(attachmentLoader)
            {
                Scale = scale
            };

            return(json.ReadSkeletonData(input));
        }
        /// <summary>
        /// Load skeleton data by json or binary automatically
        /// </summary>
        /// <param name="atlasNode"></param>
        /// <param name="atlas"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private static bool TryLoadSkeletonJsonOrBinary(WzImageProperty atlasNode, Atlas atlas, out SkeletonData data)
        {
            data = null;

            if (atlasNode == null || atlasNode.Parent == null || atlas == null)
            {
                return(false);
            }
            WzObject parent = atlasNode.Parent;

            List <WzImageProperty> childProperties;

            if (parent is WzImageProperty)
            {
                childProperties = ((WzImageProperty)parent).WzProperties;
            }
            else
            {
                childProperties = ((WzImage)parent).WzProperties;
            }


            if (childProperties != null)
            {
                WzStringProperty stringJsonProp = (WzStringProperty)childProperties.Where(child => child.Name.EndsWith(".json")).FirstOrDefault();

                if (stringJsonProp != null) // read json based
                {
                    StringReader skeletonReader = new StringReader(stringJsonProp.GetString());
                    SkeletonJson json           = new SkeletonJson(atlas);
                    data = json.ReadSkeletonData(skeletonReader);

                    return(true);
                }
                else
                {
                    // try read binary based
                    foreach (WzImageProperty property in childProperties)
                    {
                        if (property is WzBinaryProperty)
                        {
                            WzBinaryProperty soundProp = (WzBinaryProperty)property; // should be called binaryproperty actually

                            using (MemoryStream ms = new MemoryStream(soundProp.GetBytes(false)))
                            {
                                SkeletonBinary skeletonBinary = new SkeletonBinary(atlas);
                                data = skeletonBinary.ReadSkeletonData(ms);
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
示例#24
0
        public void GetData()
        {
            try
            {
                //send right
                var f_r = dh.GetFrameData(handType, Definition.MODEL_TYPE);

                //        public enum NodeType
                //{
                //    Wrist,
                //    Upperarm,
                //    Index_0,
                //    Index_1,
                //    Middle_0,
                //    Middle_1,
                //    Ring_0,
                //    Ring_1,
                //    Little_0, // 0 for near one, 1 for far one
                //    Little_1,
                //    Thumb_0,
                //    Thumb_1,
                //    Forearm,
                //    Palm
                //}


                //for (int i = 0; i < Definition.SENSOR_COUNT; i++)
                //{
                //    Console.WriteLine("{0} Node 'W is {1}", (NodeType)i, f_r.Nodes[i].X);
                //}


                //Console.WriteLine("{0} Node 'x is {1}", (NodeType)11, f_r.Nodes[11].X);

                var s = sc.UpdateRaw(f_r);

                fram         = s.ToSkeletonJson();
                skeletonJson = s.ToJson();

                handinformation = SkeletonJsonToHandinf(fram);
                //Console.WriteLine("the skeleton json is :");
                //Console.WriteLine(skeletonJson);
                //Console.WriteLine("the skeleton string is :");
                //Console.WriteLine(s.ToString());

                //Console.WriteLine(fram.Joints[(int)JointType.Hand].W);

                //Console.WriteLine(s.ToString());\
            }
            catch (Exception e)
            {
                //Console.WriteLine(e);
                return;
            }
        }
示例#25
0
        private Skeleton CreateSkeleton(string atlasName, string skeletonName)
        {
            var atlasData = ContentLoader.Load <AtlasData>(atlasName);

            atlas = new Atlas(atlasData.TextReader, "Content", MaterialLoader);
            var skeletonJson      = new SkeletonJson(atlas);
            var spineSkeletonData = ContentLoader.Load <SpineSkeletonData>(skeletonName);

            SkeletonData = skeletonJson.ReadSkeletonData(spineSkeletonData.TextReader);
            return(new Skeleton(SkeletonData));
        }
示例#26
0
    public void LoadContent(ContentManager contentManager)
    {
        skeletonRenderer = new SkeletonMeshRenderer(App.graphicsDevice);
        skeletonRenderer.PremultipliedAlpha = App.globalValues.Alpha;

        atlas = new Atlas(App.globalValues.SelectAtlasFile, new XnaTextureLoader(App.graphicsDevice));

        json         = new SkeletonJson(atlas);
        json.Scale   = App.globalValues.Scale;
        skeletonData = json.ReadSkeletonData(App.globalValues.SelectSpineFile);
        App.globalValues.SpineVersion = skeletonData.Version;

        skeleton = new Skeleton(skeletonData);

        Common.SetInitLocation(skeleton.Data.Height);
        App.globalValues.FileHash = skeleton.Data.Hash;

        stateData = new AnimationStateData(skeleton.Data);

        state = new AnimationState(stateData);

        List <string> AnimationNames = new List <string>();

        listAnimation = state.Data.skeletonData.Animations;
        foreach (Animation An in listAnimation)
        {
            AnimationNames.Add(An.name);
        }
        App.globalValues.AnimeList = AnimationNames;

        List <string> SkinNames = new List <string>();

        listSkin = state.Data.skeletonData.Skins;
        foreach (Skin Sk in listSkin)
        {
            SkinNames.Add(Sk.name);
        }
        App.globalValues.SkinList = SkinNames;

        if (App.globalValues.SelectAnimeName != "")
        {
            state.SetAnimation(0, App.globalValues.SelectAnimeName, App.globalValues.IsLoop);
        }
        else
        {
            state.SetAnimation(0, state.Data.skeletonData.animations[0].name, App.globalValues.IsLoop);
        }

        if (App.isNew)
        {
            MainWindow.SetCBAnimeName();
        }
        App.isNew = false;
    }
        public override void Initialize(GraphicsDevice gd)
        {
            _skeletonRenderer = new SkeletonRenderer(gd);
            _skeletonRenderer.PremultipliedAlpha = Props.UseAlpha;
            _effect = _skeletonRenderer.Effect as BasicEffect;

            _atlas = new Atlas(Info.AtlasFile, new XnaTextureLoader(gd, Info.PremultipliedAlpha));

            SkeletonData skeletonData;

            if (System.IO.Path.GetExtension(Info.SpineFile) == ".skel")
            {
                SkeletonBinary binary = new SkeletonBinary(_atlas);
                binary.Scale = Info.Scale;
                skeletonData = binary.ReadSkeletonData(Info.SpineFile);
            }
            else
            {
                SkeletonJson json = new SkeletonJson(_atlas);
                json.Scale   = Info.Scale;
                skeletonData = json.ReadSkeletonData(Info.SpineFile);
            }
            _skeleton = new Skeleton(skeletonData);

            AnimationStateData stateData = new AnimationStateData(_skeleton.Data);

            _state = new AnimationState(stateData);

            string curSkin = _skeleton.Data.Skins.Items[0].Name;
            string curAnim = _skeleton.Data.Animations.Items[0].Name;

            _state.SetAnimation(0, curAnim, Props.IsLoop);

            _skeleton.X      = 0; _skeleton.Y = 0;
            _skeleton.ScaleX = Props.FlipX ? 1 : -1;
            _skeleton.ScaleY = Props.FlipY ? -1 : 1;

            // Return spine info
            Props.Skin     = curSkin;
            Props.Anim     = curAnim;
            Info.Version   = skeletonData.Version;
            Info.OrgWidth  = skeletonData.Width;
            Info.OrgHeight = skeletonData.Height;
            foreach (Animation ani in _state.Data.skeletonData.Animations)
            {
                Info.AnimNames.Add(ani.Name);
            }
            foreach (Skin sk in _state.Data.skeletonData.Skins)
            {
                Info.SkinNames.Add(sk.Name);
            }

            IsLoaded = true;
        }
示例#28
0
        protected void LoadContent(GraphicsDevice gD)
        {
            graphics         = gD;
            skeletonRenderer = new SkeletonRenderer(gD);
            skeletonRenderer.PremultipliedAlpha = true;

            String name = "spineboy"; // "goblins";

            Atlas        atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(gD));
            SkeletonJson json  = new SkeletonJson(atlas);

            skeleton = new Skeleton(json.ReadSkeletonData("data/" + name + ".json"));
            if (name == "goblins")
            {
                skeleton.SetSkin("goblingirl");
            }
            skeleton.SetSlotsToSetupPose(); // Without this the skin attachments won't be attached. See SetSkin.

            // Define mixing between animations.
            AnimationStateData stateData = new AnimationStateData(skeleton.Data);

            if (name == "spineboy")
            {
                stateData.SetMix("walk", "jump", 0.2f);
                stateData.SetMix("jump", "walk", 0.4f);
            }

            state = new AnimationState(stateData);

            if (false)
            {
                // Event handling for all animations.
                state.Start    += Start;
                state.End      += End;
                state.Complete += Complete;
                state.Event    += Event;

                state.SetAnimation(0, "drawOrder", true);
            }
            else
            {
                state.SetAnimation(0, "walk", false);
                TrackEntry entry = state.AddAnimation(0, "jump", false, 0);
                entry.End += new EventHandler <StartEndArgs>(End); // Event handling for queued animations.
                state.AddAnimation(0, "walk", true, 0);
            }

            skeleton.X = 600;
            skeleton.Y = 600;
            skeleton.UpdateWorldTransform();

            headSlot = skeleton.FindSlot("head");
        }
示例#29
0
    public SkeletonData GetSkeletonData(bool quiet)
    {
        if (spriteCollection == null)
        {
            if (!quiet)
            {
                Debug.LogError("Sprite collection not set for skeleton data asset: " + name, this);
            }
            Reset();
            return(null);
        }

        if (skeletonJSON == null)
        {
            if (!quiet)
            {
                Debug.LogError("Skeleton JSON file not set for skeleton data asset: " + name, this);
            }
            Reset();
            return(null);
        }

        if (skeletonData != null)
        {
            return(skeletonData);
        }

        SkeletonJson json = new SkeletonJson(new SpriteCollectionAttachmentLoader(spriteCollection));

        json.Scale = 1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale;
        try {
            skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
        } catch (Exception ex) {
            if (!quiet)
            {
                Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
            }
            return(null);
        }

        stateData            = new AnimationStateData(skeletonData);
        stateData.DefaultMix = defaultMix;
        for (int i = 0, n = fromAnimation.Length; i < n; i++)
        {
            if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0)
            {
                continue;
            }
            stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);
        }

        return(skeletonData);
    }
示例#30
0
    public void LoadContent(ContentManager contentManager)
    {
        skeletonRenderer = new SkeletonRenderer(App.graphicsDevice);
        skeletonRenderer.PremultipliedAlpha = App.GV.Alpha;

        atlas = new Atlas(App.GV.SelectFile, new XnaTextureLoader(App.graphicsDevice));

        if (Common.IsBinaryData(App.GV.SelectFile))
        {
            binary       = new SkeletonBinary(atlas);
            binary.Scale = App.GV.Scale;
            skeletonData = binary.ReadSkeletonData(Common.GetSkelPath(App.GV.SelectFile));
        }
        else
        {
            json         = new SkeletonJson(atlas);
            json.Scale   = App.GV.Scale;
            skeletonData = json.ReadSkeletonData(Common.GetJsonPath(App.GV.SelectFile));
        }
        skeleton = new Skeleton(skeletonData);

        if (App.isNew)
        {
            App.GV.PosX = Convert.ToSingle(App.GV.FrameWidth / 2f);
            App.GV.PosY = Convert.ToSingle((skeleton.Data.Height + App.GV.FrameHeight) / 2f);
        }
        App.GV.FileHash = skeleton.Data.Hash;

        stateData = new AnimationStateData(skeleton.Data);

        state = new AnimationState(stateData);

        App.GV.AnimeList = state.Data.skeletonData.Animations.Select(x => x.Name).ToList();
        App.GV.SkinList  = state.Data.skeletonData.Skins.Select(x => x.Name).ToList();

        if (App.GV.SelectAnimeName != "")
        {
            state.SetAnimation(0, App.GV.SelectAnimeName, App.GV.IsLoop);
        }
        else
        {
            state.SetAnimation(0, state.Data.skeletonData.animations.Items[0].name, App.GV.IsLoop);
        }

        if (App.isNew)
        {
            MainWindow.SetCBAnimeName();
        }
        App.isNew = false;
    }