Search in sources :

Example 1 with IVertexConsumer

use of net.minecraftforge.client.model.pipeline.IVertexConsumer in project MinecraftForge by MinecraftForge.

the class ItemLayerModel method buildQuad.

private static BakedQuad buildQuad(Transformation transform, Direction side, TextureAtlasSprite sprite, int tint, boolean fullbright, float x0, float y0, float z0, float u0, float v0, float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3) {
    BakedQuadBuilder builder = new BakedQuadBuilder(sprite);
    builder.setQuadTint(tint);
    builder.setQuadOrientation(side);
    builder.setApplyDiffuseLighting(false);
    boolean hasTransform = !transform.isIdentity();
    IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, transform) : builder;
    int uLight, vLight;
    uLight = vLight = fullbright ? 15 : 0;
    putVertex(consumer, side, x0, y0, z0, u0, v0, uLight, vLight);
    putVertex(consumer, side, x1, y1, z1, u1, v1, uLight, vLight);
    putVertex(consumer, side, x2, y2, z2, u2, v2, uLight, vLight);
    putVertex(consumer, side, x3, y3, z3, u3, v3, uLight, vLight);
    return builder.build();
}
Also used : IVertexConsumer(net.minecraftforge.client.model.pipeline.IVertexConsumer) TRSRTransformer(net.minecraftforge.client.model.pipeline.TRSRTransformer) BakedQuadBuilder(net.minecraftforge.client.model.pipeline.BakedQuadBuilder)

Example 2 with IVertexConsumer

use of net.minecraftforge.client.model.pipeline.IVertexConsumer in project BluePower by Qmunity.

the class BPMicroblockModel method transform.

private static BakedQuad transform(BakedQuad sizeQuad, TextureAtlasSprite sprite, Direction dir, Block block) {
    BakedQuadBuilder builder = new BakedQuadBuilder();
    final IVertexConsumer consumer = new VertexTransformer(builder) {

        @Override
        public void put(int element, float... data) {
            VertexFormatElement e = this.getVertexFormat().getElements().get(element);
            if (e.getUsage() == VertexFormatElement.Usage.UV && e.getIndex() == 0) {
                Vector2f vec = new Vector2f(data[0], data[1]);
                float u = (vec.x - sizeQuad.getSprite().getU0()) / (sizeQuad.getSprite().getU1() - sizeQuad.getSprite().getU0()) * 16;
                float v = (vec.y - sizeQuad.getSprite().getV0()) / (sizeQuad.getSprite().getV1() - sizeQuad.getSprite().getV0()) * 16;
                builder.put(element, sprite.getU(u), sprite.getV(v));
            } else if (e.getUsage() == VertexFormatElement.Usage.COLOR) {
                int color;
                try {
                    color = Minecraft.getInstance().getBlockColors().getColor(block.defaultBlockState(), null, null, sizeQuad.getTintIndex());
                } catch (Exception ex) {
                    try {
                        color = Minecraft.getInstance().getBlockColors().getColor(block.defaultBlockState(), null, BlockPos.ZERO, sizeQuad.getTintIndex());
                    } catch (Exception ex2) {
                        color = 0;
                    }
                }
                int redMask = 0xFF0000, greenMask = 0xFF00, blueMask = 0xFF;
                int r = (color & redMask) >> 16;
                int g = (color & greenMask) >> 8;
                int b = (color & blueMask);
                parent.put(element, r / 255F, g / 255F, b / 255F, 1);
            } else {
                parent.put(element, data);
            }
        }
    };
    LightUtil.putBakedQuad(consumer, sizeQuad);
    return builder.build();
}
Also used : IVertexConsumer(net.minecraftforge.client.model.pipeline.IVertexConsumer) VertexTransformer(net.minecraftforge.client.model.pipeline.VertexTransformer) Vector2f(net.minecraft.util.math.vector.Vector2f) VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement) BakedQuadBuilder(net.minecraftforge.client.model.pipeline.BakedQuadBuilder)

Example 3 with IVertexConsumer

use of net.minecraftforge.client.model.pipeline.IVertexConsumer in project BluePower by Qmunity.

