public IGrassSplat AddGrassEntities(GrassEntitiesWithMaterials grassEntitiesWithMaterials)
        {
            var grassInstancesTemplate = _generator.Generate(grassEntitiesWithMaterials);

            var maticesArray  = grassInstancesTemplate.TransformMatices;
            var uniformArrays = grassInstancesTemplate.UniformArrays;

            var newGrassPacks = new List <GrassPack>();

            for (var i = 0; i < Math.Ceiling((float)maticesArray.Length / Constants.MaxInstancesPerPack); i++)
            {
                var elementsToSkipCount = i * Constants.MaxInstancesPerPack;
                var elementsToTakeCount = Math.Min(Constants.MaxInstancesPerPack,
                                                   maticesArray.Length - i * Constants.MaxInstancesPerPack);
                var packMaticesArray          = maticesArray.Skip(elementsToSkipCount).Take(elementsToTakeCount).ToArray();
                MyMaterialPropertyBlock block = new MyMaterialPropertyBlock(elementsToTakeCount);
                foreach (var aUniformArray in uniformArrays)
                {
                    aUniformArray.AddToBlock(block.Block, elementsToSkipCount, elementsToTakeCount);
                }
                newGrassPacks.Add(new GrassPack(packMaticesArray, block));
            }

            var splatInfo = new SplatInfo(grassEntitiesWithMaterials.Mesh, grassEntitiesWithMaterials.Material);

            if (!_grassPacks.ContainsKey(splatInfo))
            {
                _grassPacks.Add(splatInfo, new Dictionary <PackId, List <GrassPack> >());
            }
            lastPackId++;
            _grassPacks[splatInfo][lastPackId] = newGrassPacks;

            return(new GpuInstancingGrassSplat(splatInfo, lastPackId, this));
        }
        public GrassPack(Matrix4x4[] maticesArray, MyMaterialPropertyBlock propertiesBlock)
        {
            Preconditions.Assert(maticesArray.Length <= Constants.MaxInstancesPerPack,
                                 String.Format("In grass pack there can be at max {0} elements, but is {1}", Constants.MaxInstancesPerPack, maticesArray.Length));

            CastShadows    = ShadowCastingMode.Off;
            MaticesArray   = maticesArray;
            InstancesCount = maticesArray.Length;
            MyBlock        = propertiesBlock;
        }