Search in sources :

Example 1 with SkinCubeData

use of riskyken.armourersWorkshop.common.skin.data.SkinCubeData in project Armourers-Workshop by RiskyKen.

the class ArmourerWorldHelper method saveArmourPart.

private static SkinPart saveArmourPart(World world, ISkinPartType skinPart, int xCoord, int yCoord, int zCoord, ForgeDirection direction, boolean markerCheck) throws SkinSaveException {
    int cubeCount = getNumberOfCubesInPart(world, xCoord, yCoord, zCoord, skinPart);
    if (cubeCount < 1) {
        return null;
    }
    SkinCubeData cubeData = new SkinCubeData();
    cubeData.setCubeCount(cubeCount);
    ArrayList<CubeMarkerData> markerBlocks = new ArrayList<CubeMarkerData>();
    IRectangle3D buildSpace = skinPart.getBuildingSpace();
    IPoint3D offset = skinPart.getOffset();
    int i = 0;
    for (int ix = 0; ix < buildSpace.getWidth(); ix++) {
        for (int iy = 0; iy < buildSpace.getHeight(); iy++) {
            for (int iz = 0; iz < buildSpace.getDepth(); iz++) {
                int x = xCoord + ix + -offset.getX() + buildSpace.getX();
                int y = yCoord + iy + -offset.getY();
                int z = zCoord + iz + offset.getZ() + buildSpace.getZ();
                int xOrigin = -ix + -buildSpace.getX();
                int yOrigin = -iy + -buildSpace.getY();
                int zOrigin = -iz + -buildSpace.getZ();
                if (!world.isAirBlock(x, y, z)) {
                    Block block = world.getBlock(x, y, z);
                    if (CubeRegistry.INSTANCE.isBuildingBlock(block)) {
                        saveArmourBlockToList(world, x, y, z, xOrigin - 1, yOrigin - 1, -zOrigin, cubeData, i, markerBlocks, direction);
                        i++;
                    }
                }
            }
        }
    }
    if (markerCheck) {
        if (skinPart.getMinimumMarkersNeeded() > markerBlocks.size()) {
            throw new SkinSaveException("Missing marker for part " + skinPart.getPartName(), SkinSaveExceptionType.MARKER_ERROR);
        }
        if (markerBlocks.size() > skinPart.getMaximumMarkersNeeded()) {
            throw new SkinSaveException("Too many markers for part " + skinPart.getPartName(), SkinSaveExceptionType.MARKER_ERROR);
        }
    }
    return new SkinPart(cubeData, skinPart, markerBlocks);
}
Also used : SkinSaveException(riskyken.armourersWorkshop.common.exception.SkinSaveException) SkinCubeData(riskyken.armourersWorkshop.common.skin.data.SkinCubeData) IPoint3D(riskyken.armourersWorkshop.api.common.IPoint3D) CubeMarkerData(riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData) IRectangle3D(riskyken.armourersWorkshop.api.common.IRectangle3D) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) SkinBlock(riskyken.armourersWorkshop.common.skin.type.block.SkinBlock) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 2 with SkinCubeData

use of riskyken.armourersWorkshop.common.skin.data.SkinCubeData in project Armourers-Workshop by RiskyKen.

the class SkinBaker method cullFacesOnEquipmentPart.

