Java 类com.badlogic.gdx.graphics.g3d.utils.MeshBuilder 实例源码

项目:Radix    文件:NormalBlockRenderer.java   
@Override
public void renderNorth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // POSITIVE Z
    float u = getU(atlasIndex);
    float v = getV(atlasIndex);
    builder.setUVRange(u, v, u, v);

    c00.setPos(x1, y1, z).setNor(0, 0, 1);
    c01.setPos(x1, y2, z).setNor(0, 0, 1);
    c10.setPos(x2, y1, z).setNor(0, 0, 1);
    c11.setPos(x2, y2, z).setNor(0, 0, 1);

    Color c = getColor((int) x1, (int) y1, (int) z - 1);
    if(pcld == null) {
        builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a);
    } else {
        c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a);
        c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a);
        c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a);
        c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a);
    }

    builder.rect(c00, c10, c11, c01);
}
项目:Radix    文件:NormalBlockRenderer.java   
@Override
public void renderSouth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // NEGATIVE Z
    float u = getU(atlasIndex);
    float v = getV(atlasIndex);
    builder.setUVRange(u, v, u, v);

    c00.setPos(x1, y1, z).setNor(0, 0, -1);
    c01.setPos(x1, y2, z).setNor(0, 0, -1);
    c10.setPos(x2, y1, z).setNor(0, 0, -1);
    c11.setPos(x2, y2, z).setNor(0, 0, -1);

    Color c = getColor((int) x1, (int) y1, (int) z);
    if(pcld == null) {
        builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a);
    } else {
        c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a);
        c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a);
        c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a);
        c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a);
    }

    builder.rect(c01, c11, c10, c00);
}
项目:Radix    文件:NormalBlockRenderer.java   
@Override
public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // NEGATIVE X
    float u = getU(atlasIndex);
    float v = getV(atlasIndex);
    builder.setUVRange(u, v, u, v);

    c00.setPos(x, y1, z1).setNor(-1, 0, 0);
    c01.setPos(x, y1, z2).setNor(-1, 0, 0);
    c10.setPos(x, y2, z1).setNor(-1, 0, 0);
    c11.setPos(x, y2, z2).setNor(-1, 0, 0);

    Color c = getColor((int) x, (int) y1, (int) z1);
    if(pcld == null) {
        builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a);
    } else {
        c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a);
        c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a);
        c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a);
        c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a);
    }

    builder.rect(c01, c11, c10, c00);
}
项目:Radix    文件:NormalBlockRenderer.java   
@Override
public void renderEast(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // POSITIVE X
    float u = getU(atlasIndex);
    float v = getV(atlasIndex);
    builder.setUVRange(u, v, u, v);

    c00.setPos(x, y1, z1).setNor(1, 0, 0);
    c01.setPos(x, y1, z2).setNor(1, 0, 0);
    c10.setPos(x, y2, z1).setNor(1, 0, 0);
    c11.setPos(x, y2, z2).setNor(1, 0, 0);

    Color c = getColor((int) x - 1, (int) y1, (int) z1);
    if(pcld == null) {
        builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a);
    } else {
        c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a);
        c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a);
        c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a);
        c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a);
    }

    builder.rect(c00, c10, c11, c01);
}
项目:Radix    文件:NormalBlockRenderer.java   
@Override
public void renderTop(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // POSITIVE Y
    float u = getU(atlasIndex);
    float v = getV(atlasIndex);
    builder.setUVRange(u, v, u, v);

    c00.setPos(x1, y, z1).setNor(0, 1, 0);
    c01.setPos(x1, y, z2).setNor(0, 1, 0);
    c10.setPos(x2, y, z1).setNor(0, 1, 0);
    c11.setPos(x2, y, z2).setNor(0, 1, 0);

    Color c = getColor((int) x1, (int) y - 1, (int) z1);
    if(pcld == null) {
        builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a);
    } else {
        c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a);
        c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a);
        c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a);
        c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a);
    }

    builder.rect(c01, c11, c10, c00);
}
项目:Radix    文件:NormalBlockRenderer.java   
@Override
public void renderBottom(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // NEGATIVE Y
    float u = getU(atlasIndex);
    float v = getV(atlasIndex);
    builder.setUVRange(u, v, u, v);

    c00.setPos(x1, y, z1).setNor(0, -1, 0);
    c01.setPos(x1, y, z2).setNor(0, -1, 0);
    c10.setPos(x2, y, z1).setNor(0, -1, 0);
    c11.setPos(x2, y, z2).setNor(0, -1, 0);

    Color c = getColor((int) x1, (int) y, (int) z1);
    if(pcld == null) {
        builder.setColor(c.r*lightLevel, c.g*lightLevel, c.b*lightLevel, c.a);
    } else {
        c00.setCol(c.r*pcld.l00, c.g*pcld.l00, c.b*pcld.l00, c.a);
        c01.setCol(c.r*pcld.l01, c.g*pcld.l01, c.b*pcld.l01, c.a);
        c10.setCol(c.r*pcld.l10, c.g*pcld.l10, c.b*pcld.l10, c.a);
        c11.setCol(c.r*pcld.l11, c.g*pcld.l11, c.b*pcld.l11, c.a);
    }

    builder.rect(c00, c10, c11, c01);
}
项目:Radix    文件:GreedyMesher.java   
public void render(MeshBuilder builder) {
    BlockRenderer renderer = block.getRenderer();

    switch (side) {
        case TOP:
            renderer.renderTop(block.getTextureIndex(), x1, y1, x2, y2, z + 1, lightLevel, pcld, builder);
            break;
        case BOTTOM:
            renderer.renderBottom(block.getTextureIndex(), x1, y1, x2, y2, z, lightLevel, pcld, builder);
            break;
        case NORTH:
            renderer.renderNorth(block.getTextureIndex(), x1, y1, x2, y2, z + 1, lightLevel, pcld, builder);
            break;
        case SOUTH:
            renderer.renderSouth(block.getTextureIndex(), x1, y1, x2, y2, z, lightLevel, pcld, builder);
            break;
        case EAST:
            renderer.renderEast(block.getTextureIndex(), x1, y1, x2, y2, z + 1, lightLevel, pcld, builder);
            break;
        case WEST:
            renderer.renderWest(block.getTextureIndex(), x1, y1, x2, y2, z, lightLevel, pcld, builder);
            break;

    }
}
项目:Mundus    文件:Terrain.java   
private Terrain(int vertexResolution) {
    this.transform = new Matrix4();
    this.attribs = MeshBuilder.createAttributes(VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal
            | VertexAttributes.Usage.TextureCoordinates);
    this.posPos = attribs.getOffset(VertexAttributes.Usage.Position, -1);
    this.norPos = attribs.getOffset(VertexAttributes.Usage.Normal, -1);
    this.uvPos = attribs.getOffset(VertexAttributes.Usage.TextureCoordinates, -1);
    this.stride = attribs.vertexSize / 4;

    this.vertexResolution = vertexResolution;
    this.heightData = new float[vertexResolution * vertexResolution];

    this.terrainTexture = new TerrainTexture();
    this.terrainTexture.setTerrain(this);
    material = new Material();
    material.set(new TerrainTextureAttribute(TerrainTextureAttribute.ATTRIBUTE_SPLAT0, terrainTexture));
}
项目:Alien-Ark    文件:ControllerPlanet.java   
public static Model createInfiniteWaterPart(TypeInterpreter interpreter, int landscapeIndex, PlanetConfig planetConfig) {
    ModelBuilder modelBuilder = new ModelBuilder();
    MeshBuilder builder = new MeshBuilder();
    float waterHeight = interpreter.it.get(landscapeIndex).endValue;
    builder.begin(PlanetPart.VERTEX_ATTRIBUTES, GL20.GL_TRIANGLES);
    infiniteWaterHeight = waterHeight * planetConfig.landscapeHeight - 1;
    Vector3 corner01 = new Vector3(-INFINITE_WATER_SIZE, -INFINITE_WATER_SIZE, infiniteWaterHeight);
    Vector3 corner02 = new Vector3(INFINITE_WATER_SIZE, -INFINITE_WATER_SIZE, infiniteWaterHeight);
    Vector3 corner03 = new Vector3(INFINITE_WATER_SIZE, INFINITE_WATER_SIZE, infiniteWaterHeight);
    Vector3 corner04 = new Vector3(-INFINITE_WATER_SIZE, INFINITE_WATER_SIZE, infiniteWaterHeight);
    builder.rect(corner01, corner02, corner03, corner04, new Vector3(0, 0, 1));
    Material waterMaterial = planetConfig.layerConfigs.get(landscapeIndex).material;
    Mesh mesh = builder.end();
    modelBuilder.begin();
    modelBuilder.part(PlanetPart.LANDSCAPE_PART_NAME + landscapeIndex, mesh, GL20.GL_TRIANGLES, waterMaterial);
    return modelBuilder.end();
}
项目:Alien-Ark    文件:PlanetPart.java   
/**
 * Creates a water plane.
 * @param chunk The chunk.
 */
