15832144755
2022-01-06 7b4c8991dca9cf2a809a95e239d144697d3afb56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
 
/**
 * A model's material with modifiable parameters.  A glTF material
 * contains parameters defined by the material's technique with values
 * defined by the technique and potentially overridden by the material.
 * This class allows changing these values at runtime.
 * <p>
 * Use {@link Model#getMaterial} to create an instance.
 * </p>
 *
 * @alias ModelMaterial
 * @internalConstructor
 * @class
 *
 * @see Model#getMaterial
 */
function ModelMaterial(model, material, id) {
  this._name = material.name;
  this._id = id;
  this._uniformMap = model._uniformMaps[id];
 
  this._technique = undefined;
  this._program = undefined;
  this._values = undefined;
}
 
Object.defineProperties(ModelMaterial.prototype, {
  /**
   * The value of the <code>name</code> property of this material.
   *
   * @memberof ModelMaterial.prototype
   *
   * @type {String}
   * @readonly
   */
  name: {
    get: function () {
      return this._name;
    },
  },
 
  /**
   * The index of the material.
   *
   * @memberof ModelMaterial.prototype
   *
   * @type {String}
   * @readonly
   */
  id: {
    get: function () {
      return this._id;
    },
  },
});
 
/**
 * Assigns a value to a material parameter.  The type for <code>value</code>
 * depends on the glTF type of the parameter.  It will be a floating-point
 * number, Cartesian, or matrix.
 *
 * @param {String} name The name of the parameter.
 * @param {*} [value] The value to assign to the parameter.
 *
 * @exception {DeveloperError} name must match a parameter name in the material's technique that is targetable and not optimized out.
 *
 * @example
 * material.setValue('diffuse', new Cesium.Cartesian4(1.0, 0.0, 0.0, 1.0));  // vec4
 * material.setValue('shininess', 256.0); // scalar
 */
ModelMaterial.prototype.setValue = function (name, value) {
  //>>includeStart('debug', pragmas.debug);
  if (!defined(name)) {
    throw new DeveloperError("name is required.");
  }
  //>>includeEnd('debug');
 
  var uniformName = "u_" + name;
  var v = this._uniformMap.values[uniformName];
 
  //>>includeStart('debug', pragmas.debug);
  if (!defined(v)) {
    throw new DeveloperError(
      "name must match a parameter name in the material's technique that is targetable and not optimized out."
    );
  }
  //>>includeEnd('debug');
 
  v.value = v.clone(value, v.value);
};
 
/**
 * Returns the value of the parameter with the given <code>name</code>.  The type of the
 * returned object depends on the glTF type of the parameter.  It will be a floating-point
 * number, Cartesian, or matrix.
 *
 * @param {String} name The name of the parameter.
 * @returns {*} The value of the parameter or <code>undefined</code> if the parameter does not exist.
 */
ModelMaterial.prototype.getValue = function (name) {
  //>>includeStart('debug', pragmas.debug);
  if (!defined(name)) {
    throw new DeveloperError("name is required.");
  }
  //>>includeEnd('debug');
 
  var uniformName = "u_" + name;
  var v = this._uniformMap.values[uniformName];
 
  if (!defined(v)) {
    return undefined;
  }
 
  return v.value;
};
export default ModelMaterial;