Пример #1
0
        MaterialTextures ConfigureTextureProperties(NiTexturingProperty ntp)
        {
            var tp = new MaterialTextures();

            if (ntp.TextureCount < 1)
            {
                return(tp);
            }
            if (ntp.BaseTexture != null)
            {
                var src = (NiSourceTexture)_obj.Blocks[ntp.BaseTexture.source.Value]; tp.MainFilePath = src.FileName;
            }
            if (ntp.DarkTexture != null)
            {
                var src = (NiSourceTexture)_obj.Blocks[ntp.DarkTexture.source.Value]; tp.DarkFilePath = src.FileName;
            }
            if (ntp.DetailTexture != null)
            {
                var src = (NiSourceTexture)_obj.Blocks[ntp.DetailTexture.source.Value]; tp.DetailFilePath = src.FileName;
            }
            if (ntp.GlossTexture != null)
            {
                var src = (NiSourceTexture)_obj.Blocks[ntp.GlossTexture.source.Value]; tp.GlossFilePath = src.FileName;
            }
            if (ntp.GlowTexture != null)
            {
                var src = (NiSourceTexture)_obj.Blocks[ntp.GlowTexture.source.Value]; tp.GlowFilePath = src.FileName;
            }
            if (ntp.BumpMapTexture != null)
            {
                var src = (NiSourceTexture)_obj.Blocks[ntp.BumpMapTexture.source.Value]; tp.BumpFilePath = src.FileName;
            }
            return(tp);
        }
		public ObjectComposer AppendMaterialTextures(String texture, String normalTexture)
        {
			if(currentObject.Shader == null) throw new Exception("Append shader before customising it!");
			MaterialTextures textures = new MaterialTextures();
			textures.TextureMap = state.Load<Texture2D>(texture);
			textures.NormalMap = state.Load<Texture2D>(normalTexture);
			currentObject.Shader.Textures = textures;
            return this;
        }
Пример #3
0
        MaterialProps MeshLodDataToMaterialProperties(SiMeshLod data)
        {
            // Create the material properties.
            var mp = new MaterialProps();
            var tp = new MaterialTextures();

            foreach (var material in data.Materials)
            {
                if (tp.MainFilePath == null)
                {
                    tp.MainFilePath = material.Texture;
                }
            }
            mp.Textures = tp;
            return(mp);
        }
Пример #4
0
        MaterialTextures ConfigureTextureProperties(Core.Material.Texture[] textures)
        {
            var tp = new MaterialTextures();

            foreach (var texture in textures.Where(x => x.TexType == Core.Material.Texture.TypeEnum.Default))
            {
                var filePath = $@"Data\{texture.File.Replace("/", "\\")}";
                Log($"{texture.Map} - {filePath}");
                switch (texture.Map)
                {
                case Core.Material.Texture.MapTypeEnum.Diffuse: tp.MainFilePath = filePath; break;

                //case Core.Material.Texture.MapTypeEnum.Bumpmap: tp.BumpFilePath = filePath; break;
                case Core.Material.Texture.MapTypeEnum.Specular: tp.GlowFilePath = filePath; break;

                default: Log($"Unk {texture.Map}: {filePath}"); break;
                }
            }
            return(tp);
        }
Пример #5
0
        public void LoadContent(ContentState state)
        {
            this.texture = state.Load<Texture2D>("skydome/cloudMap");
            this.model.ModelData = state.Load<ModelData>("skydome/dome");

            MaterialShader material = new MaterialShader();

            material.SpecularColour = new Vector3(1, 1, 1);
            material.DiffuseColour = new Vector3(0.6f, 0.6f, 0.6f);
            material.SpecularPower = 64;

            MaterialTextures textures = new MaterialTextures();
            textures.TextureMap = state.Load<Texture2D>("skydome/cloudMap");
            textures.TextureMapSampler = TextureSamplerState.AnisotropicHighFiltering;
            textures.EmissiveTextureMapSampler = TextureSamplerState.AnisotropicHighFiltering;
            textures.NormalMapSampler = TextureSamplerState.AnisotropicHighFiltering;

            material.Textures = textures;

            this.shader = material;
        }
