Search in sources :

Example 1 with BlockFaceUV

use of net.minecraft.client.renderer.block.model.BlockFaceUV in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method applyUVLock.

public static BlockFaceUV applyUVLock(BlockFaceUV blockFaceUV, EnumFacing originalSide, ITransformation rotation) {
    TRSRTransformation global = new TRSRTransformation(rotation.getMatrix());
    Matrix4f uv = global.getUVLockTransform(originalSide).getMatrix();
    Vector4f vec = new Vector4f(0, 0, 0, 1);
    vec.x = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(0)) / 16;
    vec.y = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(0)) / 16;
    uv.transform(vec);
    // / vec.w;
    float uMin = 16 * vec.x;
    // / vec.w;
    float vMin = 16 * vec.y;
    vec.x = blockFaceUV.getVertexU(blockFaceUV.getVertexRotatedRev(2)) / 16;
    vec.y = blockFaceUV.getVertexV(blockFaceUV.getVertexRotatedRev(2)) / 16;
    vec.z = 0;
    vec.w = 1;
    uv.transform(vec);
    // / vec.w;
    float uMax = 16 * vec.x;
    // / vec.w;
    float vMax = 16 * vec.y;
    if (uMin > uMax) {
        float t = uMin;
        uMin = uMax;
        uMax = t;
    }
    if (vMin > vMax) {
        float t = vMin;
        vMin = vMax;
        vMax = t;
    }
    float a = (float) Math.toRadians(blockFaceUV.rotation);
    Vector3f rv = new Vector3f(MathHelper.cos(a), MathHelper.sin(a), 0);
    Matrix3f rot = new Matrix3f();
    uv.getRotationScale(rot);
    rot.transform(rv);
    int angle = MathHelper.normalizeAngle(-(int) Math.round(Math.toDegrees(Math.atan2(rv.y, rv.x)) / 90) * 90, 360);
    return new BlockFaceUV(new float[] { uMin, vMin, uMax, vMax }, angle);
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) Matrix4f(javax.vecmath.Matrix4f) Vector4f(javax.vecmath.Vector4f) Matrix3f(javax.vecmath.Matrix3f) Vector3f(javax.vecmath.Vector3f) BlockFaceUV(net.minecraft.client.renderer.block.model.BlockFaceUV)

Example 2 with BlockFaceUV

use of net.minecraft.client.renderer.block.model.BlockFaceUV in project Binnie by ForestryMC.

the class AABBModelBaker method bakeModel.

@Override
public IModelBakerModel bakeModel(boolean flip) {
    ModelRotation mr = ModelRotation.X0_Y0;
    if (flip) {
        mr = ModelRotation.X0_Y180;
    }
    // Add baked models to the current model.
    for (Pair<IBlockState, IBakedModel> bakedModel : bakedModels) {
        currentModel.addModelQuads(bakedModel);
    }
    for (Pair<IBlockState, IBakedModel> bakedModel : bakedModelsPost) {
        currentModel.addModelQuadsPost(bakedModel);
    }
    for (BoundModelBakerFace face : faces) {
        final AxisAlignedBB modelBounds = face.modelBounds;
        final Vector3f from = new Vector3f((float) modelBounds.minX * 16.0f, (float) modelBounds.minY * 16.0f, (float) modelBounds.minZ * 16.0f);
        final Vector3f to = new Vector3f((float) modelBounds.maxX * 16.0f, (float) modelBounds.maxY * 16.0f, (float) modelBounds.maxZ * 16.0f);
        final EnumFacing myFace = face.face;
        final float[] uvs = getFaceUvs(myFace, to, from);
        final BlockFaceUV uv = new BlockFaceUV(uvs, 0);
        final BlockPartFace bpf = new BlockPartFace(myFace, face.colorIndex, "", uv);
        BakedQuad bf = faceBakery.makeBakedQuad(from, to, bpf, face.spite, myFace, mr, null, true, true);
        currentModel.addQuad(myFace, bf);
    }
    return currentModel;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) ModelRotation(net.minecraft.client.renderer.block.model.ModelRotation) Vector3f(org.lwjgl.util.vector.Vector3f) EnumFacing(net.minecraft.util.EnumFacing) BlockPartFace(net.minecraft.client.renderer.block.model.BlockPartFace) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) BlockFaceUV(net.minecraft.client.renderer.block.model.BlockFaceUV)

