/** * Checks if once a mapping expression is split by "=" the resulting array * have 2 elements. * * @param vars the array. * @param statement the statement. * @throws MatParseException if the array isn't correct. */ protected void checkMappingFormat(String[] vars, Statement statement) throws MatParseException { if (vars.length != 2) { throw new MatParseException("Not a valid expression should be '<varName>[.<swizzling>] = " + "<nameSpace>.<varName>[.<swizzling>][:Condition]'", statement); } }
/** * Reads a Shader statement of this form <TYPE> <LANG> : <SOURCE> * * @param statement * @throws IOException */ protected void readShaderStatement(Statement statement) throws IOException { String[] split = statement.getLine().split(":"); if (split.length != 2) { throw new MatParseException("Shader statement syntax incorrect", statement); } String[] typeAndLang = split[0].split("\\p{javaWhitespace}+"); if (typeAndLang.length != 2) { throw new MatParseException("Shader statement syntax incorrect", statement); } shaderName = split[1].trim(); shaderLanguage = typeAndLang[1]; }
throw new MatParseException("More than 3 arguments", splitVar.length + "", statement); throw new MatParseException("Duplicate variable name " + varName, statement);
throw new MatParseException("Can't find shader node definition for: ", statement); defs = assetManager.loadAsset(new ShaderNodeDefinitionKey(definitionPath)); } catch (final AssetNotFoundException e) { throw new MatParseException("Couldn't find " + definitionPath, statement, e); throw new MatParseException(definitionName + " is not a declared as Shader Node Definition", statement);
@Override public Object load(AssetInfo assetInfo) throws IOException { AssetKey k = assetInfo.getKey(); if (!(k instanceof ShaderNodeDefinitionKey)) { throw new IOException("ShaderNodeDefinition file must be loaded via ShaderNodeDefinitionKey"); } ShaderNodeDefinitionKey key = (ShaderNodeDefinitionKey) k; loaderDelegate = new ShaderNodeLoaderDelegate(); InputStream in = assetInfo.openStream(); List<Statement> roots = BlockLanguageParser.parse(in); if (roots.size() == 2) { Statement exception = roots.get(0); String line = exception.getLine(); if (line.startsWith("Exception")) { throw new AssetLoadException(line.substring("Exception ".length())); } else { throw new MatParseException("In multiroot shader node definition, expected first statement to be 'Exception'", exception); } } else if (roots.size() != 1) { throw new MatParseException("Too many roots in J3SN file", roots.get(0)); } return loaderDelegate.readNodesDefinitions(roots.get(0).getContents(), key); } }
throw new MatParseException("Material name cannot be empty", materialStat); throw new MatParseException("Must use 'Material' when extending.", materialStat); throw new MatParseException("Extended material " + extendedMat + " cannot be found.", materialStat); throw new MatParseException("Expected ':', got '{'", materialStat); throw new MatParseException("Cannot use colon in material name/path", materialStat); readMaterialParams(statement.getContents()); }else{ throw new MatParseException("Expected material statement, got '"+statType+"'", statement);
techniqueDef.getShaderNodes().add(shaderNode); } else { throw new MatParseException("ShaderNode " + name + " is already defined", statement); throw new MatParseException("ShaderNode", split[0], statement);
shaderNodeDefinition.getInputs().add(readVariable(statement1)); } catch (RuntimeException e) { throw new MatParseException(e.getMessage(), statement1, e); throw new MatParseException(e.getMessage(), statement1, e); throw new MatParseException("one of Type, Shader, Documentation, Input, Output", split[0], statement); throw new MatParseException(e.getMessage(), statement, e);
/** * 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); shaderNodeDefinition.setPath(key.getName()); readShaderNodeDefinition(statement.getContents(), key); } } else { throw new MatParseException("ShaderNodeDefinition", split[0], statement); } } return new ArrayList<ShaderNodeDefinition>(getNodeDefinitions().values()); }
mapping = parseMapping(statement, OM_HAS_NAME_SPACE); } catch (final Exception e) { throw new MatParseException("Unexpected mapping format", statement, e); throw new MatParseException("Samplers can only be inputs", statement); storeGlobal(left, statement); } else { throw new MatParseException("Only Global nameSpace is allowed for outputMapping, got" + left.getNameSpace(), statement); throw new MatParseException(right.getName() + " is not an output variable of " + definition.getName(), statement);
renderState.setLineWidth(Float.parseFloat(split[1])); } else { throw new MatParseException(null, split[0], statement);
throw new MatParseException("ShaderNodeDefinition", split[0], statement);
technique.setNoRender(true); } else { throw new MatParseException(null, split[0], statement);
/** * Extracts and checks a condition expression. * * @param condition the condition expression. * @param statement the statement being read. * @throws MatParseException if the condition isn't valid. */ public void extractCondition(String condition, Statement statement) throws MatParseException { List<String> defines = conditionParser.extractDefines(condition); for (String string : defines) { MatParam param = findMatParam(string); if (param != null) { addDefine(param.getName(), param.getVarType()); } else { throw new MatParseException("Invalid condition, condition must match a Material Parameter named " + condition, statement); } } }
/** * check the types of a mapping, left type must match right type take the * swizzle into account * * @param mapping the mapping * @param statement1 the statement being read * @throws MatParseException */ protected void checkTypes(VariableMapping mapping, Statement statement1) throws MatParseException { if (!ShaderUtils.typesMatch(mapping)) { String ls = mapping.getLeftSwizzling().length() == 0 ? "" : "." + mapping.getLeftSwizzling(); String rs = mapping.getRightSwizzling().length() == 0 ? "" : "." + mapping.getRightSwizzling(); throw new MatParseException("Type mismatch, cannot convert " + mapping.getRightVariable().getType() + rs + " to " + mapping.getLeftVariable().getType() + ls, statement1); } if (!ShaderUtils.multiplicityMatch(mapping)) { String type1 = mapping.getLeftVariable().getType() + "[" + mapping.getLeftVariable().getMultiplicity() + "]"; String type2 = mapping.getRightVariable().getType() + "[" + mapping.getRightVariable().getMultiplicity() + "]"; throw new MatParseException("Type mismatch, cannot convert " + type1 + " to " + type2, statement1); } }
/** * Updates the material texture type of the variable mapping. * * @param statement the statement. * @param mapping the variable mapping. * @param left the left variable. * @param param the material parameter. * @throws MatParseException if the texture type isn't valid. */ private void updateMaterialTextureType(final Statement statement, final VariableMapping mapping, final ShaderNodeVariable left, final MatParam param) throws MatParseException { if (!mapping.getRightVariable().getType().contains("|")) { return; } final String type = fixSamplerType(left.getType(), mapping.getRightVariable().getType()); if (type != null) { mapping.getRightVariable().setType(type); } else { throw new MatParseException(param.getVarType().toString() + " can only be matched to one of " + param.getVarType().getGlslType().replaceAll("\\|", ",") + " found " + left.getType(), statement); } }
mapping = parseMapping(statement, IM_HAS_NAME_SPACE); } catch (final Exception e) { throw new MatParseException("Unexpected mapping format", statement, e); throw new MatParseException(left.getName() + " is not an input variable of " + definition.getName(), statement); } else if (left.getType().startsWith("sampler") && (right == null || !right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_MAT_PARAM))) { throw new MatParseException("Samplers can only be assigned to MatParams", statement); throw new MatParseException("The mapping doesn't have a right variable or a right expression.", statement); } else if (right.getNameSpace().equals(ShaderGenerator.NAME_SPACE_VERTEX_ATTRIBUTE)) { if (definition.getType() == ShaderType.Fragment) { throw new MatParseException("Cannot have an attribute as input in a fragment shader" + right.getName(), statement); throw new MatParseException("Could not find a Material Parameter named " + right.getName(), statement); throw new MatParseException("Could not find a World Parameter named " + right.getName(), statement); throw new MatParseException("Undeclared node" + right.getNameSpace() + ". Make sure this node is declared before the current node", statement); throw new MatParseException("Cannot find output variable" + right.getName() + " form ShaderNode " + node.getName(), statement);
/** * Stores a global output. * * @param var the variable to store. * @param varStatement the statement being read. * @throws MatParseException if we have duplicates of a global vertex output variable. */ public void storeGlobal(ShaderNodeVariable var, Statement varStatement) throws MatParseException { var.setShaderOutput(true); final ShaderGenerationInfo generationInfo = techniqueDef.getShaderGenerationInfo(); final ShaderNodeDefinition definition = shaderNode.getDefinition(); if (definition.getType() == ShaderType.Vertex) { ShaderNodeVariable global = generationInfo.getVertexGlobal(); if (global != null) { if (!global.getName().equals(var.getName())) { throw new MatParseException("A global output is already defined for the vertex shader: " + global.getName() + ". vertex shader can only have one global output", varStatement); } } else { generationInfo.setVertexGlobal(var); } } else if (definition.getType() == ShaderType.Fragment) { storeVariable(var, generationInfo.getFragmentGlobals()); } }
throw new MatParseException(param.getName() + " is not of Array type", statement); throw new MatParseException("Wrong multiplicity for variable" + left.getName() + ". " + multiplicity + " should be an int or a declared material parameter.", statement);
/** * check if once a mapping expression is split by "=" the resulting array * have 2 elements * * @param vars the array * @param statement the statement * @throws IOException */ protected void checkMappingFormat(String[] vars, Statement statement) throws IOException { if (vars.length != 2) { throw new MatParseException("Not a valid expression should be '<varName>[.<swizzling>] = <nameSpace>.<varName>[.<swizzling>][:Condition]'", statement); } }