コード例 #1
0
ファイル: Scene.cs プロジェクト: iFreeze-Qiu/open3mod
        /// <summary>
        /// Populates the TextureSet with all the textures required for the scene.
        /// </summary>
        private void LoadTextures()
        {
            var materials = _raw.Materials;

            foreach (var mat in materials)
            {
                var textures = mat.GetAllMaterialTextures();
                foreach (var tex in textures)
                {
                    var             path           = tex.FilePath;
                    EmbeddedTexture embeddedSource = null;
                    if (path.StartsWith("*"))
                    {
                        // Embedded texture, following the asterisk is the zero-based
                        // index of the data source in Assimp.Scene.Textures
                        uint index;
                        if (Raw.HasTextures && uint.TryParse(path.Substring(1), out index) && index < Raw.TextureCount)
                        {
                            embeddedSource = Raw.Textures[(int)index];
                        }
                        // else: just add the name to the texture set without specifying
                        // a data source, the texture will then be in a failed state
                        // but users can still replace it manually.
                    }

                    TextureSet.Add(tex.FilePath, embeddedSource);
                }
            }

            TextureSet.AddCallback((name, tex) =>
            {
                SetTexturesChangedFlag();
                return(true);
            });
        }
コード例 #2
0
 /// <summary>
 /// Requests that texture filters be re-configured as soon as possible.
 /// This is called when the texture settings are changed.
 ///
 /// This method may only be called from the UI thread.
 /// </summary>
 public void RequestReconfigureTextures()
 {
     SetTexturesChangedFlag();
     foreach (var tex in TextureSet.GetLoadedTexturesCollectionThreadsafe())
     {
         if (tex.State == Texture.TextureState.GlTextureCreated)
         {
             tex.ReconfigureUploadedTextureRequested = true;
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// Requests that all textures be re-uploaded as soon as possible.
 /// This is called when the texture settings are changed.
 ///
 /// This method may only be called from the UI thread.
 /// </summary>
 public void RequestReuploadTextures()
 {
     SetTexturesChangedFlag();
     foreach (var tex in TextureSet.GetLoadedTexturesCollectionThreadsafe())
     {
         if (tex.State == Texture.TextureState.GlTextureCreated)
         {
             tex.ReleaseUpload();
             // tex.Upload();//??????????
         }
     }
 }
コード例 #4
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();
        }
コード例 #5
0
ファイル: Scene.cs プロジェクト: acgessler/open3mod
        /// <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();
        }