Exemple #1
0
        internal ModelMesh(Mesh sourceMesh, Device device, VertexBuffer vertexBuffer, int numVertices,
			IndexBuffer indexBuffer, int primitiveCount,
			Matrix3D world, Material material)
        {
            SourceMesh = sourceMesh;
            _device = device;
            _vertexBuffer = vertexBuffer;
            _numVertices = numVertices;
            _indexBuffer = indexBuffer;
            _primitiveCount = primitiveCount;

            _effect = new SimpleEffect(device)
            {
                World = world,
                AmbientLightColor = new ColorRgbF(0.1f, 0.1f, 0.1f),
                DiffuseColor = material.DiffuseColor,
                SpecularColor = material.SpecularColor,
                SpecularPower = material.Shininess,
                Alpha = material.Transparency
            };
            if (!string.IsNullOrEmpty(material.DiffuseTextureName))
                _effect.DiffuseTexture = Texture.FromFile(device, material.DiffuseTextureName, Usage.None, Pool.Default);
            _effect.CurrentTechnique = "RenderScene";
            Opaque = (material.Transparency == 1.0f);
        }
Exemple #2
0
        public Block(Device device, TextureInfo texture, float width, float height, float depth, bool containsTransparency)
        {
            Material = new TextureMaterial(texture.Texture, containsTransparency);

            var xUV = CreateUV(texture, depth, height);
            var yUV = CreateUV(texture, width, depth);
            var zUV = CreateUV(texture, width, height);

            this.Add(new MeshRenderer
            {
                Mesh = new TexturedCube(device, width, height, depth, zUV, zUV, xUV, xUV, yUV, yUV),
                Material = Material
            });

            this.Add(new AxisAlignedBoxCollider { RadiusWidth = width / 2, RadiusHeight = height / 2, RadiusDepth = depth / 2 });
        }
Exemple #3
0
        protected void CreateMesh(IEnumerable <double> x, IEnumerable <double> y, IEnumerable <double> z, int xLength, int yLength)
        {
            lengthU = xLength;
            lengthV = yLength;
            bounds  = new Cuboid(x.Min(), y.Min(), z.Min(), x.Max(), y.Max(), z.Max());
            Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10));

            UpdateModelVertices(x, y, z, xLength, yLength);
            CreateVertsAndInds();
            colourMap        = new ColourMap(ColourMapType.HSV, 256);
            colourMapIndices = FalseColourImage.IEnumerableToIndexArray(z, xLength, yLength, 256);
            SetColorFromIndices();
            colourMapUpdateTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(0.2)
            };
            colourMapUpdateTimer.Tick += new EventHandler(colourMapUpdateTimer_Tick);

            lights = new List <SharpDX.Direct3D9.Light>();
            SharpDX.Direct3D9.Light light = new SharpDX.Direct3D9.Light()
            {
                Type = LightType.Directional
            };
            light.Diffuse   = new Color4(0.4f, 0.4f, 0.4f, 1.0f);
            light.Direction = new Vector3(0.3f, 0.3f, -0.7f);
            light.Specular  = new Color4(0.05f, 0.05f, 0.05f, 1.0f);
            lights.Add(light);

            light = new SharpDX.Direct3D9.Light()
            {
                Type = LightType.Directional
            };
            light.Diffuse   = new Color4(0.4f, 0.4f, 0.4f, 1.0f);
            light.Direction = new Vector3(-0.3f, -0.3f, -0.7f);
            light.Specular  = new Color4(0.05f, 0.05f, 0.05f, 1.0f);
            lights.Add(light);

            material          = new SharpDX.Direct3D9.Material();
            material.Specular = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Diffuse  = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Ambient  = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Power    = 10;
        }
        protected void CreateMesh(IEnumerable<double> x, IEnumerable<double> y, IEnumerable<double> z, int xLength, int yLength)
        {
            lengthU = xLength;
            lengthV = yLength;
            bounds = new Cuboid(x.Min(), y.Min(), z.Min(), x.Max(), y.Max(), z.Max());
            Cuboid modelBounds = new Cuboid(new System.Windows.Media.Media3D.Point3D(-10, -10, -10), new System.Windows.Media.Media3D.Point3D(10, 10, 10));
            UpdateModelVertices(x, y, z, xLength, yLength);
            CreateVertsAndInds();
            colourMap = new ColourMap(ColourMapType.HSV, 256);
            colourMapIndices = FalseColourImage.IEnumerableToIndexArray(z, xLength, yLength, 256);
            SetColorFromIndices();
            colourMapUpdateTimer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(0.2) };
            colourMapUpdateTimer.Tick += new EventHandler(colourMapUpdateTimer_Tick);

            lights = new List<SharpDX.Direct3D9.Light>();
            SharpDX.Direct3D9.Light light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional };
            light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f);
            light.Direction = new Vector3(0.3f, 0.3f, -0.7f);
            light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f);
            lights.Add(light);

            light = new SharpDX.Direct3D9.Light() { Type = LightType.Directional };
            light.Diffuse = new Color4(0.4f, 0.4f, 0.4f, 1.0f);
            light.Direction = new Vector3(-0.3f, -0.3f, -0.7f);
            light.Specular = new Color4(0.05f, 0.05f, 0.05f, 1.0f);
            lights.Add(light);

            material = new SharpDX.Direct3D9.Material();
            material.Specular = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Diffuse = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Ambient = new Color4(0.0f, 0.0f, 0.0f, 1.0f);
            material.Power = 10;
        }
 private void RenderSceneObjects(IEnumerable<SceneObject> sceneObjects, Material material)
 {
     _device.Material = material;
     foreach (var sceneObject in sceneObjects)
     {
         RenderSceneObject(sceneObject);
     }
 }