Пример #1
0
        private void CreateVertexBuffer()
        {
            var vertices = new VertexPositionNormalTexture[_sourceMesh.Positions.Count];

            for (int i = 0; i < _sourceMesh.Positions.Count; i++)
            {
                vertices[i].Position = ConversionUtility.ToSharpDXVector3(_sourceMesh.Positions[i]);
                vertices[i].Normal   = ConversionUtility.ToSharpDXVector3(_sourceMesh.Normals[i]);
                if (_sourceMesh.TextureCoordinates.Count - 1 >= i)
                {
                    vertices[i].TextureCoordinate = new Vector2(_sourceMesh.TextureCoordinates[i].X, _sourceMesh.TextureCoordinates[i].Y);
                }
            }
            _vertexBuffer = Buffer.Vertex.New(_device, vertices);
        }
Пример #2
0
        public void Draw(BasicEffect effect)
        {
            if (!_initialized)
            {
                throw new InvalidOperationException("Initialize must be called before Draw");
            }

            _device.SetVertexBuffer(_vertexBuffer);
            _device.SetIndexBuffer(_indexBuffer, false);

            effect.World         = ConversionUtility.ToSharpDXMatrix(_sourceMesh.Transform.Value);
            effect.DiffuseColor  = ConversionUtility.ToSharpDXVector3(_sourceMesh.Material.DiffuseColor);
            effect.SpecularColor = ConversionUtility.ToSharpDXVector3(_sourceMesh.Material.SpecularColor);
            effect.SpecularPower = _sourceMesh.Material.Shininess;

            if (!string.IsNullOrEmpty(_sourceMesh.Material.DiffuseTextureName))
            {
                effect.TextureEnabled = true;
                effect.Texture        = _texture;
            }
            else
            {
                effect.TextureEnabled = false;
                effect.Texture        = null;
            }

            effect.Alpha = _sourceMesh.Material.Transparency;

            foreach (var pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                _device.DrawIndexed(PrimitiveType.TriangleList, _sourceMesh.Indices.Count);
            }

            _device.SetIndexBuffer(null, false);
            _device.SetVertexBuffer((Buffer <VertexPositionNormalTexture>)null);
        }