Search in sources :

Example 1 with Asset

use of io.xol.chunkstories.api.content.Asset in project chunkstories by Hugobros3.

the class GLSLPreprocessor method loadRecursivly.

public static void loadRecursivly(ModsManager modsManager, Asset asset, StringBuilder into, boolean type, Set<String> alreadyIncluded) throws IOException {
    if (alreadyIncluded == null)
        alreadyIncluded = new HashSet<String>();
    Reader fileReader = asset.reader();
    BufferedReader reader = new BufferedReader(fileReader);
    // List<String> blockingDef = new ArrayList<String>();
    String l;
    while ((l = reader.readLine()) != null) {
        String strippedLine = l.replace("	", "");
        if (strippedLine.startsWith("#")) {
            String[] line = strippedLine.substring(1).replace(">", "").replace("<", "").split(" ");
            if (line.length == 2) {
                if (line[0].equals("include")) {
                    String fn = line[1];
                    String shaderInclude = asset.getName().substring(0, asset.getName().lastIndexOf("/") + 1) + fn;
                    while (shaderInclude.indexOf("..") != -1) {
                        int indexOf = shaderInclude.indexOf("..");
                        if (indexOf <= 0) {
                            System.out.println("Irresolvable path; going too far back in parents folder; " + shaderInclude);
                            break;
                        }
                        String lowerHalf = shaderInclude.substring(0, indexOf - 1);
                        String upperHalf = shaderInclude.substring(indexOf + 2);
                        lowerHalf = lowerHalf.substring(0, lowerHalf.lastIndexOf("/"));
                        shaderInclude = lowerHalf + upperHalf;
                    }
                    Asset asset2include = modsManager.getAsset(shaderInclude);
                    if (asset2include == null) {
                        System.out.println("Couldn't find shader include: " + shaderInclude);
                        continue;
                    }
                    // Prevents including same file twice and retarded loops
                    if (alreadyIncluded.add(asset2include.getName()))
                        loadRecursivly(modsManager, asset2include, into, type, alreadyIncluded);
                    else
                        System.out.println("Shader include : " + asset2include.getName() + " already included, skipping");
                    continue;
                } else if (line[0].equals("version")) {
                    into.append(l).append("\n");
                    // <- append the defines stuff after the version tag
                    defineConfiguration(into);
                    continue;
                }
            }
        }
        into.append(l).append("\n");
    }
    reader.close();
// return into;
}
Also used : BufferedReader(java.io.BufferedReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) Asset(io.xol.chunkstories.api.content.Asset) HashSet(java.util.HashSet)

Example 2 with Asset

use of io.xol.chunkstories.api.content.Asset in project chunkstories by Hugobros3.

the class CubemapGL method loadCubemapFromDisk.

public int loadCubemapFromDisk() {
    bind();
    ByteBuffer temp;
    String[] names = { "right", "left", "top", "bottom", "front", "back" };
    if (Client.getInstance().getContent().getAsset((name + "/front.png")) == null) {
        logger().info("Can't find front.png from CS-format skybox, trying MC format.");
        names = new String[] { "panorama_1", "panorama_3", "panorama_4", "panorama_5", "panorama_0", "panorama_2" };
    }
    try {
        for (int i = 0; i < 6; i++) {
            Asset pngFile = Client.getInstance().getContent().getAsset(name + "/" + names[i] + ".png");
            if (pngFile == null)
                throw new FileNotFoundException(name + "/" + names[i] + ".png");
            PNGDecoder decoder = new PNGDecoder(pngFile.read());
            temp = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
            decoder.decode(temp, decoder.getWidth() * 4, Format.RGBA);
            temp.flip();
            this.size = decoder.getHeight();
            glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, type.getInternalFormat(), decoder.getWidth(), decoder.getHeight(), 0, type.getFormat(), type.getType(), temp);
            // Anti alias
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            // Anti seam
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        }
    } catch (FileNotFoundException e) {
        logger().warn("Couldn't find file : " + e.getMessage());
    } catch (IOException e) {
        logger().error("Failed to load properly cubemap : " + name);
    }
    return glId;
}
Also used : PNGDecoder(de.matthiasmann.twl.utils.PNGDecoder) FileNotFoundException(java.io.FileNotFoundException) Asset(io.xol.chunkstories.api.content.Asset) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 3 with Asset

