Exemplo n.º 1
0
        private static Texture2d ParseMaterialTexture(ObjContext objContext, ObjMaterial objMaterial, string[] commandTokens)
        {
            string textureFileName = commandTokens[commandTokens.Length - 1];
            string textureFilePath = Path.Combine(Path.GetDirectoryName(objContext.Path), textureFileName);

            try {
                Image     textureImage = ImageCodec.Instance.Load(textureFilePath);
                Texture2d texture      = new Texture2d();

                texture.Create(textureImage);
                texture.GenerateMipmaps();

                return(texture);
            } catch (Exception exception) {
                throw new InvalidOperationException(String.Format("unable to load texture {0}", textureFileName), exception);
            }
        }
Exemplo n.º 2
0
        private void SetSphereMaterial(SceneObjectGeometry sphere, string material)
        {
            MaterialState sphereMaterial = new MaterialState();

            sphereMaterial.FrontMaterial           = new MaterialState.Material(ColorRGBAF.ColorWhite);
            sphereMaterial.FrontMaterial.Ambient   = ColorRGBAF.ColorWhite * 0.2f;
            sphereMaterial.FrontMaterial.Diffuse   = ColorRGBAF.ColorWhite * 0.8f;
            sphereMaterial.FrontMaterial.Specular  = ColorRGBAF.ColorWhite * 1.0f;
            sphereMaterial.FrontMaterial.Shininess = 32.0f;

            sphere.ObjectState.DefineState(sphereMaterial);

            if (material == null)
            {
                return;
            }

            string basePath = Path.Combine("Data", "PhotosculptTextures");
            string textureFilename, texturePath;

            textureFilename = String.Format("photosculpt-{0}-{1}.jpg", material, "diffuse");
            texturePath     = Path.Combine(basePath, textureFilename);
            if (File.Exists(texturePath))
            {
                try {
                    Image     textureImage = ImageCodec.Instance.Load(texturePath);
                    Texture2d texture      = new Texture2d();

                    texture.GenerateMipmaps();
                    texture.SamplerParams.MinFilter  = TextureMinFilter.LinearMipmapNearest;
                    texture.SamplerParams.WrapCoordR = TextureWrapMode.Repeat;                     // Texture.Wrap.MirroredRepeat;
                    texture.SamplerParams.WrapCoordS = TextureWrapMode.Repeat;
                    texture.Create(textureImage);

                    sphereMaterial.FrontMaterialDiffuseTexture  = texture;
                    sphereMaterial.FrontMaterialDiffuseTexCoord = 0;
                } catch (Exception exception) {
                    throw new InvalidOperationException(String.Format("unable to load texture {0}", texturePath), exception);
                }
            }

            textureFilename = String.Format("photosculpt-{0}-{1}.jpg", material, "normal");
            texturePath     = Path.Combine(basePath, textureFilename);
            if (File.Exists(texturePath))
            {
                try {
                    Image     textureImage = ImageCodec.Instance.Load(texturePath);
                    Texture2d texture      = new Texture2d();

                    texture.GenerateMipmaps();
                    texture.SamplerParams.MinFilter  = TextureMinFilter.LinearMipmapNearest;
                    texture.SamplerParams.WrapCoordR = TextureWrapMode.Repeat;
                    texture.SamplerParams.WrapCoordS = TextureWrapMode.Repeat;
                    texture.Create(textureImage);

                    sphereMaterial.FrontMaterialNormalTexture  = texture;
                    sphereMaterial.FrontMaterialNormalTexCoord = 0;
                } catch (Exception exception) {
                    throw new InvalidOperationException(String.Format("unable to load texture {0}", texturePath), exception);
                }
            }

            textureFilename = String.Format("photosculpt-{0}-{1}.jpg", material, "specular");
            texturePath     = Path.Combine(basePath, textureFilename);
            if (File.Exists(texturePath))
            {
                try {
                    Image     textureImage = ImageCodec.Instance.Load(texturePath);
                    Texture2d texture      = new Texture2d();

                    texture.GenerateMipmaps();
                    texture.SamplerParams.MinFilter  = TextureMinFilter.LinearMipmapNearest;
                    texture.SamplerParams.WrapCoordR = TextureWrapMode.Repeat;
                    texture.SamplerParams.WrapCoordS = TextureWrapMode.Repeat;
                    texture.Create(textureImage);

                    sphereMaterial.FrontMaterialSpecularTexture  = texture;
                    sphereMaterial.FrontMaterialSpecularTexCoord = 0;
                } catch (Exception exception) {
                    throw new InvalidOperationException(String.Format("unable to load texture {0}", texturePath), exception);
                }
            }

            textureFilename = String.Format("photosculpt-{0}-{1}.jpg", material, "ambientocclusion");
            texturePath     = Path.Combine(basePath, textureFilename);
            if (File.Exists(texturePath))
            {
                try {
                    Image     textureImage = ImageCodec.Instance.Load(texturePath);
                    Texture2d texture      = new Texture2d();

                    texture.GenerateMipmaps();
                    texture.SamplerParams.MinFilter  = TextureMinFilter.LinearMipmapNearest;
                    texture.SamplerParams.WrapCoordR = TextureWrapMode.Repeat;
                    texture.SamplerParams.WrapCoordS = TextureWrapMode.Repeat;
                    texture.Create(textureImage);

                    sphereMaterial.FrontMaterialAmbientTexture  = texture;
                    sphereMaterial.FrontMaterialAmbientTexCoord = 0;
                } catch (Exception exception) {
                    throw new InvalidOperationException(String.Format("unable to load texture {0}", texturePath), exception);
                }
            }

            textureFilename = String.Format("photosculpt-{0}-{1}.jpg", material, "displace");
            texturePath     = Path.Combine(basePath, textureFilename);
            if (File.Exists(texturePath))
            {
                try {
                    Image     textureImage = ImageCodec.Instance.Load(texturePath);
                    Texture2d texture      = new Texture2d();

                    // texture.RequestMipmapsCreation();
                    texture.SamplerParams.WrapCoordR = TextureWrapMode.Repeat;
                    texture.SamplerParams.WrapCoordS = TextureWrapMode.Repeat;
                    texture.SamplerParams.MinFilter  = TextureMinFilter.Nearest;
                    texture.SamplerParams.MagFilter  = TextureMagFilter.Nearest;
                    texture.MipmapMaxLevel           = 0;
                    texture.Create(textureImage);

                    sphereMaterial.FrontMaterialDisplacementTexture = texture;
                    // sphereMaterial.FrontMaterialDisplacementTexCoord = 0;
                    sphereMaterial.FrontMaterialDisplacementFactor = 0.2f;
                } catch (Exception exception) {
                    throw new InvalidOperationException(String.Format("unable to load texture {0}", texturePath), exception);
                }
            }
        }