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;
}
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;
}
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);
}
}
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);
}
}
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);
}
}
}
Aggregations