Browse Source

USDZExporter: Clean up. (#24865)

* USDZExporter: Clean up.

* USDZExporter: More clean up.

* Examples: Clean up.
Michael Herzog 2 năm trước cách đây
mục cha
commit
5ffc068eef
2 tập tin đã thay đổi với 46 bổ sung41 xóa
  1. 45 39
      examples/jsm/exporters/USDZExporter.js
  2. 1 2
      examples/misc_exporter_usdz.html

+ 45 - 39
examples/jsm/exporters/USDZExporter.js

@@ -6,17 +6,7 @@ import * as fflate from '../libs/fflate.module.js';
 
 class USDZExporter {
 
-	options = {
-		ar: { anchoring: { type: 'plane' }, planeAnchoring: { alignment: 'vertical' } }
-	};
-
-	setOptions( options ) {
-
-		this.options = options;
-
-	}
-
-	async parse( scene ) {
+	async parse( scene, options = { ar: { anchoring: { type: 'plane' }, planeAnchoring: { alignment: 'vertical' } } } ) {
 
 		const files = {};
 		const modelFileName = 'model.usda';
@@ -26,24 +16,7 @@ class USDZExporter {
 
 		let output = buildHeader();
 
-		output += `def Xform "Root"
-{
-    def Scope "Scenes" (
-        kind = "sceneLibrary"
-    )
-    {
-        def Xform "Scene" (
-            customData = {
-                bool preliminary_collidesWithEnvironment = 0
-                string sceneName = "Scene"
-            }
-            sceneName = "Scene"
-        )
-        {
-        token preliminary:anchoring:type = "${this.options.ar.anchoring.type}"
-        token preliminary:planeAnchoring:alignment = "${this.options.ar.planeAnchoring.alignment}"
-
-`;
+		output += buildSceneStart( options );
 
 		const materials = {};
 		const textures = {};
@@ -81,7 +54,7 @@ class USDZExporter {
 				}
 
 			} else if ( object.isCamera ) {
-				
+
 				output += buildCamera( object );
 
 			}
@@ -89,12 +62,7 @@ class USDZExporter {
 		} );
 
 
-		output += `
-        }
-    }
-}
-
-`;
+		output += buildSceneEnd();
 
 		output += buildMaterials( materials, textures );
 
@@ -211,6 +179,40 @@ function buildHeader() {
 
 }
 
+function buildSceneStart( options ) {
+
+	return `def Xform "Root"
+{
+    def Scope "Scenes" (
+        kind = "sceneLibrary"
+    )
+    {
+        def Xform "Scene" (
+            customData = {
+                bool preliminary_collidesWithEnvironment = 0
+                string sceneName = "Scene"
+            }
+            sceneName = "Scene"
+        )
+        {
+        token preliminary:anchoring:type = "${options.ar.anchoring.type}"
+        token preliminary:planeAnchoring:alignment = "${options.ar.planeAnchoring.alignment}"
+
+`;
+
+}
+
+function buildSceneEnd() {
+
+	return `
+        }
+    }
+}
+
+`;
+
+}
+
 function buildUSDFileAsString( dataToInsert ) {
 
 	let output = buildHeader();
@@ -609,20 +611,23 @@ function buildCamera( camera ) {
 
 	}
 
-	if (camera.isOrthographicCamera) {
+	if ( camera.isOrthographicCamera ) {
+
 		return `def Camera "${name}"
 		{
 			matrix4d xformOp:transform = ${ transform }
 			uniform token[] xformOpOrder = ["xformOp:transform"]
 	
 			float2 clippingRange = (${camera.near}, ${camera.far})
-			float horizontalAperture = ${(Math.abs(camera.left) + Math.abs(camera.right)) * 10}
-			float verticalAperture = ${(Math.abs(camera.top) + Math.abs(camera.bottom)) * 10}
+			float horizontalAperture = ${( Math.abs( camera.left ) + Math.abs( camera.right ) ) * 10}
+			float verticalAperture = ${( Math.abs( camera.top ) + Math.abs( camera.bottom ) ) * 10}
 			token projection = "orthographic"
 		}
 	
 	`;
+
 	} else {
+
 		return `def Camera "${name}"
 		{
 			matrix4d xformOp:transform = ${ transform }
@@ -637,6 +642,7 @@ function buildCamera( camera ) {
 		}
 	
 	`;
+
 	}
 
 }

+ 1 - 2
examples/misc_exporter_usdz.html

@@ -80,7 +80,6 @@
 				scene = new THREE.Scene();
 				scene.background = new THREE.Color( 0xf0f0f0 );
 				scene.environment = pmremGenerator.fromScene( new RoomEnvironment(), 0.04 ).texture;
-				scene.add( camera );
 
 				const loader = new GLTFLoader().setPath( 'models/gltf/DamagedHelmet/glTF/' );
 				loader.load( 'DamagedHelmet.gltf', async function ( gltf ) {
@@ -98,7 +97,7 @@
 					// USDZ
 
 					const exporter = new USDZExporter();
-					const arraybuffer = await exporter.parse( scene );
+					const arraybuffer = await exporter.parse( gltf.scene );
 					const blob = new Blob( [ arraybuffer ], { type: 'application/octet-stream' } );
 
 					const link = document.getElementById( 'link' );