private static IEnumerable <NodeInformation> GetAvailableNodesForLink(AssetViewModel viewModel, SpriteStudioSheet sheet) { var parentModelAsset = viewModel.AssetItem.Package.Session.FindAssetFromProxyObject(sheet); var modelAsset = parentModelAsset?.Asset as SpriteStudioModelAsset; if (modelAsset != null) { return(modelAsset.NodeNames.Select(nodeName => new NodeInformation(nodeName, 0, true))); } return(Enumerable.Empty <NodeInformation>()); }
protected override Task <ResultStatus> DoCommandOverride(ICommandContext commandContext) { var nodes = new List <SpriteStudioNode>(); string modelName; if (!SpriteStudioXmlImport.ParseModel(Parameters.Source, nodes, out modelName)) { return(null); } var cells = new List <SpriteStudioCell>(); var textures = new List <UFile>(); if (!SpriteStudioXmlImport.ParseCellMaps(Parameters.Source, textures, cells)) { return(null); } var anims = new List <SpriteStudioAnim>(); if (!SpriteStudioXmlImport.ParseAnimations(Parameters.Source, anims)) { return(null); } var assetManager = new ContentManager(MicrothreadLocalDatabases.ProviderService); var sheet = new SpriteSheet(); foreach (var cell in cells) { var sprite = new Sprite(cell.Name, AttachedReferenceManager.CreateProxyObject <Texture>(AssetId.Empty, Parameters.BuildTextures[cell.TextureIndex])) { Region = cell.Rectangle, Center = cell.Pivot, IsTransparent = true }; sheet.Sprites.Add(sprite); } var nodeMapping = nodes.Select((x, i) => new { Name = x.Name, Index = i }).ToDictionary(x => x.Name, x => x.Index); //fill up some basic data for our model using the first animation in the array var anim = anims[0]; foreach (var data in anim.NodesData) { int nodeIndex; if (!nodeMapping.TryGetValue(data.Key, out nodeIndex)) { continue; } var node = nodes[nodeIndex]; foreach (var pair in data.Value.Data) { var tag = pair.Key; if (pair.Value.All(x => x["time"] != "0")) { continue; } var value = pair.Value.First()["value"]; //do we always have a frame 0? should be the case actually switch (tag) { case "POSX": node.BaseState.Position.X = float.Parse(value, CultureInfo.InvariantCulture); break; case "POSY": node.BaseState.Position.Y = float.Parse(value, CultureInfo.InvariantCulture); break; case "ROTZ": node.BaseState.RotationZ = MathUtil.DegreesToRadians(float.Parse(value, CultureInfo.InvariantCulture)); break; case "PRIO": node.BaseState.Priority = int.Parse(value, CultureInfo.InvariantCulture); break; case "SCLX": node.BaseState.Scale.X = float.Parse(value, CultureInfo.InvariantCulture); break; case "SCLY": node.BaseState.Scale.Y = float.Parse(value, CultureInfo.InvariantCulture); break; case "ALPH": node.BaseState.Transparency = float.Parse(value, CultureInfo.InvariantCulture); break; case "HIDE": node.BaseState.Hide = int.Parse(value, CultureInfo.InvariantCulture); break; case "FLPH": node.BaseState.HFlipped = int.Parse(value, CultureInfo.InvariantCulture); break; case "FLPV": node.BaseState.VFlipped = int.Parse(value, CultureInfo.InvariantCulture); break; case "CELL": node.BaseState.SpriteId = int.Parse(value, CultureInfo.InvariantCulture); break; case "COLV": var color = new Color4(Color.FromBgra(int.Parse(value, CultureInfo.InvariantCulture))); node.BaseState.BlendColor = colorSpace == ColorSpace.Linear ? color.ToLinear() : color; break; case "COLB": node.BaseState.BlendType = (SpriteStudioBlending)int.Parse(value, CultureInfo.InvariantCulture); break; case "COLF": node.BaseState.BlendFactor = float.Parse(value, CultureInfo.InvariantCulture); break; } } } var spriteStudioSheet = new SpriteStudioSheet { NodesInfo = nodes, SpriteSheet = sheet }; assetManager.Save(Url, spriteStudioSheet); return(Task.FromResult(ResultStatus.Successful)); }