Пример #6
0
        public static void Render(ModelX model, IShaderEffect effect, Vector3 ambientColor, int materialsSet)
        {
            GraphicsDevice device = model.VertexBuffer.GraphicsDevice;

            Material[] materials = model.Materials(materialsSet);

            device.SetVertexBuffer(model.VertexBuffer);

            for (int steps = 0; steps < 2; ++steps)
            {
                for (int idx = 0; idx < model.Subsets.Length; ++idx)
                {
                    var subset = model.Subsets[idx];

                    Material material = materials[subset.Material];

                    if (steps == 0)
                    {
                        if (material.Opacity < 1)
                        {
                            continue;
                        }
                    }

                    if (steps == 1)
                    {
                        if (material.Opacity == 1)
                        {
                            continue;
                        }
                    }

                    device.Indices = subset.IndexBuffer;

                    //// Draw the triangle.
                    effect.DiffuseColor      = material.Diffuse;
                    effect.AmbientLightColor = ambientColor * material.Ambient;
                    effect.SpecularColor     = material.Specular;
                    effect.EmissiveColor     = material.Emissive;
                    effect.Alpha             = material.Opacity;

                    MaterialTextures textures = material.Textures;

                    effect.SpecularPower = material.SpecularExponent;

                    Texture2D texture = textures != null ? textures.Diffuse : null;

                    effect.Texture        = texture;
                    effect.TextureEnabled = texture != null;

                    effect.Apply(0);

                    int startIndex = 0;

                    while (startIndex < subset.Indices.Length)
                    {
                        int primitiveCount = Math.Min((subset.Indices.Length - startIndex) / 3, 30000);

                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, model.Vertices.Length, startIndex, primitiveCount);
                        startIndex += primitiveCount * 3;
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Draws the control.
        /// </summary>
        protected override void Draw()
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            if (_model == null || _effect == null)
            {
                return;
            }

            Vector3 center = (_model.BoundA + _model.BoundB) / 2;
            Vector3 camera = center + new Vector3(1, 0, 0) * _model.Size.Length() * 1.5f * _zoom;

            Vector3 cameraDir = camera - center;

            cameraDir.Normalize();

            //// Set transform matrices.
            float aspect = GraphicsDevice.Viewport.AspectRatio;

            _effect.World = ComputeCameraRotation(cameraDir, _horz, _vert);

            _effect.View = Matrix.CreateLookAt(camera,
                                               center, _zisUp ? new Vector3(0, 0, 1): new Vector3(0, 1, 0));

            _effect.Projection = Matrix.CreatePerspectiveFieldOfView(1, aspect, (camera - center).Length() / 4, (camera - center).Length() * 3f / _zoom);

            //// Set renderstates.
            GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;

            GraphicsDevice.SetVertexBuffer(_model.VertexBuffer);
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            _effect.VertexColorEnabled = false;

            _effect.LightingEnabled = true;

            _effect.EnableDefaultLighting();
            _effect.PreferPerPixelLighting = true;

            GraphicsDevice.BlendState = BlendState.AlphaBlend;

            Color ambientColor = new Color(32, 24, 48);

            Material[] materials = _model.Materials(_materialSet);

            for (Int32 steps = 0; steps < 2; ++steps)
            {
                for (Int32 idx = 0; idx < _model.Subsets.Length; ++idx)
                {
                    var subset = _model.Subsets[idx];

                    Material material = materials[subset.Material];

                    if (steps == 0)
                    {
                        if (material.Opacity < 1)
                        {
                            continue;
                        }
                    }

                    if (steps == 1)
                    {
                        if (material.Opacity == 1)
                        {
                            continue;
                        }
                    }

                    GraphicsDevice.Indices = subset.IndexBuffer;

                    //// Draw the triangle.
                    _effect.DiffuseColor      = material.Diffuse;
                    _effect.AmbientLightColor = ambientColor.ToVector3() * material.Ambient;
                    _effect.SpecularColor     = material.Specular;
                    _effect.EmissiveColor     = material.Emissive;
                    _effect.Alpha             = material.Opacity;

                    MaterialTextures textures = material.Textures;

                    _effect.SpecularPower  = material.SpecularExponent;
                    _effect.Texture        = textures != null ? textures.Diffuse : null;
                    _effect.TextureEnabled = _effect.Texture != null;

                    _effect.CurrentTechnique.Passes[0].Apply();

                    Int32 startIndex = 0;

                    while (startIndex < subset.Indices.Length)
                    {
                        Int32 primitiveCount = Math.Min((subset.Indices.Length - startIndex) / 3, 30000);

                        GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, _model.Vertices.Length, startIndex, primitiveCount);
                        startIndex += primitiveCount * 3;
                    }
                }
            }

            _effect.TextureEnabled     = false;
            _effect.VertexColorEnabled = true;
            _effect.LightingEnabled    = false;

            Single length = _model.Size.Length() * 1.5f;

            _effect.World = _effect.World * Matrix.CreateScale(length);

            _effect.CurrentTechnique.Passes[0].Apply();

            GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, _axes, 0, 3);
        }