Example 3 with BlockFaceUV

use of net.minecraft.client.renderer.block.model.BlockFaceUV in project Charset by CharsetMC.

the class FaceBakeryWire method makeBakedQuad.

public BakedQuad makeBakedQuad(Vector3f min, Vector3f max, int tintIndex, float[] uvOrig, TextureAtlasSprite icon, EnumFacing facing, ModelRotation rot, boolean uvLocked) {
    float[] uv = uvOrig;
    if (!uvLocked && uvScale > 1) {
        float ox = (uvOffset % uvScale) * (16.0f / uvScale);
        float oy = (uvOffset / uvScale) * (16.0f / uvScale);
        uv = new float[] { uv[0] / (float) uvScale + ox, uv[1] / (float) uvScale + oy, uv[2] / (float) uvScale + ox, uv[3] / (float) uvScale + oy };
    }
    BakedQuad quad = makeBakedQuad(min, max, new BlockPartFace(null, tintIndex, "", new BlockFaceUV(uv, 0)), icon, facing, rot, null, uvLocked, true);
    if (tintIndex == -1) {
        return quad;
    } else {
        int[] data = quad.getVertexData();
        data[3] = data[10] = data[17] = data[24] = getFaceShadeColor(tintIndex, rot.rotate(facing));
        return new IColoredBakedQuad.ColoredBakedQuad(data, tintIndex, quad.getFace());
    }
}
Also used : IColoredBakedQuad(net.minecraftforge.client.model.IColoredBakedQuad) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) BlockPartFace(net.minecraft.client.renderer.block.model.BlockPartFace) IColoredBakedQuad(net.minecraftforge.client.model.IColoredBakedQuad) BlockFaceUV(net.minecraft.client.renderer.block.model.BlockFaceUV)

Example 4 with BlockFaceUV

use of net.minecraft.client.renderer.block.model.BlockFaceUV in project ForestryMC by ForestryMC.

the class ModelBaker method bakeModel.

@Override
public IModelBakerModel bakeModel(boolean flip) {
    ModelRotation modelRotation = ModelRotation.X0_Y0;
    if (flip) {
        modelRotation = ModelRotation.X0_Y180;
    }
    // Add baked models to the current model.
    for (Pair<IBlockState, IBakedModel> bakedModel : bakedModels) {
        currentModel.addModelQuads(bakedModel);
    }
    for (Pair<IBlockState, IBakedModel> bakedModel : bakedModelsPost) {
        currentModel.addModelQuadsPost(bakedModel);
    }
    for (ModelBakerFace face : faces) {
        EnumFacing facing = face.face;
        BlockFaceUV uvFace = new BlockFaceUV(UVS, 0);
        BlockPartFace partFace = new BlockPartFace(facing, face.colorIndex, "", uvFace);
        BakedQuad quad = FACE_BAKERY.makeBakedQuad(POS_FROM, POS_TO, partFace, face.spite, facing, modelRotation, null, true, true);
        currentModel.addQuad(facing, quad);
    }
    return currentModel;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) ModelRotation(net.minecraft.client.renderer.block.model.ModelRotation) EnumFacing(net.minecraft.util.EnumFacing) BlockPartFace(net.minecraft.client.renderer.block.model.BlockPartFace) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) BlockFaceUV(net.minecraft.client.renderer.block.model.BlockFaceUV)

Aggregations

BlockFaceUV (net.minecraft.client.renderer.block.model.BlockFaceUV)4 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)3 BlockPartFace (net.minecraft.client.renderer.block.model.BlockPartFace)3 IBlockState (net.minecraft.block.state.IBlockState)2 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)2 ModelRotation (net.minecraft.client.renderer.block.model.ModelRotation)2 EnumFacing (net.minecraft.util.EnumFacing)2 Matrix3f (javax.vecmath.Matrix3f)1 Matrix4f (javax.vecmath.Matrix4f)1 Vector3f (javax.vecmath.Vector3f)1 Vector4f (javax.vecmath.Vector4f)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 IColoredBakedQuad (net.minecraftforge.client.model.IColoredBakedQuad)1 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)1 Vector3f (org.lwjgl.util.vector.Vector3f)1