Skip to content

Commit 34e9380

Browse files
committed
rename TextureSlot -> Map - better name.
1 parent 0375a7b commit 34e9380

File tree

7 files changed

+122
-122
lines changed

7 files changed

+122
-122
lines changed

examples/webgl_materials_slots.html

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<body>
3030

3131
<div id="container"></div>
32-
<div id="info"><a href="http://threejs.org" target="_blank">threejs</a> - Per-Map Per-Material UV Channel, UV Repeat/Offset, and Texel Scale/Offset/Invert<br/>via THREE.TextureSlot by <a href="http://clara.io/" target="_blank">Ben Houston</a>.</div>
32+
<div id="info"><a href="http://threejs.org" target="_blank">threejs</a> - Per-Map Per-Material UV Channel, UV Repeat/Offset, and Texel Scale/Offset/Invert<br/>via THREE.Map by <a href="http://clara.io/" target="_blank">Ben Houston</a>.</div>
3333

3434
<script src="../build/three.min.js"></script>
3535
<script src="../examples/js/controls/OrbitControls.js"></script>
@@ -203,37 +203,37 @@
203203

204204
params = {};
205205

206-
var slotParams = function( slotName ) {
207-
params[ slotName + 'TexelInvert'] = ( slotName === 'rough' );
208-
gui.add( params, slotName + 'TexelInvert' );
209-
if( slotName === "bump" ) {
210-
params[ slotName + 'TexelOffset'] = 0;
211-
params[ slotName + 'TexelScale'] = 0.05;
212-
gui.add( params, slotName + 'TexelScale', -0.1, 0.1 );
206+
var mapParams = function( mapName ) {
207+
params[ mapName + 'TexelInvert'] = ( mapName === 'rough' );
208+
gui.add( params, mapName + 'TexelInvert' );
209+
if( mapName === "bump" ) {
210+
params[ mapName + 'TexelOffset'] = 0;
211+
params[ mapName + 'TexelScale'] = 0.05;
212+
gui.add( params, mapName + 'TexelScale', -0.1, 0.1 );
213213
}
214214
else {
215-
params[ slotName + 'TexelOffset'] = ( slotName === 'rough' ) ? 0.4 : 0;
216-
if( slotName === 'rough' ) params[ slotName + 'TexelScale'] = 0.6;
217-
else if( slotName === 'emissive' ) params[ slotName + 'TexelScale'] = 0.3;
218-
else params[ slotName + 'TexelScale'] = 1.0;
219-
if( slotName !== "normal" ) {
220-
gui.add( params, slotName + 'TexelOffset', -1, 1 );
221-
gui.add( params, slotName + 'TexelScale', -1, 1 );
215+
params[ mapName + 'TexelOffset'] = ( mapName === 'rough' ) ? 0.4 : 0;
216+
if( mapName === 'rough' ) params[ mapName + 'TexelScale'] = 0.6;
217+
else if( mapName === 'emissive' ) params[ mapName + 'TexelScale'] = 0.3;
218+
else params[ mapName + 'TexelScale'] = 1.0;
219+
if( mapName !== "normal" ) {
220+
gui.add( params, mapName + 'TexelOffset', -1, 1 );
221+
gui.add( params, mapName + 'TexelScale', -1, 1 );
222222
}
223223
}
224-
params[ slotName + 'UVOffsetX'] = 0;
225-
gui.add( params, slotName + 'UVOffsetX', 0, 1 );
226-
params[ slotName + 'UVOffsetY'] = 0;
227-
gui.add( params, slotName + 'UVOffsetY', 0, 1 );
228-
params[ slotName + 'UVRepeatX'] = 1;
229-
gui.add( params, slotName + 'UVRepeatX', 0.01, 5 );
230-
params[ slotName + 'UVRepeatY'] = 1;
231-
gui.add( params, slotName + 'UVRepeatY', 0.01, 5 );
224+
params[ mapName + 'UVOffsetX'] = 0;
225+
gui.add( params, mapName + 'UVOffsetX', 0, 1 );
226+
params[ mapName + 'UVOffsetY'] = 0;
227+
gui.add( params, mapName + 'UVOffsetY', 0, 1 );
228+
params[ mapName + 'UVRepeatX'] = 1;
229+
gui.add( params, mapName + 'UVRepeatX', 0.01, 5 );
230+
params[ mapName + 'UVRepeatY'] = 1;
231+
gui.add( params, mapName + 'UVRepeatY', 0.01, 5 );
232232
};
233-
slotParams( "map" );
234-
slotParams( "normal" );
235-
slotParams( "rough" );
236-
slotParams( "emissive" );
233+
mapParams( "map" );
234+
mapParams( "normal" );
235+
mapParams( "rough" );
236+
mapParams( "emissive" );
237237
gui.open();
238238

239239
}
@@ -266,16 +266,16 @@
266266

267267
if ( standardMaterial !== undefined ) {
268268

269-
var setSlot = function( slot, name ) {
270-
slot.texelTransform = true;
271-
slot.texelScale = params[ name + 'TexelScale'];
272-
slot.texelOffset = params[ name + 'TexelOffset'];
273-
slot.texelInvert = params[ name + 'TexelInvert'];
274-
slot.uvTransform = true;
275-
slot.uvRepeat.x = params[ name + 'UVRepeatX'];
276-
slot.uvRepeat.y = params[ name + 'UVRepeatY'];
277-
slot.uvOffset.x = params[ name + 'UVOffsetX'];
278-
slot.uvOffset.y = params[ name + 'UVOffsetY'];
269+
var setSlot = function( map, name ) {
270+
map.texelTransform = true;
271+
map.texelScale = params[ name + 'TexelScale'];
272+
map.texelOffset = params[ name + 'TexelOffset'];
273+
map.texelInvert = params[ name + 'TexelInvert'];
274+
map.uvTransform = true;
275+
map.uvRepeat.x = params[ name + 'UVRepeatX'];
276+
map.uvRepeat.y = params[ name + 'UVRepeatY'];
277+
map.uvOffset.x = params[ name + 'UVOffsetX'];
278+
map.uvOffset.y = params[ name + 'UVOffsetY'];
279279
}
280280
setSlot( standardMaterial.mapSlot, "map" );
281281
setSlot( standardMaterial.normalMapSlot, "normal" );

src/materials/TextureSlot.js renamed to src/materials/Map.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
*/
55

6-
THREE.TextureSlot = function ( name, uvChannel, uvTransform, texelTransform ) {
6+
THREE.Map = function ( name, uvChannel, uvTransform, texelTransform ) {
77

88
this.name = name || "unnamed";
99

@@ -14,7 +14,7 @@ THREE.TextureSlot = function ( name, uvChannel, uvTransform, texelTransform ) {
1414
this.uvTransform = uvTransform || false;
1515
this.uvOffset = new THREE.Vector2( 0, 0 );
1616
this.uvRepeat = new THREE.Vector2( 1.0, 1.0 );
17-
//this.uvRotation = 0;
17+
//this.uvRotation = 0; - not implemented because offset/repeat fix in a vec4 uniform, rotation doesn't.
1818

1919
this.texelTransform = uvTransform || false;
2020
this.texelScale = 1.0;
@@ -23,9 +23,9 @@ THREE.TextureSlot = function ( name, uvChannel, uvTransform, texelTransform ) {
2323

2424
};
2525

26-
THREE.TextureSlot.prototype = {
26+
THREE.Map.prototype = {
2727

28-
constructor: THREE.TextureSlot,
28+
constructor: THREE.Map,
2929

3030
copy: function ( source ) {
3131

@@ -66,6 +66,6 @@ THREE.TextureSlot.prototype = {
6666

6767
};
6868

69-
THREE.TextureSlot.SupportedSlotNames = [
69+
THREE.Map.SupportedMapNames = [
7070
'map', 'lightMap', 'aoMap', 'emissiveMap', 'specularMap', 'bumpMap', 'normalMap', 'roughnessMap', 'metalnessMap', 'alphaMap', 'displacementMap'
7171
];

src/materials/MeshStandardMaterial.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,44 +67,44 @@ THREE.MeshStandardMaterial = function ( parameters ) {
6767

6868
this.color = new THREE.Color( 0xffffff ); // diffuse
6969
//this.map = null;
70-
this.mapSlot = new THREE.TextureSlot( "map", 0, false, false );
70+
this.mapSlot = new THREE.Map( "map", 0, false, false );
7171

7272
this.roughness = 0.5;
7373
//this.roughnessMap = null;
74-
this.roughnessMapSlot = new THREE.TextureSlot( "roughnessMap", 0, false, false );
74+
this.roughnessMapSlot = new THREE.Map( "roughnessMap", 0, false, false );
7575

7676
this.metalness = 0.5;
7777
//this.metalnessMap = null;
78-
this.metalnessMapSlot = new THREE.TextureSlot( "metalnessMap", 0, false, false );
78+
this.metalnessMapSlot = new THREE.Map( "metalnessMap", 0, false, false );
7979

8080
this.emissive = new THREE.Color( 0x000000 );
8181
this.emissiveIntensity = 1.0;
8282
//this.emissiveMap = null;
83-
this.emissiveMapSlot = new THREE.TextureSlot( "emissiveMap", 0, false, false );
83+
this.emissiveMapSlot = new THREE.Map( "emissiveMap", 0, false, false );
8484

8585
//this.bumpMap = null;
8686
//this.bumpScale = 1;
87-
this.bumpMapSlot = new THREE.TextureSlot( "bumpMap", 0, false, true );
87+
this.bumpMapSlot = new THREE.Map( "bumpMap", 0, false, true );
8888

8989
//this.normalMap = null;
9090
this.normalScale = new THREE.Vector2( 1, 1 );
91-
this.normalMapSlot = new THREE.TextureSlot( "normalMap", 0, false, false );
91+
this.normalMapSlot = new THREE.Map( "normalMap", 0, false, false );
9292

9393
//this.displacementMap = null;
9494
//this.displacementScale = 1;
9595
//this.displacementBias = 0;
96-
this.displacementMapSlot = new THREE.TextureSlot( "displacementMap", 0, false, true );
96+
this.displacementMapSlot = new THREE.Map( "displacementMap", 0, false, true );
9797

9898
//this.lightMap = null;
9999
//this.lightMapIntensity = 1.0;
100-
this.lightMapSlot = new THREE.TextureSlot( "lightMap", 1, false, true );
100+
this.lightMapSlot = new THREE.Map( "lightMap", 1, false, true );
101101

102102
//this.aoMap = null;
103103
this.aoMapIntensity = 1.0;
104-
this.aoMapSlot = new THREE.TextureSlot( "aoMap", 1, false, true );
104+
this.aoMapSlot = new THREE.Map( "aoMap", 1, false, true );
105105

106106
//this.alphaMap = null;
107-
this.alphaMapSlot = new THREE.TextureSlot( "alphaMap", 0, false, false );
107+
this.alphaMapSlot = new THREE.Map( "alphaMap", 0, false, false );
108108

109109
this.envMap = null;
110110
this.envMapIntensity = 1.0;

src/renderers/WebGLRenderer.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,28 +1906,28 @@ THREE.WebGLRenderer = function ( parameters ) {
19061906

19071907
}
19081908

1909-
var supportedSlots = THREE.TextureSlot.SupportedSlotNames;
1910-
for( var i = 0; i < supportedSlots.length; i ++ ) {
1911-
var slotName = supportedSlots[i];
1912-
var slot = material[ slotName + 'Slot' ];
1913-
if( slot ) {
1914-
uniforms[slotName].value = slot.texture;
1915-
if( slot.uvTransform ) {
1916-
uniforms[slotName +"UVTransformParams"].value.set(
1917-
slot.uvRepeat.x,
1918-
slot.uvRepeat.y,
1919-
slot.uvOffset.x,
1920-
slot.uvOffset.y );
1909+
var supportedMapNames = THREE.Map.SupportedMapNames;
1910+
for( var i = 0; i < supportedMapNames.length; i ++ ) {
1911+
var mapName = supportedMapNames[i];
1912+
var map = material[ mapName + 'Slot' ];
1913+
if( map ) {
1914+
uniforms[mapName].value = map.texture;
1915+
if( map.uvTransform ) {
1916+
uniforms[mapName +"UVTransformParams"].value.set(
1917+
map.uvRepeat.x,
1918+
map.uvRepeat.y,
1919+
map.uvOffset.x,
1920+
map.uvOffset.y );
19211921
}
1922-
if( slot.texelTransform ) {
1923-
var texelTransform = slot.getFlattenedTexelTransform();
1924-
uniforms[slotName +"TexelTransformParams"].value.set(
1922+
if( map.texelTransform ) {
1923+
var texelTransform = map.getFlattenedTexelTransform();
1924+
uniforms[mapName +"TexelTransformParams"].value.set(
19251925
texelTransform.texelScale,
19261926
texelTransform.texelOffset );
19271927
}
19281928
}
1929-
else if( material[ slotName ] ) {
1930-
uniforms[slotName].value = material[slotName];
1929+
else if( material[ mapName ] ) {
1930+
uniforms[mapName].value = material[mapName];
19311931
}
19321932
}
19331933
//uniforms.map.value = material.map;
@@ -2901,7 +2901,7 @@ THREE.WebGLRenderer = function ( parameters ) {
29012901

29022902
}
29032903

2904-
function uploadTexture( textureProperties, texture, slot ) {
2904+
function uploadTexture( textureProperties, texture, map ) {
29052905

29062906
if ( textureProperties.__webglInit === undefined ) {
29072907

@@ -2915,7 +2915,7 @@ THREE.WebGLRenderer = function ( parameters ) {
29152915

29162916
}
29172917

2918-
state.activeTexture( _gl.TEXTURE0 + slot );
2918+
state.activeTexture( _gl.TEXTURE0 + map );
29192919
state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
29202920

29212921
_gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
@@ -3022,7 +3022,7 @@ THREE.WebGLRenderer = function ( parameters ) {
30223022

30233023
}
30243024

3025-
this.setTexture = function ( texture, slot ) {
3025+
this.setTexture = function ( texture, map ) {
30263026

30273027
var textureProperties = properties.get( texture );
30283028

@@ -3044,13 +3044,13 @@ THREE.WebGLRenderer = function ( parameters ) {
30443044

30453045
}
30463046

3047-
uploadTexture( textureProperties, texture, slot );
3047+
uploadTexture( textureProperties, texture, map );
30483048

30493049
return;
30503050

30513051
}
30523052

3053-
state.activeTexture( _gl.TEXTURE0 + slot );
3053+
state.activeTexture( _gl.TEXTURE0 + map );
30543054
state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
30553055

30563056
};
@@ -3117,7 +3117,7 @@ THREE.WebGLRenderer = function ( parameters ) {
31173117

31183118
}
31193119

3120-
function setCubeTexture ( texture, slot ) {
3120+
function setCubeTexture ( texture, map ) {
31213121

31223122
var textureProperties = properties.get( texture );
31233123

@@ -3135,7 +3135,7 @@ THREE.WebGLRenderer = function ( parameters ) {
31353135

31363136
}
31373137

3138-
state.activeTexture( _gl.TEXTURE0 + slot );
3138+
state.activeTexture( _gl.TEXTURE0 + map );
31393139
state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
31403140

31413141
_gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
@@ -3224,7 +3224,7 @@ THREE.WebGLRenderer = function ( parameters ) {
32243224

32253225
} else {
32263226

3227-
state.activeTexture( _gl.TEXTURE0 + slot );
3227+
state.activeTexture( _gl.TEXTURE0 + map );
32283228
state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
32293229

32303230
}
@@ -3233,9 +3233,9 @@ THREE.WebGLRenderer = function ( parameters ) {
32333233

32343234
}
32353235

3236-
function setCubeTextureDynamic ( texture, slot ) {
3236+
function setCubeTextureDynamic ( texture, map ) {
32373237

3238-
state.activeTexture( _gl.TEXTURE0 + slot );
3238+
state.activeTexture( _gl.TEXTURE0 + map );
32393239
state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
32403240

32413241
}

0 commit comments

Comments
 (0)