/**
   * find the definiton from this statement (loads it if necessary)
   *
   * @param statement the statement being read
   * @return the definition
   * @throws IOException
   */
  public ShaderNodeDefinition findDefinition(Statement statement) throws IOException {
    String defLine[] = statement.getLine().split(":");
    String defName = defLine[1].trim();

    ShaderNodeDefinition def = getNodeDefinitions().get(defName);
    if (def == null) {
      if (defLine.length == 3) {
        List<ShaderNodeDefinition> defs = null;
        try {
          defs = assetManager.loadAsset(new ShaderNodeDefinitionKey(defLine[2].trim()));
        } catch (AssetNotFoundException e) {
          throw new MatParseException("Couldn't find " + defLine[2].trim(), statement, e);
        }

        for (ShaderNodeDefinition definition : defs) {
          definition.setPath(defLine[2].trim());
          if (defName.equals(definition.getName())) {
            def = definition;
          }
          if (!(getNodeDefinitions().containsKey(definition.getName()))) {
            getNodeDefinitions().put(definition.getName(), definition);
          }
        }
      }
      if (def == null) {
        throw new MatParseException(
            defName + " is not a declared as Shader Node Definition", statement);
      }
    }
    return def;
  }
Ejemplo n.º 2
0
 public Material(AssetManager contentMan, String defName) {
   this((MaterialDef) contentMan.loadAsset(new AssetKey(defName)));
 }
Ejemplo n.º 3
0
  private void loadFromRoot(List<Statement> roots) throws IOException {
    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 IOException("In multiroot material, expected first statement to be 'Exception'");
      }
    } else if (roots.size() != 1) {
      throw new IOException("Too many roots in J3M/J3MD file");
    }

    boolean extending = false;
    Statement materialStat = roots.get(0);
    String materialName = materialStat.getLine();
    if (materialName.startsWith("MaterialDef")) {
      materialName = materialName.substring("MaterialDef ".length()).trim();
      extending = false;
    } else if (materialName.startsWith("Material")) {
      materialName = materialName.substring("Material ".length()).trim();
      extending = true;
    } else {
      throw new IOException("Specified file is not a Material file");
    }

    String[] split = materialName.split(":", 2);

    if (materialName.equals("")) {
      throw new MatParseException("Material name cannot be empty", materialStat);
    }

    if (split.length == 2) {
      if (!extending) {
        throw new MatParseException("Must use 'Material' when extending.", materialStat);
      }

      String extendedMat = split[1].trim();

      MaterialDef def = (MaterialDef) assetManager.loadAsset(new AssetKey(extendedMat));
      if (def == null) {
        throw new MatParseException(
            "Extended material " + extendedMat + " cannot be found.", materialStat);
      }

      material = new Material(def);
      material.setKey(key);
      material.setName(split[0].trim());
      //            material.setAssetName(fileName);
    } else if (split.length == 1) {
      if (extending) {
        throw new MatParseException("Expected ':', got '{'", materialStat);
      }
      materialDef = new MaterialDef(assetManager, materialName);
      // NOTE: pass file name for defs so they can be loaded later
      materialDef.setAssetName(key.getName());
    } else {
      throw new MatParseException("Cannot use colon in material name/path", materialStat);
    }

    for (Statement statement : materialStat.getContents()) {
      split = statement.getLine().split("[ \\{]");
      String statType = split[0];
      if (extending) {
        if (statType.equals("MaterialParameters")) {
          readExtendingMaterialParams(statement.getContents());
        } else if (statType.equals("AdditionalRenderState")) {
          readAdditionalRenderState(statement.getContents());
        } else if (statType.equals("Transparent")) {
          readTransparentStatement(statement.getLine());
        }
      } else {
        if (statType.equals("Technique")) {
          readTechnique(statement);
        } else if (statType.equals("MaterialParameters")) {
          readMaterialParams(statement.getContents());
        } else {
          throw new MatParseException(
              "Expected material statement, got '" + statType + "'", statement);
        }
      }
    }
  }
Ejemplo n.º 4
0
 public static void main(String[] args) {
   AssetManager assetManager = JmeSystem.newAssetManager();
   assetManager.registerLocator("/", ClasspathLocator.class);
   assetManager.registerLoader(TextLoader.class, "fnt");
   System.out.println(assetManager.loadAsset("Interface/Fonts/Console.fnt"));
 }