示例#1
0
  /**
   * Pass a texture to the material shader.
   *
   * @param name the name of the texture defined in the material definition (j3md) (for example
   *     Texture for Lighting.j3md)
   * @param value the Texture object previously loaded by the asset manager
   */
  public void setTexture(String name, Texture value) {
    if (value == null) {
      // clear it
      clearParam(name);
      return;
    }

    VarType paramType = null;
    switch (value.getType()) {
      case TwoDimensional:
        paramType = VarType.Texture2D;
        break;
      case TwoDimensionalArray:
        paramType = VarType.TextureArray;
        break;
      case ThreeDimensional:
        paramType = VarType.Texture3D;
        break;
      case CubeMap:
        paramType = VarType.TextureCubeMap;
        break;
      default:
        throw new UnsupportedOperationException("Unknown texture type: " + value.getType());
    }

    setTextureParam(name, paramType, value);
  }
示例#2
0
  /**
   * Pass a parameter to the material shader.
   *
   * @param name the name of the parameter defined in the material definition (j3md)
   * @param type the type of the parameter {@link VarType}
   * @param value the value of the parameter
   */
  public void setParam(String name, VarType type, Object value) {
    checkSetParam(type, name);

    if (type.isTextureType()) {
      setTextureParam(name, type, (Texture) value);
    } else {
      MatParam val = getParam(name);
      if (val == null) {
        MatParam paramDef = def.getMaterialParam(name);
        paramValues.put(name, new MatParam(type, name, value, paramDef.getFixedFuncBinding()));
      } else {
        val.setValue(value);
      }

      if (technique != null) {
        technique.notifyParamChanged(name, type, value);
      }
    }
  }
  private void readValueParam(String statement) throws IOException {
    // Use limit=1 incase filename contains colons
    String[] split = statement.split(":", 2);
    if (split.length != 2) {
      throw new IOException("Value parameter statement syntax incorrect");
    }
    String name = split[0].trim();

    // parse value
    MatParam p = material.getMaterialDef().getMaterialParam(name);
    if (p == null) {
      throw new IOException("The material parameter: " + name + " is undefined.");
    }

    Object valueObj = readValue(p.getVarType(), split[1]);
    if (p.getVarType().isTextureType()) {
      material.setTextureParam(name, p.getVarType(), (Texture) valueObj);
    } else {
      material.setParam(name, p.getVarType(), valueObj);
    }
  }