Search in sources :

Example 11 with VertexFormat

use of net.minecraft.client.renderer.vertex.VertexFormat in project BuildCraft by BuildCraft.

the class RobotStationModel method createItemModel.

public PerspAwareModelBase createItemModel() {
    ImmutableList.Builder<BakedQuad> quads = ImmutableList.builder();
    VertexFormat format = DefaultVertexFormats.ITEM;
    quads.addAll(INSTANCE.bakeCutout(EnumRobotStationState.Available, EnumFacing.SOUTH, format));
    return new PerspAwareModelBase(format, quads.build(), baseSprite, getPluggableTransforms());
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) ImmutableList(com.google.common.collect.ImmutableList) PerspAwareModelBase(buildcraft.core.lib.client.model.PerspAwareModelBase) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 12 with VertexFormat

use of net.minecraft.client.renderer.vertex.VertexFormat in project ImmersiveEngineering by BluSunrize.

the class TileEntityStructuralArm method modifyQuads.

@Override
@SideOnly(Side.CLIENT)
public List<BakedQuad> modifyQuads(IBlockState object, List<BakedQuad> quads) {
    float lowerHeight = slopePosition / (float) totalLength;
    float upperHeight = (slopePosition + 1F) / totalLength;
    double lowerV = 16 * lowerHeight;
    double upperV = 16 * upperHeight;
    TextureAtlasSprite tas = quads.get(0).getSprite();
    VertexFormat format = quads.get(0).getFormat();
    quads = new ArrayList<>();
    Matrix4 mat = new Matrix4(facing);
    Vector3f[] vertices;
    {
        float y03 = onCeiling ? 1 : upperHeight;
        float y12 = onCeiling ? 1 : lowerHeight;
        float y47 = onCeiling ? 1 - upperHeight : 0;
        float y56 = onCeiling ? 1 - lowerHeight : 0;
        vertices = new Vector3f[] { // 0
        new Vector3f(0, y03, 0), // 1
        new Vector3f(0, y12, 1), // 2
        new Vector3f(1, y12, 1), // 3
        new Vector3f(1, y03, 0), // 4
        new Vector3f(0, y47, 0), // 5
        new Vector3f(0, y56, 1), // 6
        new Vector3f(1, y56, 1), // 7
        new Vector3f(1, y47, 0) };
    }
    for (int i = 0; i < vertices.length; i++) vertices[i] = mat.apply(vertices[i]);
    // TOP
    addCulledQuad(quads, format, Arrays.copyOf(vertices, 4), UP, tas, new double[] { 0, 0, 16, 16 }, new float[] { 1, 1, 1, 1 });
    // BOTTOM
    addCulledQuad(quads, format, getArrayByIndices(vertices, 7, 6, 5, 4), DOWN, tas, new double[] { 0, 0, 16, 16 }, new float[] { 1, 1, 1, 1 });
    // SIDES
    addSides(quads, vertices, tas, lowerV, upperV, false);
    addSides(quads, vertices, tas, lowerV, upperV, true);
    if (isAtEnd(true))
        // HIGHER END
        addCulledQuad(quads, format, getArrayByIndices(vertices, 0, 3, 7, 4), NORTH, tas, new double[] { 0, 0, 16, 16 }, new float[] { 1, 1, 1, 1 });
    return quads;
}
Also used : TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Vector3f(org.lwjgl.util.vector.Vector3f) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 13 with VertexFormat

use of net.minecraft.client.renderer.vertex.VertexFormat in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method renderModelTESRFancy.

/**
 * Renders the given quads. Uses the local and neighbour brightnesses to calculate lighting
 *
 * @param quads     the quads to render
 * @param renderer  the BufferBuilder to render to
 * @param world     the world the model is in. Will be used to obtain lighting information
 * @param pos       the position that this model is in. Use the position the the quads are actually in, not the rendering block
 * @param useCached Whether to use cached information for world local data. Set to true if the previous call to this method was in the same tick and for the same world+pos
 */
