Ejemplo n.º 1
0
        /// <summary>
        /// Starts tree building process with given settings.
        /// </summary>
        public static void BuildNodeTree(TreeImportSettings settings)
        {
            var processors = new List <PointProcessor>();

            foreach (var inputFile in settings.inputFiles)
            {
                var processor = CreateProcessor(inputFile);
                if (processor != null)
                {
                    processors.Add(processor);
                }
            }

            if (processors.Count == 0)
            {
                Debug.LogError("All of given point cloud files are invalid or unsupported.");
                return;
            }

            var bounds = CalculateBounds(processors);

            var transformationData = new TransformationData(bounds, settings);

            var unityBounds = bounds.GetUnityBounds(settings);
            var transform   = transformationData.TransformationMatrix;

            unityBounds.center  = transform.MultiplyPoint3x4(unityBounds.center);
            unityBounds.extents = transform.MultiplyVector(unityBounds.extents);

            NodeProcessorDispatcher dispatcher;

            try
            {
                EditorUtility.DisplayProgressBar("Creating dispatcher", "Preparing target directory...", 0f);
                dispatcher = new NodeProcessorDispatcher(settings.outputPath, settings);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }

            foreach (var processor in processors)
            {
                if (!processor.ConvertPoints(dispatcher, transformationData))
                {
                    Debug.Log("Import cancelled.");
                    return;
                }
            }

            if (dispatcher.ProcessPoints(unityBounds))
            {
                Debug.Log("Octree build finished successfully.");
            }
            else
            {
                Debug.Log("Octree build failed.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts tree building process with given settings.
        /// </summary>
        public static bool BuildNodeTree(TreeImportSettings settings)
        {
            var processors = new List <PointProcessor>();

            foreach (var inputFile in settings.inputFiles)
            {
                var processor = CreateProcessor(Utility.GetFullPath(inputFile));
                if (processor != null)
                {
                    processors.Add(processor);
                }
            }

            if (processors.Count == 0)
            {
                Debug.LogError("All of given point cloud files are invalid or unsupported.");
                return(false);
            }

            var bounds = CalculateBounds(processors);

            var transformationData = new TransformationData(bounds, settings);

            var unityBounds = bounds.GetUnityBounds(settings);
            var transform   = transformationData.TransformationMatrix;

            unityBounds.center  = transform.MultiplyPoint3x4(unityBounds.center);
            unityBounds.extents = transform.MultiplyVector(unityBounds.extents);

            TreeImportData importData = null;

            if (settings.generateMesh && settings.roadOnlyMesh)
            {
                var histogram = GenerateHistogram(processors, bounds);
                importData = new TreeImportData(unityBounds, histogram);
            }
            else
            {
                importData = new TreeImportData(unityBounds);
            }

            NodeProcessorDispatcher dispatcher;
            var fullOutputPath = Utility.GetFullPath(settings.outputPath);

            try
            {
                EditorUtility.DisplayProgressBar("Creating dispatcher", "Preparing target directory...", 0f);
                dispatcher = new NodeProcessorDispatcher(fullOutputPath, settings);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }

            foreach (var processor in processors)
            {
                if (!processor.ConvertPoints(dispatcher, transformationData))
                {
                    Debug.Log("Import cancelled.");
                    return(false);
                }
            }

            if (dispatcher.ProcessPoints(importData))
            {
                dispatcher.GetPointCountResults(out var total, out var used, out var discarded);
                Debug.Log($"Octree build finished successfully.\n" +
                          $"Used points: {used}/{total} ({discarded} discarded on low tree levels)");
                return(true);
            }
            else
            {
                Debug.Log("Octree build failed.");
                return(false);
            }
        }