codechicken.lib.render.CCModel Java Examples

The following examples show how to use codechicken.lib.render.CCModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StoneRenderer.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, BufferBuilder buffer) {
    //otherwise, we are in solid rendering layer and render primary stone
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    Matrix4 translation = new Matrix4();
    translation.translate(pos.getX(), pos.getY(), pos.getZ());
    TextureAtlasSprite stoneSprite = TextureUtils.getBlockTexture("stone");
    Material material = ((BlockSurfaceRock) state.getBlock()).getStoneMaterial(world, pos, state);
    int renderingColor = GTUtility.convertRGBtoOpaqueRGBA_CL(material.materialRGB);
    IVertexOperation[] operations = new IVertexOperation[] {
        new IconTransformation(stoneSprite),
        new ColourMultiplier(renderingColor),
        new TransformationList(translation)};
    if (world != null) {
        renderState.setBrightness(world, pos);
    }
    renderState.setPipeline(operations);
    CCModel actualModel = getActualModel(world, pos);
    renderState.setModel(actualModel);
    renderState.render();
    return true;
}
 
Example #2
Source File: ShapeModelGenerator.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static CCModel[] generateFullBlockVariants(CCModel originalModel) {
    CCModel[] result = new CCModel[3];
    for (int i = 0; i < 3; i++) {
        Transformation rotation = Rotation.sideRotations[i * 2].at(Vector3.center);
        CCModel rotatedModel = originalModel.copy().apply(rotation);
        result[i] = rotatedModel;
    }
    return result;
}
 
Example #3
Source File: ShapeModelGenerator.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static CCModel[] generateRotatedVariants(CCModel originalModel) {
    CCModel[] result = new CCModel[6];
    double modelHeight = originalModel.verts[2].vec.y;
    double translate = 1.0 - modelHeight;
    for (int i = 0; i < 3; i++) {
        EnumFacing side = EnumFacing.VALUES[i * 2 + 1];
        Transformation rotation = Rotation.sideRotations[i * 2].at(Vector3.center);
        Transformation translation = new Translation(side.getFrontOffsetX() * translate, side.getFrontOffsetY() * translate, side.getFrontOffsetZ() * translate);
        CCModel negativeModel = originalModel.copy().apply(rotation);
        CCModel positiveModel = negativeModel.copy().apply(translation);
        result[i * 2] = negativeModel;
        result[i * 2 + 1] = positiveModel;
    }
    return result;
}
 
Example #4
Source File: ShapeModelGenerator.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static CCModel generateModel(int angles, double height, double radius, double segmentHeight) {
    int amountOfSegments = (int) Math.ceil(height / segmentHeight);
    CCModel initialModel = CCModel.quadModel(angles * 4 * amountOfSegments);
    double radiansPerAngle = (Math.PI * 2) / (angles * 1.0);
    for (int i = 0; i < angles; i++) {
        Vector3 first = generatePoint(radiansPerAngle, i, radius);
        Vector3 second = generatePoint(radiansPerAngle, i + 1, radius);
        Vector3 firstTop = first.copy().add(0.0, segmentHeight, 0.0);
        Vector3 secondTop = second.copy().add(0.0, segmentHeight, 0.0);
        double width = first.copy().subtract(second).mag();
        double heightLeft = height;
        for (int j = 0; j < amountOfSegments; j++) {
            double actualHeight = firstTop.y - first.y;
            double textureHeight = 1.0 * (actualHeight / segmentHeight);
            double textureWidth = (textureHeight / actualHeight) * width;
            int offset = i * amountOfSegments * 4 + j * 4;
            initialModel.verts[offset] = new Vertex5(first.copy(), 0.0, 0.0);
            initialModel.verts[offset + 1] = new Vertex5(firstTop.copy(), 0.0, textureHeight);
            initialModel.verts[offset + 2] = new Vertex5(secondTop.copy(), textureWidth, textureHeight);
            initialModel.verts[offset + 3] = new Vertex5(second.copy(), textureWidth, 0.0);

            heightLeft -= actualHeight;
            double nextSegmentHeight = Math.min(segmentHeight, heightLeft);
            first.add(0.0, actualHeight, 0.0);
            second.add(0.0, actualHeight, 0.0);
            firstTop.y = first.y + nextSegmentHeight;
            secondTop.y = second.y + nextSegmentHeight;
        }
    }
    initialModel.computeNormals();
    return initialModel;
}
 
Example #5
Source File: InvPipeRenderer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void registerIcons(TextureMap map) {
    this.jointTextureSprite = map.registerSprite(new ResourceLocation(GTValues.MODID, "blocks/inv_pipe/joint"));
    this.pipeTextureSprite = map.registerSprite(new ResourceLocation(GTValues.MODID, "blocks/inv_pipe/pipe"));

    InventoryPipeType pipeType = InventoryPipeType.NORMAL;
    float thickness = pipeType.getThickness();
    double height = (1.0f - thickness) / 2.0f;
    CCModel connectionModel = ShapeModelGenerator.generateModel(3, height, thickness / 3.0f, height);
    CCModel fullBlockModel = ShapeModelGenerator.generateModel(3, 1.0f, thickness / 3.0f, height);

    this.fullBlockVariants = ShapeModelGenerator.generateFullBlockVariants(fullBlockModel);
    this.connectionModels = ShapeModelGenerator.generateRotatedVariants(connectionModel);
}
 
