Beispiel #1
0
        /// <summary>
        /// Construct a scene given a file name, throw if loading fails
        /// </summary>
        /// <param name="file">File name to be loaded</param>
        public Scene(string file)
        {
            _file    = file;
            _baseDir = Path.GetDirectoryName(file);

            _logStore = new LogStore();

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                using (var imp = new AssimpContext())
                {
                    LogStream.IsVerboseLoggingEnabled = true;
                    using (var pipe = new LogPipe(_logStore))
                    {
                        // Assimp configuration:

                        //  - if no normals are present, generate them using a threshold
                        //    angle of 66 degrees.
                        imp.SetConfig(new NormalSmoothingAngleConfig(66.0f));

                        // start with TargetRealTimeMaximumQuality and add/remove flags
                        // according to the import configuration
                        var postprocess = GetPostProcessStepsFlags();

                        //  - request lots of post processing steps, the details of which
                        //    can be found in the TargetRealTimeMaximumQuality docs.
                        _raw = imp.ImportFile(file, postprocess);
                        if (_raw == null)
                        {
                            Dispose();
                            throw new Exception("failed to read file: " + file);
                        }

                        _incomplete = _raw.SceneFlags.HasFlag(SceneFlags.Incomplete);
                    }
                }
            }
            catch (AssimpException ex)
            {
                Dispose();
                throw new Exception("failed to read file: " + file + " (" + ex.Message + ")");
            }

            stopwatch.Stop();
            _loadingTime = stopwatch.ElapsedMilliseconds;

            _animator   = new SceneAnimator(this);
            _textureSet = new TextureSet(BaseDir);
            LoadTextures();

            // compute a bounding box (AABB) for the scene we just loaded
            ComputeBoundingBox(out _sceneMin, out _sceneMax, out _sceneCenter);
            _pivot = _sceneCenter;

            CountVertsAndFaces(out _totalVertexCount, out _totalTriangleCount, out _totalLineCount, out _totalPointCount);

            CreateRenderingBackend();
        }
Beispiel #2
0
        /// <summary>
        /// Construct a scene given a file name, throw if loading fails
        /// </summary>
        /// <param name="file">File name to be loaded</param>
        public Scene(string file)
        {
            _file = file;
            _baseDir = Path.GetDirectoryName(file);

            _logStore = new LogStore();

            var stopwatch = new Stopwatch();
            stopwatch.Start();

            try
            {
                using (var imp = new AssimpContext())
                {
                    LogStream.IsVerboseLoggingEnabled = true;
                    using(var pipe = new LogPipe(_logStore))
                    {
                        // Assimp configuration:

                        //  - if no normals are present, generate them using a threshold
                        //    angle of 66 degrees.
                        imp.SetConfig(new NormalSmoothingAngleConfig(66.0f));

                        // start with TargetRealTimeMaximumQuality and add/remove flags
                        // according to the import configuration
                        var postprocess = GetPostProcessStepsFlags();

                        //  - request lots of post processing steps, the details of which
                        //    can be found in the TargetRealTimeMaximumQuality docs.
                        _raw = imp.ImportFile(file, postprocess);
                        if (_raw == null)
                        {
                            Dispose();
                            throw new Exception("failed to read file: " + file);
                        }

                        _incomplete = _raw.SceneFlags.HasFlag(SceneFlags.Incomplete);
                    }
                }
            }
            catch(AssimpException ex)
            {
                Dispose();
                throw new Exception("failed to read file: " + file + " (" + ex.Message + ")");
            }

            stopwatch.Stop();
            _loadingTime = stopwatch.ElapsedMilliseconds;

            _animator = new SceneAnimator(this);
            _textureSet = new TextureSet(BaseDir);
            LoadTextures();

            // compute a bounding box (AABB) for the scene we just loaded
            ComputeBoundingBox(out _sceneMin, out _sceneMax, out _sceneCenter);
            _pivot = _sceneCenter;

            CountVertsAndFaces(out _totalVertexCount, out _totalTriangleCount, out _totalLineCount, out _totalPointCount);

            CreateRenderingBackend();
        }