예제 #1
0
            public static Option <MeshSet> TryCreate(
                FileInfo file,
                Paths paths,
                IEnumerable <FileInfo> meshes,
                ILogger logger)
            {
                var matcher = NamePattern.Match(file.Name);

                if (!matcher.Success || matcher.Groups[2].Value.ToLower() != "base")
                {
                    return(None);
                }

                var key     = matcher.Groups[1].Value;
                var meshSet = Try(new MeshSet(key, file, paths));

                meshSet.ToEither().LeftAsEnumerable().Iter(e =>
                {
                    logger.LogError(e, "Failed to read mesh resource '{}'.", file.Path);
                });

                var result = meshSet.ToOption();

                result.Iter(m => meshes.Iter(m.TryAdd));

                return(result);
            }
예제 #2
0
            public void TryAdd(FileInfo file)
            {
                IEnumerable <Task> CreateTasks(FileInfo f)
                {
                    if (f.Directory != File.Directory || f == File)
                    {
                        return(Lst <Task> .Empty);
                    }

                    var m = NamePattern.Match(f.Name);

                    if (!m.Success || m.Groups[1].Value != Key)
                    {
                        return(Lst <Task> .Empty);
                    }

                    var key = m.Groups[2].Value;

                    if (key.ToLower().StartsWith("morphs"))
                    {
                        Lst <string> shapes;

                        using (var mesh = ResourceLoader.Load <ArrayMesh>(f.Path))
                        {
                            shapes = mesh.GetBlendShapeNames().Freeze();
                        }

                        string NormalizeName(string name)
                        {
                            const string prefix = "morphs_";

                            if (name.ToLower().StartsWith(prefix))
                            {
                                return(name.Substring(prefix.Length));
                            }

                            return(name);
                        }

                        return
                            (from shape in shapes
                             from surface in Surfaces
                             select new BlendShapeTask(NormalizeName(shape), f, surface, shape, this));
                    }

                    return(Surfaces.Map(s => new MorphedMeshTask(key, f, s, this)).Freeze());
                }

                var newTasks = CreateTasks(file);

                _tasks = _tasks.Append(newTasks).Freeze();
            }