public static void renderModelTESRFancy(List<BakedQuad> quads, BufferBuilder renderer, World world, BlockPos pos, boolean useCached) {
    // TODO include matrix transformations?, cache normals?
    if (Config.IEConfig.disableFancyTESR)
        renderModelTESRFast(quads, renderer, world, pos);
    else {
        if (!useCached) {
            // Calculate surrounding brighness and split into block and sky light
            for (EnumFacing f : EnumFacing.VALUES) {
                int val = world.getCombinedLight(pos.offset(f), 0);
                neighbourBrightness[0][f.getIndex()] = (val >> 16) & 255;
                neighbourBrightness[1][f.getIndex()] = val & 255;
            }
            // calculate the different correction factors for all 8 possible light vectors
            for (int type = 0; type < 2; type++) for (int i = 0; i < 8; i++) {
                float sSquared = 0;
                if ((i & 1) != 0)
                    sSquared += scaledSquared(neighbourBrightness[type][5], 255F);
                else
                    sSquared += scaledSquared(neighbourBrightness[type][4], 255F);
                if ((i & 2) != 0)
                    sSquared += scaledSquared(neighbourBrightness[type][1], 255F);
                else
                    sSquared += scaledSquared(neighbourBrightness[type][0], 255F);
                if ((i & 4) != 0)
                    sSquared += scaledSquared(neighbourBrightness[type][3], 255F);
                else
                    sSquared += scaledSquared(neighbourBrightness[type][2], 255F);
                normalizationFactors[type][i] = (float) Math.sqrt(sSquared);
            }
        }
        int localBrightness = world.getCombinedLight(pos, 0);
        for (BakedQuad quad : quads) {
            int[] vData = quad.getVertexData();
            VertexFormat format = quad.getFormat();
            int size = format.getIntegerSize();
            int uv = format.getUvOffsetById(0) / 4;
            // extract position info from the quad
            for (int i = 0; i < 4; i++) {
                quadCoords[i][0] = Float.intBitsToFloat(vData[size * i]);
                quadCoords[i][1] = Float.intBitsToFloat(vData[size * i + 1]);
                quadCoords[i][2] = Float.intBitsToFloat(vData[size * i + 2]);
            }
            // generate the normal vector
            side1.x = quadCoords[1][0] - quadCoords[3][0];
            side1.y = quadCoords[1][1] - quadCoords[3][1];
            side1.z = quadCoords[1][2] - quadCoords[3][2];
            side2.x = quadCoords[2][0] - quadCoords[0][0];
            side2.y = quadCoords[2][1] - quadCoords[0][1];
            side2.z = quadCoords[2][2] - quadCoords[0][2];
            Vector3f.cross(side1, side2, normal);
            normal.normalise();
            // calculate the final light values and do the rendering
            int l1 = getLightValue(neighbourBrightness[0], normalizationFactors[0], (localBrightness >> 16) & 255);
            int l2 = getLightValue(neighbourBrightness[1], normalizationFactors[1], localBrightness & 255);
            for (int i = 0; i < 4; ++i) {
                renderer.pos(quadCoords[i][0], quadCoords[i][1], quadCoords[i][2]).color(255, 255, 255, 255).tex(Float.intBitsToFloat(vData[size * i + uv]), Float.intBitsToFloat(vData[size * i + uv + 1])).lightmap(l1, l2).endVertex();
            }
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 14 with VertexFormat

use of net.minecraft.client.renderer.vertex.VertexFormat in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method renderModelTESRFast.

public static void renderModelTESRFast(List<BakedQuad> quads, BufferBuilder renderer, World world, BlockPos pos) {
    int brightness = world.getCombinedLight(pos, 0);
    int l1 = (brightness >> 0x10) & 0xFFFF;
    int l2 = brightness & 0xFFFF;
    for (BakedQuad quad : quads) {
        int[] vData = quad.getVertexData();
        VertexFormat format = quad.getFormat();
        int size = format.getIntegerSize();
        int uv = format.getUvOffsetById(0) / 4;
        for (int i = 0; i < 4; ++i) {
            renderer.pos(Float.intBitsToFloat(vData[size * i]), Float.intBitsToFloat(vData[size * i + 1]), Float.intBitsToFloat(vData[size * i + 2])).color(255, 255, 255, 255).tex(Float.intBitsToFloat(vData[size * i + uv]), Float.intBitsToFloat(vData[size * i + uv + 1])).lightmap(l1, l2).endVertex();
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 15 with VertexFormat

use of net.minecraft.client.renderer.vertex.VertexFormat in project ImmersiveEngineering by BluSunrize.

the class SmartLightingQuad method pipe.

@Override
public void pipe(IVertexConsumer consumer) {
    IBlockAccess world = null;
    BlockInfo info = null;
    if (consumer instanceof VertexLighterFlat) {
        try {
            info = (BlockInfo) blockInfo.get(consumer);
            world = info.getWorld();
            if (world instanceof ChunkCache)
                world = ((ChunkCache) world).world;
            consumer = (IVertexConsumer) parent.get(consumer);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    consumer.setQuadOrientation(this.getFace());
    if (this.hasTintIndex())
        consumer.setQuadTint(this.getTintIndex());
    float[] data = new float[4];
    VertexFormat format = consumer.getVertexFormat();
    int count = format.getElementCount();
    int[] eMap = LightUtil.mapFormats(format, DefaultVertexFormats.ITEM);
    int itemCount = DefaultVertexFormats.ITEM.getElementCount();
    eMap[eMap.length - 1] = 2;
    for (int v = 0; v < 4; v++) for (int e = 0; e < count; e++) if (eMap[e] != itemCount) {
        if (// lightmap is UV with 2 shorts
        format.getElement(e).getUsage() == EnumUsage.UV && format.getElement(e).getType() == EnumType.SHORT) {
            int brightness;
            if (!ignoreLight && world != null && !(world instanceof ChunkCache)) {
                BlockPos here = blockPos.add(relativePos[v][0], relativePos[v][1], relativePos[v][2]);
                brightness = world.getCombinedLight(here, 0);
            } else
                brightness = staticBrightness;
            data[0] = ((float) ((brightness >> 0x04) & 0xF) * 0x20) / 0xFFFF;
            data[1] = ((float) ((brightness >> 0x14) & 0xF) * 0x20) / 0xFFFF;
        } else
            LightUtil.unpack(this.getVertexData(), data, DefaultVertexFormats.ITEM, v, eMap[e]);
        consumer.put(e, data);
    } else
        consumer.put(e, 0);
}
Also used : ChunkCache(net.minecraft.world.ChunkCache) IBlockAccess(net.minecraft.world.IBlockAccess) BlockPos(net.minecraft.util.math.BlockPos) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Aggregations

VertexFormat (net.minecraft.client.renderer.vertex.VertexFormat)23 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)10 PerspAwareModelBase (buildcraft.core.lib.client.model.PerspAwareModelBase)4 ImmutableList (com.google.common.collect.ImmutableList)4 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)4 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)2 Tessellator (net.minecraft.client.renderer.Tessellator)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 VertexFormatElement (net.minecraft.client.renderer.vertex.VertexFormatElement)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)1 MutableQuad (buildcraft.lib.client.model.MutableQuad)1 LensPluggable (buildcraft.transport.pluggable.LensPluggable)1 IWidgetIcon (com.enderio.core.api.client.render.IWidgetIcon)1 Vector4f (com.enderio.core.common.vecmath.Vector4f)1 Lists (com.google.common.collect.Lists)1 ConduitDisplayMode (crazypants.enderio.base.conduit.ConduitDisplayMode)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1