Example #6
Source File: StoneRenderer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static CCModel getActualModel(IBlockAccess world, BlockPos pos) {
    TileEntitySurfaceRock tileEntity = BlockSurfaceRockNew.getTileEntity(world, pos);
    if (tileEntity != null) {
        if (tileEntity.cachedModel == null) {
            Random random = new Random(MathHelper.getPositionRandom(pos));
            tileEntity.cachedModel = generateModel(random);
        }
        return (CCModel) tileEntity.cachedModel;
    }
    return placeholderModels[0];
}
 
Example #7
Source File: StonePileModelGenerator.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static CCModel generatePebblePileModel(Random random) {
    List<IndexedCuboid6> cuboid6s = generateCuboidList(random);
    CCModel ccModel = CCModel.quadModel(cuboid6s.size() * 24);
    for (int i = 0; i < cuboid6s.size(); i++) {
        IndexedCuboid6 cuboid6 = cuboid6s.get(i);
        ccModel.generateBlock(i * 24, cuboid6);
        int b = (int) cuboid6.data;
        int[] colours = ccModel.getOrAllocate(ColourAttribute.attributeKey);
        int color = (b & 0xFF) << 24 | (b & 0xFF) << 16 | (b & 0xFF) << 8 | (0xFF);
        Arrays.fill(colours, i * 24, i* 24 + 24, color);
    }
    return ccModel;
}
 
Example #8
Source File: RenderTileEnderChest.java    From EnderStorage with MIT License 5 votes vote down vote up
public static void renderChest(CCRenderState ccrs, MatrixStack mStack, IRenderTypeBuffer getter, int rotation, double yToCamera, Frequency freq, float lidAngle, int pearlOffset) {
    Matrix4 mat = new Matrix4(mStack);
    if (lidAngle != 0) {//Micro optimization, lid closed, dont render starfield.
        renderEndPortal.render(mat, getter, yToCamera);
    }
    ccrs.reset();
    mStack.push();
    mStack.translate(0, 1.0, 1.0);
    mStack.scale(1.0F, -1.0F, -1.0F);
    mStack.translate(0.5, 0.5, 0.5);
    mStack.rotate(new Quaternion(0, rotation * 90, 0, true));
    mStack.translate(-0.5, -0.5, -0.5);
    model.chestLid.rotateAngleX = lidAngle;
    model.render(mStack, getter.getBuffer(chestType), ccrs.brightness, ccrs.overlay, freq.hasOwner());
    mStack.pop();

    //Buttons
    ccrs.bind(buttonType, getter);
    EnumColour[] colours = freq.toArray();
    for (int i = 0; i < 3; i++) {
        CCModel button = ButtonModelLibrary.button.copy();
        button.apply(BlockEnderChest.buttonT[i]);
        button.apply(new Translation(0.5, 0, 0.5));
        button.apply(new Rotation(lidAngle, 1, 0, 0).at(new Vector3(0, 9D / 16D, 1 / 16D)));
        button.apply(new Rotation((-90 * (rotation)) * MathHelper.torad, Vector3.Y_POS).at(new Vector3(0.5, 0, 0.5)));
        button.render(ccrs, mat, new UVTranslation(0.25 * (colours[i].getWoolMeta() % 4), 0.25 * (colours[i].getWoolMeta() / 4)));
    }
    mat.translate(0.5, 0, 0.5);

    //Pearl
    if (lidAngle != 0) {//Micro optimization, lid closed, dont render pearl.
        double time = ClientUtils.getRenderTime() + pearlOffset;
        Matrix4 pearlMat = RenderUtils.getMatrix(mat.copy(), new Vector3(0, 0.2 + lidAngle * -0.5 + RenderUtils.getPearlBob(time), 0), new Rotation(time / 3, new Vector3(0, 1, 0)), 0.04);
        ccrs.brightness = 15728880;
        ccrs.bind(pearlType, getter);
        CCModelLibrary.icosahedron4.render(ccrs, pearlMat);
    }
    ccrs.reset();
}
 
Example #9
Source File: FluidPipeRenderer.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PipeModelInfo(CCModel[] connectionModels, CCModel[] fullBlockModels) {
    this.connectionModels = connectionModels;
    this.fullBlockModels = fullBlockModels;
}
 
Example #10
Source File: StoneRenderer.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static CCModel generateModel(Random random) {
    return StonePileModelGenerator.generatePebblePileModel(random);
}
 
