Example #1
0
 public TextureModel Create(Stream stream)
 {
     if (stream == null)
     {
         return(null);
     }
     lock (streamDict)
     {
         if (streamDict.TryGetValue(stream, out var tex))
         {
             if (tex.TryGetTarget(out var target))
             {
                 if (logger.IsEnabled(LogLevel.Debug))
                 {
                     logger.LogDebug("Reuse existing TextureModel. Guid: {}", target.Guid);
                 }
                 return(target);
             }
             streamDict.Remove(stream);
         }
         var newTexModel = new TextureModel(stream);
         streamDict.Add(stream, new WeakReference <TextureModel>(newTexModel));
         if (logger.IsEnabled(LogLevel.Debug))
         {
             logger.LogDebug("Created new TextureModel. Guid: {}", newTexModel.Guid);
         }
         return(newTexModel);
     }
 }
 public TextureDetailViewModel(TextureModel textureModel)
 {
     AbsoluteFilePath = textureModel.FilePath;
     FileName = textureModel.Name;
     Width = 100;
     Height = 100;
 }
 /// <summary>
 /// Called when [create vertex buffer].
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="buffer">The buffer.</param>
 /// <param name="geometry">The geometry.</param>
 /// <param name="deviceResources">The device resources.</param>
 /// <param name="bufferIndex"></param>
 protected override void OnCreateVertexBuffer(DeviceContextProxy context, IElementsBufferProxy buffer, int bufferIndex, Geometry3D geometry, IDeviceResources deviceResources)
 {
     if (geometry is IBillboardText billboardGeometry)
     {
         billboardGeometry.DrawTexture(deviceResources);
         if (billboardGeometry.BillboardVertices != null && billboardGeometry.BillboardVertices.Count > 0)
         {
             Type = billboardGeometry.Type;
             buffer.UploadDataToBuffer(context, billboardGeometry.BillboardVertices, billboardGeometry.BillboardVertices.Count, 0, geometry.PreDefinedVertexCount);
             if (texture != billboardGeometry.Texture)
             {
                 texture = billboardGeometry.Texture;
                 var newView = texture == null ?
                               null : deviceResources.MaterialTextureManager.Register(texture);
                 RemoveAndDispose(ref textureView);
                 textureView = Collect(newView);
             }
         }
         else
         {
             RemoveAndDispose(ref textureView);
             texture = null;
             buffer.UploadDataToBuffer(context, emptyVerts, 0);
         }
     }
 }
Example #4
0
            public void UpdateTexture(TextureModel texture, ITextureResourceManager manager)
            {
                var tex = manager.Register(texture, true);

                RemoveAndDispose(ref textureView);
                textureView = tex;
            }
Example #5
0
        public JsonResult List()
        {
            var mongo = new MongoHelper();
            var docs  = mongo.FindAll(Constant.TextureCollectionName);

            var list = new List <TextureModel>();

            foreach (var i in docs)
            {
                var info = new TextureModel
                {
                    ID          = i["ID"].AsObjectId.ToString(),
                    Name        = i["Name"].AsString,
                    TotalPinYin = i["TotalPinYin"].ToString(),
                    FirstPinYin = i["FirstPinYin"].ToString(),
                    Type        = i["Type"].AsString,
                    Url         = i["Url"].AsString,
                    CreateTime  = i["CreateTime"].ToUniversalTime(),
                    UpdateTime  = i["UpdateTime"].ToUniversalTime(),
                    Thumbnail   = i["Thumbnail"].ToString()
                };
                list.Add(info);
            }

            list = list.OrderByDescending(o => o.UpdateTime).ToList();

            return(Json(new
            {
                Code = 200,
                Msg = "获取成功!",
                Data = list
            }));
        }
