Search in sources :

Example 1 with VertexInfo

use of com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo in project libgdx by libgdx.

the class ConeShapeBuilder method build.

public static void build(MeshPartBuilder builder, float width, float height, float depth, int divisions, float angleFrom, float angleTo, boolean close) {
    // FIXME create better cylinder method (- axis on which to create the cone (matrix?))
    builder.ensureVertices(divisions + 2);
    builder.ensureTriangleIndices(divisions);
    final float hw = width * 0.5f;
    final float hh = height * 0.5f;
    final float hd = depth * 0.5f;
    final float ao = MathUtils.degreesToRadians * angleFrom;
    final float step = (MathUtils.degreesToRadians * (angleTo - angleFrom)) / divisions;
    final float us = 1f / divisions;
    float u = 0f;
    float angle = 0f;
    VertexInfo curr1 = vertTmp3.set(null, null, null, null);
    curr1.hasUV = curr1.hasPosition = curr1.hasNormal = true;
    VertexInfo curr2 = vertTmp4.set(null, null, null, null).setPos(0, hh, 0).setNor(0, 1, 0).setUV(0.5f, 0);
    final short base = builder.vertex(curr2);
    short i1, i2 = 0;
    for (int i = 0; i <= divisions; i++) {
        angle = ao + step * i;
        u = 1f - us * i;
        curr1.position.set(MathUtils.cos(angle) * hw, 0f, MathUtils.sin(angle) * hd);
        curr1.normal.set(curr1.position).nor();
        curr1.position.y = -hh;
        curr1.uv.set(u, 1);
        i1 = builder.vertex(curr1);
        // FIXME don't duplicate lines and points
        if (i != 0)
            builder.triangle(base, i1, i2);
        i2 = i1;
    }
    if (close)
        EllipseShapeBuilder.build(builder, width, depth, 0, 0, divisions, 0, -hh, 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, 180f - angleTo, 180f - angleFrom);
}
Also used : VertexInfo(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo)

Example 2 with VertexInfo

use of com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo in project libgdx by libgdx.

the class CylinderShapeBuilder method build.

/** Build a cylinder */
public static void build(MeshPartBuilder builder, float width, float height, float depth, int divisions, float angleFrom, float angleTo, boolean close) {
    // FIXME create better cylinder method (- axis on which to create the cylinder (matrix?))
    final float hw = width * 0.5f;
    final float hh = height * 0.5f;
    final float hd = depth * 0.5f;
    final float ao = MathUtils.degreesToRadians * angleFrom;
    final float step = (MathUtils.degreesToRadians * (angleTo - angleFrom)) / divisions;
    final float us = 1f / divisions;
    float u = 0f;
    float angle = 0f;
    VertexInfo curr1 = vertTmp3.set(null, null, null, null);
    curr1.hasUV = curr1.hasPosition = curr1.hasNormal = true;
    VertexInfo curr2 = vertTmp4.set(null, null, null, null);
    curr2.hasUV = curr2.hasPosition = curr2.hasNormal = true;
    short i1, i2, i3 = 0, i4 = 0;
    builder.ensureVertices(2 * (divisions + 1));
    builder.ensureRectangleIndices(divisions);
    for (int i = 0; i <= divisions; i++) {
        angle = ao + step * i;
        u = 1f - us * i;
        curr1.position.set(MathUtils.cos(angle) * hw, 0f, MathUtils.sin(angle) * hd);
        curr1.normal.set(curr1.position).nor();
        curr1.position.y = -hh;
        curr1.uv.set(u, 1);
        curr2.position.set(curr1.position);
        curr2.normal.set(curr1.normal);
        curr2.position.y = hh;
        curr2.uv.set(u, 0);
        i2 = builder.vertex(curr1);
        i1 = builder.vertex(curr2);
        // FIXME don't duplicate lines and points
        if (i != 0)
            builder.rect(i3, i1, i2, i4);
        i4 = i2;
        i3 = i1;
    }
    if (close) {
        EllipseShapeBuilder.build(builder, width, depth, 0, 0, divisions, 0, hh, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, angleFrom, angleTo);
        EllipseShapeBuilder.build(builder, width, depth, 0, 0, divisions, 0, -hh, 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, 180f - angleTo, 180f - angleFrom);
    }
}
Also used : VertexInfo(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo)