private void createWaterPart(Chunk chunk, int landscapeIndex) {
    MeshBuilder builder = meshBuilders.get(landscapeIndex);
    float WATER_HEIGHT = interpreter.it.get(landscapeIndex).endValue;
    builder.begin(VERTEX_ATTRIBUTES, GL20.GL_TRIANGLES);
    float z = WATER_HEIGHT * planetConfig.landscapeHeight;
    float width = chunk.getWidth() * tileSize;
    float height = chunk.getHeight() * tileSize;

    Vector3 corner01 = new Vector3(0f, 0f, z);
    Vector3 corner02 = new Vector3(width, 0f, z);
    Vector3 corner03 = new Vector3(width, height, z);
    Vector3 corner04 = new Vector3(0f, height, z);

    builder.rect(corner01, corner02, corner03, corner04, new Vector3(0, 0, 1));
    Material waterMaterial = planetConfig.layerConfigs.get(landscapeIndex).material;
    Mesh mesh = builder.end();
    modelBuilder.node().id = LANDSCAPE_NODE_NAME + landscapeIndex;
    modelBuilder.part(LANDSCAPE_PART_NAME + landscapeIndex, mesh, GL20.GL_TRIANGLES, waterMaterial);
}
项目:Argent    文件:Terrain.java   
public Terrain(int vertexResolution) {
    this.transform = new Matrix4();
    this.attribs = MeshBuilder.createAttributes(Position | Normal | TextureCoordinates);
    this.posPos = attribs.getOffset(Position, -1);
    this.norPos = attribs.getOffset(Normal, -1);
    this.uvPos = attribs.getOffset(TextureCoordinates, -1);
    this.stride = attribs.vertexSize / 4;

    this.vertexResolution = vertexResolution;
    this.heightData = new float[vertexResolution * vertexResolution];

    material = Reference.Defaults.Models.material();
}
项目:libgdx-shaders    文件:FrameBufferScreen.java   
private void build() {
    region = new TextureRegion(assetManager.<Texture>get("img/lena.png"));

    shaderManager.createFrameBuffer("frameBuffer01");

    final MeshBuilder meshBuilder = new MeshBuilder();
    meshBuilder.begin(VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked | VertexAttributes.Usage.TextureCoordinates, GL20.GL_TRIANGLES);
    meshBuilder.rect(
            0f, 200f, 0f,
            200f, 200f, 0f,
            200f, 0f, 0f,
            0f, 0f, 0f,
            0f, 0f, 0f);
    rectangle = meshBuilder.end();
}
项目:Radix    文件:Chunk.java   
@Override
public void rerender() {
    if (cleanedUp)
        return;

    boolean neighborSunlightChanging = false;
    for(int x = startPosition.x - 16; x <= startPosition.x + 16; x += 16) {
        for(int z = startPosition.z - 16; z <= startPosition.z + 16; z += 16) {
            IChunk c = getWorld().getChunk(x, z);
            if(c != null && c.waitingOnLightFinish()) {
                neighborSunlightChanging = true;
            }
        }
    }
    if(neighborSunlightChanging)
        return;

    if (!setup) {
        meshBuilder = new MeshBuilder();
        modelBuilder = new ModelBuilder();

        setup = true;
    }

    sunlightChanged = false;

    if(meshing) {
        meshWhenDone = true;
    } else {
        meshing = true;
        parentWorld.addToMeshQueue(this::updateFaces);
    }
}
项目:Radix    文件:GrassRenderer.java   
@Override
public void renderTop(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    float u = getU(atlasIndex);
    float v = getV(atlasIndex);
    builder.setUVRange(u, v, u, v);

    MeshPartBuilder.VertexInfo c00 = new MeshPartBuilder.VertexInfo().setPos(x1, y, z1).setNor(0, 1, 0);
    MeshPartBuilder.VertexInfo c01 = new MeshPartBuilder.VertexInfo().setPos(x1, y, z2).setNor(0, 1, 0);
    MeshPartBuilder.VertexInfo c10 = new MeshPartBuilder.VertexInfo().setPos(x2, y, z1).setNor(0, 1, 0);
    MeshPartBuilder.VertexInfo c11 = new MeshPartBuilder.VertexInfo().setPos(x2, y, z2).setNor(0, 1, 0);

    IChunk chunk = RadixClient.getInstance().getWorld().getChunk((int) x1, (int) z1);
    Biome biome;
    if(chunk != null) {
        biome = chunk.getBiome();
    } else {
        biome = RadixAPI.instance.getBiomeByID(0);
    }
    int[] color = biome.getGrassColor((int) y - 1);
    float r = color[0]/255f;
    float g = color[1]/255f;
    float b = color[2]/255f;
    if(pcld == null) {
        builder.setColor(r*lightLevel, g*lightLevel, b*lightLevel, 1);
    } else {
        c00.setCol(r*pcld.l00, g*pcld.l00, b*pcld.l00, 1);
        c01.setCol(r*pcld.l01, g*pcld.l01, b*pcld.l01, 1);
        c10.setCol(r*pcld.l10, g*pcld.l10, b*pcld.l10, 1);
        c11.setCol(r*pcld.l11, g*pcld.l11, b*pcld.l11, 1);
    }

    builder.rect(c01, c11, c10, c00);
}
项目:Radix    文件:MetadataHeightRenderer.java   
@Override
public void renderNorth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    int zi = MathUtils.floor(z - 1);
    int xi = MathUtils.floor(x1);
    int yi = MathUtils.floor(y1);
    IWorld world = RadixClient.getInstance().getWorld();
    IChunk chunk = world.getChunk(xi, zi);
    short meta = 0;
    try {
        meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1));
    } catch (CoordinatesOutOfBoundsException e) {
        e.printStackTrace();
    }
    super.renderNorth(atlasIndex, x1, y1, x2, y1 + getHeight(meta), z, lightLevel, pcld, builder);
}
项目:Radix    文件:MetadataHeightRenderer.java   
@Override
public void renderSouth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    int zi = MathUtils.floor(z);
    int xi = MathUtils.floor(x1);
    int yi = MathUtils.floor(y1);
    IWorld world = RadixClient.getInstance().getWorld();
    IChunk chunk = world.getChunk(xi, zi);
    short meta = 0;
    try {
        meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1));
    } catch (CoordinatesOutOfBoundsException e) {
        e.printStackTrace();
    }
    super.renderSouth(atlasIndex, x1, y1, x2, y1 + getHeight(meta), z, lightLevel, pcld, builder);
}
项目:Radix    文件:MetadataHeightRenderer.java   
@Override
public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    int zi = MathUtils.floor(z1);
    int xi = MathUtils.floor(x);
    int yi = MathUtils.floor(y1);
    IWorld world = RadixClient.getInstance().getWorld();
    IChunk chunk = world.getChunk(xi, zi);
    short meta = 0;
    try {
        meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1));
    } catch (CoordinatesOutOfBoundsException e) {
        e.printStackTrace();
    }
    super.renderWest(atlasIndex, z1, y1, z2, y1 + getHeight(meta), x, lightLevel, pcld, builder);
}
项目:Radix    文件:MetadataHeightRenderer.java   
@Override
public void renderEast(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    int zi = MathUtils.floor(z1);
    int xi = MathUtils.floor(x - 1);
    int yi = MathUtils.floor(y1);
    IWorld world = RadixClient.getInstance().getWorld();
    IChunk chunk = world.getChunk(xi, zi);
    short meta = 0;
    try {
        meta = chunk.getMeta(xi & (world.getChunkSize() - 1), yi, zi & (world.getChunkSize() - 1));
    } catch (CoordinatesOutOfBoundsException e) {
        e.printStackTrace();
    }
    super.renderEast(atlasIndex, z1, y1, z2, y1 + getHeight(meta), x, lightLevel, pcld, builder);
}
项目:Radix    文件:MetadataHeightRenderer.java   
@Override
public void renderTop(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    int zi = MathUtils.floor(z1);
    int xi = MathUtils.floor(x1);
    int yi = MathUtils.floor(y - 1);
    IWorld world = RadixClient.getInstance().getWorld();
    IChunk chunk = world.getChunk(xi, zi);
    short meta = 0;
    try {
        meta = chunk.getMeta(xi & (world.getChunkSize()-1), yi, zi & (world.getChunkSize()-1));
    } catch (CoordinatesOutOfBoundsException e) {
        e.printStackTrace();
    }
    super.renderTop(atlasIndex, x1, z1, x2, z2, y - (1 - getHeight(meta)), lightLevel, pcld, builder);
}
项目:Radix    文件:GreedyMesher.java   
public Mesh meshFaces(List<Face> faces, MeshBuilder builder) {
    builder.begin(VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates | VertexAttributes.Usage.ColorPacked | VertexAttributes.Usage.Normal, GL20.GL_TRIANGLES);

    builder.ensureVertices(faces.size() * 4);
    for (Face f : faces) {
        f.render(builder);
    }
    return builder.end();
}
项目:Alien-Ark    文件:PlanetPart.java   
public PlanetPart(Chunk chunk, float tileSize, PlanetConfig pPlanetConfig, TypeInterpreter interpreter,
                  CollectedItemCache collectedItemCache, double seed) {

    this.tileSize = tileSize;
    this.planetConfig = pPlanetConfig;
    this.interpreter = interpreter;

    if (pPlanetConfig.layerConfigs.size() != interpreter.it.size()) {
        Log.e(PlanetPart.class, "Interpreter items count " + interpreter.it.size()
                + " (opusConfig.json) and layer config count " + pPlanetConfig.layerConfigs.size()
                + " (sceneConfig.json) not equal.");
    }

    // create MeshBuilder for every landscape layer
    for (int i = 0; i < interpreter.it.size(); i++) {
        meshBuilders.add(new MeshBuilder());
    }
    modelBuilder = new ModelBuilder();

    modelBuilder.begin();
    createLandscapePart(chunk);
    for (int i = 0; i < pPlanetConfig.layerConfigs.size(); i++) {
        PlanetConfig.LandscapeLayerConfig layerConfig = pPlanetConfig.layerConfigs.get(i);
        if (CollisionTypes.byName(layerConfig.collisionType) == CollisionTypes.WATER) {
            createWaterPart(chunk, i);
        }
    }
    model = modelBuilder.end();
    modelInstance = new ModelInstance(model);
    modelInstance.transform.translate(getChunkGraphicX(chunk), getChunkGraphicY(chunk), 0);

    initPhysics();
    initCollectibles(chunk, collectedItemCache, 0);
    initArtifacts(chunk);
    initRaceWayPoints(chunk);
}
项目:ForgE    文件:DayNightSkybox.java   
private Renderable getCubeRenderable() {
  if (dayNightRenderable == null) {
    this.dayNightRenderable           = new DayNightSkyRenderable();
    //this.dayNightRenderable.mesh      = buildMesh();
    MeshBuilder meshBuilder = new MeshBuilder();
    meshBuilder.begin(new VertexAttributes(VertexAttribute.Position(), VertexAttribute.TexCoords(0)), GL30.GL_TRIANGLES); {
      meshBuilder.sphere(10,10,10,30,10);
    } this.dayNightRenderable.mesh    = meshBuilder.end();
    dayNightRenderable.primitiveType  = GL30.GL_TRIANGLES;
    dayNightRenderable.worldTransform.idt();
  }

  return dayNightRenderable;
}
项目:HelixEngine    文件:TilePermissionsGridDisplayable.java   
public TilePermissionsGridDisplayable(Tile[][] tiles, TextureAtlas atlas) {
  this.atlas = atlas;

  MeshBuilder meshBuilder = new MeshBuilder();

  meshBuilder.begin(VertexAttributes.Usage.Position |
                    VertexAttributes.Usage.TextureCoordinates,
                    GL20.GL_TRIANGLES);

  for (int y = 0; y < tiles.length; y++) {
    for (int x = 0; x < tiles[y].length; x++) {
      // TODO: Cache regions
      meshBuilder.setUVRange(
          atlas.findRegion(tiles[y][x].getPermissions().name()));

      meshBuilder.rect(x,     y,     0,
                       x + 1, y,     0,
                       x + 1, y + 1, 0,
                       x,     y + 1, 0,
                       0,     0,     1);
    }
  }

  Mesh mesh = meshBuilder.end();

  ModelBuilder modelBuilder = new ModelBuilder();
  modelBuilder.begin();

  TextureAttribute diffuse
      = TextureAttribute.createDiffuse(atlas.getTextures().first());

  modelBuilder.part("grid", mesh, GL20.GL_TRIANGLES, new Material(diffuse));

  instance = new ModelInstance(modelBuilder.end());

  instance.transform.translate(0, 0, Z_OFFSET);
}
项目:amatsukaze    文件:MikuMaterial.java   
public Mesh getMesh() {
    if(mesh == null) {
        MeshBuilder builder = new MeshBuilder();
        builder.begin(
            new VertexAttributes(
                VertexAttribute.Position(),
                VertexAttribute.Normal(),
                VertexAttribute.TexCoords(0)),
            GL20.GL_TRIANGLES
        );


        for(int i = 0 ; i < m_pVertexes.length ; ++i) {
            MMD_VERTEX_DESC vert = m_pVertexes[i].pOriginalVert;
            MMD_VECTOR3 point = vert.original.point;
            MMD_VECTOR3 normal = vert.original.normal;
            MMD_VECTOR2 uv = vert.original.uv;
            builder.vertex(
                point.x, point.y, point.z,
                normal.x, normal.y, normal.z,
                uv.x, uv.y
            );
        }

        mesh = builder.end();
    }
    return mesh;
}
项目:gdx-tilemap3d    文件:ChunkVertexGenerator.java   
protected void addMesh(MeshBuilder builder, Tile tile, TileMesh sourceMesh, TileChunk chunk, TileCoord position, Matrix4 transform, Color color, int firstVertex, int numVertices) {
    // adjust position by the tilemesh offset. TileMesh's are modeled using the
    // origin (0,0,0) as the center and are 1 unit wide/deep/tall. So, their
    // max extents are from -0.5,-0.5,-0.5 to 0.5,0.5,0.5. For rendering
    // purposes in a chunk, we want the extents to be 0,0,0 to 1,1,1. This
    // adjustment fixes that
    tmpOffset.set(TileMesh.OFFSET);
    tmpOffset.x += (float)position.x;
    tmpOffset.y += (float)position.y;
    tmpOffset.z += (float)position.z;

    Vertices sourceVertices = sourceMesh.getVertices();
    sourceVertices.moveTo(firstVertex);

    // copy vertices
    for (int i = 0; i < numVertices; ++i) {
        sourceVertices.getVertex(vertex);

        // TODO: need to play with vertex/mesh color combinations a bit more to see if this is really correct
        vertex.color.set(
                vertex.color.r * color.r,
                vertex.color.g * color.g,
                vertex.color.b * color.b,
                vertex.color.a * color.a
        );

        // transform if applicable... (this will probably just be per-tile rotation)
        if (transform != null) {
            vertex.position.mul(transform);
            vertex.normal.rot(transform);
        }

        // translate vertex into "world/tilemap space"
        vertex.position.add(tmpOffset);

        builder.vertex(vertex);
        sourceVertices.moveNext();
    }
}
项目:Radix    文件:World.java   
private ModelInstance createSkybox() {
    if(skyboxModel != null) {
        skyboxModel.dispose();
    }
    if(skyboxTexture == null) {
        skyboxTexture = new Texture(Gdx.files.internal("textures/world/skybox.png"));
    }

    MeshBuilder builder = new MeshBuilder();
    builder.begin(VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates, GL20.GL_TRIANGLES);

    int x1 = -256;
    int y1 = -256;
    int z1 = -256;
    int x2 = 256;
    int y2 = 256;
    int z2 = 256;
    float sideU1 = 0;
    float sideU2 = 1/3f;
    float sideV1 = 0;
    float sideV2 = 1;
    float topU1 = sideU2;
    float topU2 = topU1+sideU2;
    float bottomU1 = topU2+sideU2;
    float bottomU2 = bottomU1+sideU2;
    float topV1 = 0;
    float topV2 = 1;
    float bottomV1 = 0;
    float bottomV2 = 1;
    MeshPartBuilder.VertexInfo bottomLeftBack = new MeshPartBuilder.VertexInfo().setPos(x1, y1, z1).setUV(sideU1, sideV2);
    MeshPartBuilder.VertexInfo bottomRightBack = new MeshPartBuilder.VertexInfo().setPos(x2, y1, z1).setUV(sideU2, sideV2);
    MeshPartBuilder.VertexInfo bottomRightFront = new MeshPartBuilder.VertexInfo().setPos(x2, y1, z2).setUV(sideU1, sideV2);
    MeshPartBuilder.VertexInfo bottomLeftFront = new MeshPartBuilder.VertexInfo().setPos(x1, y1, z2).setUV(sideU2, sideV2);
    MeshPartBuilder.VertexInfo topLeftBack = new MeshPartBuilder.VertexInfo().setPos(x1, y2, z1).setUV(sideU1, sideV1);
    MeshPartBuilder.VertexInfo topRightBack = new MeshPartBuilder.VertexInfo().setPos(x2, y2, z1).setUV(sideU2, sideV1);
    MeshPartBuilder.VertexInfo topRightFront = new MeshPartBuilder.VertexInfo().setPos(x2, y2, z2).setUV(sideU1, sideV1);
    MeshPartBuilder.VertexInfo topLeftFront = new MeshPartBuilder.VertexInfo().setPos(x1, y2, z2).setUV(sideU2, sideV1);
    // Negative Z
    builder.rect(bottomLeftBack, bottomRightBack, topRightBack, topLeftBack);
    // Positive Z
    builder.rect(topLeftFront, topRightFront, bottomRightFront, bottomLeftFront);
    // Negative X
    builder.rect(bottomLeftBack, topLeftBack, topLeftFront, bottomLeftFront);
    // Positive X
    builder.rect(bottomRightFront, topRightFront, topRightBack, bottomRightBack);
    // Positive Y
    builder.rect(topLeftBack.setUV(topU1, topV1),
            topRightBack.setUV(topU2, topV1),
            topRightFront.setUV(topU2, topV2),
            topLeftFront.setUV(topU1, topV2));
    // Negative Y
    builder.rect(bottomLeftFront.setUV(bottomU1, bottomV2),
            bottomRightFront.setUV(bottomU2, bottomV2),
            bottomRightBack.setUV(bottomU2, bottomV1),
            bottomLeftBack.setUV(bottomU1, bottomV1));
    Mesh skybox = builder.end();

    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    modelBuilder.part("skybox", skybox, GL20.GL_TRIANGLES, new Material(
            TextureAttribute.createDiffuse(skyboxTexture)));
    return new ModelInstance(skyboxModel = modelBuilder.end());
}
项目:Radix    文件:FenceRenderer.java   
@Override
public void renderNorth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // POSITIVE Z
    super.renderNorth(atlasIndex, x1 + 0.5f - R, y1, x2 - 0.5f + R, y2, z - 0.5f + R, lightLevel, pcld, builder);
}
项目:Radix    文件:FenceRenderer.java   
@Override
public void renderSouth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // NEGATIVE Z
    super.renderSouth(atlasIndex, x1 + 0.5f - R, y1, x2 - 0.5f + R, y2, z + 0.5f - R, lightLevel, pcld, builder);
}
项目:Radix    文件:FenceRenderer.java   
@Override
public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // NEGATIVE X
    super.renderWest(atlasIndex, z1 + 0.5f - R, y1, z2 - 0.5f + R, y2, x + 0.5f - R, lightLevel, pcld, builder);
}
项目:Radix    文件:FenceRenderer.java   
@Override
public void renderEast(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // POSITIVE X
    super.renderEast(atlasIndex, z1 + 0.5f - R, y1, z2 - 0.5f + R, y2, x - 0.5f + R, lightLevel, pcld, builder);
}
项目:Radix    文件:FenceRenderer.java   
@Override
public void renderTop(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // POSITIVE Y
    super.renderTop(atlasIndex, x1 + 0.5f - R, z1 + 0.5f - R, x2 - 0.5f + R, z2 - 0.5f + R, y, lightLevel, pcld, builder);
}
项目:Radix    文件:FenceRenderer.java   
@Override
public void renderBottom(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    // NEGATIVE Y
    super.renderBottom(atlasIndex, x1 + 0.5f - R, z1 + 0.5f - R, x2 - 0.5f + R, z2 - 0.5f + R, y, lightLevel, pcld, builder);
}
项目:Radix    文件:GrassRenderer.java   
@Override
public void renderNorth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    super.renderNorth(atlasIndex + SIDE_OFFSET, x1, y1, x2, y2, z, lightLevel, pcld, builder);
}
项目:Radix    文件:GrassRenderer.java   
@Override
public void renderSouth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    super.renderSouth(atlasIndex + SIDE_OFFSET, x1, y1, x2, y2, z, lightLevel, pcld, builder);
}
项目:Radix    文件:GrassRenderer.java   
@Override
public void renderEast(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    super.renderEast(atlasIndex + SIDE_OFFSET, z1, y1, z2, y2, x, lightLevel, pcld, builder);
}
项目:Radix    文件:GrassRenderer.java   
@Override
public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    super.renderWest(atlasIndex + SIDE_OFFSET, z1, y1, z2, y2, x, lightLevel, pcld, builder);
}
项目:Radix    文件:GrassRenderer.java   
@Override
public void renderBottom(int atlasIndex, float x1, float z1, float x2, float z2, float y, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    super.renderBottom(atlasIndex + BOTTOM_OFFSET, x1, z1, x2, z2, y, lightLevel, pcld, builder);
}
项目:Radix    文件:FlatFoliageRenderer.java   
@Override
public void renderNorth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    super.renderNorth(atlasIndex, x1, y1, x2, y2, z - 0.5f, lightLevel, pcld, builder);
}
项目:Radix    文件:FlatFoliageRenderer.java   
@Override
public void renderSouth(int atlasIndex, float x1, float y1, float x2, float y2, float z, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    super.renderSouth(atlasIndex, x1, y1, x2, y2, z + 0.5f, lightLevel, pcld, builder);
}
项目:Radix    文件:FlatFoliageRenderer.java   
@Override
public void renderWest(int atlasIndex, float z1, float y1, float z2, float y2, float x, float lightLevel, PerCornerLightData pcld, MeshBuilder builder) {
    super.renderWest(atlasIndex, z1, y1, z2, y2, x + 0.5f, lightLevel, pcld, builder);
}