Example #6
0
    public void LoadDefaultTextureDirectoryIntoDatabase(ILiteCollection <TextureModel> textures)
    {
        // Create some default textures
        TextureModel t1 = new TextureModel
        {
            Name            = "Shiny",
            IsGrained       = false,
            RealWorldHeight = 20,
            RealWorldWidth  = 20
        };

        TextureModel t2 = new TextureModel
        {
            Name            = "Woody",
            IsGrained       = true,
            RealWorldHeight = 15,
            RealWorldWidth  = 20
        };

        TextureModel t3 = new TextureModel
        {
            Name            = "Splintered",
            IsGrained       = true,
            RealWorldHeight = 20,
            RealWorldWidth  = 15
        };


        textures.Insert(t1);
        textures.Insert(t2);
        textures.Insert(t3);
    }
            private void CreateTextureView(TextureModel texture)
            {
                var newRes = texture == null ? null : textureManager.Register(texture);

                RemoveAndDispose(ref textureResource);
                textureResource = newRes;
            }
        public void GenerateDefaultTexture()
        {
            //Create White Image
            PixelFormat pixelFormat = PixelFormats.Bgr24;
            int         rawStride   = (pixelFormat.BitsPerPixel + 7) / 8;

            byte[] rawImage = new byte[rawStride];
            for (int i = 0; i < rawStride; i++)
            {
                rawImage[i] = 170;
            }

            //Convert to memorystream
            BitmapSource     bitmap       = BitmapSource.Create(1, 1, 96, 96, pixelFormat, null, rawImage, rawStride);
            PngBitmapEncoder encoder      = new PngBitmapEncoder();
            MemoryStream     memoryStream = new MemoryStream();

            encoder.Frames.Add(BitmapFrame.Create(bitmap));
            encoder.Save(memoryStream);
            memoryStream.Position = 0;

            //Apply to Materials
            TerrainMeshMainTexture               = new TextureModel(memoryStream);
            TerrainMeshBorderTexture             = new TextureModel(memoryStream);
            TerrainMeshMainMaterial.DiffuseMap   = TerrainMeshMainTexture;
            TerrainMeshBorderMaterial.DiffuseMap = TerrainMeshBorderTexture;
        }
Example #9
0
        /// <summary>
        /// Registers the specified material unique identifier.
        /// </summary>
        /// <param name="textureModel">The texture model.</param>
        /// <param name="enableAutoGenMipMap">Enable generate mipmaps automatically</param>
        /// <returns></returns>
        public ShaderResourceViewProxy Register(TextureModel textureModel, bool enableAutoGenMipMap)
        {
            if (textureModel == null)
            {
                return(null);
            }
            var targetDict = enableAutoGenMipMap ? resourceDictionaryMipMaps : resourceDictionaryNoMipMaps;

            lock (targetDict)
            {
                if (targetDict.TryGetValue(textureModel.Guid, out var view))
                {
                    Debug.WriteLine("Re-using existing texture resource");
                    view.IncRef();
                    return(view);
                }
                else
                {
                    Debug.WriteLine("Creating new texture resource");
                    var proxy = new ShaderResourceViewProxy(device);
                    proxy.CreateView(textureModel, true, enableAutoGenMipMap);
                    proxy.Guid      = textureModel.Guid;
                    proxy.Disposed += (s, e) =>
                    {
                        lock (targetDict)
                        {
                            targetDict.Remove(proxy.Guid);
                        }
                    };
                    targetDict.Add(textureModel.Guid, proxy);
                    return(proxy);
                }
            }
        }
Example #10
0
 public TextureModel Create(string texturePath)
 {
     if (string.IsNullOrEmpty(texturePath))
     {
         return(null);
     }
     lock (fileDict)
     {
         if (fileDict.TryGetValue(texturePath, out var tex))
         {
             if (tex.TryGetTarget(out var target))
             {
                 if (logger.IsEnabled(LogLevel.Debug))
                 {
                     logger.LogDebug("Reuse existing TextureModel. Guid: {}", target.Guid);
                 }
                 return(target);
             }
             fileDict.Remove(texturePath);
         }
         var newTexModel = new TextureModel(texturePath);
         fileDict.Add(texturePath, new WeakReference <TextureModel>(newTexModel));
         if (logger.IsEnabled(LogLevel.Debug))
         {
             logger.LogDebug("Created new TextureModel. Guid: {}", newTexModel.Guid);
         }
         return(newTexModel);
     }
 }
