forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-material.js
More file actions
77 lines (66 loc) · 2.49 KB
/
Copy pathbasic-material.js
File metadata and controls
77 lines (66 loc) · 2.49 KB
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
pc.extend(pc, function () {
/**
* @name pc.BasicMaterial
* @class A Basic material is for rendering unlit geometry, either using a constant color or a
* color map modulated with a color.
* @property {pc.Color} color The flat color of the material (RGBA, where each component is 0 to 1).
* @property {pc.Texture} colorMap The color map of the material. If specified, the color map is
* modulated by the color property.
* @example
* // Create a new Basic material
* var material = new pc.BasicMaterial();
*
* // Set the material to have a texture map that is multiplied by a red color
* material.color.set(1, 0, 0);
* material.colorMap = diffuseMap;
*
* // Notify the material that it has been modified
* material.update();
*
* @extends pc.Material
*/
var BasicMaterial = function () {
this.color = new pc.Color(1, 1, 1, 1);
this.colorMap = null;
this.vertexColors = false;
this.update();
};
BasicMaterial = pc.inherits(BasicMaterial, pc.Material);
pc.extend(BasicMaterial.prototype, {
/**
* @function
* @name pc.BasicMaterial#clone
* @description Duplicates a Basic material. All properties are duplicated except textures
* where only the references are copied.
* @returns {pc.BasicMaterial} A cloned Basic material.
*/
clone: function () {
var clone = new pc.BasicMaterial();
pc.Material.prototype._cloneInternal.call(this, clone);
clone.color.copy(this.color);
clone.colorMap = this.colorMap;
clone.vertexColors = this.vertexColors;
clone.update();
return clone;
},
update: function () {
this.clearParameters();
this.setParameter('uColor', this.color.data);
if (this.colorMap) {
this.setParameter('texture_diffuseMap', this.colorMap);
}
},
updateShader: function (device) {
var options = {
skin: !!this.meshInstances[0].skinInstance,
vertexColors: this.vertexColors,
diffuseMap: this.colorMap
};
var library = device.getProgramLibrary();
this.shader = library.getProgram('basic', options);
}
});
return {
BasicMaterial: BasicMaterial
};
}());