public void CreateTextureViews(Device device, CustomMaterialGeometryModel3D model)
 {
     this.device = device;
     if (material != null)
     {
         CreateTextureView(material.DiffuseMap, ref this.texDiffuseMapView);
         CreateTextureView(material.NormalMap, ref this.texNormalMapView);
         CreateTextureView(material.DisplacementMap, ref this.texDisplacementMapView);
         CreateTextureView(material.DiffuseAlphaMap, ref this.texDiffuseAlphaMapView);
         CreateTextureView(material.SpecularMap, ref this.texSpecularMapView);
         CreateTextureView(material.EmissiveMap, ref this.texEmissiveMapView);
     }
     else
     {
         Disposer.RemoveAndDispose(ref this.texDiffuseMapView);
         Disposer.RemoveAndDispose(ref this.texNormalMapView);
         Disposer.RemoveAndDispose(ref this.texDisplacementMapView);
         Disposer.RemoveAndDispose(ref this.texDiffuseAlphaMapView);
         Disposer.RemoveAndDispose(ref this.texSpecularMapView);
         Disposer.RemoveAndDispose(ref this.texEmissiveMapView);
     }
 }
Example #2
0
            public void CreateTextureViews(Device device, CustomMaterialGeometryModel3D model)
            {
                if (material != null)
                {
                    /// --- has texture
                    if (material.DiffuseMap != null && model.RenderDiffuseMap)
                    {
                        Disposer.RemoveAndDispose(ref this.texDiffuseMapView);
                        this.texDiffuseMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.DiffuseMap);
                    }

                    if (material.DiffuseAlphaMap != null)
                    {
                        Disposer.RemoveAndDispose(ref this.texDiffuseAlphaMapView);
                        this.texDiffuseAlphaMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.DiffuseAlphaMap);
                    }

                    // --- has bumpmap
                    if (material.NormalMap != null && model.RenderNormalMap)
                    {
                        var geometry = model.geometryInternal as MeshGeometry3D;
                        if (geometry != null)
                        {
                            if (geometry.Tangents == null)
                            {
                                //System.Windows.MessageBox.Show(string.Format("No Tangent-Space found. NormalMap will be omitted."), "Warrning", MessageBoxButton.OK);
                                material.NormalMap = null;
                            }
                            else
                            {
                                Disposer.RemoveAndDispose(ref this.texNormalMapView);
                                this.texNormalMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.NormalMap);
                            }
                        }
                    }

                    // --- has displacement map
                    if (material.DisplacementMap != null && model.RenderDisplacementMap)
                    {
                        Disposer.RemoveAndDispose(ref this.texDisplacementMapView);
                        this.texDisplacementMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.DisplacementMap);
                    }

                    // --- has color table
                    if (material.ColorTable != null && model.RenderColorTable)
                    {
                        Disposer.RemoveAndDispose(ref this.texColorTableView);
                        this.texColorTableView = TextureLoader.FromMemoryAsShaderResourceView(device, material.ColorTable);
                    }

                    // --- has mask map
                    if (material.MaskMap != null && model.RenderMaskMap)
                    {
                        Disposer.RemoveAndDispose(ref this.texMaskMapView);
                        this.texMaskMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.MaskMap);
                    }

                    // --- has specular map
                    if (material.SpecularMap != null && model.RenderSpecularMap)
                    {
                        Disposer.RemoveAndDispose(ref this.texSpecularMapView);
                        this.texSpecularMapView = TextureLoader.FromMemoryAsShaderResourceView(device, material.SpecularMap);
                    }
                }
            }