Search in sources :

Example 1 with BakingVertexBuffer

use of codechicken.lib.render.buffer.BakingVertexBuffer in project LogisticsPipes by RS485.

the class Model3D method renderToQuads.

@Override
@SideOnly(Side.CLIENT)
@SneakyThrows({ IllegalAccessException.class })
public List<BakedQuad> renderToQuads(VertexFormat format, I3DOperation... i3dOperations) {
    List<IVertexOperation> list = new ArrayList<>();
    Set<String> hash = new HashSet<>();
    hash.add(String.valueOf(format.hashCode()));
    boolean cachable = true;
    for (I3DOperation op : i3dOperations) {
        IVertexOperation iVertexOperation = (IVertexOperation) op.getOriginal();
        list.add(iVertexOperation);
        if (iVertexOperation instanceof IconTransformation) {
            hash.add(((IconTransformation) iVertexOperation).icon.toString());
        } else if (iVertexOperation instanceof Rotation) {
            hash.add(iVertexOperation.toString());
        } else if (iVertexOperation instanceof Scale) {
            hash.add(iVertexOperation.toString());
        } else if (iVertexOperation instanceof Translation) {
            hash.add(iVertexOperation.toString());
        } else {
            cachable = false;
        }
    }
    if (cachable) {
        List<BakedQuad> content = renderCache.getIfPresent(hash.hashCode());
        if (content != null) {
            return content;
        }
    }
    BakingVertexBuffer buffer = BakingVertexBuffer.create();
    CCRenderState ccrs = CCRenderState.instance();
    ccrs.reset();
    ccrs.startDrawing(0x7, format, buffer);
    model.render(ccrs, list.toArray(new IVertexOperation[0]));
    buffer.finishDrawing();
    emptyHashMap.clear();
    if (spiteMap != null) {
        spiteMap.set(buffer, emptyHashMap);
    }
    List<BakedQuad> quads = buffer.bake();
    if (cachable) {
        renderCache.put(hash.hashCode(), quads);
    }
    return quads;
}
Also used : IVertexOperation(codechicken.lib.render.pipeline.IVertexOperation) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Translation(codechicken.lib.vec.Translation) ArrayList(java.util.ArrayList) Scale(codechicken.lib.vec.Scale) I3DOperation(logisticspipes.proxy.object3d.interfaces.I3DOperation) Rotation(codechicken.lib.vec.Rotation) BakingVertexBuffer(codechicken.lib.render.buffer.BakingVertexBuffer) CCRenderState(codechicken.lib.render.CCRenderState) HashSet(java.util.HashSet) IconTransformation(codechicken.lib.vec.uv.IconTransformation) SneakyThrows(lombok.SneakyThrows) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

CCRenderState (codechicken.lib.render.CCRenderState)1 BakingVertexBuffer (codechicken.lib.render.buffer.BakingVertexBuffer)1 IVertexOperation (codechicken.lib.render.pipeline.IVertexOperation)1 Rotation (codechicken.lib.vec.Rotation)1 Scale (codechicken.lib.vec.Scale)1 Translation (codechicken.lib.vec.Translation)1 IconTransformation (codechicken.lib.vec.uv.IconTransformation)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 I3DOperation (logisticspipes.proxy.object3d.interfaces.I3DOperation)1 SneakyThrows (lombok.SneakyThrows)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1