UNPKG

4 kBJavaScriptView Raw
1import { Material } from './Material.js';
2import { MultiplyOperation } from '../constants.js';
3import { Vector2 } from '../math/Vector2.js';
4import { Color } from '../math/Color.js';
5
6/**
7 * @author mrdoob / http://mrdoob.com/
8 * @author alteredq / http://alteredqualia.com/
9 *
10 * parameters = {
11 * color: <hex>,
12 * specular: <hex>,
13 * shininess: <float>,
14 * opacity: <float>,
15 *
16 * map: new THREE.Texture( <Image> ),
17 *
18 * lightMap: new THREE.Texture( <Image> ),
19 * lightMapIntensity: <float>
20 *
21 * aoMap: new THREE.Texture( <Image> ),
22 * aoMapIntensity: <float>
23 *
24 * emissive: <hex>,
25 * emissiveIntensity: <float>
26 * emissiveMap: new THREE.Texture( <Image> ),
27 *
28 * bumpMap: new THREE.Texture( <Image> ),
29 * bumpScale: <float>,
30 *
31 * normalMap: new THREE.Texture( <Image> ),
32 * normalScale: <Vector2>,
33 *
34 * displacementMap: new THREE.Texture( <Image> ),
35 * displacementScale: <float>,
36 * displacementBias: <float>,
37 *
38 * specularMap: new THREE.Texture( <Image> ),
39 *
40 * alphaMap: new THREE.Texture( <Image> ),
41 *
42 * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
43 * combine: THREE.Multiply,
44 * reflectivity: <float>,
45 * refractionRatio: <float>,
46 *
47 * wireframe: <boolean>,
48 * wireframeLinewidth: <float>,
49 *
50 * skinning: <bool>,
51 * morphTargets: <bool>,
52 * morphNormals: <bool>
53 * }
54 */
55
56function MeshPhongMaterial( parameters ) {
57
58 Material.call( this );
59
60 this.type = 'MeshPhongMaterial';
61
62 this.color = new Color( 0xffffff ); // diffuse
63 this.specular = new Color( 0x111111 );
64 this.shininess = 30;
65
66 this.map = null;
67
68 this.lightMap = null;
69 this.lightMapIntensity = 1.0;
70
71 this.aoMap = null;
72 this.aoMapIntensity = 1.0;
73
74 this.emissive = new Color( 0x000000 );
75 this.emissiveIntensity = 1.0;
76 this.emissiveMap = null;
77
78 this.bumpMap = null;
79 this.bumpScale = 1;
80
81 this.normalMap = null;
82 this.normalScale = new Vector2( 1, 1 );
83
84 this.displacementMap = null;
85 this.displacementScale = 1;
86 this.displacementBias = 0;
87
88 this.specularMap = null;
89
90 this.alphaMap = null;
91
92 this.envMap = null;
93 this.combine = MultiplyOperation;
94 this.reflectivity = 1;
95 this.refractionRatio = 0.98;
96
97 this.wireframe = false;
98 this.wireframeLinewidth = 1;
99 this.wireframeLinecap = 'round';
100 this.wireframeLinejoin = 'round';
101
102 this.skinning = false;
103 this.morphTargets = false;
104 this.morphNormals = false;
105
106 this.setValues( parameters );
107
108}
109
110MeshPhongMaterial.prototype = Object.create( Material.prototype );
111MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
112
113MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
114
115MeshPhongMaterial.prototype.copy = function ( source ) {
116
117 Material.prototype.copy.call( this, source );
118
119 this.color.copy( source.color );
120 this.specular.copy( source.specular );
121 this.shininess = source.shininess;
122
123 this.map = source.map;
124
125 this.lightMap = source.lightMap;
126 this.lightMapIntensity = source.lightMapIntensity;
127
128 this.aoMap = source.aoMap;
129 this.aoMapIntensity = source.aoMapIntensity;
130
131 this.emissive.copy( source.emissive );
132 this.emissiveMap = source.emissiveMap;
133 this.emissiveIntensity = source.emissiveIntensity;
134
135 this.bumpMap = source.bumpMap;
136 this.bumpScale = source.bumpScale;
137
138 this.normalMap = source.normalMap;
139 this.normalScale.copy( source.normalScale );
140
141 this.displacementMap = source.displacementMap;
142 this.displacementScale = source.displacementScale;
143 this.displacementBias = source.displacementBias;
144
145 this.specularMap = source.specularMap;
146
147 this.alphaMap = source.alphaMap;
148
149 this.envMap = source.envMap;
150 this.combine = source.combine;
151 this.reflectivity = source.reflectivity;
152 this.refractionRatio = source.refractionRatio;
153
154 this.wireframe = source.wireframe;
155 this.wireframeLinewidth = source.wireframeLinewidth;
156 this.wireframeLinecap = source.wireframeLinecap;
157 this.wireframeLinejoin = source.wireframeLinejoin;
158
159 this.skinning = source.skinning;
160 this.morphTargets = source.morphTargets;
161 this.morphNormals = source.morphNormals;
162
163 return this;
164
165};
166
167
168export { MeshPhongMaterial };