Search in sources :

Example 11 with MutableQuad

use of buildcraft.lib.client.model.MutableQuad in project BuildCraft by BuildCraft.

the class VariablePartCuboidBase method addQuads.

@Override
public void addQuads(List<MutableQuad> addTo, ITextureGetter spriteLookup) {
    if (visible.evaluate()) {
        float[] f = bakePosition(from);
        float[] t = bakePosition(to);
        boolean s = shade.evaluate();
        int l = (int) (light.evaluate() & 15);
        int rgba = RenderUtil.swapARGBforABGR((int) colour.evaluate());
        for (EnumFacing face : EnumFacing.VALUES) {
            VariableFaceData data = getFaceData(face, spriteLookup);
            if (data != null) {
                Vector3f radius = new Vector3f(t[0] - f[0], t[1] - f[1], t[2] - f[2]);
                radius.scale(0.5f);
                Vector3f center = new Vector3f(f);
                center.add(radius);
                MutableQuad quad = ModelUtil.createFace(face, center, radius, data.uvs);
                quad.rotateTextureUp(data.rotations);
                quad.lighti(l, 0);
                quad.colouri(rgba);
                quad.texFromSprite(data.sprite);
                quad.setSprite(data.sprite);
                quad.setShade(s);
                if (data.bothSides) {
                    addTo.add(quad.copyAndInvertNormal());
                } else if (data.invertNormal) {
                    quad = quad.copyAndInvertNormal();
                }
                addTo.add(quad);
            }
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Vector3f(javax.vecmath.Vector3f) MutableQuad(buildcraft.lib.client.model.MutableQuad)

Example 12 with MutableQuad

use of buildcraft.lib.client.model.MutableQuad in project BuildCraft by BuildCraft.

the class ItemRenderUtil method renderItemStack.

/**
 * Used to render a lot of items in sequential order. Assumes that you don't change the glstate inbetween calls.
 * You must call {@link #endItemBatch()} after your have rendered all of the items.
 */
public static void renderItemStack(double x, double y, double z, ItemStack stack, int lightc, EnumFacing dir, BufferBuilder bb) {
    if (stack.isEmpty()) {
        return;
    }
    if (dir == null) {
        dir = EnumFacing.EAST;
    }
    dir = BCLibConfig.rotateTravelingItems.changeFacing(dir);
    IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(stack);
    model = model.getOverrides().handleItemState(model, stack, null, null);
    boolean requireGl = stack.hasEffect() || model.isBuiltInRenderer();
    if (bb != null && !requireGl) {
        bb.setTranslation(x, y, z);
        float scale = 0.30f;
        MutableQuad q = new MutableQuad(-1, null);
        for (EnumPipePart part : EnumPipePart.VALUES) {
            for (BakedQuad quad : model.getQuads(null, part.face, 0)) {
                q.fromBakedItem(quad);
                q.translated(-0.5, -0.5, -0.5);
                q.scaled(scale);
                q.rotate(EnumFacing.SOUTH, dir, 0, 0, 0);
                if (quad.hasTintIndex()) {
                    int colour = Minecraft.getMinecraft().getItemColors().colorMultiplier(stack, quad.getTintIndex());
                    if (EntityRenderer.anaglyphEnable) {
                        colour = TextureUtil.anaglyphColor(colour);
                    }
                    q.multColouri(colour, colour >> 8, colour >> 16, 0xFF);
                }
                q.lighti(lightc);
                Vector3f normal = q.getCalculatedNormal();
                q.normalvf(normal);
                q.multShade();
                q.render(bb);
            }
        }
        bb.setTranslation(0, 0, 0);
        return;
    }
    if (!inBatch) {
        inBatch = true;
        Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        GL11.glPushMatrix();
        GL11.glTranslated(x, y, z);
        GL11.glScaled(0.3, 0.3, 0.3);
        RenderHelper.disableStandardItemLighting();
    }
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lightc % (float) 0x1_00_00, lightc / (float) 0x1_00_00);
    Minecraft.getMinecraft().getRenderItem().renderItem(stack, model);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Vector3f(javax.vecmath.Vector3f) EnumPipePart(buildcraft.api.core.EnumPipePart) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) MutableQuad(buildcraft.lib.client.model.MutableQuad)

Example 13 with MutableQuad

use of buildcraft.lib.client.model.MutableQuad in project BuildCraft by BuildCraft.

the class BuildCraftBakedModel method createQuadsItemLayer.

public static List<MutableQuad> createQuadsItemLayer(final List<TextureAtlasSprite> sprites) {
    ImmutableList.Builder<ResourceLocation> builder = ImmutableList.builder();
    for (int i = 0; i < sprites.size(); i++) {
        builder.add(new ResourceLocation("buildcraftbakedmodel:spriteindex" + i));
    }
    final ImmutableList<ResourceLocation> locations = builder.build();
    ItemLayerModel model = new ItemLayerModel(locations);
    IBakedModel baked = model.bake(ModelRotation.X0_Y0, DefaultVertexFormats.BLOCK, new Function<ResourceLocation, TextureAtlasSprite>() {

        @Override
        public TextureAtlasSprite apply(ResourceLocation input) {
            return sprites.get(locations.indexOf(input));
        }
    });
    Matrix4f itemToEdge = new Matrix4f();
    itemToEdge.setIdentity();
    itemToEdge.setRotation(new AxisAngle4f(0, 1, 0, (float) (Math.PI / 2)));
    Matrix4f translation = new Matrix4f();
    translation.setIdentity();
    translation.setTranslation(new Vector3f(-15 / 32f, 0, 1));
    translation.mul(itemToEdge);
    List<MutableQuad> mutableQuads = ModelUtil.toMutableQuadList(baked, false);
    for (MutableQuad mutable : mutableQuads) {
        mutable.transform(translation);
        mutable.setTint(-1);
    }
    return mutableQuads;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ItemLayerModel(net.minecraftforge.client.model.ItemLayerModel) Matrix4f(javax.vecmath.Matrix4f) ResourceLocation(net.minecraft.util.ResourceLocation) Vector3f(javax.vecmath.Vector3f) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) AxisAngle4f(javax.vecmath.AxisAngle4f) MutableQuad(buildcraft.lib.client.model.MutableQuad)

Example 14 with MutableQuad

use of buildcraft.lib.client.model.MutableQuad in project BuildCraft by BuildCraft.

the class RenderResizableCuboid method bakeCuboidFace.

private static void bakeCuboidFace(List<MutableQuad> quads, EntityResizableCuboid cuboid, EnumFacing face, TextureAtlasSprite[] sprites, int[] flips, Vec3d textureStart, Vec3d textureSize, Vec3d size, Vec3d textureOffset, boolean out, boolean in) {
    int ordinal = face.ordinal();
    if (sprites[ordinal] == null) {
        return;
    }
    Vec3d textureEnd = textureStart.add(textureSize);
    float[] uv = getUVArray(sprites[ordinal], flips[ordinal], face, textureStart, textureEnd);
    List<RenderInfo> renderInfoList = getRenderInfos(uv, face, size, textureSize, textureOffset);
    Axis u = face.getAxis() == Axis.X ? Axis.Z : Axis.X;
    Axis v = face.getAxis() == Axis.Y ? Axis.Z : Axis.Y;
    double other = face.getAxisDirection() == AxisDirection.POSITIVE ? VecUtil.getValue(size, face.getAxis()) : 0;
    /* Swap the face if this is positive: the renderer returns indexes that ALWAYS are for the negative face, so
         * light it properly this way */
    // face = face.getAxisDirection() == AxisDirection.NEGATIVE ? face : face.getOpposite();
    EnumFacing opposite = face.getOpposite();
    boolean flip = ModelUtil.shouldInvertForRender(face);
    for (RenderInfo ri : renderInfoList) {
        ri = ri.offset(cuboid, face.getAxis());
        double otherMoved = other + VecUtil.getValue(cuboid.getPositionVector(), face.getAxis());
        if (flip ? out : in) {
            MutableQuad mutable = new MutableQuad(-1, face);
            bakePoint(mutable.vertex_0, face, u, v, otherMoved, ri, true, false);
            bakePoint(mutable.vertex_1, face, u, v, otherMoved, ri, true, true);
            bakePoint(mutable.vertex_2, face, u, v, otherMoved, ri, false, true);
            bakePoint(mutable.vertex_3, face, u, v, otherMoved, ri, false, false);
            quads.add(mutable);
        }
        if (flip ? in : out) {
            MutableQuad mutable = new MutableQuad(-1, face);
            bakePoint(mutable.vertex_0, opposite, u, v, otherMoved, ri, false, false);
            bakePoint(mutable.vertex_1, opposite, u, v, otherMoved, ri, false, true);
            bakePoint(mutable.vertex_2, opposite, u, v, otherMoved, ri, true, true);
            bakePoint(mutable.vertex_3, opposite, u, v, otherMoved, ri, true, false);
            quads.add(mutable);
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) Vec3d(net.minecraft.util.math.Vec3d) Axis(net.minecraft.util.EnumFacing.Axis) MutableQuad(buildcraft.lib.client.model.MutableQuad)

Example 15 with MutableQuad

use of buildcraft.lib.client.model.MutableQuad in project BuildCraft by BuildCraft.

the class PipeWireRenderer method getQuads.

private static MutableQuad[] getQuads(EnumWirePart part) {
    MutableQuad[] quads = new MutableQuad[6];
    Tuple3f center = new // 
    Point3f(// 
    0.5f + (part.x.getOffset() * 4.51f / 16f), // 
    0.5f + (part.y.getOffset() * 4.51f / 16f), // 
    0.5f + (part.z.getOffset() * 4.51f / 16f));
    Tuple3f radius = new Point3f(1 / 32f, 1 / 32f, 1 / 32f);
    UvFaceData uvs = new UvFaceData();
    int off = func(part.x) * 4 + func(part.y) * 2 + func(part.z);
    uvs.minU = off / 16f;
    uvs.maxU = (off + 1) / 16f;
    uvs.minV = 0;
    uvs.maxV = 1 / 16f;
    for (EnumFacing face : EnumFacing.VALUES) {
        quads[face.ordinal()] = ModelUtil.createFace(face, center, radius, uvs);
    }
    return quads;
}
Also used : UvFaceData(buildcraft.lib.client.model.ModelUtil.UvFaceData) Tuple3f(javax.vecmath.Tuple3f) Point3f(javax.vecmath.Point3f) EnumFacing(net.minecraft.util.EnumFacing) MutableQuad(buildcraft.lib.client.model.MutableQuad)

Aggregations

MutableQuad (buildcraft.lib.client.model.MutableQuad)31 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)19 Matrix4f (javax.vecmath.Matrix4f)11 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)10 Vector3f (javax.vecmath.Vector3f)8 IModel (net.minecraftforge.client.model.IModel)8 EnumFacing (net.minecraft.util.EnumFacing)7 IFlexibleBakedModel (net.minecraftforge.client.model.IFlexibleBakedModel)6 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 Vec3d (net.minecraft.util.math.Vec3d)3 UvFaceData (buildcraft.lib.client.model.ModelUtil.UvFaceData)2 Tuple3f (javax.vecmath.Tuple3f)2 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)2 Profiler (net.minecraft.profiler.Profiler)2 Axis (net.minecraft.util.EnumFacing.Axis)2 ItemLayerModel (net.minecraftforge.client.model.ItemLayerModel)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 EntityResizableCuboid (buildcraft.core.lib.EntityResizableCuboid)1