Example #11
Source File: ButtonModelLibrary.java    From EnderStorage with MIT License 4 votes vote down vote up
private static void generateButton() {
    button = CCModel.quadModel(20);
    Vector3 min = TileFrequencyOwner.selection_button.min;
    Vector3 max = TileFrequencyOwner.selection_button.max;
    Vector3[] corners = new Vector3[8];
    corners[0] = new Vector3(min.x, min.y, min.z);
    corners[1] = new Vector3(max.x, min.y, min.z);
    corners[3] = new Vector3(min.x, max.y, min.z);
    corners[2] = new Vector3(max.x, max.y, min.z);
    corners[4] = new Vector3(min.x, min.y, max.z);
    corners[5] = new Vector3(max.x, min.y, max.z);
    corners[7] = new Vector3(min.x, max.y, max.z);
    corners[6] = new Vector3(max.x, max.y, max.z);

    int i = 0;
    Vertex5[] verts = button.verts;

    verts[i++] = new Vertex5(corners[7], 0.0938, 0.0625);
    verts[i++] = new Vertex5(corners[6], 0.1562, 0.0625);
    verts[i++] = new Vertex5(corners[2], 0.1562, 0.1875);
    verts[i++] = new Vertex5(corners[3], 0.0938, 0.1875);

    verts[i++] = new Vertex5(corners[4], 0.0938, 0.0313);
    verts[i++] = new Vertex5(corners[5], 0.1562, 0.0624);
    verts[i++] = new Vertex5(corners[6], 0.1562, 0.0624);
    verts[i++] = new Vertex5(corners[7], 0.0938, 0.0313);

    verts[i++] = new Vertex5(corners[0], 0.0938, 0.2186);
    verts[i++] = new Vertex5(corners[3], 0.0938, 0.1876);
    verts[i++] = new Vertex5(corners[2], 0.1562, 0.1876);
    verts[i++] = new Vertex5(corners[1], 0.1562, 0.2186);

    verts[i++] = new Vertex5(corners[6], 0.1563, 0.0626);
    verts[i++] = new Vertex5(corners[5], 0.1874, 0.0626);
    verts[i++] = new Vertex5(corners[1], 0.1874, 0.1874);
    verts[i++] = new Vertex5(corners[2], 0.1563, 0.1874);

    verts[i++] = new Vertex5(corners[7], 0.0937, 0.0626);
    verts[i++] = new Vertex5(corners[3], 0.0937, 0.1874);
    verts[i++] = new Vertex5(corners[0], 0.0626, 0.1874);
    verts[i++] = new Vertex5(corners[4], 0.0626, 0.0626);

    button.computeNormals();
}
 
Example #12
Source File: RenderEnderStorage.java    From EnderStorage with MIT License 4 votes vote down vote up
private static void generateButton()
{
    button = CCModel.quadModel(20);
    Vector3 min = TileFrequencyOwner.selection_button.min;
    Vector3 max = TileFrequencyOwner.selection_button.max;
    Vector3[] corners = new Vector3[8];
    corners[0] = new Vector3(min.x, min.y, min.z);
    corners[1] = new Vector3(max.x, min.y, min.z);
    corners[3] = new Vector3(min.x, max.y, min.z);
    corners[2] = new Vector3(max.x, max.y, min.z);
    corners[4] = new Vector3(min.x, min.y, max.z);
    corners[5] = new Vector3(max.x, min.y, max.z);
    corners[7] = new Vector3(min.x, max.y, max.z);
    corners[6] = new Vector3(max.x, max.y, max.z);
    
    int i = 0;
    Vertex5[] verts = button.verts;
    
    verts[i++] = new Vertex5(corners[7], 0.0938, 0.0625);
    verts[i++] = new Vertex5(corners[6], 0.1562, 0.0625);
    verts[i++] = new Vertex5(corners[2], 0.1562, 0.1875);
    verts[i++] = new Vertex5(corners[3], 0.0938, 0.1875);

    verts[i++] = new Vertex5(corners[4], 0.0938, 0.0313);
    verts[i++] = new Vertex5(corners[5], 0.1562, 0.0624);
    verts[i++] = new Vertex5(corners[6], 0.1562, 0.0624);
    verts[i++] = new Vertex5(corners[7], 0.0938, 0.0313);
    
    verts[i++] = new Vertex5(corners[0], 0.0938, 0.2186);
    verts[i++] = new Vertex5(corners[3], 0.0938, 0.1876);
    verts[i++] = new Vertex5(corners[2], 0.1562, 0.1876);
    verts[i++] = new Vertex5(corners[1], 0.1562, 0.2186);

    verts[i++] = new Vertex5(corners[6], 0.1563, 0.0626);
    verts[i++] = new Vertex5(corners[5], 0.1874, 0.0626);
    verts[i++] = new Vertex5(corners[1], 0.1874, 0.1874);
    verts[i++] = new Vertex5(corners[2], 0.1563, 0.1874);

    verts[i++] = new Vertex5(corners[7], 0.0937, 0.0626);
    verts[i++] = new Vertex5(corners[3], 0.0937, 0.1874);
    verts[i++] = new Vertex5(corners[0], 0.0626, 0.1874);
    verts[i++] = new Vertex5(corners[4], 0.0626, 0.0626);
    
    button.computeNormals();
}
 
Example #13
Source File: LC.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
public LC compute(Vector3 vec, Vector3 normal) {
    int side = CCModel.findSide(normal);
    if (side < 0)
        return set(12, 1, 0, 0, 0);
    return compute(vec, side);
}