Search in sources :

Example 21 with MutableQuad

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

the class PipeWireRenderer method getQuads.

private static MutableQuad[] getQuads(EnumWireBetween between) {
    // 4 rather than 6 -- don't render the end caps
    MutableQuad[] quads = new MutableQuad[4];
    int i = 0;
    Vec3d center;
    Vec3d radius;
    boolean ax = between.mainAxis == Axis.X;
    boolean ay = between.mainAxis == Axis.Y;
    boolean az = between.mainAxis == Axis.Z;
    if (between.to == null) {
        double cL = 0.5f - 4.51f / 16f;
        double cU = 0.5f + 4.51f / 16f;
        center = new // 
        Vec3d(// 
        ax ? 0.5f : (between.xy ? cU : cL), // 
        ay ? 0.5f : ((ax ? between.xy : between.yz) ? cU : cL), // 
        az ? 0.5f : (between.yz ? cU : cL));
        double rC = 4.01f / 16f;
        double rN = 1f / 16f / 2;
        radius = new // 
        Vec3d(// 
        ax ? rC : rN, // 
        ay ? rC : rN, // 
        az ? rC : rN);
    } else {
        // we are a connection
        double cL = (8 - 4.51) / 16;
        double cU = (8 + 4.51) / 16;
        radius = new // 
        Vec3d(// 
        ax ? 2.99 / 32 : 1 / 32.0, // 
        ay ? 2.99 / 32 : 1 / 32.0, // 
        az ? 2.99 / 32 : 1 / 32.0);
        center = new // 
        Vec3d(// 
        ax ? (0.5 + 6.505 / 16 * between.to.getFrontOffsetX()) : (between.xy ? cU : cL), // 
        ay ? (0.5 + 6.505 / 16 * between.to.getFrontOffsetY()) : ((ax ? between.xy : between.yz) ? cU : cL), // 
        az ? (0.5 + 6.505 / 16 * between.to.getFrontOffsetZ()) : (between.yz ? cU : cL));
    }
    UvFaceData uvBase = new UvFaceData();
    uvBase.minU = (float) VecUtil.getValue(center.subtract(radius), between.mainAxis);
    uvBase.maxU = (float) VecUtil.getValue(center.add(radius), between.mainAxis);
    uvBase.minV = 0;
    uvBase.maxV = 1 / 16f;
    Tuple3f centerFloat = VecUtil.convertFloat(center);
    Tuple3f radiusFloat = VecUtil.convertFloat(radius);
    for (EnumFacing face : EnumFacing.VALUES) {
        if (face.getAxis() == between.mainAxis) {
            continue;
        }
        UvFaceData uvs = new UvFaceData(uvBase);
        Axis aAxis = between.mainAxis;
        Axis fAxis = face.getAxis();
        boolean fPositive = face.getAxisDirection() == AxisDirection.POSITIVE;
        int rotations = 0;
        boolean swapU = false;
        boolean swapV = false;
        if (aAxis == Axis.X) {
            swapV = fPositive;
        } else if (aAxis == Axis.Y) {
            rotations = 1;
            swapU = (fAxis == Axis.X) != fPositive;
            swapV = fAxis == Axis.Z;
        } else {
            // aAxis == Axis.Z
            if (fAxis == Axis.Y) {
                rotations = 1;
            }
            swapU = face == EnumFacing.DOWN;
            swapV = face != EnumFacing.EAST;
        }
        if (swapU) {
            float t = uvs.minU;
            uvs.minU = uvs.maxU;
            uvs.maxU = t;
        }
        if (swapV) {
            float t = uvs.minV;
            uvs.minV = uvs.maxV;
            uvs.maxV = t;
        }
        MutableQuad quad = ModelUtil.createFace(face, centerFloat, radiusFloat, uvs);
        if (rotations > 0)
            quad.rotateTextureUp(rotations);
        quads[i++] = quad;
    }
    return quads;
}
Also used : UvFaceData(buildcraft.lib.client.model.ModelUtil.UvFaceData) Tuple3f(javax.vecmath.Tuple3f) EnumFacing(net.minecraft.util.EnumFacing) Vec3d(net.minecraft.util.math.Vec3d) Axis(net.minecraft.util.EnumFacing.Axis) MutableQuad(buildcraft.lib.client.model.MutableQuad)

