Skip to content

Commit 46cb577

Browse files
committed
chore: BufferGeometry rename uv2 to uv1
mrdoob/three.js#25943
1 parent 40a4d33 commit 46cb577

File tree

7 files changed

+47
-72
lines changed

7 files changed

+47
-72
lines changed

src/exporters/ColladaExporter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ class ColladaExporter {
346346
}
347347

348348
// serialize lightmap uvs
349-
if ('uv2' in bufferGeometry.attributes) {
349+
if ('uv1' in bufferGeometry.attributes) {
350350
const uvName = `${meshid}-texcoord2`
351-
gnode += this.getAttribute(bufferGeometry.attributes.uv2, uvName, ['S', 'T'], 'float')
351+
gnode += this.getAttribute(bufferGeometry.attributes.uv1, uvName, ['S', 'T'], 'float')
352352
triangleInputs += `<input semantic="TEXCOORD" source="#${uvName}" offset="0" set="1" />`
353353
}
354354

src/lines/LineSegments2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function raycastWorldUnits(lineSegments, intersects) {
6767
face: null,
6868
faceIndex: i,
6969
uv: null,
70-
uv2: null,
70+
uv1: null,
7171
})
7272
}
7373
}
@@ -187,7 +187,7 @@ function raycastScreenSpace(lineSegments, camera, intersects) {
187187
face: null,
188188
faceIndex: i,
189189
uv: null,
190-
uv2: null,
190+
uv1: null,
191191
})
192192
}
193193
}