public static int[][][] cullFacesOnEquipmentPart(SkinPart skinPart) {
    SkinCubeData cubeData = skinPart.getCubeData();
    cubeData.setupFaceFlags();
    skinPart.getClientSkinPartData().totalCubesInPart = new int[CubeRegistry.INSTANCE.getTotalCubes()];
    Rectangle3D pb = skinPart.getPartBounds();
    int[][][] cubeArray = new int[pb.getWidth()][pb.getHeight()][pb.getDepth()];
    int updates = 0;
    for (int i = 0; i < cubeData.getCubeCount(); i++) {
        int cubeId = cubeData.getCubeId(i);
        byte[] cubeLoc = cubeData.getCubeLocation(i);
        skinPart.getClientSkinPartData().totalCubesInPart[cubeId] += 1;
        int x = (int) cubeLoc[0] - pb.getX();
        int y = (int) cubeLoc[1] - pb.getY();
        int z = (int) cubeLoc[2] - pb.getZ();
        cubeArray[x][y][z] = i + 1;
        if (ConfigHandlerClient.slowModelBaking) {
            updates++;
            if (updates > 40) {
                try {
                    Thread.sleep(1);
                    updates = 0;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    ArrayList<CubeLocation> openList = new ArrayList<CubeLocation>();
    HashSet<Integer> closedSet = new HashSet<Integer>();
    CubeLocation startCube = new CubeLocation(-1, -1, -1);
    openList.add(startCube);
    closedSet.add(startCube.hashCode());
    while (openList.size() > 0) {
        CubeLocation cl = openList.get(openList.size() - 1);
        openList.remove(openList.size() - 1);
        ArrayList<CubeLocation> foundLocations = checkCubesAroundLocation(cubeData, cl, pb, cubeArray);
        for (int i = 0; i < foundLocations.size(); i++) {
            CubeLocation foundLocation = foundLocations.get(i);
            if (!closedSet.contains(foundLocation.hashCode())) {
                closedSet.add(foundLocation.hashCode());
                if (isCubeInSearchArea(foundLocation, pb)) {
                    openList.add(foundLocation);
                }
            }
        }
        if (ConfigHandlerClient.slowModelBaking) {
            updates++;
            if (updates > 40) {
                try {
                    Thread.sleep(1);
                    updates = 0;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return cubeArray;
}
Also used : SkinCubeData(riskyken.armourersWorkshop.common.skin.data.SkinCubeData) ArrayList(java.util.ArrayList) Rectangle3D(riskyken.armourersWorkshop.api.common.skin.Rectangle3D) HashSet(java.util.HashSet)

Example 3 with SkinCubeData

use of riskyken.armourersWorkshop.common.skin.data.SkinCubeData in project Armourers-Workshop by RiskyKen.

the class SkinPartSerializer method loadSkinPart.

public static SkinPart loadSkinPart(DataInputStream stream, int version) throws IOException, InvalidCubeTypeException {
    ISkinPartType skinPart = null;
    SkinCubeData cubeData = null;
    ArrayList<CubeMarkerData> markerBlocks = null;
    if (version < 6) {
        skinPart = SkinTypeRegistry.INSTANCE.getSkinPartFromLegacyId(stream.readByte());
        if (skinPart == null) {
            ModLogger.log(Level.ERROR, "Skin part was null");
            throw new IOException("Skin part was null");
        }
    } else {
        String regName = null;
        if (version > 12) {
            regName = StreamUtils.readString(stream, Charsets.US_ASCII);
        } else {
            regName = stream.readUTF();
        }
        if (regName.equals("armourers:skirt.base")) {
            regName = "armourers:legs.skirt";
        }
        if (regName.equals("armourers:bow.base")) {
            regName = "armourers:bow.frame1";
        }
        if (regName.equals("armourers:arrow.base")) {
            regName = "armourers:bow.arrow";
        }
        skinPart = SkinTypeRegistry.INSTANCE.getSkinPartFromRegistryName(regName);
        if (skinPart == null) {
            ModLogger.log(Level.ERROR, "Skin part was null - reg name: " + regName + " version: " + version);
            throw new IOException("Skin part was null - reg name: " + regName + " version: " + version);
        }
    }
    cubeData = new SkinCubeData();
    cubeData.readFromStream(stream, version, skinPart);
    markerBlocks = new ArrayList<CubeMarkerData>();
    if (version > 8) {
        int markerCount = stream.readInt();
        for (int i = 0; i < markerCount; i++) {
            markerBlocks.add(new CubeMarkerData(stream, version));
        }
    }
    return new SkinPart(cubeData, skinPart, markerBlocks);
}
Also used : ISkinPartType(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType) SkinCubeData(riskyken.armourersWorkshop.common.skin.data.SkinCubeData) CubeMarkerData(riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData) IOException(java.io.IOException) SkinPart(riskyken.armourersWorkshop.common.skin.data.SkinPart)

Example 4 with SkinCubeData

use of riskyken.armourersWorkshop.common.skin.data.SkinCubeData in project Armourers-Workshop by RiskyKen.

the class ArmourerWorldHelper method loadSkinPartIntoWorld.

private static void loadSkinPartIntoWorld(World world, SkinPart partData, int xCoord, int yCoord, int zCoord, ForgeDirection direction, boolean mirror) {
    ISkinPartType skinPart = partData.getPartType();
    IRectangle3D buildSpace = skinPart.getBuildingSpace();
    IPoint3D offset = skinPart.getOffset();
    SkinCubeData cubeData = partData.getCubeData();
    for (int i = 0; i < cubeData.getCubeCount(); i++) {
        ICube blockData = cubeData.getCube(i);
        int meta = 0;
        for (int j = 0; j < partData.getMarkerBlocks().size(); j++) {
            CubeMarkerData cmd = partData.getMarkerBlocks().get(j);
            byte[] loc = cubeData.getCubeLocation(i);
            if (cmd.x == loc[0] & cmd.y == loc[1] & cmd.z == loc[2]) {
                meta = cmd.meta;
                break;
            }
        }
        int xOrigin = -offset.getX();
        int yOrigin = -offset.getY() + -buildSpace.getY();
        int zOrigin = offset.getZ();
        loadSkinBlockIntoWorld(world, xCoord, yCoord, zCoord, xOrigin, yOrigin, zOrigin, blockData, direction, meta, cubeData, i, mirror);
    }
}
Also used : ISkinPartType(riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType) SkinCubeData(riskyken.armourersWorkshop.common.skin.data.SkinCubeData) IPoint3D(riskyken.armourersWorkshop.api.common.IPoint3D) IRectangle3D(riskyken.armourersWorkshop.api.common.IRectangle3D) CubeMarkerData(riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData) ICube(riskyken.armourersWorkshop.common.skin.cubes.ICube)

Example 5 with SkinCubeData

use of riskyken.armourersWorkshop.common.skin.data.SkinCubeData in project Armourers-Workshop by RiskyKen.

the class SkinBaker method buildPartDisplayListArray.

public static void buildPartDisplayListArray(SkinPart partData, int[][] dyeColour, int[] dyeUseCount, int[][][] cubeArray) {
    boolean multipassSkinRendering = ClientProxy.useMultipassSkinRendering();
    ArrayList<ColouredFace>[] renderLists;
    int lodLevels = ConfigHandlerClient.maxLodLevels;
    /* LOD Indexs
         * 
         * with multipass;
         * 0 = normal
         * 1 = glowing
         * 2 = glass
         * 3 = glass glowing
         * 
         * without multipass
         * 0 = normal
         * 1 = glowing
         */
    renderLists = (ArrayList<ColouredFace>[]) new ArrayList[ClientProxy.getNumberOfRenderLayers() * (lodLevels + 1)];
    for (int i = 0; i < renderLists.length; i++) {
        renderLists[i] = new ArrayList<ColouredFace>();
    }
    float scale = 0.0625F;
    SkinCubeData cubeData = partData.getCubeData();
    Rectangle3D pb = partData.getPartBounds();
    for (int ix = 0; ix < pb.getWidth(); ix++) {
        for (int iy = 0; iy < pb.getHeight(); iy++) {
            for (int iz = 0; iz < pb.getDepth(); iz++) {
                int i = getIndexForLocation(ix, iy, iz, pb, cubeArray) - 1;
                if (i != -1) {
                    byte[] loc = cubeData.getCubeLocation(i);
                    byte[] paintType = cubeData.getCubePaintType(i);
                    ICube cube = partData.getCubeData().getCube(i);
                    byte a = (byte) 255;
                    if (cube.needsPostRender()) {
                        a = (byte) 127;
                    }
                    byte[] r = cubeData.getCubeColourR(i);
                    byte[] g = cubeData.getCubeColourG(i);
                    byte[] b = cubeData.getCubeColourB(i);
                    for (int j = 0; j < 6; j++) {
                        int paint = paintType[j] & 0xFF;
                        if (paint >= 1 && paint <= 8 && cubeData.getFaceFlags(i).get(j)) {
                            dyeUseCount[paint - 1]++;
                            dyeColour[0][paint - 1] += r[j] & 0xFF;
                            dyeColour[1][paint - 1] += g[j] & 0xFF;
                            dyeColour[2][paint - 1] += b[j] & 0xFF;
                        }
                        if (paint == 253) {
                            dyeUseCount[8]++;
                            dyeColour[0][8] += r[j] & 0xFF;
                            dyeColour[1][8] += g[j] & 0xFF;
                            dyeColour[2][8] += b[j] & 0xFF;
                        }
                        if (paint == 254) {
                            dyeUseCount[9]++;
                            dyeColour[0][9] += r[j] & 0xFF;
                            dyeColour[1][9] += g[j] & 0xFF;
                            dyeColour[2][9] += b[j] & 0xFF;
                        }
                    }
                    int listIndex = 0;
                    if (multipassSkinRendering) {
                        if (cube.isGlowing() && !cube.needsPostRender()) {
                            listIndex = 1;
                        }
                        if (cube.needsPostRender() && !cube.isGlowing()) {
                            listIndex = 2;
                        }
                        if (cube.isGlowing() && cube.needsPostRender()) {
                            listIndex = 3;
                        }
                    } else {
                        if (cube.isGlowing()) {
                            listIndex = 1;
                        }
                    }
                    for (int j = 0; j < 6; j++) {
                        if (cubeData.getFaceFlags(i).get(j)) {
                            ColouredFace ver = new ColouredFace(loc[0], loc[1], loc[2], r[j], g[j], b[j], a, paintType[j], (byte) j, (byte) (1));
                            renderLists[listIndex].add(ver);
                        }
                    }
                }
                // Create model LODs
                for (int lod = 1; lod < lodLevels + 1; lod++) {
                    byte lodLevel = (byte) Math.pow(2, lod);
                    if ((ix) % lodLevel == 0 & (iy) % lodLevel == 0 & (iz) % lodLevel == 0) {
                        for (int j = 0; j < 6; j++) {
                            boolean showFace = getAverageFaceFlags(ix, iy, iz, lodLevel, cubeArray, cubeData, pb, j);
                            if (showFace) {
                                byte[] avegC = getAverageRGBAT(ix, iy, iz, lodLevel, cubeArray, cubeData, pb, j);
                                ICube cube = CubeRegistry.INSTANCE.getCubeFormId(avegC[5]);
                                int listIndex = 0;
                                if (multipassSkinRendering) {
                                    if (cube.isGlowing() && !cube.needsPostRender()) {
                                        listIndex = 1;
                                    }
                                    if (cube.needsPostRender() && !cube.isGlowing()) {
                                        listIndex = 2;
                                    }
                                    if (cube.isGlowing() && cube.needsPostRender()) {
                                        listIndex = 3;
                                    }
                                } else {
                                    if (cube.isGlowing()) {
                                        listIndex = 1;
                                    }
                                }
                                int lodIndex = ((lod) * ClientProxy.getNumberOfRenderLayers()) + listIndex;
                                ColouredFace ver = new ColouredFace((byte) (ix + pb.getX()), (byte) (iy + pb.getY()), (byte) (iz + pb.getZ()), avegC[0], avegC[1], avegC[2], avegC[3], avegC[4], (byte) j, lodLevel);
                                renderLists[lodIndex].add(ver);
                            }
                        }
                    }
                }
            }
        }
    }
    partData.getClientSkinPartData().setVertexLists(renderLists);
}
Also used : SkinCubeData(riskyken.armourersWorkshop.common.skin.data.SkinCubeData) ArrayList(java.util.ArrayList) Rectangle3D(riskyken.armourersWorkshop.api.common.skin.Rectangle3D) ICube(riskyken.armourersWorkshop.common.skin.cubes.ICube)

Aggregations

SkinCubeData (riskyken.armourersWorkshop.common.skin.data.SkinCubeData)5 ArrayList (java.util.ArrayList)3 CubeMarkerData (riskyken.armourersWorkshop.common.skin.cubes.CubeMarkerData)3 IPoint3D (riskyken.armourersWorkshop.api.common.IPoint3D)2 IRectangle3D (riskyken.armourersWorkshop.api.common.IRectangle3D)2 Rectangle3D (riskyken.armourersWorkshop.api.common.skin.Rectangle3D)2 ISkinPartType (riskyken.armourersWorkshop.api.common.skin.type.ISkinPartType)2 ICube (riskyken.armourersWorkshop.common.skin.cubes.ICube)2 SkinPart (riskyken.armourersWorkshop.common.skin.data.SkinPart)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Block (net.minecraft.block.Block)1 SkinSaveException (riskyken.armourersWorkshop.common.exception.SkinSaveException)1 SkinBlock (riskyken.armourersWorkshop.common.skin.type.block.SkinBlock)1