Ejemplo n.º 1
0
 public DrawRunner(
     IDrawRunnerOptions options,
     IProcessRunner processRunner,
     IRepositoryDataLoader loader,
     ITreeBuilder treeBuilder,
     ISimplifier simplifier,
     IFileSystem fileSystem,
     ITreeRendererFactory treeRendererFactory,
     IGraphVizWriterFactory graphVizFactory,
     IRemoteHelper remoteHelper,
     ITextWriterFactory textWriterFactory,
     IExternalAppPathProvider appPathProvider,
     IBranchingStrategyProvider strategyProvider,
     ILogger <DrawRunner> log)
     : base(options, log)
 {
     _processRunner       = processRunner;
     _loader              = loader;
     _treeBuilder         = treeBuilder;
     _simplifier          = simplifier;
     _fileSystem          = fileSystem;
     _treeRendererFactory = treeRendererFactory;
     _graphVizFactory     = graphVizFactory;
     _remoteHelper        = remoteHelper;
     _textWriterFactory   = textWriterFactory;
     _appPathProvider     = appPathProvider;
     _strategyProvider    = strategyProvider;
 }
Ejemplo n.º 2
0
        public DefaultDependencyResolverTest()
        {
            this.simplifier = new Simplifier();
            this.differentiator = new Differentiator();

            this.resolver = new DefaultDependencyResolver(
                new Type[] { typeof(ISimplifier), typeof(IDifferentiator) },
                new object[] { this.simplifier, this.differentiator });
        }
        public DefaultDependencyResolverTest()
        {
            this.simplifier     = new Simplifier();
            this.differentiator = new Differentiator();

            this.resolver = new DefaultDependencyResolver(
                new Type[] { typeof(ISimplifier), typeof(IDifferentiator) },
                new object[] { this.simplifier, this.differentiator });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Derivative" /> class.
        /// </summary>
        /// <param name="differentiator">The differentiator.</param>
        /// <param name="simplifier">The simplifier.</param>
        /// <param name="args">The arguments.</param>
        /// <exception cref="System.ArgumentNullException"><paramref name="args"/> is null.</exception>
        public Derivative(IDifferentiator differentiator, ISimplifier simplifier, IExpression[] args)
            : base(args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            this.Differentiator = differentiator;
            this.Simplifier     = simplifier;
        }
Ejemplo n.º 5
0
 public StringSimplifier(
     ISimplifier simplifier,
     ITokenizer tokenizer,
     IExpressionFormatter formatter,
     IModelBuilder modelBuilder)
 {
     mSimplifier   = simplifier;
     mTokenizer    = tokenizer;
     mFormatter    = formatter;
     mModelBuilder = modelBuilder;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Processor" /> class.
        /// </summary>
        /// <param name="lexer">The lexer.</param>
        /// <param name="parser">The parser.</param>
        /// <param name="simplifier">The simplifier.</param>
        /// <param name="differentiator">The differentiator.</param>
        /// <param name="parameters">The collection of parameters.</param>
        public Processor(ILexer lexer, IParser parser, ISimplifier simplifier, IDifferentiator differentiator, ExpressionParameters parameters)
        {
            Lexer          = lexer;
            Simplifier     = simplifier;
            Differentiator = differentiator;
            Parser         = parser;

            Parameters    = parameters;
            NumeralSystem = NumeralSystem.Decimal;
            DoSimplify    = true;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Processor"/> class.
 /// </summary>
 /// <param name="lexer">The lexer.</param>
 /// <param name="parser">The parser.</param>
 /// <param name="simplifier">The simplifier.</param>
 /// <param name="differentiator">The differentiator.</param>
 public Processor(
     ILexer lexer,
     IParser parser,
     ISimplifier simplifier,
     IDifferentiator differentiator)
     : this(
         lexer,
         parser,
         simplifier,
         differentiator,
         new TypeAnalyzer(),
         new ExpressionParameters(AngleMeasurement.Degree, new ParameterCollection(), new FunctionCollection()))
 {
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Simplify"/> class.
 /// </summary>
 /// <param name="simplifier">The simplifier.</param>
 /// <param name="expression">The argument of function.</param>
 public Simplify(ISimplifier simplifier, IExpression expression) : base(expression)
 {
     this.Simplifier = simplifier;
 }
Ejemplo n.º 9
0
        public IEnumerator CreateImpl()
        {
            try
            {
                using (m_queue = new JobQueue(8))
                {
                    Stopwatch sw = new Stopwatch();

                    AssetDatabase.Refresh();
                    AssetDatabase.SaveAssets();

                    sw.Reset();
                    sw.Start();

                    EditorUtility.DisplayProgressBar("Bake HLOD", "Initialize Bake", 0.0f);


                    TerrainData data = m_hlod.TerrainData;

                    m_size = data.size;

                    m_heightmap = new Heightmap(data.heightmapResolution, data.heightmapResolution, data.size,
                                                data.GetHeights(0, 0, data.heightmapResolution, data.heightmapResolution));

                    string materialPath = AssetDatabase.GUIDToAssetPath(m_hlod.MaterialGUID);
                    m_terrainMaterial = AssetDatabase.LoadAssetAtPath <Material>(materialPath);
                    if (m_terrainMaterial == null)
                    {
                        m_terrainMaterial = new Material(Shader.Find("Standard"));
                    }

                    m_terrainMaterialInstanceId = m_terrainMaterial.GetInstanceID();
                    m_terrainMaterialName       = m_terrainMaterial.name;

                    using (m_alphamaps = new DisposableList <WorkingTexture>())
                        using (m_layers = new DisposableList <Layer>())
                        {
                            for (int i = 0; i < data.alphamapTextures.Length; ++i)
                            {
                                m_alphamaps.Add(new WorkingTexture(Allocator.Persistent, data.alphamapTextures[i]));
                            }

                            for (int i = 0; i < data.terrainLayers.Length; ++i)
                            {
                                m_layers.Add(new Layer(data.terrainLayers[i]));
                            }


                            QuadTreeSpaceSplitter splitter =
                                new QuadTreeSpaceSplitter(0.0f);

                            SpaceNode rootNode = splitter.CreateSpaceTree(m_hlod.GetBounds(), m_hlod.ChunkSize * 2.0f,
                                                                          m_hlod.transform.position, null, progress => { });

                            EditorUtility.DisplayProgressBar("Bake HLOD", "Create mesh", 0.0f);

                            using (DisposableList <HLODBuildInfo> buildInfos = CreateBuildInfo(data, rootNode))
                            {
                                yield return(m_queue.WaitFinish());

                                //Write material & textures

                                for (int i = 0; i < buildInfos.Count; ++i)
                                {
                                    int curIndex = i;
                                    m_queue.EnqueueJob(() =>
                                    {
                                        ISimplifier simplifier = (ISimplifier)Activator.CreateInstance(m_hlod.SimplifierType,
                                                                                                       new object[] { m_hlod.SimplifierOptions });
                                        simplifier.SimplifyImmidiate(buildInfos[curIndex]);
                                    });
                                }

                                EditorUtility.DisplayProgressBar("Bake HLOD", "Simplify meshes", 0.0f);
                                yield return(m_queue.WaitFinish());

                                Debug.Log("[TerrainHLOD] Simplify: " + sw.Elapsed.ToString("g"));
                                sw.Reset();
                                sw.Start();
                                EditorUtility.DisplayProgressBar("Bake HLOD", "Make border", 0.0f);

                                for (int i = 0; i < buildInfos.Count; ++i)
                                {
                                    HLODBuildInfo info = buildInfos[i];
                                    m_queue.EnqueueJob(() =>
                                    {
                                        for (int oi = 0; oi < info.WorkingObjects.Count; ++oi)
                                        {
                                            WorkingObject o       = info.WorkingObjects[oi];
                                            int borderVertexCount = m_hlod.BorderVertexCount * Mathf.RoundToInt(Mathf.Pow(2.0f, (float)info.Distances[oi]));
                                            using (WorkingMesh m = MakeBorder(o.Mesh, info.Heightmap, borderVertexCount))
                                            {
                                                ReampUV(m, info.Heightmap);
                                                o.SetMesh(MakeFillHoleMesh(m));
                                            }
                                        }
                                    });
                                }
                                yield return(m_queue.WaitFinish());

                                Debug.Log("[TerrainHLOD] Make Border: " + sw.Elapsed.ToString("g"));
                                sw.Reset();
                                sw.Start();


                                for (int i = 0; i < buildInfos.Count; ++i)
                                {
                                    SpaceNode     node = buildInfos[i].Target;
                                    HLODBuildInfo info = buildInfos[i];
                                    if (node.HasChild() == false)
                                    {
                                        SpaceNode parent = node.ParentNode;
                                        node.ParentNode = null;

                                        GameObject go = new GameObject(buildInfos[i].Name);

                                        for (int wi = 0; wi < info.WorkingObjects.Count; ++wi)
                                        {
                                            WorkingObject wo       = info.WorkingObjects[wi];
                                            GameObject    targetGO = null;
                                            if (wi == 0)
                                            {
                                                targetGO = go;
                                            }
                                            else
                                            {
                                                targetGO = new GameObject(wi.ToString());
                                                targetGO.transform.SetParent(go.transform, false);
                                            }

                                            List <Material> materials = new List <Material>();
                                            for (int mi = 0; mi < wo.Materials.Count; ++mi)
                                            {
                                                WorkingMaterial wm = wo.Materials[mi];
                                                if (wm.NeedWrite() == false)
                                                {
                                                    materials.Add(wm.ToMaterial());
                                                    continue;
                                                }

                                                Material mat          = new Material(wm.ToMaterial());
                                                string[] textureNames = wm.GetTextureNames();
                                                for (int ti = 0; ti < textureNames.Length; ++ti)
                                                {
                                                    WorkingTexture wt  = wm.GetTexture(textureNames[ti]);
                                                    Texture2D      tex = wt.ToTexture();
                                                    tex.wrapMode = wt.WrapMode;
                                                    mat.name     = targetGO.name + "_Mat";
                                                    mat.SetTexture(textureNames[ti], tex);
                                                }
                                                mat.EnableKeyword("_NORMALMAP");
                                                materials.Add(mat);
                                            }

                                            targetGO.AddComponent <MeshFilter>().sharedMesh        = wo.Mesh.ToMesh();
                                            targetGO.AddComponent <MeshRenderer>().sharedMaterials = materials.ToArray();
                                        }

                                        go.transform.SetParent(m_hlod.transform, false);
                                        m_hlod.AddGeneratedResource(go);

                                        parent.Objects.Add(go);
                                        buildInfos.RemoveAt(i);
                                        i -= 1;
                                    }
                                }

                                //controller
                                IStreamingBuilder builder =
                                    (IStreamingBuilder)Activator.CreateInstance(m_hlod.StreamingType,
                                                                                new object[] { m_hlod, m_hlod.StreamingOptions });

                                builder.Build(rootNode, buildInfos, m_hlod.gameObject, m_hlod.CullDistance, m_hlod.LODDistance, true, false,
                                              progress =>
                                {
                                    EditorUtility.DisplayProgressBar("Bake HLOD", "Storing results.",
                                                                     0.75f + progress * 0.25f);
                                });

                                Debug.Log("[TerrainHLOD] Build: " + sw.Elapsed.ToString("g"));
                            }
                        }

                    EditorUtility.SetDirty(m_hlod.gameObject);
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
                GC.Collect();
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Derivative" /> class.
 /// </summary>
 /// <param name="differentiator">The differentiator.</param>
 /// <param name="simplifier">The simplifier.</param>
 /// <param name="expression">The expression.</param>
 public Derivative(IDifferentiator differentiator, ISimplifier simplifier, IExpression expression)
     : this(differentiator, simplifier, new[] { expression })
 {
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Del"/> class.
 /// </summary>
 /// <param name="differentiator">The differentiator.</param>
 /// <param name="simplifier">The simplifier.</param>
 /// <param name="expression">The expression.</param>
 public Del(IDifferentiator differentiator, ISimplifier simplifier, IExpression expression)
     : base(expression)
 {
     this.Differentiator = differentiator;
     this.Simplifier     = simplifier;
 }
Ejemplo n.º 12
0
 public FileRepository(IServiceProvider serviceProvider, DataRepositoryContext context, ISimplifier simplifier, IDataEventHandlers eventHandlers = null)
     : base(serviceProvider, context, eventHandlers)
 {
     _simplifier = simplifier;
 }
Ejemplo n.º 13
0
        public static IEnumerator Create(HLOD hlod)
        {
            try
            {
                Stopwatch sw = new Stopwatch();

                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();

                sw.Reset();
                sw.Start();

                hlod.ConvertedPrefabObjects.Clear();
                hlod.GeneratedObjects.Clear();

                Bounds bounds = hlod.GetBounds();

                List <GameObject> hlodTargets = ObjectUtils.HLODTargets(hlod.gameObject);
                ISpaceSplitter    spliter     = new QuadTreeSpaceSplitter(5.0f);
                SpaceNode         rootNode    = spliter.CreateSpaceTree(bounds, hlod.ChunkSize, hlod.transform.position, hlodTargets, progress =>
                {
                    EditorUtility.DisplayProgressBar("Bake HLOD", "Splitting space", progress * 0.25f);
                });

                if (hlodTargets.Count == 0)
                {
                    EditorUtility.DisplayDialog("Empty HLOD sources.",
                                                "There are no objects to be included in the HLOD.",
                                                "Ok");
                    yield break;
                }


                using (DisposableList <HLODBuildInfo> buildInfos = CreateBuildInfo(rootNode, hlod.MinObjectSize))
                {
                    if (buildInfos.Count == 0 || buildInfos[0].WorkingObjects.Count == 0)
                    {
                        EditorUtility.DisplayDialog("Empty HLOD sources.",
                                                    "There are no objects to be included in the HLOD.",
                                                    "Ok");
                        yield break;
                    }


                    Debug.Log("[HLOD] Splite space: " + sw.Elapsed.ToString("g"));
                    sw.Reset();
                    sw.Start();

                    ISimplifier simplifier = (ISimplifier)Activator.CreateInstance(hlod.SimplifierType,
                                                                                   new object[] { hlod.SimplifierOptions });
                    for (int i = 0; i < buildInfos.Count; ++i)
                    {
                        yield return(new BranchCoroutine(simplifier.Simplify(buildInfos[i])));
                    }

                    yield return(new WaitForBranches(progress =>
                    {
                        EditorUtility.DisplayProgressBar("Bake HLOD", "Simplify meshes",
                                                         0.25f + progress * 0.25f);
                    }));

                    Debug.Log("[HLOD] Simplify: " + sw.Elapsed.ToString("g"));
                    sw.Reset();
                    sw.Start();


                    using (IBatcher batcher =
                               (IBatcher)Activator.CreateInstance(hlod.BatcherType, new object[] { hlod.BatcherOptions }))
                    {
                        batcher.Batch(hlod.transform.position, buildInfos,
                                      progress =>
                        {
                            EditorUtility.DisplayProgressBar("Bake HLOD", "Generating combined static meshes.",
                                                             0.5f + progress * 0.25f);
                        });
                    }
                    Debug.Log("[HLOD] Batch: " + sw.Elapsed.ToString("g"));
                    sw.Reset();
                    sw.Start();


                    IStreamingBuilder builder =
                        (IStreamingBuilder)Activator.CreateInstance(hlod.StreamingType,
                                                                    new object[] { hlod, hlod.StreamingOptions });
                    builder.Build(rootNode, buildInfos, hlod.gameObject, hlod.CullDistance, hlod.LODDistance, false, true,
                                  progress =>
                    {
                        EditorUtility.DisplayProgressBar("Bake HLOD", "Storing results.",
                                                         0.75f + progress * 0.25f);
                    });
                    Debug.Log("[HLOD] Build: " + sw.Elapsed.ToString("g"));
                    sw.Reset();
                    sw.Start();

                    EditorUtility.SetDirty(hlod.gameObject);
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
Ejemplo n.º 14
0
 public SimplifierTest()
 {
     simplifier = new Simplifier();
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Derivative" /> class.
 /// </summary>
 /// <param name="differentiator">The differentiator.</param>
 /// <param name="simplifier">The simplifier.</param>
 /// <param name="expression">The expression.</param>
 /// <param name="variable">The variable.</param>
 /// <param name="point">The point of derivation.</param>
 public Derivative(IDifferentiator differentiator, ISimplifier simplifier, IExpression expression, Variable variable, Number point)
     : this(differentiator, simplifier, new[] { expression, variable, point })
 {
 }
 public SymbolicSimplificationFacade(IExpressionFormatter expressionFormatter, IAggregateSimplifier simplifier, IModelBuilder modelBuilder)
 {
     mExpressionFormatter = expressionFormatter;
     mSimplifier          = simplifier;
     mModelBuilder        = modelBuilder;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Parser" /> class.
 /// </summary>
 /// <param name="lexer">The lexer.</param>
 /// <param name="simplifier">The simplifier.</param>
 /// <param name="factory">The factory.</param>
 public Parser(ILexer lexer, ISimplifier simplifier, IExpressionFactory factory)
 {
     this.lexer = lexer;
     this.simplifier = simplifier;
     this.factory = factory;
 }
Ejemplo n.º 18
0
 public static async Task <string> GenerateIdName <TData, TId>(
     this DataRepository <TData, TId> repository,
     ISimplifier simplifier,
     string source,
     Func <string, (string body, string suffix)> split,
Ejemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Differentiator"/> class.
 /// </summary>
 /// <param name="simplifier">The simplifier.</param>
 public Differentiator(ISimplifier simplifier)
 {
     this.simplifier = simplifier;
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExpressionFactory"/> class.
 /// </summary>
 public ExpressionFactory(IDifferentiator differentiator, ISimplifier simplifier)
 {
     this.differentiator = differentiator;
     this.simplifier     = simplifier;
 }
Ejemplo n.º 21
0
        public static IEnumerator Create(HLOD hlod)
        {
            try
            {
                Stopwatch sw = new Stopwatch();

                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();

                sw.Reset();
                sw.Start();

                Bounds bounds = hlod.GetBounds();

                List <GameObject> hlodTargets = ObjectUtils.HLODTargets(hlod.gameObject);
                ISpaceSplitter    spliter     = new QuadTreeSpaceSplitter(hlod.transform.position, 5.0f, hlod.MinSize);
                SpaceNode         rootNode    = spliter.CreateSpaceTree(bounds, hlodTargets, progress =>
                {
                    EditorUtility.DisplayProgressBar("Bake HLOD", "Splitting space", progress * 0.25f);
                });

                List <HLODBuildInfo> buildInfos = CreateBuildInfo(rootNode, hlod.ThresholdSize);

                Debug.Log("[HLOD] Splite space: " + sw.Elapsed.ToString("g"));
                sw.Reset();
                sw.Start();

                ISimplifier simplifier = (ISimplifier)Activator.CreateInstance(hlod.SimplifierType, new object[] { hlod });
                for (int i = 0; i < buildInfos.Count; ++i)
                {
                    yield return(new BranchCoroutine(simplifier.Simplify(buildInfos[i])));
                }

                yield return(new WaitForBranches(progress =>
                {
                    EditorUtility.DisplayProgressBar("Bake HLOD", "Simplify meshes", 0.25f + progress * 0.25f);
                }));

                Debug.Log("[HLOD] Simplify: " + sw.Elapsed.ToString("g"));
                sw.Reset();
                sw.Start();


                IBatcher batcher = (IBatcher)Activator.CreateInstance(hlod.BatcherType, new object[] { hlod });
                batcher.Batch(buildInfos, progress =>
                {
                    EditorUtility.DisplayProgressBar("Bake HLOD", "Generating combined static meshes.", 0.5f + progress * 0.25f);
                });
                Debug.Log("[HLOD] Batch: " + sw.Elapsed.ToString("g"));
                sw.Reset();
                sw.Start();

                try
                {
                    AssetDatabase.StartAssetEditing();
                    IStreamingBuilder builder =
                        (IStreamingBuilder)Activator.CreateInstance(hlod.StreamingType, new object[] { hlod });
                    builder.Build(rootNode, buildInfos, progress =>
                    {
                        EditorUtility.DisplayProgressBar("Bake HLOD", "Storing results.", 0.75f + progress * 0.25f);
                    });
                    Debug.Log("[HLOD] Build: " + sw.Elapsed.ToString("g"));
                    sw.Reset();
                    sw.Start();
                }
                finally
                {
                    AssetDatabase.StopAssetEditing();
                    Debug.Log("[HLOD] Importing: " + sw.Elapsed.ToString("g"));
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
            //hlod.Root = rootNode;
        }