use of io.xol.chunkstories.api.content.Asset in project chunkstories by Hugobros3.

the class VoxelsStore method reloadVoxelTypes.

@SuppressWarnings("unchecked")
private void reloadVoxelTypes() {
    // Discard previous voxels
    // Arrays.fill(voxels, null);
    // attributedIds.clear();
    voxelsByName.clear();
    // First load the default voxel renderer
    try {
        Class<VoxelRenderer> defaultVoxelRendererClass = (Class<VoxelRenderer>) content.modsManager().getClassByName("io.xol.chunkstories.core.voxel.renderers.DefaultVoxelRenderer");
        Constructor<VoxelRenderer> defaultVoxelRendererConstructor = defaultVoxelRendererClass.getConstructor(Voxels.class);
        defaultVoxelRenderer = defaultVoxelRendererConstructor.newInstance(this);
    } catch (Exception e) {
        System.out.println("could not instanciate the default voxel renderer");
        System.exit(-900);
    }
    Iterator<Asset> i = content.modsManager().getAllAssetsByExtension("voxels");
    while (i.hasNext()) {
        Asset f = i.next();
        logger().debug("Reading voxels definitions in : " + f);
        readVoxelsDefinitions(f);
    }
}
Also used : Asset(io.xol.chunkstories.api.content.Asset) VoxelRenderer(io.xol.chunkstories.api.rendering.voxel.VoxelRenderer) IOException(java.io.IOException) IllegalVoxelDeclarationException(io.xol.chunkstories.api.exceptions.content.IllegalVoxelDeclarationException)

Example 4 with Asset

use of io.xol.chunkstories.api.content.Asset in project chunkstories by Hugobros3.

the class VoxelMaterialsStore method reload.

public void reload() {
    materials.clear();
    Iterator<Asset> i = store.modsManager().getAllAssetsByExtension("materials");
    while (i.hasNext()) {
        Asset f = i.next();
        readDefinitions(f);
    }
}
Also used : Asset(io.xol.chunkstories.api.content.Asset)

Example 5 with Asset

use of io.xol.chunkstories.api.content.Asset in project chunkstories by Hugobros3.

the class VoxelModelsStore method resetAndLoadModels.

public void resetAndLoadModels() {
    models.clear();
    Iterator<AssetHierarchy> allFiles = voxels.parent().modsManager().getAllUniqueEntries();
    while (allFiles.hasNext()) {
        AssetHierarchy entry = allFiles.next();
        if (entry.getName().startsWith("./voxels/blockmodels/") && entry.getName().endsWith(".model")) {
            Asset f = entry.topInstance();
            readBlockModel(f);
        }
    }
}
Also used : Asset(io.xol.chunkstories.api.content.Asset) AssetHierarchy(io.xol.chunkstories.api.content.mods.AssetHierarchy)

Aggregations

Asset (io.xol.chunkstories.api.content.Asset)22 IOException (java.io.IOException)6 AssetHierarchy (io.xol.chunkstories.api.content.mods.AssetHierarchy)5 File (java.io.File)3 ArrayList (java.util.ArrayList)3 IterableIterator (io.xol.chunkstories.api.util.IterableIterator)2 BufferedReader (java.io.BufferedReader)2 Iterator (java.util.Iterator)2 PNGDecoder (de.matthiasmann.twl.utils.PNGDecoder)1 ClientInterface (io.xol.chunkstories.api.client.ClientInterface)1 IllegalVoxelDeclarationException (io.xol.chunkstories.api.exceptions.content.IllegalVoxelDeclarationException)1 MeshLoadException (io.xol.chunkstories.api.exceptions.content.MeshLoadException)1 PluginLoadException (io.xol.chunkstories.api.exceptions.plugins.PluginLoadException)1 AnimatableMesh (io.xol.chunkstories.api.mesh.AnimatableMesh)1 Mesh (io.xol.chunkstories.api.mesh.Mesh)1 VoxelRenderer (io.xol.chunkstories.api.rendering.voxel.VoxelRenderer)1 ForeignCodeClassLoader (io.xol.chunkstories.content.sandbox.ForeignCodeClassLoader)1 NotAPluginException (io.xol.chunkstories.plugin.NotAPluginException)1 PluginInformationImplementation (io.xol.chunkstories.plugin.PluginInformationImplementation)1 BufferedImage (java.awt.image.BufferedImage)1