Skip to content

Commit 08fbd47

Browse files
authored
[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
1 parent cd38537 commit 08fbd47

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

examples/jsm/loaders/lwo/IFFParser.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,13 @@ class IFFParser {
651651
// LAYR: number[U2], flags[U2], pivot[VEC12], name[S0], parent[U2]
652652
parseLayer( length ) {
653653

654+
var number = this.reader.getUint16();
655+
var flags = this.reader.getUint16(); // If the least significant bit of flags is set, the layer is hidden.
656+
var pivot = this.reader.getFloat32Array( 3 ); // Note: this seems to be superflous, as the geometry is translated when pivot is present
654657
var layer = {
655-
number: this.reader.getUint16(),
656-
flags: this.reader.getUint16(), // If the least significant bit of flags is set, the layer is hidden.
657-
pivot: this.reader.getFloat32Array( 3 ), // Note: this seems to be superflous, as the geometry is translated when pivot is present
658+
number: number,
659+
flags: flags, // If the least significant bit of flags is set, the layer is hidden.
660+
pivot: [ - pivot[ 0 ], pivot[ 1 ], pivot[ 2 ] ], // Note: this seems to be superflous, as the geometry is translated when pivot is present
658661
name: this.reader.getString(),
659662
};
660663

@@ -676,8 +679,8 @@ class IFFParser {
676679
this.currentPoints = [];
677680
for ( var i = 0; i < length / 4; i += 3 ) {
678681

679-
// z -> -z to match three.js right handed coords
680-
this.currentPoints.push( this.reader.getFloat32(), this.reader.getFloat32(), - this.reader.getFloat32() );
682+
// x -> -x to match three.js right handed coords
683+
this.currentPoints.push( - this.reader.getFloat32(), this.reader.getFloat32(), this.reader.getFloat32() );
681684

682685
}
683686

3.38 KB
Loading

examples/webgl_loader_lwo.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
document.body.appendChild( container );
4242

4343
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 200 );
44-
camera.position.set( - 0.7, 14.6, 43.2 );
44+
camera.position.set( 0.7, 14.6, - 43.2 );
4545

4646
scene = new THREE.Scene();
4747
scene.background = new THREE.Color( 0xa0a0a0 );
@@ -50,7 +50,7 @@
5050
scene.add( ambientLight );
5151

5252
const light1 = new THREE.DirectionalLight( 0xc1c1c1, 3 );
53-
light1.position.set( 0, 200, 100 );
53+
light1.position.set( 0, 200, - 100 );
5454
scene.add( light1 );
5555

5656
const grid = new THREE.GridHelper( 200, 20, 0x000000, 0x000000 );
@@ -62,13 +62,13 @@
6262
loader.load( 'models/lwo/Objects/LWO3/Demo.lwo', function ( object ) {
6363

6464
const phong = object.meshes[ 0 ];
65-
phong.position.set( - 2, 12, 0 );
65+
phong.position.set( 2, 12, 0 );
6666

6767
const standard = object.meshes[ 1 ];
68-
standard.position.set( 2, 12, 0 );
68+
standard.position.set( - 2, 12, 0 );
6969

7070
const rocket = object.meshes[ 2 ];
71-
rocket.position.set( 0, 10.5, - 1 );
71+
rocket.position.set( 0, 10.5, 1 );
7272

7373
scene.add( phong, standard, rocket );
7474

@@ -82,7 +82,7 @@
8282
container.appendChild( renderer.domElement );
8383

8484
const controls = new OrbitControls( camera, renderer.domElement );
85-
controls.target.set( 1.33, 10, - 6.7 );
85+
controls.target.set( - 1.33, 10, 6.7 );
8686
controls.update();
8787

8888
window.addEventListener( 'resize', onWindowResize );

0 commit comments

Comments
 (0)