예제 #1
0
  // <TYPE> <LANG> : <SOURCE>
  private void readShaderStatement(String statement) throws IOException {
    String[] split = statement.split(":");
    if (split.length != 2) {
      throw new IOException("Shader statement syntax incorrect" + statement);
    }
    String[] typeAndLang = split[0].split(whitespacePattern);

    for (Shader.ShaderType shaderType : Shader.ShaderType.values()) {
      if (typeAndLang[0].equals(shaderType.toString() + "Shader")) {

        readShaderDefinition(
            shaderType, split[1].trim(), Arrays.copyOfRange(typeAndLang, 1, typeAndLang.length));
      }
    }
  }
  /**
   * effectiveliy 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);
      }
    }
  }