فهرست منبع

[Loader] Fix for LWOLoader geometry correction (#28029)

* [Loader] Fix for LWOLoader geometry correction

fix: IFFParser.js now reads x as -x instead of z to -z. This now sets the geometry and pivot points in the correct location.

This fixes #26733

* fix: webgl_loader_lwo updated with corrected coordinates for meshes and lights and cameras
WORMSS 1 سال پیش
والد
کامیت
08fbd476f8
3فایلهای تغییر یافته به همراه14 افزوده شده و 11 حذف شده
  1. 8 5
      examples/jsm/loaders/lwo/IFFParser.js
  2. BIN
      examples/screenshots/webgl_loader_lwo.jpg
  3. 6 6
      examples/webgl_loader_lwo.html

+ 8 - 5
examples/jsm/loaders/lwo/IFFParser.js

@@ -651,10 +651,13 @@ class IFFParser {
 	// LAYR: number[U2], flags[U2], pivot[VEC12], name[S0], parent[U2]
 	parseLayer( length ) {
 
+		var number = this.reader.getUint16();
+		var flags = this.reader.getUint16(); // If the least significant bit of flags is set, the layer is hidden.
+		var pivot = this.reader.getFloat32Array( 3 ); // Note: this seems to be superflous, as the geometry is translated when pivot is present
 		var layer = {
-			number: this.reader.getUint16(),
-			flags: this.reader.getUint16(), // If the least significant bit of flags is set, the layer is hidden.
-			pivot: this.reader.getFloat32Array( 3 ), // Note: this seems to be superflous, as the geometry is translated when pivot is present
+			number: number,
+			flags: flags, // If the least significant bit of flags is set, the layer is hidden.
+			pivot: [ - pivot[ 0 ], pivot[ 1 ], pivot[ 2 ] ], // Note: this seems to be superflous, as the geometry is translated when pivot is present
 			name: this.reader.getString(),
 		};
 
@@ -676,8 +679,8 @@ class IFFParser {
 		this.currentPoints = [];
 		for ( var i = 0; i < length / 4; i += 3 ) {
 
-			// z -> -z to match three.js right handed coords
-			this.currentPoints.push( this.reader.getFloat32(), this.reader.getFloat32(), - this.reader.getFloat32() );
+			// x -> -x to match three.js right handed coords
+			this.currentPoints.push( - this.reader.getFloat32(), this.reader.getFloat32(), this.reader.getFloat32() );
 
 		}
 

BIN
examples/screenshots/webgl_loader_lwo.jpg


+ 6 - 6
examples/webgl_loader_lwo.html

@@ -41,7 +41,7 @@
 				document.body.appendChild( container );
 
 				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 200 );
-				camera.position.set( - 0.7, 14.6, 43.2 );
+				camera.position.set( 0.7, 14.6, - 43.2 );
 
 				scene = new THREE.Scene();
 				scene.background = new THREE.Color( 0xa0a0a0 );
@@ -50,7 +50,7 @@
 				scene.add( ambientLight );
 
 				const light1 = new THREE.DirectionalLight( 0xc1c1c1, 3 );
-				light1.position.set( 0, 200, 100 );
+				light1.position.set( 0, 200, - 100 );
 				scene.add( light1 );
 
 				const grid = new THREE.GridHelper( 200, 20, 0x000000, 0x000000 );
@@ -62,13 +62,13 @@
 				loader.load( 'models/lwo/Objects/LWO3/Demo.lwo', function ( object ) {
 
 					const phong = object.meshes[ 0 ];
-					phong.position.set( - 2, 12, 0 );
+					phong.position.set( 2, 12, 0 );
 
 					const standard = object.meshes[ 1 ];
-					standard.position.set( 2, 12, 0 );
+					standard.position.set( - 2, 12, 0 );
 
 					const rocket = object.meshes[ 2 ];
-					rocket.position.set( 0, 10.5, - 1 );
+					rocket.position.set( 0, 10.5, 1 );
 
 					scene.add( phong, standard, rocket );
 
@@ -82,7 +82,7 @@
 				container.appendChild( renderer.domElement );
 
 				const controls = new OrbitControls( camera, renderer.domElement );
-				controls.target.set( 1.33, 10, - 6.7 );
+				controls.target.set( - 1.33, 10, 6.7 );
 				controls.update();
 
 				window.addEventListener( 'resize', onWindowResize );