Example 22 with MutableQuad

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

the class PlugBakerSimple method bake.

@Override
public List<BakedQuad> bake(K key) {
    MutableQuad[] quads = provider.getCutoutQuads();
    if (quads != lastSeen) {
        cached.clear();
        MutableQuad copy = new MutableQuad();
        for (EnumFacing to : EnumFacing.VALUES) {
            List<BakedQuad> list = new ArrayList<>();
            for (MutableQuad q : quads) {
                copy.copyFrom(q);
                copy.rotate(EnumFacing.WEST, to, 0.5f, 0.5f, 0.5f);
                copy.multShade();
                list.add(copy.toBakedBlock());
            }
            cached.put(to, list);
        }
        lastSeen = quads;
    }
    return cached.get(key.side);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) MutableQuad(buildcraft.lib.client.model.MutableQuad)

Example 23 with MutableQuad

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

the class MutableQuadTest method testRotations.

@Test
public void testRotations() {
    for (EnumFacing from : EnumFacing.VALUES) {
        for (EnumFacing to : EnumFacing.VALUES) {
            Vec3i vec = from.getDirectionVec();
            MutableQuad q = new MutableQuad();
            q.vertex_0.positionf(vec.getX(), vec.getY(), vec.getZ());
            q.rotate(from, to, 0, 0, 0);
            float ex = to.getFrontOffsetX();
            float ey = to.getFrontOffsetY();
            float ez = to.getFrontOffsetZ();
            Assert.assertEquals(from + " -> " + to + " [X]", ex, q.vertex_0.position_x, 0.001f);
            Assert.assertEquals(from + " -> " + to + " [Y]", ey, q.vertex_0.position_y, 0.001f);
            Assert.assertEquals(from + " -> " + to + " [Z]", ez, q.vertex_0.position_z, 0.001f);
        }
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) EnumFacing(net.minecraft.util.EnumFacing) MutableQuad(buildcraft.lib.client.model.MutableQuad) Test(org.junit.Test)

Example 24 with MutableQuad

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

the class GatePluggableModel method renderGate.

public List<MutableQuad> renderGate(KeyPlugGate gate, VertexFormat format) {
    TextureAtlasSprite logicSprite = gate.lit ? gate.logic.getIconLit() : gate.logic.getIconDark();
    TextureAtlasSprite materialSprite = gate.material.getIconBlock();
    IModel main = modelMain();
    IModel material = modelMaterial();
    List<MutableQuad> quads = Lists.newArrayList();
    IFlexibleBakedModel baked = main.bake(ModelRotation.X0_Y0, format, singleTextureFunction(logicSprite));
    for (BakedQuad quad : baked.getGeneralQuads()) {
        MutableQuad mutable = MutableQuad.create(quad, format);
        quads.add(mutable);
    }
    if (materialSprite != null) {
        // Its null for redstone (As we don't render any material for redstone gates)
        baked = material.bake(ModelRotation.X0_Y0, format, singleTextureFunction(materialSprite));
        for (BakedQuad quad : baked.getGeneralQuads()) {
            quads.add(MutableQuad.create(quad, format));
        }
    }
    for (GateExpansionModelKey<?> expansion : gate.expansions) {
        generate(quads, expansion);
    }
    return quads;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IModel(net.minecraftforge.client.model.IModel) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) IFlexibleBakedModel(net.minecraftforge.client.model.IFlexibleBakedModel) MutableQuad(buildcraft.lib.client.model.MutableQuad)

Example 25 with MutableQuad

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

the class ModelPowerAdapter method bakeCutout.

private List<BakedQuad> bakeCutout(EnumFacing face, VertexFormat format) {
    IModel model = modelPowerAdapter();
    TextureAtlasSprite sprite = spritePowerAdapter;
    List<BakedQuad> quads = Lists.newArrayList();
    List<BakedQuad> bakedQuads = renderAdapter(model, sprite, format);
    Matrix4f matrix = MatrixUtil.rotateTowardsFace(face);
    for (BakedQuad quad : bakedQuads) {
        MutableQuad mutable = MutableQuad.create(quad);
        mutable.transform(matrix);
        ModelUtil.appendBakeQuads(quads, format, mutable);
    }
    return quads;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IModel(net.minecraftforge.client.model.IModel) Matrix4f(javax.vecmath.Matrix4f) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) 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