Пример #1
0
        private void Apply(InstancedModel model)
        {
            if (model == null || Texture == null)
            {
                return;
            }

            var random     = new Random(Seed);
            var transforms = new List <Matrix>();
            var texture    = ContentPipeline.LoadContent <Texture2DContent>(Texture.Filename, new Microsoft.Xna.Framework.Content.Pipeline.TextureImporter());

            texture.ConvertBitmapType(typeof(PixelBitmapContent <float>));

            var map = (PixelBitmapContent <float>)texture.Mipmaps[0];

            for (int z = 0; z < map.Height; z++)
            {
                for (int x = 0; x < map.Width; ++x)
                {
                    var probability = map.GetPixel(x, z) * Density * 0.0001 * Step * Step;
                    var count       = (int)Math.Floor(probability);
                    if (random.NextDouble() < probability - count)
                    {
                        count++;
                    }

                    for (int i = 0; i < count; ++i)
                    {
                        var xx = random.NextDouble();
                        var zz = random.NextDouble();

                        Matrix transform = new Matrix();
                        transform.M11 = transform.M33 = HorizontalScale.Min + (float)random.NextDouble() * (HorizontalScale.Max - HorizontalScale.Min);
                        transform.M22 = VerticalScale.Min + (float)random.NextDouble() * (VerticalScale.Max - VerticalScale.Min);
                        transform.M44 = 1;

                        if (RandomizeRotation)
                        {
                            Matrix rotation;
                            Matrix.CreateRotationY((float)random.NextDouble() * MathHelper.Pi * 2, out rotation);
                            Matrix.Multiply(ref transform, ref rotation, out transform);
                        }

                        transform.M41 = (x * Step) + (float)(xx * Step);
                        transform.M43 = (z * Step) + (float)(zz * Step);

                        transforms.Add(transform);
                    }
                }
            }

            model.SetInstanceTransforms(transforms.ToArray());
        }
Пример #2
0
        public static byte[] Compile(string effectCode)
        {
            using (var stream = new FileStream(Path.Combine(Path.GetTempPath(), Path.GetTempFileName()), FileMode.Create))
            {
                var writer = new StreamWriter(stream);
                writer.Write(effectCode);
                writer.Flush();
                stream.Seek(0, SeekOrigin.Begin);

                return(ContentPipeline.LoadContent <CompiledEffectContent>(stream
                                                                           , new Microsoft.Xna.Framework.Content.Pipeline.EffectImporter()
                                                                           , new EffectProcessor()).GetEffectCode());
            }
        }
Пример #3
0
 public object Import(Stream stream, IServiceProvider serviceProvider)
 {
     return(ContentPipeline.LoadContent <Nine.Graphics.Heightmap>(stream, new Microsoft.Xna.Framework.Content.Pipeline.TextureImporter(), this));
 }