Ejemplo n.º 1
0
 public override bool FileExists(string path)
 {
     return(index.ContainsKey(AssetPath.CorrectSlashes(path)));
 }
Ejemplo n.º 2
0
        public override void SetAttributes(string path, AssetAttributes attributes)
        {
            var desc = GetDescriptor(path);

            index[AssetPath.CorrectSlashes(path)] = desc;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Generates Tangerine Font.
        /// </summary>
        /// <param name="config"> Tangerine Font Config. </param>
        /// <param name="assetDirectory"> Path to asset directory. </param>
        /// <param name="outputPath"> Path for Tangerine Font and it's textures </param>
        public static void GenerateFont(TftConfig config, string assetDirectory, string outputPath)
        {
            var fontCharCollection = new FontCharCollection();
            var chars = new CharCache(config.Height, null, fontCharCollection.Textures)
            {
                Padding        = config.Padding,
                MinTextureSize = config.TextureSize,
                MaxTextureSize = config.TextureSize,
            };
            var missingCharacters = new List <char>();
            var margin            = new Vector2(config.Margin * .5f);

            foreach (var charSet in config.CharSets)
            {
                var fontPath = AssetPath.Combine(assetDirectory, charSet.Font);
                if (!File.Exists(fontPath))
                {
                    Console.WriteLine($"Missing font: {fontPath}\n Please ensure font existence!!!");
                    return;
                }
                var fontData = File.ReadAllBytes(fontPath);
                chars.FontRenderer = new FontRenderer(fontData)
                {
                    LcdSupported = false
                };
                missingCharacters.Clear();
                foreach (var c in charSet.Chars)
                {
                    if (config.ExcludeChars.Any(character => character == c))
                    {
                        continue;
                    }
                    var fontChar = chars.Get(c);
                    if (fontChar == FontChar.Null)
                    {
                        missingCharacters.Add(c);
                        continue;
                    }
                    fontChar.ACWidths += margin;
                    if (config.IsSdf)
                    {
                        fontChar.ACWidths       *= config.SdfScale;
                        fontChar.Height         *= config.SdfScale;
                        fontChar.Width          *= config.SdfScale;
                        fontChar.Padding        *= config.SdfScale;
                        fontChar.VerticalOffset *= config.SdfScale;
                        if (fontChar.KerningPairs != null)
                        {
                            for (int i = 0; i < fontChar.KerningPairs.Count; i++)
                            {
                                var pair = fontChar.KerningPairs[i];
                                pair.Kerning            *= config.SdfScale;
                                fontChar.KerningPairs[i] = pair;
                            }
                        }
                    }
                    fontCharCollection.Add(fontChar);
                }
                if (missingCharacters.Count > 0)
                {
                    Console.WriteLine($"Characters: {string.Join("", missingCharacters)} -- are missing in font {charSet.Font}");
                }
                GenerateKerningPairs(fontCharCollection, chars.FontRenderer.Face, config);
            }
            if (config.IsSdf)
            {
                foreach (var texture in fontCharCollection.Textures)
                {
                    SdfConverter.ConvertToSdf(texture.GetPixels(), texture.ImageSize.Width, texture.ImageSize.Height, config.Padding / 2);
                }
            }
            using (var font = new Font(fontCharCollection)) {
                SaveAsTft(font, config, assetDirectory, outputPath);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generates Tangerine Font.
        /// </summary>
        /// <param name="configPath"> Path to configuration file relative to <paramref name="assetDirectory"/>. </param>
        /// <param name="assetDirectory"> Path to asset directory. </param>
        public static void GenerateFont(string configPath, string assetDirectory)
        {
            var config = InternalPersistence.Instance.ReadObjectFromFile <TftConfig>(AssetPath.Combine(assetDirectory, configPath));

            GenerateFont(config, assetDirectory, Path.ChangeExtension(configPath, null));
        }
Ejemplo n.º 5
0
        private static string FixPath(string modelPath, string path)
        {
            var baseDir = Path.GetDirectoryName(modelPath);

            return(AssetPath.CorrectSlashes(Path.Combine(AssetPath.CorrectSlashes(baseDir), AssetPath.CorrectSlashes(path))));
        }
Ejemplo n.º 6
0
        public Model3DAttachment Parse(string modelPath, bool useBundle = true)
        {
            modelPath = AssetPath.CorrectSlashes(
                Path.Combine(Path.GetDirectoryName(modelPath) ?? "",
                             Path.GetFileNameWithoutExtension(AssetPath.CorrectSlashes(modelPath) ?? "")
                             ));
            var attachmentPath = modelPath + Model3DAttachment.FileExtension;

            try {
                ModelAttachmentFormat modelAttachmentFormat;
                if (useBundle)
                {
                    if (!AssetBundle.Current.FileExists(attachmentPath))
                    {
                        return(null);
                    }
                    modelAttachmentFormat = Serialization.ReadObject <ModelAttachmentFormat>(attachmentPath);
                }
                else
                {
                    if (!File.Exists(attachmentPath))
                    {
                        return(null);
                    }
                    modelAttachmentFormat = Serialization.ReadObjectFromFile <ModelAttachmentFormat>(attachmentPath);
                }

                var attachment = new Model3DAttachment {
                    ScaleFactor = modelAttachmentFormat.ScaleFactor
                };
                if (modelAttachmentFormat.MeshOptions != null)
                {
                    foreach (var meshOptionFormat in modelAttachmentFormat.MeshOptions)
                    {
                        var meshOption = new Model3DAttachment.MeshOption()
                        {
                            Id            = meshOptionFormat.Key,
                            HitTestTarget = meshOptionFormat.Value.HitTestTarget
                        };
                        if (!string.IsNullOrEmpty(meshOptionFormat.Value.CullMode))
                        {
                            switch (meshOptionFormat.Value.CullMode)
                            {
                            case "None":
                                meshOption.CullMode = CullMode.None;
                                break;

                            case "CullClockwise":
                                meshOption.CullMode = CullMode.CullClockwise;
                                break;

                            case "CullCounterClockwise":
                                meshOption.CullMode = CullMode.CullCounterClockwise;
                                break;
                            }
                        }
                        attachment.MeshOptions.Add(meshOption);
                    }
                }

                if (modelAttachmentFormat.Animations != null)
                {
                    foreach (var animationFormat in modelAttachmentFormat.Animations)
                    {
                        var animation = new Model3DAttachment.Animation {
                            Name = animationFormat.Key,
                        };

                        if (animationFormat.Value.Markers != null)
                        {
                            foreach (var markerFormat in animationFormat.Value.Markers)
                            {
                                var markerData = new Model3DAttachment.MarkerData {
                                    Marker = new Marker {
                                        Id    = markerFormat.Key,
                                        Frame = FixFrame(markerFormat.Value.Frame)
                                    }
                                };
                                if (!string.IsNullOrEmpty(markerFormat.Value.Action))
                                {
                                    switch (markerFormat.Value.Action)
                                    {
                                    case "Start":
                                        markerData.Marker.Action = MarkerAction.Play;
                                        break;

                                    case "Stop":
                                        markerData.Marker.Action = MarkerAction.Stop;
                                        break;

                                    case "Jump":
                                        markerData.Marker.Action = MarkerAction.Jump;
                                        markerData.Marker.JumpTo = markerFormat.Value.JumpTarget;
                                        break;
                                    }
                                }
                                if (markerFormat.Value.Blending != null)
                                {
                                    markerData.Blending = new BlendingOption((int)markerFormat.Value.Blending);
                                }
                                if (markerFormat.Value.SourceMarkersBlending != null)
                                {
                                    foreach (var elem in markerFormat.Value.SourceMarkersBlending)
                                    {
                                        animation.MarkersBlendings.Add(new Model3DAttachment.MarkerBlendingData {
                                            DestMarkerId   = markerFormat.Key,
                                            SourceMarkerId = elem.Key,
                                            Blending       = new BlendingOption(elem.Value),
                                        });
                                    }
                                }

                                animation.Markers.Add(markerData);
                            }
                        }

                        if (animationFormat.Value.Blending != null)
                        {
                            animation.Blending = new BlendingOption((int)animationFormat.Value.Blending);
                        }

                        if (animationFormat.Value.Nodes != null)
                        {
                            animation.Nodes = new ObservableCollection <Model3DAttachment.NodeData>(
                                animationFormat.Value.Nodes.Select(n => new Model3DAttachment.NodeData {
                                Id = n
                            }));
                        }

                        if (animationFormat.Value.IgnoredNodes != null && animationFormat.Value.IgnoredNodes.Count > 0)
                        {
                            if (animation.Nodes.Count > 0)
                            {
                                throw new Exception("Conflict between 'Nodes' and 'IgnoredNodes' in animation '{0}", animation.Name);
                            }
                            animation.IgnoredNodes = new ObservableCollection <Model3DAttachment.NodeData>(
                                animationFormat.Value.IgnoredNodes.Select(n => new Model3DAttachment.NodeData {
                                Id = n
                            }));
                        }

                        attachment.Animations.Add(animation);
                    }
                }

                if (modelAttachmentFormat.MaterialEffects != null)
                {
                    foreach (var materialEffectFormat in modelAttachmentFormat.MaterialEffects)
                    {
                        var materialEffect = new Model3DAttachment.MaterialEffect()
                        {
                            Name         = materialEffectFormat.Key,
                            MaterialName = materialEffectFormat.Value.MaterialName,
                            Path         = FixPath(modelPath, materialEffectFormat.Value.Path)
                        };
                        if (materialEffectFormat.Value.Blending != null)
                        {
                            materialEffect.Blending = new BlendingOption((int)materialEffectFormat.Value.Blending);
                        }
                        attachment.MaterialEffects.Add(materialEffect);
                    }
                }

                return(attachment);
            } catch (System.Exception e) {
                throw new System.Exception(modelPath + ": " + e.Message, e);
            }
        }