Search in sources :

Example 1 with VertexFormat

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

the class VertexBufferConsumer method put.

public void put(int e, float... data) {
    VertexFormat format = getVertexFormat();
    if (renderer.isColorDisabled() && format.getElement(e).getUsage() == EnumUsage.COLOR) {
        data = dummyColor;
    }
    LightUtil.pack(data, quadData, format, v, e);
    if (e == format.getElementCount() - 1) {
        v++;
        if (v == 4) {
            renderer.addVertexData(quadData);
            renderer.putPosition(offset.getX(), offset.getY(), offset.getZ());
            //Arrays.fill(quadData, 0);
            v = 0;
        }
    }
}
Also used : VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 2 with VertexFormat

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

the class VertexLighterFlat method processQuad.

@Override
protected void processQuad() {
    float[][] position = quadData[posIndex];
    float[][] normal = null;
    float[][] lightmap = quadData[lightmapIndex];
    float[][] color = quadData[colorIndex];
    if (normalIndex != -1 && (quadData[normalIndex][0][0] != -1 || quadData[normalIndex][0][1] != -1 || quadData[normalIndex][0][2] != -1)) {
        normal = quadData[normalIndex];
    } else {
        normal = new float[4][4];
        Vector3f v1 = new Vector3f(position[3]);
        Vector3f t = new Vector3f(position[1]);
        Vector3f v2 = new Vector3f(position[2]);
        v1.sub(t);
        t.set(position[0]);
        v2.sub(t);
        v1.cross(v2, v1);
        v1.normalize();
        for (int v = 0; v < 4; v++) {
            normal[v][0] = v1.x;
            normal[v][1] = v1.y;
            normal[v][2] = v1.z;
            normal[v][3] = 0;
        }
    }
    int multiplier = -1;
    if (tint != -1) {
        multiplier = blockInfo.getColorMultiplier(tint);
    }
    VertexFormat format = parent.getVertexFormat();
    int count = format.getElementCount();
    for (int v = 0; v < 4; v++) {
        position[v][0] += blockInfo.getShx();
        position[v][1] += blockInfo.getShy();
        position[v][2] += blockInfo.getShz();
        float x = position[v][0] - .5f;
        float y = position[v][1] - .5f;
        float z = position[v][2] - .5f;
        //if(blockInfo.getBlock().isFullCube())
        {
            x += normal[v][0] * .5f;
            y += normal[v][1] * .5f;
            z += normal[v][2] * .5f;
        }
        float blockLight = lightmap[v][0], skyLight = lightmap[v][1];
        updateLightmap(normal[v], lightmap[v], x, y, z);
        if (dataLength[lightmapIndex] > 1) {
            if (blockLight > lightmap[v][0])
                lightmap[v][0] = blockLight;
            if (skyLight > lightmap[v][1])
                lightmap[v][1] = skyLight;
        }
        updateColor(normal[v], color[v], x, y, z, tint, multiplier);
        if (diffuse) {
            float d = LightUtil.diffuseLight(normal[v][0], normal[v][1], normal[v][2]);
            for (int i = 0; i < 3; i++) {
                color[v][i] *= d;
            }
        }
        if (EntityRenderer.anaglyphEnable) {
            applyAnaglyph(color[v]);
        }
        // no need for remapping cause all we could've done is add 1 element to the end
        for (int e = 0; e < count; e++) {
            VertexFormatElement element = format.getElement(e);
            switch(element.getUsage()) {
                case POSITION:
                    // position adding moved to VertexBufferConsumer due to x and z not fitting completely into a float
                    /*float[] pos = new float[4];
                        System.arraycopy(position[v], 0, pos, 0, position[v].length);
                        pos[0] += blockInfo.getBlockPos().getX();
                        pos[1] += blockInfo.getBlockPos().getY();
                        pos[2] += blockInfo.getBlockPos().getZ();*/
                    parent.put(e, position[v]);
                    break;
                case NORMAL:
                    if (normalIndex != -1) {
                        parent.put(e, normal[v]);
                        break;
                    }
                case COLOR:
                    parent.put(e, color[v]);
                    break;
                case UV:
                    if (element.getIndex() == 1) {
                        parent.put(e, lightmap[v]);
                        break;
                    }
                default:
                    parent.put(e, quadData[e][v]);
            }
        }
    }
    tint = -1;
}
Also used : Vector3f(javax.vecmath.Vector3f) VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 3 with VertexFormat

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

