예제 #1
0
 public static void SetDistributionMap(InstancedModel model, DistributionMap value)
 {
     if (value != null)
     {
         value.Apply(model);
     }
 }
예제 #2
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());
        }
예제 #3
0
 public InstancedModelMesh(InstancedModel model, int index)
 {
     this.model = model;
     this.index = index;
 }
예제 #4
0
 public static DistributionMap GetDistributionMap(InstancedModel model)
 {
     return(null);
 }