Exemplo n.º 1
0
  private List<TextureOptionValue> parseTextureOptions(final List<String> values) {
    final List<TextureOptionValue> matchList = new ArrayList<TextureOptionValue>();

    if (values.isEmpty() || values.size() == 1) {
      return matchList;
    }

    // Loop through all but the last value, the last one is going to be the path.
    for (int i = 0; i < values.size() - 1; i++) {
      final String value = values.get(i);
      final TextureOption textureOption = TextureOption.getTextureOption(value);

      if (textureOption == null
          && !value.contains("\\")
          && !value.contains("/")
          && !values.get(0).equals("Flip")
          && !values.get(0).equals("Repeat")) {
        logger.log(
            Level.WARNING,
            "Unknown texture option \"{0}\" encountered for \"{1}\" in material \"{2}\"",
            new Object[] {value, key, material.getKey().getName()});
      } else if (textureOption != null) {
        final String option = textureOption.getOptionValue(value);
        matchList.add(new TextureOptionValue(textureOption, option));
      }
    }

    return matchList;
  }
Exemplo n.º 2
0
  private List<String> tokenizeTextureValue(final String value) {
    final List<String> matchList = new ArrayList<String>();
    final Pattern regex = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'");
    final Matcher regexMatcher = regex.matcher(value.trim());

    while (regexMatcher.find()) {
      if (regexMatcher.group(1) != null) {
        matchList.add(regexMatcher.group(1));
      } else if (regexMatcher.group(2) != null) {
        matchList.add(regexMatcher.group(2));
      } else {
        matchList.add(regexMatcher.group());
      }
    }

    return matchList;
  }
Exemplo n.º 3
0
  private void readTechnique(Statement techStat) throws IOException {
    isUseNodes = false;
    String[] split = techStat.getLine().split(whitespacePattern);

    String name;
    if (split.length == 1) {
      name = TechniqueDef.DEFAULT_TECHNIQUE_NAME;
    } else if (split.length == 2) {
      name = split[1];
    } else {
      throw new IOException("Technique statement syntax incorrect");
    }

    String techniqueUniqueName = materialDef.getAssetName() + "@" + name;
    technique = new TechniqueDef(name, techniqueUniqueName.hashCode());

    for (Statement statement : techStat.getContents()) {
      readTechniqueStatement(statement);
    }

    technique.setShaderPrologue(createShaderPrologue(presetDefines));

    switch (technique.getLightMode()) {
      case Disable:
        technique.setLogic(new DefaultTechniqueDefLogic(technique));
        break;
      case MultiPass:
        technique.setLogic(new MultiPassLightingLogic(technique));
        break;
      case SinglePass:
        technique.setLogic(new SinglePassLightingLogic(technique));
        break;
      case StaticPass:
        technique.setLogic(new StaticPassLightingLogic(technique));
        break;
      case SinglePassAndImageBased:
        technique.setLogic(new SinglePassAndImageBasedLightingLogic(technique));
        break;
      default:
        throw new UnsupportedOperationException();
    }

    List<TechniqueDef> techniqueDefs = new ArrayList<>();

    if (isUseNodes) {
      nodesLoaderDelegate.computeConditions();

      // used for caching later, the shader here is not a file.

      // KIRILL 9/19/2015
      // Not sure if this is needed anymore, since shader caching
      // is now done by TechniqueDef.
      technique.setShaderFile(
          technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100");
      techniqueDefs.add(technique);
    } else if (shaderNames.containsKey(Shader.ShaderType.Vertex)
        && shaderNames.containsKey(Shader.ShaderType.Fragment)) {
      if (shaderLanguages.size() > 1) {
        for (int i = 1; i < shaderLanguages.size(); i++) {
          TechniqueDef td = null;
          try {
            td = (TechniqueDef) technique.clone();
          } catch (CloneNotSupportedException e) {
            e.printStackTrace();
          }
          td.setShaderFile(shaderNames, shaderLanguages.get(i));
          techniqueDefs.add(td);
        }
      }
      technique.setShaderFile(shaderNames, shaderLanguages.get(0));
      techniqueDefs.add(technique);

    } else {
      technique = null;
      shaderLanguages.clear();
      shaderNames.clear();
      presetDefines.clear();
      langSize = 0;
      logger.log(Level.WARNING, "Fixed function technique was ignored");
      logger.log(
          Level.WARNING,
          "Fixed function technique ''{0}'' was ignored for material {1}",
          new Object[] {name, key});
      return;
    }

    for (TechniqueDef techniqueDef : techniqueDefs) {
      materialDef.addTechniqueDef(techniqueDef);
    }

    technique = null;
    langSize = 0;
    shaderLanguages.clear();
    shaderNames.clear();
    presetDefines.clear();
  }