/// <summary>
 ///     Agregar modelos a una celda
 /// </summary>
 private void addModelsToCell(GrillaRegularNode node, List <TgcMesh> modelos)
 {
     foreach (var mesh in modelos)
     {
         if (EscenarioManual.testAABBAABB(node.BoundingBox, mesh.BoundingBox))
         {
             node.Models.Add(mesh);
         }
     }
 }
        /// <summary>
        ///     Construye la grilla
        /// </summary>
        private GrillaRegularNode[,,] buildGrid(List <TgcMesh> modelos, TgcBoundingAxisAlignBox sceneBounds, TGCVector3 cellDim)
        {
            var sceneSize = sceneBounds.calculateSize();

            var gx = (int)FastMath.Ceiling(sceneSize.X / cellDim.X) + 1;
            var gy = (int)FastMath.Ceiling(sceneSize.Y / cellDim.Y) + 1;
            var gz = (int)FastMath.Ceiling(sceneSize.Z / cellDim.Z) + 1;

            var grid = new GrillaRegularNode[gx, gy, gz];

            //Construir grilla
            for (var x = 0; x < gx; x++)
            {
                for (var y = 0; y < gy; y++)
                {
                    for (var z = 0; z < gz; z++)
                    {
                        //Crear celda
                        var node = new GrillaRegularNode();

                        //Crear BoundingBox de celda
                        var pMin = new TGCVector3(sceneBounds.PMin.X + x * cellDim.X, sceneBounds.PMin.Y + y * cellDim.Y,
                                                  sceneBounds.PMin.Z + z * cellDim.Z);
                        var pMax = TGCVector3.Add(pMin, cellDim);
                        node.BoundingBox = new TgcBoundingAxisAlignBox(pMin, pMax);

                        //Cargar modelos en celda
                        node.Models = new List <TgcMesh>();
                        addModelsToCell(node, modelos);

                        grid[x, y, z] = node;
                    }
                }
            }

            return(grid);
        }