Skip to content

Commit 76ceae5

Browse files
authored
GLTFExporter: Fix export of normal maps. (#2234)
* Update three.js * Add examples * Update * Update patch and delete examples
1 parent 64b8ae5 commit 76ceae5

3 files changed

Lines changed: 66 additions & 2 deletions

File tree

examples-testing/changes.patch

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,70 @@ index c19eb94a6..7900c0e18 100644
12451245
ctx.fillStyle = '#005BBB';
12461246
ctx.fillRect(0, 0, 64, 64);
12471247
ctx.fillStyle = '#FFD500';
1248+
diff --git a/examples-testing/examples/misc_exporter_gltf_normals.ts b/examples-testing/examples/misc_exporter_gltf_normals.ts
1249+
index 6ca397191..4cbc0c74b 100644
1250+
--- a/examples-testing/examples/misc_exporter_gltf_normals.ts
1251+
+++ b/examples-testing/examples/misc_exporter_gltf_normals.ts
1252+
@@ -1,14 +1,15 @@
1253+
-import * as THREE from '../build/three.module.js';
1254+
+import * as THREE from 'three';
1255+
1256+
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
1257+
import { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js';
1258+
1259+
//
1260+
1261+
-let container;
1262+
+let container: HTMLDivElement;
1263+
1264+
-let camera, scene, renderer;
1265+
-let mesh1, mesh2;
1266+
+let camera: THREE.PerspectiveCamera, scene: THREE.Scene, renderer: THREE.WebGLRenderer;
1267+
+let mesh1: THREE.Mesh<THREE.PlaneGeometry, THREE.MeshStandardMaterial>,
1268+
+ mesh2: THREE.Mesh<THREE.PlaneGeometry, THREE.MeshStandardMaterial>;
1269+
1270+
init();
1271+
render();
1272+
@@ -115,7 +116,7 @@ function render() {
1273+
1274+
//
1275+
1276+
-function exportGLTF(input) {
1277+
+function exportGLTF(input: THREE.Object3D[]) {
1278+
const gltfExporter = new GLTFExporter();
1279+
1280+
const options = {
1281+
@@ -138,7 +139,7 @@ function exportGLTF(input) {
1282+
);
1283+
}
1284+
1285+
-document.getElementById('export_objects').addEventListener('click', function () {
1286+
+document.getElementById('export_objects')!.addEventListener('click', function () {
1287+
exportGLTF([mesh1, mesh2]);
1288+
});
1289+
1290+
@@ -146,7 +147,7 @@ const link = document.createElement('a');
1291+
link.style.display = 'none';
1292+
document.body.appendChild(link); // Firefox workaround, see #6594
1293+
1294+
-function save(blob, filename) {
1295+
+function save(blob: Blob, filename: string) {
1296+
link.href = URL.createObjectURL(blob);
1297+
link.download = filename;
1298+
link.click();
1299+
@@ -154,10 +155,10 @@ function save(blob, filename) {
1300+
// URL.revokeObjectURL( url ); breaks Firefox...
1301+
}
1302+
1303+
-function saveString(text, filename) {
1304+
+function saveString(text: string, filename: string) {
1305+
save(new Blob([text], { type: 'text/plain' }), filename);
1306+
}
1307+
1308+
-function saveArrayBuffer(buffer, filename) {
1309+
+function saveArrayBuffer(buffer: ArrayBuffer, filename: string) {
1310+
save(new Blob([buffer], { type: 'application/octet-stream' }), filename);
1311+
}
12481312
diff --git a/examples-testing/examples/misc_exporter_ktx2.ts b/examples-testing/examples/misc_exporter_ktx2.ts
12491313
index c96889a24..1c8535e0e 100644
12501314
--- a/examples-testing/examples/misc_exporter_ktx2.ts

three.js

types/three/examples/jsm/exporters/GLTFExporter.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ declare class GLTFExporter {
8888
parse(
8989
input: Object3D | Object3D[],
9090
onDone: (gltf: ArrayBuffer | { [key: string]: unknown }) => void,
91-
onError: (error: ErrorEvent) => void,
91+
onError: ((error: ErrorEvent) => void) | null,
9292
options?: GLTFExporterOptions,
9393
): void;
9494

0 commit comments

Comments
 (0)