瀏覽代碼

Examples: Add GLTFExporter to sculpt example.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Mr.doob 1 月之前
父節點
當前提交
ac381dd067
共有 1 個文件被更改,包括 28 次插入1 次删除
  1. 28 1
      examples/webgl_sculpt.html

+ 28 - 1
examples/webgl_sculpt.html

@@ -28,6 +28,7 @@
 
 			import * as THREE from 'three';
 			import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
+			import { GLTFExporter } from 'three/addons/exporters/GLTFExporter.js';
 			import { Sculpt } from 'three/addons/sculpt/Sculpt.js';
 			import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
 
@@ -38,6 +39,29 @@
 			const _forward = new THREE.Vector3( 0, 0, 1 );
 			const _mouse = new THREE.Vector3();
 
+			const link = document.createElement( 'a' );
+			link.style.display = 'none';
+			document.body.appendChild( link );
+
+			function exportGLTF() {
+
+				const exporter = new GLTFExporter();
+
+				exporter.parse( mesh, function ( buffer ) {
+
+					const blob = new Blob( [ buffer ], { type: 'application/octet-stream' } );
+					link.href = URL.createObjectURL( blob );
+					link.download = 'sculpt.glb';
+					link.click();
+
+				}, function ( error ) {
+
+					console.error( error );
+
+				}, { binary: true } );
+
+			}
+
 			init();
 
 			function init() {
@@ -120,7 +144,8 @@
 					subdivision: 0.75,
 					decimation: 0,
 					negative: false,
-					wireframe: false
+					wireframe: false,
+					export: exportGLTF
 				};
 
 				const gui = new GUI();
@@ -167,6 +192,8 @@
 
 				} );
 
+				gui.add( params, 'export' );
+
 				// 3D Cursor
 
 				const cursorMaterial = new THREE.MeshBasicMaterial( {

粤ICP备19079148号