Esempio n. 1
0
  public void render() {
    updateNearbyChunkMeshes(false);

    material.getShader().setUniform("View", client.getActiveCamera().getView());
    material.getShader().setUniform("Projection", client.getActiveCamera().getProjection());

    renderChunks();
  }
Esempio n. 2
0
  public void setup() {
    world = client.getDefaultWorld();
    // World world = client.getWorld("world");
    material =
        (RenderMaterial)
            Spout.getFilesystem()
                .getResource("material://Spout/resources/resources/materials/BasicMaterial.smt");

    updateNearbyChunkMeshes(false);
    // GL11.glEnable(GL11.GL_CULL_FACE);
  }
Esempio n. 3
0
  private void renderChunks() {
    for (ChunkMeshBatch renderer : chunkRenderers) {
      material.getShader().setUniform("Model", renderer.getTransform());

      // It's hard to look right
      // at the world baby
      // But here's my frustrum
      // so cull me maybe?
      if (client.getActiveCamera().getFrustum().intersects(renderer)) {
        renderer.render();
      }
    }
  }
Esempio n. 4
0
  /**
   * Updates the list of chunks around the player.
   *
   * @param force Forces the update
   * @return True if the list was changed
   */
  public boolean updateNearbyChunkMeshes(boolean force) {
    if (world == null) {
      world = client.getDefaultWorld();
      if (world != null)
        System.out.println("World updated to " + world.getName() + "-" + world.getUID());
    }

    if (world == null) {
      try {
        Thread.sleep(5);
      } catch (InterruptedException e) {
      }
      return false;
    }

    int chunkViewDistance = client.getActivePlayer().getViewDistance() / 16;

    Point currentPos = client.getActivePlayer().getTransform().getPosition();

    int currentChunkX = currentPos.getChunkX();
    int currentChunkY = currentPos.getChunkY();
    int currentChunkZ = currentPos.getChunkZ();

    if (currentChunkX == lastChunkX
        && currentChunkY == lastChunkY
        && currentChunkZ == lastChunkZ
        && !force
        && !firstUpdate) {
      return false;
    }
    // just add all visible chunks

    if (chunkRenderers.size() == 0 || force) {
      chunkRenderers.clear();

      int cubeMinX = currentChunkX - chunkViewDistance;
      int cubeMinY = currentChunkY - chunkViewDistance;
      int cubeMinZ = currentChunkZ - chunkViewDistance;

      int cubeMaxX = currentChunkX + chunkViewDistance;
      int cubeMaxY = currentChunkY + chunkViewDistance;
      int cubeMaxZ = currentChunkZ + chunkViewDistance;

      Vector3 batchMin =
          ChunkMeshBatch.getBatchCoordinates(new Vector3(cubeMinX, cubeMinY, cubeMinZ));
      Vector3 batchMax =
          ChunkMeshBatch.getBatchCoordinates(new Vector3(cubeMaxX, cubeMaxY, cubeMaxZ));

      for (int x = batchMin.getFloorX(); x <= batchMax.getFloorX(); x++) {
        for (int y = batchMin.getFloorY(); y <= batchMax.getFloorY(); y++) {
          for (int z = batchMin.getFloorZ(); z <= batchMax.getFloorZ(); z++) {
            Vector3 chunkCoords = ChunkMeshBatch.getChunkCoordinates(new Vector3(x, y, z));
            ChunkMeshBatch batch =
                new ChunkMeshBatch(
                    material,
                    world,
                    chunkCoords.getFloorX(),
                    chunkCoords.getFloorY(),
                    chunkCoords.getFloorZ());
            addChunkMeshBatch(batch);
            batch.update();

            System.out.println(batch);
          }
        }
      }
    } else {
      Cube oldView =
          new Cube(
              new Point(
                  world,
                  lastChunkX - chunkViewDistance,
                  lastChunkY - chunkViewDistance,
                  lastChunkZ - chunkViewDistance),
              chunkViewDistance * 2);
      Cube newView =
          new Cube(
              new Point(
                  world,
                  currentChunkX - chunkViewDistance,
                  currentChunkY - chunkViewDistance,
                  currentChunkZ - chunkViewDistance),
              chunkViewDistance * 2);

      Vector3 min = oldView.getBase().min(newView.getBase());
      Vector3 max =
          oldView.getBase().add(oldView.getSize()).max(newView.getBase().add(newView.getSize()));

      // Shared area
      Vector3 ignoreMin = oldView.getBase().max(newView.getBase());
      Vector3 ignoreMax =
          oldView.getBase().add(oldView.getSize()).min(newView.getBase().add(newView.getSize()));
      Cuboid ignore = new Cuboid(new Point(ignoreMin, world), ignoreMax.subtract(ignoreMin));

      for (int x = min.getFloorX(); x < max.getFloorX(); x++) {
        for (int y = min.getFloorY(); y < max.getFloorY(); y++) {
          for (int z = min.getFloorZ(); z < max.getFloorZ(); z++) {
            Vector3 vec = new Vector3(x, y, z);
            if (ignore.contains(vec)) {
              continue;
            }

            Vector3 pos = ChunkMeshBatch.getChunkCoordinates(vec);

            if (oldView.contains(vec)) {
              ChunkMeshBatch c =
                  chunkRenderersByPosition.get(pos.getFloorX(), pos.getFloorY(), pos.getFloorZ());
              removeChunkMeshBatch(c);
              continue;
            }

            if (newView.contains(vec)) {
              ChunkMeshBatch c =
                  new ChunkMeshBatch(
                      material, world, pos.getFloorX(), pos.getFloorY(), pos.getFloorZ());
              addChunkMeshBatch(c);
              c.update();
            }
          }
        }
      }
    }

    firstUpdate = false;
    lastChunkX = currentChunkX;
    lastChunkY = currentChunkY;
    lastChunkZ = currentChunkZ;

    return true;
  }