the class BPMultipartModel method transform.

private static BakedQuad transform(BakedQuad quad, Pair<Integer, Integer> colorPair, Boolean fullBright) {
    BakedQuadBuilder builder = new BakedQuadBuilder();
    final IVertexConsumer consumer = new VertexTransformer(builder) {

        @Override
        public void put(int element, float... data) {
            VertexFormatElement e = this.getVertexFormat().getElements().get(element);
            if (e.getUsage() == VertexFormatElement.Usage.COLOR) {
                int color = quad.getTintIndex() == 2 ? colorPair.getSecond() : colorPair.getFirst();
                int redMask = 0xFF0000, greenMask = 0xFF00, blueMask = 0xFF;
                int r = (color & redMask) >> 16;
                int g = (color & greenMask) >> 8;
                int b = (color & blueMask);
                parent.put(element, r / 255F, g / 255F, b / 255F, 1);
            } else {
                parent.put(element, data);
            }
        }
    };
    LightUtil.putBakedQuad(consumer, quad);
    BakedQuad finalQuad = builder.build();
    if (fullBright)
        LightUtil.setLightData(finalQuad, 240);
    return finalQuad;
}
Also used : BakedQuad(net.minecraft.client.renderer.model.BakedQuad) IVertexConsumer(net.minecraftforge.client.model.pipeline.IVertexConsumer) VertexTransformer(net.minecraftforge.client.model.pipeline.VertexTransformer) VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement) BakedQuadBuilder(net.minecraftforge.client.model.pipeline.BakedQuadBuilder)

Example 4 with IVertexConsumer

use of net.minecraftforge.client.model.pipeline.IVertexConsumer in project MinecraftForge by MinecraftForge.

the class ItemTextureQuadConverter method putQuad.

private static BakedQuad putQuad(Transformation transform, Direction side, TextureAtlasSprite sprite, int color, int tint, float x1, float y1, float x2, float y2, float z, float u1, float v1, float u2, float v2, int luminosity) {
    BakedQuadBuilder builder = new BakedQuadBuilder(sprite);
    builder.setQuadTint(tint);
    builder.setQuadOrientation(side);
    builder.setApplyDiffuseLighting(luminosity == 0);
    // only apply the transform if it's not identity
    boolean hasTransform = !transform.isIdentity();
    IVertexConsumer consumer = hasTransform ? new TRSRTransformer(builder, transform) : builder;
    if (side == Direction.SOUTH) {
        putVertex(consumer, side, x1, y1, z, u1, v2, color, luminosity);
        putVertex(consumer, side, x2, y1, z, u2, v2, color, luminosity);
        putVertex(consumer, side, x2, y2, z, u2, v1, color, luminosity);
        putVertex(consumer, side, x1, y2, z, u1, v1, color, luminosity);
    } else {
        putVertex(consumer, side, x1, y1, z, u1, v2, color, luminosity);
        putVertex(consumer, side, x1, y2, z, u1, v1, color, luminosity);
        putVertex(consumer, side, x2, y2, z, u2, v1, color, luminosity);
        putVertex(consumer, side, x2, y1, z, u2, v2, color, luminosity);
    }
    return builder.build();
}
Also used : IVertexConsumer(net.minecraftforge.client.model.pipeline.IVertexConsumer) TRSRTransformer(net.minecraftforge.client.model.pipeline.TRSRTransformer) BakedQuadBuilder(net.minecraftforge.client.model.pipeline.BakedQuadBuilder)

Aggregations

BakedQuadBuilder (net.minecraftforge.client.model.pipeline.BakedQuadBuilder)4 IVertexConsumer (net.minecraftforge.client.model.pipeline.IVertexConsumer)4 VertexFormatElement (net.minecraft.client.renderer.vertex.VertexFormatElement)2 TRSRTransformer (net.minecraftforge.client.model.pipeline.TRSRTransformer)2 VertexTransformer (net.minecraftforge.client.model.pipeline.VertexTransformer)2 BakedQuad (net.minecraft.client.renderer.model.BakedQuad)1 Vector2f (net.minecraft.util.math.vector.Vector2f)1