the class ProxyClient method bakeModels.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void bakeModels(ModelBakeEvent event) {
    if (prismModel != null) {
        for (Orientation o : Orientation.values()) {
            ModelResourceLocation location = new ModelResourceLocation("charset:laser_prism", "orientation=" + o.name().toLowerCase());
            IBakedModel model = prismModel.bake(o.toTransformation(), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter());
            event.getModelRegistry().putObject(location, model);
        }
    }
    // Patch jars to glow
    for (EnumFacing facing : EnumFacing.VALUES) {
        for (LaserColor color : LaserColor.VALUES) {
            if (color == LaserColor.NONE)
                continue;
            IBlockState state = CharsetLaser.blockJar.getDefaultState().withProperty(CharsetLaser.LASER_COLOR, color).withProperty(Properties.FACING, facing);
            ModelResourceLocation location = new ModelResourceLocation("charset:light_jar", "color=" + color.getName() + ",facing=" + facing.getName());
            IBakedModel model = event.getModelRegistry().getObject(location);
            VertexFormat format = new VertexFormat(DefaultVertexFormats.ITEM);
            format.addElement(DefaultVertexFormats.TEX_2S);
            if (model != null) {
                SimpleMultiLayerBakedModel result = new SimpleMultiLayerBakedModel(model);
                BlockRenderLayer layerPre = MinecraftForgeClient.getRenderLayer();
                for (BlockRenderLayer layer : BlockRenderLayer.values()) {
                    if (CharsetLaser.blockJar.canRenderInLayer(CharsetLaser.blockJar.getDefaultState(), layer)) {
                        ForgeHooksClient.setRenderLayer(layer);
                        for (int i = 0; i <= 6; i++) {
                            EnumFacing facingIn = (i < 6) ? EnumFacing.getFront(i) : null;
                            for (BakedQuad quadIn : model.getQuads(state, facingIn, 0)) {
                                result.addQuad(layer, facingIn, ModelTransformer.transform(quadIn, (quad, element, data) -> {
                                    if (quad.getTintIndex() == 1 && element == DefaultVertexFormats.TEX_2S) {
                                        return new float[] { 15f * 0x20 / 0xFFFF, 0, 0, 0 };
                                    }
                                    return data;
                                }, (bakedQuad -> {
                                    if (bakedQuad.getTintIndex() == 1) {
                                        return format;
                                    } else {
                                        return bakedQuad.getFormat();
                                    }
                                })));
                            }
                        }
                    }
                }
                ForgeHooksClient.setRenderLayer(layerPre);
                event.getModelRegistry().putObject(location, result);
            }
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) SimpleMultiLayerBakedModel(pl.asie.charset.lib.render.model.SimpleMultiLayerBakedModel) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ModelBakeEvent(net.minecraftforge.client.event.ModelBakeEvent) ModelRegistryEvent(net.minecraftforge.client.event.ModelRegistryEvent) Properties(pl.asie.charset.lib.Properties) LaserRenderer(pl.asie.charset.module.optics.laser.system.LaserRenderer) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) MinecraftForgeClient(net.minecraftforge.client.MinecraftForgeClient) LaserTintHandler(pl.asie.charset.module.optics.laser.blocks.LaserTintHandler) DefaultVertexFormats(net.minecraft.client.renderer.vertex.DefaultVertexFormats) PixelOperationSprite(pl.asie.charset.lib.render.sprite.PixelOperationSprite) Side(net.minecraftforge.fml.relauncher.Side) CommandCharset(pl.asie.charset.lib.command.CommandCharset) RegistryUtils(pl.asie.charset.lib.utils.RegistryUtils) TextureStitchEvent(net.minecraftforge.client.event.TextureStitchEvent) ColorHandlerEvent(net.minecraftforge.client.event.ColorHandlerEvent) ModelLoader(net.minecraftforge.client.model.ModelLoader) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ModelTransformer(pl.asie.charset.lib.render.model.ModelTransformer) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) LaserColor(pl.asie.charset.api.laser.LaserColor) EnumFacing(net.minecraft.util.EnumFacing) SubCommandDebugLasersClient(pl.asie.charset.module.optics.laser.system.SubCommandDebugLasersClient) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IModel(net.minecraftforge.client.model.IModel) RenderUtils(pl.asie.charset.lib.utils.RenderUtils) IBlockState(net.minecraft.block.state.IBlockState) MinecraftForge(net.minecraftforge.common.MinecraftForge) Orientation(pl.asie.charset.lib.utils.Orientation) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) ForgeHooksClient(net.minecraftforge.client.ForgeHooksClient) SimpleMultiLayerBakedModel(pl.asie.charset.lib.render.model.SimpleMultiLayerBakedModel) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Orientation(pl.asie.charset.lib.utils.Orientation) LaserColor(pl.asie.charset.api.laser.LaserColor) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with VertexFormat

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

the class ModelTransformer method transform.

public static BakedQuad transform(BakedQuad quad, IVertexTransformer transformer, @Nullable Function<BakedQuad, VertexFormat> format2) {
    VertexFormat format = format2 != null ? format2.apply(quad) : quad.getFormat();
    UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
    LightUtil.putBakedQuad(new VertexTransformerWrapper(builder, quad, transformer), quad);
    return builder.build();
}
Also used : UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 5 with VertexFormat

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

the class HalfBakedQuad method putVertexData.

private void putVertexData(@Nonnull Builder builder, @Nonnull Vertex v, float w) {
    VertexFormat format = builder.getVertexFormat();
    for (int e = 0; e < format.getElementCount(); e++) {
        switch(format.getElement(e).getUsage()) {
            case POSITION:
                builder.put(e, (float) v.x(), (float) v.y(), (float) v.z(), 1);
                break;
            case COLOR:
                float d = LightUtil.diffuseLight(v.nx(), v.ny(), v.nz());
                builder.put(e, d * color.x, d * color.y, d * color.z, color.w);
                break;
            case UV:
                builder.put(e, tex.getInterpolatedU(v.u() * 16) * w, tex.getInterpolatedV(v.v() * 16) * w, 0, w);
                break;
            case NORMAL:
                builder.put(e, v.nx(), v.ny(), v.nz(), 0);
                break;
            default:
                builder.put(e);
        }
    }
}
Also used : 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