Example #11
0
        public void AddTextureTest()
        {
            //Arrange
            SetUp();
            using (db = context.litedb)
            {
                TextureModel texture = new TextureModel()
                {
                    Name            = "Pink",
                    IsGrained       = false,
                    RealWorldHeight = 15,
                    RealWorldWidth  = 15
                };

                // Act
                repo.AddTexture(texture);

                // Assert
                Assert.AreEqual("Pink", genericRepo.GetById(texture.ID).Name);
                Assert.AreEqual(4, genericRepo.GetAll().Count());

                Console.WriteLine("ID: " + texture.ID + " Name: " + texture.Name +
                                  " Width: " + texture.RealWorldWidth + " Height: " + texture.RealWorldHeight);

                for (int i = 1; i <= genericRepo.GetAll().Count(); i++)
                {
                    Console.WriteLine("ID: " + genericRepo.GetById(i).ID + " Name: " + genericRepo.GetById(i).Name);
                }

                // Clean Up
                DeleteTextures();
            }
        }
Example #12
0
 public TextureDetailViewModel(TextureModel textureModel)
 {
     AbsoluteFilePath = textureModel.FilePath;
     FileName         = textureModel.Name;
     Width            = 100;
     Height           = 100;
 }
Example #13
0
        public async void TextureUpdate()
        {
            // Arrange
            this.QuarryDbContext.Textures.AddRange(
                new TextureEntity()
            {
                TextureId = 1, TextureName = "Crystaline", CompanyId = 1, DeletedInd = false
            },
                new TextureEntity()
            {
                TextureId = 2, TextureName = "Milky", CompanyId = 1, DeletedInd = false
            });
            await this.SaveChangesAsync(this.QuarryDbContext);

            TextureModel model = new TextureModel()
            {
                TextureId = 2, TextureName = "Grey"
            };

            // Act
            AjaxModel <NTModel> ajaxModel = await this.Controller.TextureUpdate(model);

            // Assert
            TextureEntity entity = this.QuarryDbContext.Textures.Where(e => e.TextureId == 2).First();

            Assert.Equal(entity.TextureName, "Grey");
            Assert.Equal(ajaxModel.Message, QuarryMessages.TextureSaveSuccess);
        }
        /// <summary>
        /// Registers the specified material unique identifier.
        /// </summary>
        /// <param name="textureModel">The texture model.</param>
        /// <param name="disableAutoGenMipMap">Disable generate mipmaps automatically</param>
        /// <returns></returns>
        public ShaderResourceViewProxy Register(TextureModel textureModel, bool disableAutoGenMipMap)
        {
            if (textureModel == null || textureModel.GetKey() == null)
            {
                return(null);
            }
            var targetDict = disableAutoGenMipMap ? resourceDictionaryNoMipMaps : resourceDictionaryMipMaps;

            lock (targetDict)
            {
                if (targetDict.TryGetValue(textureModel.GetKey(), out ShaderResourceViewProxy view))
                {
                    view.IncRef();
                    return(view);
                }
                else
                {
                    var proxy = new ShaderResourceViewProxy(device);
                    proxy.CreateView(textureModel, disableAutoGenMipMap);
                    proxy.Disposed += (s, e) =>
                    {
                        lock (targetDict)
                        {
                            targetDict.Remove(textureModel.GetKey());
                        }
                    };
                    targetDict.Add(textureModel.GetKey(), proxy);
                    return(proxy);
                }
            }
        }
Example #15
0
 public void AddTexture(TextureModel texture)
 {
     if (ModelVerification(texture))
     {
         genericRepo.Insert(texture);
     }
 }
