コード例 #1
0
        /// <summary>
        /// Enqueues an in-memory (embedded) texture loading job to the queue.
        /// </summary>
        /// <param name="dataSource">Assimp texture to read from</param>
        /// <param name="refName">Name to report to the callback</param>
        /// <param name="callback">Callback to be invoked when loading is complete</param>
        public static void Enqueue(Assimp.EmbeddedTexture dataSource, string refName, CompletionCallback callback)
        {
            Debug.Assert(dataSource != null);
            Debug.Assert(refName != null);
            Debug.Assert(callback != null);

            if (_thread == null)
            {
                StartThread();
            }

            Queue.Add(new TextureFromMemoryTask(dataSource, refName, callback));
        }
コード例 #2
0
        /// <summary>
        /// Start loading a texture from a given embedded texture
        /// </summary>
        /// <param name="dataSource">Source texture from assimp</param>
        /// <param name="refName">Sentinel name of the texture. This is the name
        ///    that is set as FileName.</param>
        /// <param name="callback">Optional callback to be invoked
        ///   when loading to memory is either complete or is definitely
        ///   failed.)</param>
        public Texture(Assimp.EmbeddedTexture dataSource, string refName, CompletionCallback callback)
        {
            _file       = refName;
            _dataSource = dataSource;
            _callback   = (s, image, actualLocation, status) => callback(this);

            if (CoreSettings.CoreSettings.Default.LoadTextures)
            {
                LoadAsync();
            }
            else
            {
                SetImage(null, TextureLoader.LoadResult.FileNotFound);
            }
        }
コード例 #3
0
        private void GetTexture(Assimp.TextureSlot tslot, out Texture2D texture, out float useColorMap)
        {
            string fullpath = Path.IsPathRooted(tslot.FilePath) ? tslot.FilePath : directoryName + "\\" + tslot.FilePath;

            texture     = new Texture2D(1, 1, TextureFormat.RGBA32, 0, true);
            useColorMap = 0f;
            if (File.Exists(fullpath))
            {
                texture     = GetOrCreateTextureFromFile(fullpath);
                useColorMap = 1f;
            }
            else
            {
                List <Assimp.EmbeddedTexture> texts          = scene.Textures;
                Assimp.EmbeddedTexture        diffuseTexture = texts.Find(x => x.Filename == tslot.FilePath);
                if (diffuseTexture != null)
                {
                    byte[] data = diffuseTexture.CompressedData;
                    texture.LoadImage(data);
                    useColorMap = 1f;
                }
            }
        }
コード例 #4
0
ファイル: TextureQueue.cs プロジェクト: zyjiang0571/open3mod
 public TextureFromMemoryTask(Assimp.EmbeddedTexture dataSource, string refName, CompletionCallback callback)
     : base(callback)
 {
     _dataSource = dataSource;
     _refName    = refName;
 }
コード例 #5
0
        public EmbeddedTextureLoader(Assimp.EmbeddedTexture tex)
        {
            if (tex.IsCompressed)
            {
                var compTex = tex;
                if (!compTex.HasCompressedData)
                {
                    return;
                }

                // note: have to keep the stream open for the lifetime of the image, so don't Dispose()
                SetFromStream(new MemoryStream(compTex.CompressedData));
                return;
            }

            var rawTex = tex;

            if (!rawTex.HasNonCompressedData || rawTex.Width < 1 || rawTex.Height < 1)
            {
                return;
            }
            var texels = rawTex.NonCompressedData;


            var image = new Bitmap(rawTex.Width, rawTex.Height, PixelFormat.Format32bppArgb);

            var        bounds = new Rectangle(0, 0, rawTex.Width, rawTex.Height);
            BitmapData bmpData;

            try
            {
                bmpData = image.LockBits(bounds, ImageLockMode.WriteOnly, image.PixelFormat);
                // ignore exceptions thrown by LockBits - we just can't read the image in this case
            }
            catch
            {
                return;
            }

            var ptr = bmpData.Scan0;

            Debug.Assert(bmpData.Stride > 0);

            var countBytes = bmpData.Stride * image.Height;
            var tempBuffer = new byte[countBytes];

            var dataLineLength = image.Width * 4;
            var padding        = bmpData.Stride - dataLineLength;

            Debug.Assert(padding >= 0);

            var n = 0;

            foreach (var texel in texels)
            {
                tempBuffer[n++] = texel.B;
                tempBuffer[n++] = texel.G;
                tempBuffer[n++] = texel.R;
                tempBuffer[n++] = texel.A;

                if (n % dataLineLength == 0)
                {
                    n += padding;
                }
            }

            Marshal.Copy(tempBuffer, 0, ptr, countBytes);
            image.UnlockBits(bmpData);

            _image  = image;
            _result = LoadResult.Good;
        }
コード例 #6
0
ファイル: Texture.cs プロジェクト: Kolky/open3mod
        /// <summary>
        /// Start loading a texture from a given embedded texture
        /// </summary>
        /// <param name="dataSource">Source texture from assimp</param>
        /// <param name="refName">Sentinel name of the texture. This is the name
        ///    that is set as FileName.</param>
        /// <param name="callback">Optional callback to be invoked
        ///   when loading to memory is either complete or is definitely
        ///   failed.)</param>
        public Texture(Assimp.EmbeddedTexture dataSource, string refName, CompletionCallback callback)
        {
            _originalFile = refName;
            _dataSource = dataSource;
            _callback = (s, image, actualLocation, status) => callback(this);

            if (CoreSettings.CoreSettings.Default.LoadTextures)
            {
                LoadAsync();
            }
            else
            {
                SetImage(null, TextureLoader.LoadResult.FileNotFound);
            }
        }
コード例 #7
0
ファイル: TextureQueue.cs プロジェクト: Kolky/open3mod
 public TextureFromMemoryTask(Assimp.EmbeddedTexture dataSource, string refName, CompletionCallback callback)
     : base(callback)
 {
     _dataSource = dataSource;
     _refName = refName;
 }