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; }
protected override void LoadContent () { skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice); skeletonRenderer.PremultipliedAlpha = true; // String name = "spineboy"; // String name = "goblins-mesh"; String name = "raptor"; bool binaryData = true; Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice)); float scale = 1; if (name == "spineboy") scale = 0.6f; if (name == "raptor") scale = 0.5f; SkeletonData skeletonData; if (binaryData) { SkeletonBinary binary = new SkeletonBinary(atlas); binary.Scale = scale; skeletonData = binary.ReadSkeletonData(assetsFolder + name + ".skel"); } else { SkeletonJson json = new SkeletonJson(atlas); json.Scale = scale; skeletonData = json.ReadSkeletonData(assetsFolder + name + ".json"); } skeleton = new Skeleton(skeletonData); if (name == "goblins-mesh") skeleton.SetSkin("goblin"); // Define mixing between animations. AnimationStateData stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); if (name == "spineboy") { stateData.SetMix("run", "jump", 0.2f); stateData.SetMix("jump", "run", 0.4f); // Event handling for all animations. state.Start += Start; state.End += End; state.Complete += Complete; state.Event += Event; state.SetAnimation(0, "test", false); TrackEntry entry = state.AddAnimation(0, "jump", false, 0); entry.End += End; // Event handling for queued animations. state.AddAnimation(0, "run", true, 0); } else if (name == "raptor") { state.SetAnimation(0, "walk", true); state.SetAnimation(1, "empty", false); state.AddAnimation(1, "gungrab", false, 2); } else { state.SetAnimation(0, "walk", true); } skeleton.X = 400; skeleton.Y = 590; skeleton.UpdateWorldTransform(); headSlot = skeleton.FindSlot("head"); }
public SpineData(string pSkeletonName, SpineDataSettings pSettings) { Initialize(); settings = pSettings; atlas = new Atlas(EngineSettings.DefaultPathSpine + "\\" + pSkeletonName + ".atlas", new XnaTextureLoader(EngineSettings.Graphics.GraphicsDevice)); json = new SkeletonJson(atlas); }
void OnCurLoadFinish() {//先临时验证一下代码构造spine动画,两个atlas的设计问题较多,必须要休整一下播放组件 GameObject curObj = new GameObject(); curObj.name = "spine-cur"; SkeletonAnimationCL ani = curObj.AddComponent <SkeletonAnimationCL>(); //AtlasAsset assAtlas = new AtlasAsset(); //assAtlas.materials = new Material[1]; //assAtlas.materials[0] = new Material(Shader.Find("Spine/Skeleton")); //assAtlas.materials[0].mainTexture = curAtlasTex; Dictionary <string, Texture2D> texs = new Dictionary <string, Texture2D>(); texs["cur.png"] = curAtlasTex; var atlas = new Spine.Atlas(new System.IO.StringReader(curAtlas), "", new TextureLoad(texs)); atlas.FlipV(); //assAtlas.SetAtlas(atlas); Spine.SkeletonJson sjson = new Spine.SkeletonJson(atlas); sjson.Scale = 1.0f / 64.0f; var data = sjson.ReadSkeletonData(new System.IO.StringReader(curSK)); ani.skeleton = new Spine.Skeleton(data); ani.Reset(); ani.state.SetAnimation(0, "idle", true); }
public RawSpineData(string pSkeletonDataPath, string pSkeletonName) { skeletonRenderer = new SkeletonRenderer(EngineSettings.Graphics.GraphicsDevice); skeletonRenderer.PremultipliedAlpha = SpineSettings.PremultipliedAlphaRendering; atlas = new Atlas(pSkeletonDataPath + pSkeletonName + ".atlas", new XnaTextureLoader(EngineSettings.Graphics.GraphicsDevice)); json = new SkeletonJson(atlas); }
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); }
void Apply (SkeletonRenderer skeletonRenderer) { atlas = atlasAsset.GetAtlas(); float scale = skeletonRenderer.skeletonDataAsset.scale; var enumerator = attachments.GetEnumerator(); while (enumerator.MoveNext()) { var entry = (SlotRegionPair)enumerator.Current; var slot = skeletonRenderer.skeleton.FindSlot(entry.slot); var region = atlas.FindRegion(entry.region); slot.Attachment = region.ToRegionAttachment(entry.region, scale); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); this.skeletonRenderer = new SkeletonRegionRenderer(GraphicsDevice); var atlas = new Atlas(@"Assets\crab.atlas", new XnaTextureLoader(GraphicsDevice)); var json = new SkeletonJson(atlas); this.skeleton = new Skeleton(json.ReadSkeletonData(@"Assets\skeleton.json")); this.animation = this.skeleton.Data.FindAnimation("Walk"); this.skeleton.X = 750; this.skeleton.Y = 700; }
public SpinePlayer(string atlasPath, string jsonPath) { Name = jsonPath; _skeletonRenderer = new SkeletonRenderer(Render.Device); var atlas = new Atlas(atlasPath, new XnaTextureLoader(Render.Device)); var json = new SkeletonJson(atlas); Skeleton = new Skeleton(json.ReadSkeletonData(jsonPath)); Skeleton.SetSlotsToSetupPose(); // Without this the skin attachments won't be attached. See SetSkin. var stateData = new AnimationStateData(Skeleton.Data); State = new AnimationState(stateData); IsVisible = true; }
public Avatar(string AnimationFile) { SkeletonRenderer = new SkeletonRenderer(Vector3.UnitY, Vector3.UnitZ); String name = AnimationFile; Atlas atlas = new Atlas(name + ".atlas", new OpenTKTextureLoader()); SkeletonJson json = new SkeletonJson(atlas); Skeleton = new Skeleton(json.ReadSkeletonData(name + ".json")); Skeleton.SetSlotsToSetupPose(); // Define mixing between animations. StateData = new AnimationStateData(Skeleton.Data); State = new AnimationState(StateData); Skeleton.X = 0; Skeleton.Y = 0; Skeleton.UpdateWorldTransform(); }
protected override void LoadContent() { skeletonRenderer = new SkeletonRenderer(GraphicsDevice); String name = "spineboy"; // "goblins"; Atlas atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(GraphicsDevice)); 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 (true) { state.SetAnimation("drawOrder", true); } else { state.SetAnimation("walk", false); state.AddAnimation("jump", false); state.AddAnimation("walk", true); } skeleton.X = 320; skeleton.Y = 440; skeleton.UpdateWorldTransform(); headSlot = skeleton.FindSlot("head"); }
protected override SkeletonData Read(ContentReader input, SkeletonData existingInstance) { string atlasAssetName = input.ReadString(); string skeletonDataName = input.ReadString(); string skeletonJsonText = input.ReadString(); Atlas atlas = input.ContentManager.Load <Atlas>(atlasAssetName); SkeletonJson skeletonJson = new SkeletonJson(atlas); SkeletonData skeletonData; using (TextReader textReader = new StringReader(skeletonJsonText)) { skeletonData = skeletonJson.ReadSkeletonData(textReader); } skeletonData.Name = skeletonDataName; return(skeletonData); }
protected override void Dispose(bool disposing) { if (this.textureMaps != null) { foreach (var textureMap in this.textureMaps) { if (textureMap != null && !textureMap.IsDisposed) { textureMap.Dispose (); } } this.textureMaps = null; } this.atlas.Dispose(); this.atlas = null; base.Dispose (disposing); }
void Apply (SkeletonRenderer skeletonRenderer) { atlas = atlasAsset.GetAtlas(); AtlasAttachmentLoader loader = new AtlasAttachmentLoader(atlas); float scaleMultiplier = skeletonRenderer.skeletonDataAsset.scale; var enumerator = attachments.GetEnumerator(); while (enumerator.MoveNext()) { var entry = (SlotRegionPair)enumerator.Current; var regionAttachment = loader.NewRegionAttachment(null, entry.region, entry.region); regionAttachment.Width = regionAttachment.RegionOriginalWidth * scaleMultiplier; regionAttachment.Height = regionAttachment.RegionOriginalHeight * scaleMultiplier; regionAttachment.SetColor(new Color(1, 1, 1, 1)); regionAttachment.UpdateOffset(); var slot = skeletonRenderer.skeleton.FindSlot(entry.slot); slot.Attachment = regionAttachment; } }
public MixAndMatchScreen(Example game) : base(game) { atlas = new Atlas("data/mix-and-match.atlas", new XnaTextureLoader(game.GraphicsDevice)); SkeletonJson json = new SkeletonJson(atlas); json.Scale = 0.5f; SkeletonData skeletonData = json.ReadSkeletonData("data/mix-and-match-pro.json"); skeleton = new Skeleton(skeletonData); AnimationStateData stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); skeleton.X = game.GraphicsDevice.Viewport.Width / 2; skeleton.Y = game.GraphicsDevice.Viewport.Height; state.SetAnimation(0, "dance", true); // Create a new skin, by mixing and matching other skins // that fit together. Items making up the girl are individual // skins. Using the skin API, a new skin is created which is // a combination of all these individual item skins. var mixAndMatchSkin = new Spine.Skin("custom-girl"); mixAndMatchSkin.AddSkin(skeletonData.FindSkin("skin-base")); mixAndMatchSkin.AddSkin(skeletonData.FindSkin("nose/short")); mixAndMatchSkin.AddSkin(skeletonData.FindSkin("eyelids/girly")); mixAndMatchSkin.AddSkin(skeletonData.FindSkin("eyes/violet")); mixAndMatchSkin.AddSkin(skeletonData.FindSkin("hair/brown")); mixAndMatchSkin.AddSkin(skeletonData.FindSkin("clothes/hoodie-orange")); mixAndMatchSkin.AddSkin(skeletonData.FindSkin("legs/pants-jeans")); mixAndMatchSkin.AddSkin(skeletonData.FindSkin("accessories/bag")); mixAndMatchSkin.AddSkin(skeletonData.FindSkin("accessories/hat-red-yellow")); skeleton.SetSkin(mixAndMatchSkin); }
public RaptorScreen(Example game) : base(game) { // Load the texture atlas atlas = new Atlas("data/raptor.atlas", new XnaTextureLoader(game.GraphicsDevice)); // Load the .json file using a scale of 0.5 SkeletonJson json = new SkeletonJson(atlas); json.Scale = 0.5f; SkeletonData skeletonData = json.ReadSkeletonData("data/raptor-pro.json"); // Create the skeleton and animation state skeleton = new Skeleton(skeletonData); AnimationStateData stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); // Center within the viewport skeleton.X = game.GraphicsDevice.Viewport.Width / 2; skeleton.Y = game.GraphicsDevice.Viewport.Height; // Set the "walk" animation on track one and let it loop forever state.SetAnimation(0, "walk", true); }
public AtlasAttachmentLoader (Atlas atlas) { if (atlas == null) throw new ArgumentNullException("atlas cannot be null."); this.atlas = atlas; }
protected override void LoadContent() { // Two color tint effect, comment line 80 to disable var spineEffect = Content.Load <Effect>("spine-xna-example-content\\SpineEffect"); spineEffect.Parameters["World"].SetValue(Matrix.Identity); spineEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up)); skeletonRenderer = new SkeletonRenderer(GraphicsDevice); skeletonRenderer.PremultipliedAlpha = false; skeletonRenderer.Effect = spineEffect; skeletonDebugRenderer = new SkeletonDebugRenderer(GraphicsDevice); skeletonDebugRenderer.DisableAll(); skeletonDebugRenderer.DrawClipping = true; // String name = "spineboy-ess"; // String name = "goblins-pro"; // String name = "raptor-pro"; // String name = "tank-pro"; String name = "coin-pro"; String atlasName = name.Replace("-pro", "").Replace("-ess", ""); if (name == "goblins-pro") { atlasName = "goblins-mesh"; } bool binaryData = false; Atlas atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice)); float scale = 1; if (name == "spineboy-ess") { scale = 0.6f; } if (name == "raptor-pro") { scale = 0.5f; } if (name == "tank-pro") { scale = 0.3f; } if (name == "coin-pro") { scale = 1; } SkeletonData skeletonData; if (binaryData) { SkeletonBinary binary = new SkeletonBinary(atlas); binary.Scale = scale; skeletonData = binary.ReadSkeletonData(assetsFolder + name + ".skel"); } else { SkeletonJson json = new SkeletonJson(atlas); json.Scale = scale; skeletonData = json.ReadSkeletonData(assetsFolder + name + ".json"); } skeleton = new Skeleton(skeletonData); if (name == "goblins-pro") { skeleton.SetSkin("goblin"); } // Define mixing between animations. AnimationStateData stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); if (name == "spineboy-ess") { skeleton.SetAttachment("head-bb", "head"); stateData.SetMix("run", "jump", 0.2f); stateData.SetMix("jump", "run", 0.4f); // Event handling for all animations. state.Start += Start; state.End += End; state.Complete += Complete; state.Event += Event; state.SetAnimation(0, "run", true); TrackEntry entry = state.AddAnimation(0, "jump", false, 0); entry.End += End; // Event handling for queued animations. state.AddAnimation(0, "run", true, 0); } else if (name == "raptor-pro") { state.SetAnimation(0, "walk", true); state.AddAnimation(1, "gun-grab", false, 2); } else if (name == "coin-pro") { state.SetAnimation(0, "animation", true); } else if (name == "tank-pro") { skeleton.X += 300; state.SetAnimation(0, "drive", true); } else { state.SetAnimation(0, "walk", true); } skeleton.X += 400; skeleton.Y += GraphicsDevice.Viewport.Height; skeleton.UpdateWorldTransform(); headSlot = skeleton.FindSlot("head"); }
protected override void LoadContent() { skeletonRenderer = new SkeletonRenderer(GraphicsDevice); String name = "spineboy"; // "goblins"; Atlas atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(GraphicsDevice)); 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 (true) { // Event handling for all animations. state.Start += new EventHandler(Start); state.End += new EventHandler(End); state.Complete += new EventHandler<CompleteArgs>(Complete); state.Event += new EventHandler<EventTriggeredArgs>(Event); state.SetAnimation("drawOrder", true); } else { state.SetAnimation("walk", false); QueueEntry entry = state.AddAnimation("jump", false); entry.End += new EventHandler(End); // Event handling for queued animations. state.AddAnimation("walk", true); } skeleton.X = 320; skeleton.Y = 440; skeleton.UpdateWorldTransform(); headSlot = skeleton.FindSlot("head"); }
private void Load(TextReader reader, string imagesDir, TextureLoader textureLoader) { if (textureLoader == null) { throw new ArgumentNullException("textureLoader cannot be null."); } this.textureLoader = textureLoader; string[] array = new string[4]; AtlasPage atlasPage = null; for (;;) { string text = reader.ReadLine(); if (text == null) { break; } if (text.Trim().Length == 0) { atlasPage = null; } else if (atlasPage == null) { atlasPage = new AtlasPage(); atlasPage.name = text; if (Atlas.ReadTuple(reader, array) == 2) { atlasPage.width = int.Parse(array[0]); atlasPage.height = int.Parse(array[1]); Atlas.ReadTuple(reader, array); } atlasPage.format = (Format)Enum.Parse(typeof(Format), array[0], false); Atlas.ReadTuple(reader, array); atlasPage.minFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), array[0], false); atlasPage.magFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), array[1], false); string a = Atlas.ReadValue(reader); atlasPage.uWrap = TextureWrap.ClampToEdge; atlasPage.vWrap = TextureWrap.ClampToEdge; if (a == "x") { atlasPage.uWrap = TextureWrap.Repeat; } else if (a == "y") { atlasPage.vWrap = TextureWrap.Repeat; } else if (a == "xy") { atlasPage.uWrap = (atlasPage.vWrap = TextureWrap.Repeat); } textureLoader.Load(atlasPage, Path.Combine(imagesDir, text)); this.pages.Add(atlasPage); } else { AtlasRegion atlasRegion = new AtlasRegion(); atlasRegion.name = text; atlasRegion.page = atlasPage; atlasRegion.rotate = bool.Parse(Atlas.ReadValue(reader)); Atlas.ReadTuple(reader, array); int num = int.Parse(array[0]); int num2 = int.Parse(array[1]); Atlas.ReadTuple(reader, array); int num3 = int.Parse(array[0]); int num4 = int.Parse(array[1]); atlasRegion.u = (float)num / (float)atlasPage.width; atlasRegion.v = (float)num2 / (float)atlasPage.height; if (atlasRegion.rotate) { atlasRegion.u2 = (float)(num + num4) / (float)atlasPage.width; atlasRegion.v2 = (float)(num2 + num3) / (float)atlasPage.height; } else { atlasRegion.u2 = (float)(num + num3) / (float)atlasPage.width; atlasRegion.v2 = (float)(num2 + num4) / (float)atlasPage.height; } atlasRegion.x = num; atlasRegion.y = num2; atlasRegion.width = Math.Abs(num3); atlasRegion.height = Math.Abs(num4); if (Atlas.ReadTuple(reader, array) == 4) { atlasRegion.splits = new int[] { int.Parse(array[0]), int.Parse(array[1]), int.Parse(array[2]), int.Parse(array[3]) }; if (Atlas.ReadTuple(reader, array) == 4) { atlasRegion.pads = new int[] { int.Parse(array[0]), int.Parse(array[1]), int.Parse(array[2]), int.Parse(array[3]) }; Atlas.ReadTuple(reader, array); } } atlasRegion.originalWidth = int.Parse(array[0]); atlasRegion.originalHeight = int.Parse(array[1]); Atlas.ReadTuple(reader, array); atlasRegion.offsetX = (float)int.Parse(array[0]); atlasRegion.offsetY = (float)int.Parse(array[1]); atlasRegion.index = int.Parse(Atlas.ReadValue(reader)); this.regions.Add(atlasRegion); } } }
public ResourceAttachmentLoader(Atlas atlas) { mAtlas = atlas; }
protected override void LoadContent() { skeletonRenderer = new SkeletonRenderer(GraphicsDevice); String name = "spineboy"; // "goblins"; Atlas atlas = new Atlas("data/" + name + ".atlas", new XnaTextureLoader(GraphicsDevice)); SkeletonJson json = new SkeletonJson(atlas); skeleton = new Skeleton(json.ReadSkeletonData("data/" + name + ".json")); if (name == "goblins") skeleton.SetSkin("goblingirl"); skeleton.SetSlotsToBindPose(); // 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); state.SetAnimation("walk", false); state.AddAnimation("jump", false); state.AddAnimation("walk", true); skeleton.RootBone.X = 320; skeleton.RootBone.Y = 440; skeleton.UpdateWorldTransform(); }
public void LoadContent(ContentManager content, GraphicsDevice graphicsDevice) { blankTex = content.Load<Texture2D>("Textures/Blank"); skeletonRenderer = new SkeletonRenderer(graphicsDevice); Atlas atlas = new Atlas(graphicsDevice, System.IO.Path.Combine(content.RootDirectory, "spineboy.atlas")); SkeletonJson json = new SkeletonJson(atlas); json.Scale = 0.5f; skeleton = new Skeleton(json.readSkeletonData("spineboy", File.ReadAllText(System.IO.Path.Combine(content.RootDirectory, "spineboy.json")))); skeleton.SetSkin("default"); skeleton.SetSlotsToBindPose(); walkAnimation = skeleton.Data.FindAnimation("walk"); jumpAnimation = skeleton.Data.FindAnimation("jump"); crawlAnimation = skeleton.Data.FindAnimation("crawl"); fallAnimation = skeleton.Data.FindAnimation("fall"); grabAnimation = skeleton.Data.FindAnimation("grab"); climbAnimation = skeleton.Data.FindAnimation("climb"); skeleton.RootBone.X = Position.X; skeleton.RootBone.Y = Position.Y; skeleton.UpdateWorldTransform(); }
public SkeletonData GetSkeletonData (bool quiet) { if (atlasAssets == null) { atlasAssets = new AtlasAsset[0]; if (!quiet) Debug.LogError("Atlas not set for SkeletonData asset: " + name, this); Reset(); return null; } if (skeletonJSON == null) { if (!quiet) Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this); Reset(); return null; } #if !SPINE_TK2D if (atlasAssets.Length == 0) { Reset(); return null; } #else if (atlasAssets.Length == 0 && spriteCollection == null) { Reset(); return null; } #endif Atlas[] atlasArr = new Atlas[atlasAssets.Length]; for (int i = 0; i < atlasAssets.Length; i++) { if (atlasAssets[i] == null) { Reset(); return null; } atlasArr[i] = atlasAssets[i].GetAtlas(); if (atlasArr[i] == null) { Reset(); return null; } } if (skeletonData != null) return skeletonData; AttachmentLoader attachmentLoader; float skeletonDataScale; #if !SPINE_TK2D attachmentLoader = new AtlasAttachmentLoader(atlasArr); skeletonDataScale = scale; #else if (spriteCollection != null) { attachmentLoader = new Spine.Unity.TK2D.SpriteCollectionAttachmentLoader(spriteCollection); skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale); } else { if (atlasArr.Length == 0) { Reset(); if (!quiet) Debug.LogError("Atlas not set for SkeletonData asset: " + name, this); return null; } attachmentLoader = new AtlasAttachmentLoader(atlasArr); skeletonDataScale = scale; } #endif try { //var stopwatch = new System.Diagnostics.Stopwatch(); if (skeletonJSON.name.ToLower().Contains(".skel")) { var input = new MemoryStream(skeletonJSON.bytes); var binary = new SkeletonBinary(attachmentLoader); binary.Scale = skeletonDataScale; //stopwatch.Start(); skeletonData = binary.ReadSkeletonData(input); } else { var input = new StringReader(skeletonJSON.text); var json = new SkeletonJson(attachmentLoader); json.Scale = skeletonDataScale; //stopwatch.Start(); skeletonData = json.ReadSkeletonData(input); } //stopwatch.Stop(); //Debug.Log(stopwatch.Elapsed); } 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); FillStateData(); return skeletonData; }
public SkeletonJson(Atlas atlas) : this(new AtlasAttachmentLoader(atlas)) { }
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); }
public void Initialize() { atlas = null; DebugSlots = false; DebugBones = false; PremultipliedAlpha = false; ImagesDirectory = string.Empty; DebugSlotColor = CCColor4B.Magenta; DebugBoneColor = CCColor4B.Blue; DebugJointColor = CCColor4B.Red; batcher = new CCMeshBatcher(CCDrawManager.GraphicsDevice); OpacityModifyRGB = true; Schedule(); }
public CCSkeleton(string skeletonDataFile, string atlasFile, float scale = 0) { Initialize(); using (StreamReader atlasStream = new StreamReader(CCFileUtils.GetFileStream(atlasFile))) { atlas = new Atlas(atlasStream, "", new CocosSharpTextureLoader()); } SkeletonJson json = new SkeletonJson(atlas); json.Scale = scale == 0 ? (1 / Director.ContentScaleFactor) : scale; using (StreamReader skeletonDataStream = new StreamReader(CCFileUtils.GetFileStream(skeletonDataFile))) { SkeletonData skeletonData = json.ReadSkeletonData(skeletonDataStream); skeletonData.Name = skeletonDataFile; SetSkeletonData(skeletonData, true); } }
public void Initialize() { atlas = null; DebugSlots = false; DebugBones = false; PremultipliedAlpha = false; ImagesDirectory = string.Empty; DebugSlotColor = CCColor4B.Magenta; DebugBoneColor = CCColor4B.Blue; DebugJointColor = CCColor4B.Red; skeletonGeometry = new CCGeometryNode (); OpacityModifyRGB = true; AddChild(skeletonGeometry); AddChild(debugger); Schedule(); }
/// <returns>The atlas or null if it could not be loaded.</returns> public virtual Atlas GetAtlas () { if (atlasFile == null) { Debug.LogError("Atlas file not set for atlas asset: " + name, this); Clear(); return null; } if (materials == null || materials.Length == 0) { Debug.LogError("Materials not set for atlas asset: " + name, this); Clear(); return null; } if (atlas != null) return atlas; try { atlas = new Atlas(new StringReader(atlasFile.text), "", new MaterialsTextureLoader(this)); atlas.FlipV(); return atlas; } catch (Exception ex) { Debug.LogError("Error reading atlas file for atlas asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this); return null; } }
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(); }
public SkeletonJson (Atlas atlas) : this(new AtlasAttachmentLoader(atlas)) { }
protected override void LoadContent() { bool useNormalmapShader = false; Effect spineEffect; if (!useNormalmapShader) { // Two color tint effect. Note that you can also use the default BasicEffect instead. spineEffect = Content.Load <Effect>("spine-xna-example-content\\SpineEffect"); } else { spineEffect = Content.Load <Effect>("spine-xna-example-content\\SpineEffectNormalmap"); spineEffect.Parameters["Light0_Direction"].SetValue(new Vector3(-0.5265408f, 0.5735765f, -0.6275069f)); spineEffect.Parameters["Light0_Diffuse"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f)); spineEffect.Parameters["Light0_Specular"].SetValue(new Vector3(1, 0.9607844f, 0.8078432f)); spineEffect.Parameters["Light0_SpecularExponent"].SetValue(2.0f); } spineEffect.Parameters["World"].SetValue(Matrix.Identity); spineEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up)); skeletonRenderer = new SkeletonRenderer(GraphicsDevice); skeletonRenderer.PremultipliedAlpha = false; skeletonRenderer.Effect = spineEffect; skeletonDebugRenderer = new SkeletonDebugRenderer(GraphicsDevice); skeletonDebugRenderer.DisableAll(); skeletonDebugRenderer.DrawClipping = true; // String name = "spineboy-pro"; String name = "raptor-pro"; // String name = "tank-pro"; //String name = "coin-pro"; if (useNormalmapShader) { name = "raptor-pro"; // we only have normalmaps for raptor } String atlasName = name.Replace("-pro", "").Replace("-ess", ""); bool binaryData = false; Atlas atlas; if (!useNormalmapShader) { atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice)); } else { atlas = new Atlas(assetsFolder + atlasName + ".atlas", new XnaTextureLoader(GraphicsDevice, loadMultipleTextureLayers: true, textureSuffixes: new string[] { "", "_normals" })); } float scale = 1; if (name == "spineboy-pro") { scale = 0.6f; } if (name == "raptor-pro") { scale = 0.5f; } if (name == "tank-pro") { scale = 0.3f; } if (name == "coin-pro") { scale = 1; } SkeletonData skeletonData; if (binaryData) { SkeletonBinary binary = new SkeletonBinary(atlas); binary.Scale = scale; skeletonData = binary.ReadSkeletonData(assetsFolder + name + ".skel"); } else { SkeletonJson json = new SkeletonJson(atlas); json.Scale = scale; skeletonData = json.ReadSkeletonData(assetsFolder + name + ".json"); } skeleton = new Skeleton(skeletonData); if (name == "goblins-pro") { skeleton.SetSkin("goblin"); } // Define mixing between animations. AnimationStateData stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); if (name == "spineboy-pro") { skeleton.SetAttachment("head-bb", "head"); stateData.SetMix("run", "jump", 0.2f); stateData.SetMix("jump", "run", 0.4f); // Event handling for all animations. state.Start += Start; state.End += End; state.Complete += Complete; state.Event += Event; state.SetAnimation(0, "run", true); TrackEntry entry = state.AddAnimation(0, "jump", false, 0); entry.End += End; // Event handling for queued animations. state.AddAnimation(0, "run", true, 0); } else if (name == "raptor-pro") { state.SetAnimation(0, "walk", true); state.AddAnimation(1, "gun-grab", false, 2); } else if (name == "coin-pro") { state.SetAnimation(0, "animation", true); } else if (name == "tank-pro") { skeleton.X += 300; state.SetAnimation(0, "drive", true); } else { state.SetAnimation(0, "walk", true); } skeleton.X += 400; skeleton.Y += GraphicsDevice.Viewport.Height; skeleton.UpdateWorldTransform(); headSlot = skeleton.FindSlot("head"); }
protected override void LoadContent() { skeletonRenderer = new SkeletonRenderer(GraphicsDevice); this.atlas = new Atlas("Content/crab.atlas", new XnaTextureLoader(GraphicsDevice)); SkeletonJson json = new SkeletonJson(atlas); this.skeleton = new Skeleton(json.ReadSkeletonData("Content/crab-skeleton.json")); this.animationWalk = skeleton.Data.FindAnimation ("WalkLeft"); this.animationJump = skeleton.Data.FindAnimation ("Jump"); this.skeleton.SetSlotsToSetupPose(); // Without this the skin attachments won't be attached. See SetSkin. this.animation = 0; this.SetSkeletonStartPosition (); // used for debugging - draw the bones this.lineTexture = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color); this.lineTexture.SetData(new[]{Color.White}); this.textureMaps.Add(lineTexture); base.LoadContent (); }
protected override void LoadContent() { skeletonRenderer = new SkeletonRenderer(GraphicsDevice); Atlas atlas = new Atlas(GraphicsDevice, "data/spineboy.atlas"); SkeletonJson json = new SkeletonJson(atlas); skeleton = new Skeleton(json.readSkeletonData("spineboy", File.ReadAllText("data/spineboy.json"))); animation = skeleton.Data.FindAnimation("walk"); skeleton.RootBone.X = 320; skeleton.RootBone.Y = 440; skeleton.UpdateWorldTransform(); }
public CCSkeletonAnimation(string skeletonDataFile, Atlas atlas, float scale) : base(skeletonDataFile,atlas,scale) { this.initializer(); }
public SkeletonJson(Atlas atlas) { this.attachmentLoader = new AtlasAttachmentLoader(atlas); Scale = 1; }
protected override void LoadContent() { skeletonRenderer = new SkeletonRenderer(GraphicsDevice); Texture2D texture = Util.LoadTexture(GraphicsDevice, "data/goblins.png"); Atlas atlas = new Atlas("data/goblins.atlas", texture, texture.Width, texture.Height); SkeletonJson json = new SkeletonJson(atlas); skeleton = new Skeleton(json.ReadSkeletonData("data/goblins.json")); skeleton.SetSkin("goblingirl"); skeleton.SetSlotsToBindPose(); // Without this the skin attachments won't be attached. See SetSkin. animation = skeleton.Data.FindAnimation("walk"); skeleton.RootBone.X = 320; skeleton.RootBone.Y = 440; skeleton.UpdateWorldTransform(); }
protected override void LoadContent() { // Two color tint effect, comment line 76 to disable var spineEffect = Content.Load <Effect>("Content\\SpineEffect"); spineEffect.Parameters["World"].SetValue(Matrix.Identity); spineEffect.Parameters["View"].SetValue(Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 1.0f), Vector3.Zero, Vector3.Up)); skeletonRenderer = new SkeletonRenderer(GraphicsDevice); skeletonRenderer.PremultipliedAlpha = true; skeletonRenderer.Effect = spineEffect; // String name = "spineboy"; // String name = "goblins-mesh"; // String name = "raptor"; // String name = "tank"; // String name = "coin"; String name = "TwoColorTest"; bool binaryData = true; Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice)); float scale = 1; if (name == "spineboy") { scale = 0.6f; } if (name == "raptor") { scale = 0.5f; } if (name == "tank") { scale = 0.3f; } if (name == "TwoColorTest") { scale = 0.5f; } SkeletonData skeletonData; if (binaryData) { SkeletonBinary binary = new SkeletonBinary(atlas); binary.Scale = scale; skeletonData = binary.ReadSkeletonData(assetsFolder + name + ".skel"); } else { SkeletonJson json = new SkeletonJson(atlas); json.Scale = scale; skeletonData = json.ReadSkeletonData(assetsFolder + name + ".json"); } skeleton = new Skeleton(skeletonData); if (name == "goblins-mesh") { skeleton.SetSkin("goblin"); } // Define mixing between animations. AnimationStateData stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); if (name == "spineboy") { stateData.SetMix("run", "jump", 0.2f); stateData.SetMix("jump", "run", 0.4f); // Event handling for all animations. state.Start += Start; state.End += End; state.Complete += Complete; state.Event += Event; state.SetAnimation(0, "test", false); TrackEntry entry = state.AddAnimation(0, "jump", false, 0); entry.End += End; // Event handling for queued animations. state.AddAnimation(0, "run", true, 0); } else if (name == "raptor") { state.SetAnimation(0, "walk", true); state.AddAnimation(1, "gungrab", false, 2); } else if (name == "coin") { state.SetAnimation(0, "rotate", true); } else if (name == "tank") { state.SetAnimation(0, "drive", true); } else if (name == "TwoColorTest") { state.SetAnimation(0, "animation", true); } else { state.SetAnimation(0, "walk", true); } skeleton.X = 400 + (name == "tank" ? 300: 0); skeleton.Y = 580 + (name == "TwoColorTest" ? -300 : 0); skeleton.UpdateWorldTransform(); headSlot = skeleton.FindSlot("head"); }
private SpatialTypeRecord Load(GraphicsDevice device, string contentPath) { SpatialTypeRecord record = new SpatialTypeRecord(); using (Stream contentStream = TitleContainer.OpenStream(contentPath)) { using (XmlReader reader = XmlReader.Create(contentStream)) { XmlSkeletonDefElement xmldef = new XmlSkeletonDefElement(); xmldef.ReadXml(reader); Atlas atlas = new Atlas(xmldef.Atlas.Source, new XnaTextureLoader(device)); SkeletonJson json = new SkeletonJson(atlas); record.Data = json.ReadSkeletonData(xmldef.Skeleton.Source); record.DefaultAnimationMap = xmldef.BuildDefaultAnimationMap(); record.DirectedAnimationMap = xmldef.BuildDirectedAnimationMap(); record.ActivityMap = xmldef.BuildActivityMap(); record.DefaultAnimation = xmldef.ActivityMap.DefaultAnimation; } } _registered[contentPath] = record; return record; }
protected override void LoadContent() { skeletonRenderer = new SkeletonMeshRenderer(GraphicsDevice); skeletonRenderer.PremultipliedAlpha = true; // String name = "spineboy"; // String name = "goblins-mesh"; String name = "raptor"; Atlas atlas = new Atlas(assetsFolder + name + ".atlas", new XnaTextureLoader(GraphicsDevice)); SkeletonJson json = new SkeletonJson(atlas); if (name == "spineboy") { json.Scale = 0.6f; } if (name == "raptor") { json.Scale = 0.5f; } skeleton = new Skeleton(json.ReadSkeletonData(assetsFolder + name + ".json")); if (name == "goblins-mesh") { skeleton.SetSkin("goblin"); } // Define mixing between animations. AnimationStateData stateData = new AnimationStateData(skeleton.Data); state = new AnimationState(stateData); if (name == "spineboy") { stateData.SetMix("run", "jump", 0.2f); stateData.SetMix("jump", "run", 0.4f); // Event handling for all animations. state.Start += Start; state.End += End; state.Complete += Complete; state.Event += Event; state.SetAnimation(0, "test", false); TrackEntry entry = state.AddAnimation(0, "jump", false, 0); entry.End += End; // Event handling for queued animations. state.AddAnimation(0, "run", true, 0); } else if (name == "raptor") { state.SetAnimation(0, "walk", true); state.SetAnimation(1, "empty", false); state.AddAnimation(1, "gungrab", false, 2); } else { state.SetAnimation(0, "walk", true); } skeleton.X = 400; skeleton.Y = 590; skeleton.UpdateWorldTransform(); headSlot = skeleton.FindSlot("head"); }
void OnCurLoadFinish() { //先临时验证一下代码构造spine动画,两个atlas的设计问题较多,必须要休整一下播放组件 GameObject curObj=new GameObject(); curObj.name="spine-cur"; SkeletonAnimationCL ani = curObj.AddComponent<SkeletonAnimationCL>(); //AtlasAsset assAtlas = new AtlasAsset(); //assAtlas.materials = new Material[1]; //assAtlas.materials[0] = new Material(Shader.Find("Spine/Skeleton")); //assAtlas.materials[0].mainTexture = curAtlasTex; Dictionary<string, Texture2D> texs = new Dictionary<string, Texture2D>(); texs["cur.png"] = curAtlasTex; var atlas = new Spine.Atlas(new System.IO.StringReader(curAtlas), "", new TextureLoad(texs)); atlas.FlipV(); //assAtlas.SetAtlas(atlas); Spine.SkeletonJson sjson = new Spine.SkeletonJson(atlas); sjson.Scale = 1.0f/64.0f; var data=sjson.ReadSkeletonData(new System.IO.StringReader(curSK)); ani.skeleton = new Spine.Skeleton(data); ani.Reset(); ani.state.SetAnimation(0, "idle", true); }