Example #16
0
        private void glControl_ContextCreated(object sender, OpenGL.GlControlEventArgs e)
        {
            GlControl glControl = (GlControl)sender;

            if (Gl.CurrentExtensions != null && Gl.CurrentExtensions.DebugOutput_ARB)
            {
                Gl.DebugMessageCallback(_debugProc, IntPtr.Zero);
                Gl.DebugMessageControl(Gl.DebugSource.DontCare, Gl.DebugType.DontCare, Gl.DebugSeverity.DontCare, 0, null, true);
            }

            _displayManager.createDisplay(Gl.CurrentVersion);

            if (Gl.CurrentVersion != null && Gl.CurrentVersion.Api == KhronosVersion.ApiGl && glControl.MultisampleBits > 0)
            {
                Gl.Enable(EnableCap.Multisample);
            }

            bool result = Soil.NET.WrapSOIL.Initialize();

            if (result == false)
            {
                MessageBox.Show("SOIL: Not initialized: " + Soil.NET.WrapSOIL.GetSoilLastError());
                return;
            }

            _model        = _loader.loadToVAO(_vertices, _textureCoords, _indices);
            _texture      = new ModelTexture(_loader.loadTexture("image"));
            _textureModel = new TextureModel(_model, _texture);
            _shader       = new StaticShader();
        }
 /// <summary>
 /// Creates the view from texture model.
 /// </summary>
 /// <param name="texture">The stream.</param>
 /// <param name="disableAutoGenMipMap">Disable auto mipmaps generation</param>
 /// <exception cref="ArgumentOutOfRangeException"/>
 public void CreateView(TextureModel texture, bool disableAutoGenMipMap = false)
 {
     this.DisposeAndClear();
     if (texture != null && device != null)
     {
         if (texture.IsCompressed && texture.CompressedStream != null)
         {
             resource      = Collect(TextureLoader.FromMemoryAsShaderResource(device, texture.CompressedStream, disableAutoGenMipMap));
             textureView   = Collect(new ShaderResourceView(device, resource));
             TextureFormat = textureView.Description.Format;
         }
         else if (texture.NonCompressedData != null && texture.NonCompressedData.Length > 0)
         {
             if (texture.Width * texture.Height > texture.NonCompressedData.Length)
             {
                 throw new ArgumentOutOfRangeException($"Texture width * height = {texture.Width * texture.Height} is larger than texture data length {texture.NonCompressedData.Length}.");
             }
             else if (texture.Height <= 1)
             {
                 if (texture.Width == 0)
                 {
                     CreateView(texture.NonCompressedData, texture.UncompressedFormat, true, disableAutoGenMipMap);
                 }
                 else
                 {
                     CreateView(texture.NonCompressedData, texture.Width, texture.UncompressedFormat, true, disableAutoGenMipMap);
                 }
             }
             else
             {
                 CreateView(texture.NonCompressedData, texture.Width, texture.Height, texture.UncompressedFormat, true, disableAutoGenMipMap);
             }
         }
     }
 }
Example #18
0
 private void UpdateTexture(TextureModel texture)
 {
     if (ViewBoxMeshModel.Material is ViewCubeMaterialCore material)
     {
         material.DiffuseMap = texture;
     }
 }
 // Updates Terrain and Border Texture
 public void UpdateTextures(MemoryStream terrainMainColors, MemoryStream terrainBorderColors)
 {
     TerrainMeshMainTexture               = new TextureModel(terrainMainColors);
     TerrainMeshBorderTexture             = new TextureModel(terrainBorderColors);
     TerrainMeshMainMaterial.DiffuseMap   = TerrainMeshMainTexture;
     TerrainMeshBorderMaterial.DiffuseMap = TerrainMeshBorderTexture;
 }
Example #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BillboardSingleImage3D"/> class.
 /// </summary>
 /// <param name="texture">The image texture.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 public BillboardSingleImage3D(TextureModel texture, float width, float height)
 {
     this.Texture = texture;
     Width        = width;
     Height       = height;
     Texture.CompressedStream.Position = 0;
 }
Example #21
0
            private void UpdateTexture(TextureModel texture)
            {
                var newTexture = texture == null ?
                                 null : EffectTechnique.EffectsManager.MaterialTextureManager.Register(texture);

                RemoveAndDispose(ref textureProxy);
                textureProxy = newTexture;
            }
Example #22
0
 private void UpdateTexture(TextureModel texture)
 {
     RemoveAndDispose(ref textureProxy);
     if (texture != null)
     {
         textureProxy = Collect(EffectTechnique.EffectsManager.MaterialTextureManager.Register(texture));
     }
 }