src/loaders/ColladaLoader.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ class ColladaLoader extends Loader {
18661866
const position = { array: [], stride: 0 }
18671867
const normal = { array: [], stride: 0 }
18681868
const uv = { array: [], stride: 0 }
1869-
const uv2 = { array: [], stride: 0 }
1869+
const uv1 = { array: [], stride: 0 }
18701870
const color = { array: [], stride: 0 }
18711871

18721872
const skinIndex = { array: [], stride: 4 }
@@ -1981,7 +1981,7 @@ class ColladaLoader extends Loader {
19811981
break
19821982

19831983
case 'TEXCOORD1':
1984-
buildGeometryData(primitive, sources[id], input.offset, uv2.array)
1984+
buildGeometryData(primitive, sources[id], input.offset, uv1.array)
19851985
uv.stride = sources[id].stride
19861986
break
19871987

@@ -2008,8 +2008,8 @@ class ColladaLoader extends Loader {
20082008
break
20092009

20102010
case 'TEXCOORD1':
2011-
buildGeometryData(primitive, sources[input.id], input.offset, uv2.array)
2012-
uv2.stride = sources[input.id].stride
2011+
buildGeometryData(primitive, sources[input.id], input.offset, uv1.array)
2012+
uv1.stride = sources[input.id].stride
20132013
break
20142014
}
20152015
}
@@ -2025,7 +2025,7 @@ class ColladaLoader extends Loader {
20252025
}
20262026
if (color.array.length > 0) geometry.setAttribute('color', new Float32BufferAttribute(color.array, color.stride))
20272027
if (uv.array.length > 0) geometry.setAttribute('uv', new Float32BufferAttribute(uv.array, uv.stride))
2028-
if (uv2.array.length > 0) geometry.setAttribute('uv2', new Float32BufferAttribute(uv2.array, uv2.stride))
2028+
if (uv1.array.length > 0) geometry.setAttribute('uv1', new Float32BufferAttribute(uv1.array, uv1.stride))
20292029

20302030
if (skinIndex.array.length > 0) {
20312031
geometry.setAttribute('skinIndex', new Float32BufferAttribute(skinIndex.array, skinIndex.stride))
@@ -2496,14 +2496,14 @@ class ColladaLoader extends Loader {
24962496
if (value > joint.limits.max || value < joint.limits.min) {
24972497
console.warn(
24982498
'THREE.ColladaLoader: Joint ' +
2499-
jointIndex +
2500-
' value ' +
2501-
value +
2502-
' outside of limits (min: ' +
2503-
joint.limits.min +
2504-
', max: ' +
2505-
joint.limits.max +
2506-
').',
2499+
jointIndex +
2500+
' value ' +
2501+
value +
2502+
' outside of limits (min: ' +
2503+
joint.limits.min +
2504+
', max: ' +
2505+
joint.limits.max +
2506+
').',
25072507
)
25082508
} else if (joint.static) {
25092509
console.warn('THREE.ColladaLoader: Joint ' + jointIndex + ' is static.')

src/loaders/FBXLoader.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,13 +1274,7 @@ class GeometryParser {
12741274
}
12751275

12761276
buffers.uvs.forEach(function (uvBuffer, i) {
1277-
// subsequent uv buffers are called 'uv1', 'uv2', ...
1278-
let name = 'uv' + (i + 1).toString()
1279-
1280-
// the first uv buffer is just called 'uv'
1281-
if (i === 0) {
1282-
name = 'uv'
1283-
}
1277+
const name = i === 0 ? 'uv' : `uv${i}`;
12841278

12851279
geo.setAttribute(name, new Float32BufferAttribute(buffers.uvs[i], 2))
12861280
})

src/loaders/LWOLoader.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ class LWOTreeParser {
148148

149149
const materials = this.getMaterials(geometry.userData.matNames, layer.geometry.type)
150150

151-
this.duplicateUVs(geometry, materials)
152-
153151
if (layer.geometry.type === 'points') mesh = new Points(geometry, materials)
154152
else if (layer.geometry.type === 'lines') mesh = new LineSegments(geometry, materials)
155153
else mesh = new Mesh(geometry, materials)
@@ -222,23 +220,6 @@ class LWOTreeParser {
222220
return m.name === name
223221
})[0]
224222
}
225-
226-
// If the material has an aoMap, duplicate UVs
227-
duplicateUVs(geometry, materials) {
228-
let duplicateUVs = false
229-
230-
if (!Array.isArray(materials)) {
231-
if (materials.aoMap) duplicateUVs = true
232-
} else {
233-
materials.forEach(function (material) {
234-
if (material.aoMap) duplicateUVs = true
235-
})
236-
}
237-
238-
if (!duplicateUVs) return
239-
240-
geometry.setAttribute('uv2', new BufferAttribute(geometry.attributes.uv.array, 2))
241-
}
242223
}
243224

244225
class MaterialParser {

src/misc/ProgressiveLightmap.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ class ProgressiveLightMap {
5252
shader.vertexShader =
5353
'#define USE_LIGHTMAP\n' +
5454
shader.vertexShader.slice(0, -1) +
55-
' gl_Position = vec4((uv2 - 0.5) * 2.0, 1.0, 1.0); }'
55+
' gl_Position = vec4((uv1 - 0.5) * 2.0, 1.0, 1.0); }'
5656

5757
// Fragment Shader: Set Pixels to average in the Previous frame's Shadows
5858
const bodyStart = shader.fragmentShader.indexOf('void main() {')
5959
shader.fragmentShader =
60-
'varying vec2 vUv2;\n' +
60+
'varying vec2 vuv1;\n' +
6161
shader.fragmentShader.slice(0, bodyStart) +
6262
' uniform sampler2D previousShadowMap;\n uniform float averagingWindow;\n' +
6363
shader.fragmentShader.slice(bodyStart - 1, -1) +
64-
`\nvec3 texelOld = texture2D(previousShadowMap, vUv2).rgb;
64+
`\nvec3 texelOld = texture2D(previousShadowMap, vuv1).rgb;
6565
gl_FragColor.rgb = mix(texelOld, gl_FragColor.rgb, 1.0/averagingWindow);
6666
}`
6767

@@ -79,7 +79,7 @@ class ProgressiveLightMap {
7979
}
8080

8181
/**
82-
* Sets these objects' materials' lightmaps and modifies their uv2's.
82+
* Sets these objects' materials' lightmaps and modifies their uv1's.
8383
* @param {Object3D} objects An array of objects and lights to set up your lightmap.
8484
*/
8585
addObjectsToLightMap(objects) {
@@ -124,14 +124,14 @@ class ProgressiveLightMap {
124124
// Pack the objects' lightmap UVs into the same global space
125125
const dimensions = potpack(this.uv_boxes)
126126
this.uv_boxes.forEach((box) => {
127-
const uv2 = objects[box.index].geometry.getAttribute('uv').clone()
128-
for (let i = 0; i < uv2.array.length; i += uv2.itemSize) {
129-
uv2.array[i] = (uv2.array[i] + box.x + padding) / dimensions.w
130-
uv2.array[i + 1] = (uv2.array[i + 1] + box.y + padding) / dimensions.h
127+
const uv1 = objects[box.index].geometry.getAttribute('uv').clone()
128+
for (let i = 0; i < uv1.array.length; i += uv1.itemSize) {
129+
uv1.array[i] = (uv1.array[i] + box.x + padding) / dimensions.w
130+
uv1.array[i + 1] = (uv1.array[i + 1] + box.y + padding) / dimensions.h
131131
}
132132

133-
objects[box.index].geometry.setAttribute('uv2', uv2)
134-
objects[box.index].geometry.getAttribute('uv2').needsUpdate = true
133+
objects[box.index].geometry.setAttribute('uv1', uv1)
134+
objects[box.index].geometry.getAttribute('uv1').needsUpdate = true
135135
})
136136
}
137137

src/modifiers/TessellateModifier.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ class TessellateModifier {
5757
const hasNormals = attributes.normal !== undefined
5858
const hasColors = attributes.color !== undefined
5959
const hasUVs = attributes.uv !== undefined
60-
const hasUV2s = attributes.uv2 !== undefined
60+
const hasUV1s = attributes.uv1 !== undefined
6161

6262
let positions = attributes.position.array
6363
let normals = hasNormals ? attributes.normal.array : null
6464
let colors = hasColors ? attributes.color.array : null
6565
let uvs = hasUVs ? attributes.uv.array : null
66-
let uv2s = hasUV2s ? attributes.uv2.array : null
66+
let uv1s = hasUV1s ? attributes.uv1.array : null
6767

6868
let positions2 = (positions as unknown) as number[]
6969
let normals2 = (normals as unknown) as number[]
7070
let colors2 = (colors as unknown) as number[]
7171
let uvs2 = (uvs as unknown) as number[]
72-
let uv2s2 = (uv2s as unknown) as number[]
72+
let uv1s2 = (uv1s as unknown) as number[]
7373

7474
let iteration = 0
7575
let tessellating = true
@@ -113,14 +113,14 @@ class TessellateModifier {
113113
uvs2.push(u3.x, u3.y)
114114
}
115115

116-
if (hasUV2s) {
116+
if (hasUV1s) {
117117
const u21 = u2s[a]
118118
const u22 = u2s[b]
119119
const u23 = u2s[c]
120120

121-
uv2s2.push(u21.x, u21.y)
122-
uv2s2.push(u22.x, u22.y)
123-
uv2s2.push(u23.x, u23.y)
121+
uv1s2.push(u21.x, u21.y)
122+
uv1s2.push(u22.x, u22.y)
123+
uv1s2.push(u23.x, u23.y)
124124
}
125125
}
126126

@@ -146,9 +146,9 @@ class TessellateModifier {
146146
uvs2 = []
147147
}
148148

149-
if (hasUV2s) {
150-
uv2s = uv2s2 as any
151-
uv2s2 = []
149+
if (hasUV1s) {
150+
uv1s = uv1s2 as any
151+
uv1s2 = []
152152
}
153153

154154
for (let i = 0, i2 = 0, il = positions.length; i < il; i += 9, i2 += 6) {
@@ -174,10 +174,10 @@ class TessellateModifier {
174174
uc.fromArray(uvs, i2 + 4)
175175
}
176176

177-
if (hasUV2s && uv2s) {
178-
u2a.fromArray(uv2s, i2 + 0)
179-
u2b.fromArray(uv2s, i2 + 2)
180-
u2c.fromArray(uv2s, i2 + 4)
177+
if (hasUV1s && uv1s) {
178+
u2a.fromArray(uv1s, i2 + 0)
179+
u2b.fromArray(uv1s, i2 + 2)
180+
u2c.fromArray(uv1s, i2 + 4)
181181
}
182182

183183
const dab = va.distanceToSquared(vb)
@@ -192,7 +192,7 @@ class TessellateModifier {
192192
if (hasNormals) nm.lerpVectors(na, nb, 0.5)
193193
if (hasColors) cm.lerpColors(ca, cb, 0.5)
194194
if (hasUVs) um.lerpVectors(ua, ub, 0.5)
195-
if (hasUV2s) u2m.lerpVectors(u2a, u2b, 0.5)
195+
if (hasUV1s) u2m.lerpVectors(u2a, u2b, 0.5)
196196

197197
addTriangle(0, 3, 2)
198198
addTriangle(3, 1, 2)
@@ -201,7 +201,7 @@ class TessellateModifier {
201201
if (hasNormals) nm.lerpVectors(nb, nc, 0.5)
202202
if (hasColors) cm.lerpColors(cb, cc, 0.5)
203203
if (hasUVs) um.lerpVectors(ub, uc, 0.5)
204-
if (hasUV2s) u2m.lerpVectors(u2b, u2c, 0.5)
204+
if (hasUV1s) u2m.lerpVectors(u2b, u2c, 0.5)
205205

206206
addTriangle(0, 1, 3)
207207
addTriangle(3, 2, 0)
@@ -210,7 +210,7 @@ class TessellateModifier {
210210
if (hasNormals) nm.lerpVectors(na, nc, 0.5)
211211
if (hasColors) cm.lerpColors(ca, cc, 0.5)
212212
if (hasUVs) um.lerpVectors(ua, uc, 0.5)
213-
if (hasUV2s) u2m.lerpVectors(u2a, u2c, 0.5)
213+
if (hasUV1s) u2m.lerpVectors(u2a, u2c, 0.5)
214214

215215
addTriangle(0, 1, 3)
216216
addTriangle(3, 1, 2)
@@ -237,8 +237,8 @@ class TessellateModifier {
237237
geometry2.setAttribute('uv', new Float32BufferAttribute(uvs2 as any, 2))
238238
}
239239

240-
if (hasUV2s) {
241-
geometry2.setAttribute('uv2', new Float32BufferAttribute(uv2s2 as any, 2))
240+
if (hasUV1s) {
241+
geometry2.setAttribute('uv1', new Float32BufferAttribute(uv1s2 as any, 2))
242242
}
243243

244244
return geometry2

0 commit comments

Comments
 (0)