use of com.jme3.util.blockparser.Statement in project jmonkeyengine by jMonkeyEngine.
the class ShaderNodeLoaderDelegate method readNodesDefinitions.
/**
* Read the ShaderNodesDefinitions block and returns a list of
* ShaderNodesDefinition This method is used by the j3sn loader
*
* note that the order of the definitions in the list is not guaranteed.
*
* @param statements the list statements to parse
* @param key the ShaderNodeDefinitionKey
* @return a list of ShaderNodesDefinition
* @throws IOException
*/
public List<ShaderNodeDefinition> readNodesDefinitions(List<Statement> statements, ShaderNodeDefinitionKey key) throws IOException {
for (Statement statement : statements) {
String[] split = statement.getLine().split("[ \\{]");
if (statement.getLine().startsWith("ShaderNodeDefinition")) {
String name = statement.getLine().substring("ShaderNodeDefinition".length()).trim();
if (!getNodeDefinitions().containsKey(name)) {
shaderNodeDefinition = new ShaderNodeDefinition();
getNodeDefinitions().put(name, shaderNodeDefinition);
shaderNodeDefinition.setName(name);
readShaderNodeDefinition(statement.getContents(), key);
}
} else {
throw new MatParseException("ShaderNodeDefinition", split[0], statement);
}
}
return new ArrayList<ShaderNodeDefinition>(getNodeDefinitions().values());
}
use of com.jme3.util.blockparser.Statement in project jmonkeyengine by jMonkeyEngine.
the class MTLLoader method load.
@SuppressWarnings("empty-statement")
public Object load(AssetInfo info) throws IOException {
reset();
this.key = info.getKey();
this.assetManager = info.getManager();
folderName = info.getKey().getFolder();
matList = new MaterialList();
InputStream in = null;
try {
in = info.openStream();
scan = new Scanner(in);
scan.useLocale(Locale.US);
while (readLine()) ;
} finally {
if (in != null) {
in.close();
}
}
if (matName != null) {
// still have a material in the vars
createMaterial();
resetMaterial();
}
MaterialList list = matList;
return list;
}
use of com.jme3.util.blockparser.Statement in project jmonkeyengine by jMonkeyEngine.
the class HDRLoader method load.
public Image load(InputStream in, boolean flipY) throws IOException {
float gamma = -1f;
float exposure = -1f;
float[] colorcorr = new float[] { -1f, -1f, -1f };
int width = -1, height = -1;
boolean verifiedFormat = false;
while (true) {
String ln = readString(in);
ln = ln.trim();
if (ln.startsWith("#") || ln.equals("")) {
if (ln.equals("#?RADIANCE") || ln.equals("#?RGBE"))
verifiedFormat = true;
// comment or empty statement
continue;
} else if (ln.startsWith("+") || ln.startsWith("-")) {
// + or - mark image resolution and start of data
String[] resData = ln.split("\\s");
if (resData.length != 4) {
throw new IOException("Invalid resolution string in HDR file");
}
if (!resData[0].equals("-Y") || !resData[2].equals("+X")) {
logger.warning("Flipping/Rotating attributes ignored!");
}
//if (resData[0].endsWith("X")){
// first width then height
// width = Integer.parseInt(resData[1]);
// height = Integer.parseInt(resData[3]);
//}else{
width = Integer.parseInt(resData[3]);
height = Integer.parseInt(resData[1]);
break;
} else {
// regular command
int index = ln.indexOf("=");
if (index < 1) {
logger.log(Level.FINE, "Ignored string: {0}", ln);
continue;
}
String var = ln.substring(0, index).trim().toLowerCase();
String value = ln.substring(index + 1).trim().toLowerCase();
if (var.equals("format")) {
if (!value.equals("32-bit_rle_rgbe") && !value.equals("32-bit_rle_xyze")) {
throw new IOException("Unsupported format in HDR picture");
}
} else if (var.equals("exposure")) {
exposure = Float.parseFloat(value);
} else if (var.equals("gamma")) {
gamma = Float.parseFloat(value);
} else {
logger.log(Level.WARNING, "HDR Command ignored: {0}", ln);
}
}
}
assert width != -1 && height != -1;
if (!verifiedFormat)
logger.warning("Unsure if specified image is Radiance HDR");
// some HDR images can get pretty big
System.gc();
// each pixel times size of component times # of components
Format pixelFormat;
if (writeRGBE) {
pixelFormat = Format.RGBA8;
} else {
pixelFormat = Format.RGB16F;
}
dataStore = BufferUtils.createByteBuffer(width * height * pixelFormat.getBitsPerPixel());
int bytesPerPixel = pixelFormat.getBitsPerPixel() / 8;
int scanLineBytes = bytesPerPixel * width;
for (int y = height - 1; y >= 0; y--) {
if (flipY)
dataStore.position(scanLineBytes * y);
decodeScanline(in, width);
}
in.close();
dataStore.rewind();
//HDR files color data is actually stored in linear space.
return new Image(pixelFormat, width, height, dataStore, ColorSpace.Linear);
}
use of com.jme3.util.blockparser.Statement in project jmonkeyengine by jMonkeyEngine.
the class ShaderNodeLoaderDelegate method readNodes.
/**
* Reads a list of ShaderNodes
*
* @param statements the list of statements to read
* @throws IOException
*/
public void readNodes(List<Statement> statements) throws IOException {
if (techniqueDef.getShaderNodes() == null) {
techniqueDef.setShaderNodes(new ArrayList<ShaderNode>());
techniqueDef.setShaderGenerationInfo(new ShaderGenerationInfo());
}
for (Statement statement : statements) {
String[] split = statement.getLine().split("[ \\{]");
if (statement.getLine().startsWith("ShaderNode ")) {
String name = statement.getLine().substring("ShaderNode".length()).trim();
if (nodes == null) {
nodes = new HashMap<String, ShaderNode>();
}
if (!nodes.containsKey(name)) {
shaderNode = new ShaderNode();
shaderNode.setName(name);
techniqueDef.getShaderGenerationInfo().getUnusedNodes().add(name);
readShaderNode(statement.getContents());
nodes.put(name, shaderNode);
techniqueDef.getShaderNodes().add(shaderNode);
} else {
throw new MatParseException("ShaderNode " + name + " is already defined", statement);
}
} else {
throw new MatParseException("ShaderNode", split[0], statement);
}
}
}
use of com.jme3.util.blockparser.Statement in project jmonkeyengine by jMonkeyEngine.
the class ShaderNodeLoaderDelegate method readShaderNodeDefinition.
/**
* effectively reads the ShaderNodesDefinitions block
*
* @param statements the list of statements to parse
* @param key the ShaderNodeDefinitionKey
* @throws IOException
*/
protected void readShaderNodeDefinition(List<Statement> statements, ShaderNodeDefinitionKey key) throws IOException {
boolean isLoadDoc = key instanceof ShaderNodeDefinitionKey && ((ShaderNodeDefinitionKey) key).isLoadDocumentation();
for (Statement statement : statements) {
String[] split = statement.getLine().split("[ \\{]");
String line = statement.getLine();
if (line.startsWith("Type")) {
String type = line.substring(line.lastIndexOf(':') + 1).trim();
shaderNodeDefinition.setType(Shader.ShaderType.valueOf(type));
} else if (line.startsWith("Shader ")) {
readShaderStatement(statement);
shaderNodeDefinition.getShadersLanguage().add(shaderLanguage);
shaderNodeDefinition.getShadersPath().add(shaderName);
} else if (line.startsWith("Documentation")) {
if (isLoadDoc) {
String doc = "";
for (Statement statement1 : statement.getContents()) {
doc += "\n" + statement1.getLine();
}
shaderNodeDefinition.setDocumentation(doc);
}
} else if (line.startsWith("Input")) {
varNames = "";
for (Statement statement1 : statement.getContents()) {
shaderNodeDefinition.getInputs().add(readVariable(statement1));
}
} else if (line.startsWith("Output")) {
varNames = "";
for (Statement statement1 : statement.getContents()) {
if (statement1.getLine().trim().equals("None")) {
shaderNodeDefinition.setNoOutput(true);
} else {
shaderNodeDefinition.getOutputs().add(readVariable(statement1));
}
}
} else {
throw new MatParseException("one of Type, Shader, Documentation, Input, Output", split[0], statement);
}
}
}
Aggregations