Example #23
0
        public MainViewModel()
        {
            EffectsManager = new DefaultEffectsManager();
            // ----------------------------------------------
            // titles
            this.Title    = "Hardware Tessellation Demo";
            this.SubTitle = "WPF & SharpDX";

            // ---------------------------------------------
            // camera setup
            this.Camera = new PerspectiveCamera {
                Position = new Point3D(7, 10, 12), LookDirection = new Vector3D(-7, -10, -12), UpDirection = new Vector3D(0, 1, 0)
            };

            // ---------------------------------------------
            // setup lighting
            this.AmbientLightColor          = Color.FromArgb(1, 12, 12, 12);
            this.DirectionalLightColor      = Colors.White;
            this.DirectionalLightDirection1 = new Vector3D(-0, -20, -20);
            this.DirectionalLightDirection2 = new Vector3D(-0, -1, +50);
            this.DirectionalLightDirection3 = new Vector3D(0, +1, 0);

            // ---------------------------------------------
            // model trafo
            this.DefaultTransform = new Media3D.TranslateTransform3D(0, -0, 0);

            // ---------------------------------------------
            // model material
            this.DefaultMaterial = new PhongMaterial
            {
                AmbientColor       = Colors.Gray.ToColor4(),
                DiffuseColor       = Colors.Red.ToColor4(), // Colors.LightGray,
                SpecularColor      = Colors.White.ToColor4(),
                SpecularShininess  = 100f,
                DiffuseMap         = TextureModel.Create(new System.Uri(@"./Media/TextureCheckerboard2.dds", System.UriKind.RelativeOrAbsolute).ToString()),
                NormalMap          = TextureModel.Create(new System.Uri(@"./Media/TextureCheckerboard2_dot3.dds", System.UriKind.RelativeOrAbsolute).ToString()),
                EnableTessellation = true, RenderShadowMap = true
            };
            FloorMaterial.RenderShadowMap = true;
            // ---------------------------------------------
            // init model
            this.LoadModel(@"./Media/teapot_quads_tex.obj", this.meshTopology == MeshTopologyEnum.PNTriangles ?
                           MeshFaces.Default : MeshFaces.QuadPatches);
            // ---------------------------------------------
            // floor plane grid
            this.Grid          = LineBuilder.GenerateGrid(10);
            this.GridColor     = Colors.Black;
            this.GridTransform = new Media3D.TranslateTransform3D(-5, -4, -5);

            var builder = new MeshBuilder(true, true, true);

            builder.AddBox(new Vector3(0, -5, 0), 60, 0.5, 60, BoxFaces.All);
            FloorModel = builder.ToMesh();

            Instances = new Matrix[] { Matrix.Identity, Matrix.Translation(10, 0, 10), Matrix.Translation(-10, 0, 10), Matrix.Translation(10, 0, -10), Matrix.Translation(-10, 0, -10), };
        }
 /// <summary>
 /// Creates the view from texture model.
 /// </summary>
 /// <param name="texture">The stream.</param>
 /// <param name="createSRV">Create ShaderResourceView</param>
 /// <param name="enableAutoGenMipMap">Enable auto mipmaps generation</param>
 /// <exception cref="ArgumentOutOfRangeException"/>
 public void CreateView(TextureModel texture, bool createSRV = true, bool enableAutoGenMipMap = true)
 {
     this.DisposeAndClear();
     if (texture != null && device != null && texture.TextureInfoLoader != null)
     {
         var  content = texture.TextureInfoLoader.Load(texture.Guid);
         bool succ    = HandleTextureContent(content, createSRV, content.GenerateMipMaps && enableAutoGenMipMap);
         texture.TextureInfoLoader.Complete(texture.Guid, content, succ);
     }
 }
Example #25
0
        public static bool ModelVerification(TextureModel model)
        {
            bool isValid = false;

            if (true)
            {
                isValid = true;
            }
            return(isValid);
        }
Example #26
0
        public bool DeleteTexture(TextureModel texture)
        {
            bool deleted = false;

            if (ModelVerification(texture))
            {
                genericRepo.Delete(texture.ID);
                deleted = true;
            }
            return(deleted);
        }
Example #27
0
        private void buttonEnvironment_Click(object sender, RoutedEventArgs e)
        {
            var texture     = TextureModel.Create("Cubemap_Grandcanyon.dds");
            var environment = new EnvironmentMap3D()
            {
                Texture = texture
            };

            viewport.Items.Add(environment);
            viewmodel.EnableEnvironmentButtons = false;
        }