Example 3 with VertexInfo

use of com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo in project libgdx by libgdx.

the class EllipseShapeBuilder method build.

/** Build an ellipse */
public static void build(MeshPartBuilder builder, float width, float height, float innerWidth, float innerHeight, int divisions, float centerX, float centerY, float centerZ, float normalX, float normalY, float normalZ, float tangentX, float tangentY, float tangentZ, float binormalX, float binormalY, float binormalZ, float angleFrom, float angleTo) {
    if (innerWidth <= 0 || innerHeight <= 0) {
        builder.ensureVertices(divisions + 2);
        builder.ensureTriangleIndices(divisions);
    } else if (innerWidth == width && innerHeight == height) {
        builder.ensureVertices(divisions + 1);
        builder.ensureIndices(divisions + 1);
        if (builder.getPrimitiveType() != GL20.GL_LINES)
            throw new GdxRuntimeException("Incorrect primitive type : expect GL_LINES because innerWidth == width && innerHeight == height");
    } else {
        builder.ensureVertices((divisions + 1) * 2);
        builder.ensureRectangleIndices(divisions + 1);
    }
    final float ao = MathUtils.degreesToRadians * angleFrom;
    final float step = (MathUtils.degreesToRadians * (angleTo - angleFrom)) / divisions;
    final Vector3 sxEx = tmpV1.set(tangentX, tangentY, tangentZ).scl(width * 0.5f);
    final Vector3 syEx = tmpV2.set(binormalX, binormalY, binormalZ).scl(height * 0.5f);
    final Vector3 sxIn = tmpV3.set(tangentX, tangentY, tangentZ).scl(innerWidth * 0.5f);
    final Vector3 syIn = tmpV4.set(binormalX, binormalY, binormalZ).scl(innerHeight * 0.5f);
    VertexInfo currIn = vertTmp3.set(null, null, null, null);
    currIn.hasUV = currIn.hasPosition = currIn.hasNormal = true;
    currIn.uv.set(.5f, .5f);
    currIn.position.set(centerX, centerY, centerZ);
    currIn.normal.set(normalX, normalY, normalZ);
    VertexInfo currEx = vertTmp4.set(null, null, null, null);
    currEx.hasUV = currEx.hasPosition = currEx.hasNormal = true;
    currEx.uv.set(.5f, .5f);
    currEx.position.set(centerX, centerY, centerZ);
    currEx.normal.set(normalX, normalY, normalZ);
    final short center = builder.vertex(currEx);
    float angle = 0f;
    final float us = 0.5f * (innerWidth / width);
    final float vs = 0.5f * (innerHeight / height);
    short i1, i2 = 0, i3 = 0, i4 = 0;
    for (int i = 0; i <= divisions; i++) {
        angle = ao + step * i;
        final float x = MathUtils.cos(angle);
        final float y = MathUtils.sin(angle);
        currEx.position.set(centerX, centerY, centerZ).add(sxEx.x * x + syEx.x * y, sxEx.y * x + syEx.y * y, sxEx.z * x + syEx.z * y);
        currEx.uv.set(.5f + .5f * x, .5f + .5f * y);
        i1 = builder.vertex(currEx);
        if (innerWidth <= 0f || innerHeight <= 0f) {
            if (i != 0)
                builder.triangle(i1, i2, center);
            i2 = i1;
        } else if (innerWidth == width && innerHeight == height) {
            if (i != 0)
                builder.line(i1, i2);
            i2 = i1;
        } else {
            currIn.position.set(centerX, centerY, centerZ).add(sxIn.x * x + syIn.x * y, sxIn.y * x + syIn.y * y, sxIn.z * x + syIn.z * y);
            currIn.uv.set(.5f + us * x, .5f + vs * y);
            i2 = i1;
            i1 = builder.vertex(currIn);
            if (i != 0)
                builder.rect(i1, i2, i4, i3);
            i4 = i2;
            i3 = i1;
        }
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) VertexInfo(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo) Vector3(com.badlogic.gdx.math.Vector3)

Example 4 with VertexInfo

use of com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo in project libgdx by libgdx.

the class SphereShapeBuilder method build.

/** @deprecated use {@link MeshPartBuilder#setVertexTransform(Matrix4)} instead of using the method signature taking a matrix. */
@Deprecated
public static void build(MeshPartBuilder builder, final Matrix4 transform, float width, float height, float depth, int divisionsU, int divisionsV, float angleUFrom, float angleUTo, float angleVFrom, float angleVTo) {
    // FIXME create better sphere method (- only one vertex for each pole, - position)
    final float hw = width * 0.5f;
    final float hh = height * 0.5f;
    final float hd = depth * 0.5f;
    final float auo = MathUtils.degreesToRadians * angleUFrom;
    final float stepU = (MathUtils.degreesToRadians * (angleUTo - angleUFrom)) / divisionsU;
    final float avo = MathUtils.degreesToRadians * angleVFrom;
    final float stepV = (MathUtils.degreesToRadians * (angleVTo - angleVFrom)) / divisionsV;
    final float us = 1f / divisionsU;
    final float vs = 1f / divisionsV;
    float u = 0f;
    float v = 0f;
    float angleU = 0f;
    float angleV = 0f;
    VertexInfo curr1 = vertTmp3.set(null, null, null, null);
    curr1.hasUV = curr1.hasPosition = curr1.hasNormal = true;
    final int s = divisionsU + 3;
    tmpIndices.clear();
    tmpIndices.ensureCapacity(divisionsU * 2);
    tmpIndices.size = s;
    int tempOffset = 0;
    builder.ensureVertices((divisionsV + 1) * (divisionsU + 1));
    builder.ensureRectangleIndices(divisionsU);
    for (int iv = 0; iv <= divisionsV; iv++) {
        angleV = avo + stepV * iv;
        v = vs * iv;
        final float t = MathUtils.sin(angleV);
        final float h = MathUtils.cos(angleV) * hh;
        for (int iu = 0; iu <= divisionsU; iu++) {
            angleU = auo + stepU * iu;
            u = 1f - us * iu;
            // Fixme : wrong normal calculation if transform
            curr1.position.set(MathUtils.cos(angleU) * hw * t, h, MathUtils.sin(angleU) * hd * t).mul(transform);
            curr1.normal.set(curr1.position).nor();
            curr1.uv.set(u, v);
            tmpIndices.set(tempOffset, builder.vertex(curr1));
            final int o = tempOffset + s;
            if (// FIXME don't duplicate lines and points
            (iv > 0) && (iu > 0))
                builder.rect(tmpIndices.get(tempOffset), tmpIndices.get((o - 1) % s), tmpIndices.get((o - (divisionsU + 2)) % s), tmpIndices.get((o - (divisionsU + 1)) % s));
            tempOffset = (tempOffset + 1) % tmpIndices.size;
        }
    }
}
Also used : VertexInfo(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo)

Example 5 with VertexInfo

use of com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo in project libgdx by libgdx.

the class HeightField method updateSmooth.

private void updateSmooth() {
    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            VertexInfo v = getVertexAt(vertex00, x, y);
            getWeightedNormalAt(v.normal, x, y);
            setVertex(y * width + x, v);
        }
    }
    mesh.setVertices(vertices);
}
Also used : VertexInfo(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo)

Aggregations

VertexInfo (com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder.VertexInfo)6 Vector3 (com.badlogic.gdx.math.Vector3)1 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1