Beispiel #1
0
  /**
   * Clear a parameter from this material. The parameter must exist
   *
   * @param name the name of the parameter to clear
   */
  public void clearParam(String name) {
    checkSetParam(null, name);
    MatParam matParam = getParam(name);
    if (matParam == null) {
      return;
    }

    paramValues.remove(name);
    if (matParam instanceof MatParamTexture) {
      int texUnit = ((MatParamTexture) matParam).getUnit();
      nextTexUnit--;
      for (MatParam param : paramValues.values()) {
        if (param instanceof MatParamTexture) {
          MatParamTexture texParam = (MatParamTexture) param;
          if (texParam.getUnit() > texUnit) {
            texParam.setUnit(texParam.getUnit() - 1);
          }
        }
      }
      sortingId = -1;
    }
    if (technique != null) {
      technique.notifyParamChanged(name, null, null);
    }
  }
Beispiel #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);
      }
    }
  }
Beispiel #3
0
  /**
   * Set a texture parameter.
   *
   * @param name The name of the parameter
   * @param type The variable type {@link VarType}
   * @param value The texture value of the parameter.
   * @throws IllegalArgumentException is value is null
   */
  public void setTextureParam(String name, VarType type, Texture value) {
    if (value == null) {
      throw new IllegalArgumentException();
    }

    checkSetParam(type, name);
    MatParamTexture val = getTextureParam(name);
    if (val == null) {
      paramValues.put(name, new MatParamTexture(type, name, value, nextTexUnit++));
    } else {
      val.setTextureValue(value);
    }

    if (technique != null) {
      technique.notifyParamChanged(name, type, nextTexUnit - 1);
    }

    // need to recompute sort ID
    sortingId = -1;
  }