Example #28
0
        private Tuple <Material, Media3D.Transform3D> LoadNoise()
        {
            var m = new VolumeTextureDDS3DMaterial();

            m.Texture = TextureModel.Create("NoiseVolume.dds");
            m.Color   = new Color4(1, 1, 1, 0.01f);
            m.Freeze();
            var transform = new Media3D.ScaleTransform3D(1, 1, 1);

            transform.Freeze();
            return(new Tuple <Material, Media3D.Transform3D>(m, transform));
        }
Example #29
0
        public void Editar(String n, int r, int g, int b)
        {
            bool stado = false;

            for (int i = 0; i < lista.Count; i++)
            {
                if (lista[i].name == n)
                {
                    stado         = true;
                    lista[i].name = n;

                    if (lista[i].R1 >= r)
                    {
                        lista[i].R1 = r;
                    }
                    else
                    {
                        lista[i].R2 = r;
                    }
                    if (lista[i].G1 >= g)
                    {
                        lista[i].G1 = g;
                    }
                    else
                    {
                        lista[i].G2 = g;
                    }
                    if (lista[i].B1 >= b)
                    {
                        lista[i].B1 = b;
                    }
                    else
                    {
                        lista[i].B2 = b;
                    }
                }
            }
            if (!stado)
            {
                TextureModel modelo = new TextureModel()
                {
                    name = n,
                    R1   = r,
                    R2   = r,
                    G1   = g,
                    G2   = g,
                    B1   = b,
                    B2   = b,
                };
                lista.Add(modelo);
            }
        }
Example #30
0
        public async void TextureAdd()
        {
            // Arrange
            TextureModel model = new TextureModel() { TextureId = 0, TextureName = "Crystaline" };

            // Act
            AjaxModel<NTModel> ajaxModel = await this.Controller.TextureAdd(model);

            // Assert
            TextureEntity entity = this.QuarryDbContext.Textures.Last();
            Assert.Equal(entity.TextureName, "Crystaline");
            Assert.Equal(ajaxModel.Message, QuarryMessages.TextureSaveSuccess);
        }
Example #31
0
        public void TestGetLessImportantDuplicate_BothAreImportant()
        {
            // Arrange
            TextureModel modelA = new TextureModel(@"C:\test\test2\hienokuva1.png");
            TextureModel modelB = new TextureModel(@"C:\test\test2\hienokuva2.png");
            ICompareCondition <TextureModel> comparer = new HasSamePathAndFileNameCompareCondition();

            // Act
            TextureModel duplicateModel = comparer.GetLessImportantDuplicate(modelA, modelB);

            // Assert
            Assert.IsNull(duplicateModel, "Duplicate model was NOT null!");
        }
 private void CreateTextureView(TextureModel texture, int index)
 {
     RemoveAndDispose(ref TextureResource);
     TextureResource = texture == null ? null : Collect(textureManager.Register(texture));
     if (TextureResource != null)
     {
         textureIndex |= 1u << index;
     }
     else
     {
         textureIndex &= ~(1u << index);
     }
 }
Example #33
0
        public async void TextureUpdate()
        {
            // Arrange
            this.QuarryDbContext.Textures.AddRange(
                    new TextureEntity() { TextureId = 1, TextureName = "Crystaline", CompanyId = 1, DeletedInd = false },
                    new TextureEntity() { TextureId = 2, TextureName = "Milky", CompanyId = 1, DeletedInd = false });
            await this.SaveChangesAsync(this.QuarryDbContext);

            TextureModel model = new TextureModel() { TextureId = 2, TextureName = "Grey" };

            // Act
            AjaxModel<NTModel> ajaxModel = await this.Controller.TextureUpdate(model);

            // Assert
            TextureEntity entity = this.QuarryDbContext.Textures.Where(e => e.TextureId == 2).First();
            Assert.Equal(entity.TextureName, "Grey");
            Assert.Equal(ajaxModel.Message, QuarryMessages.TextureSaveSuccess);
        }
Example #34
0
 public void AddTexture(TextureModel textureModel)
 {
     _textureModels.Add(textureModel);
 }