Skip to content

Commit

Permalink
[Loader] Fix for LWOLoader geometry correction (#28029)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
WORMSS authored Apr 2, 2024
1 parent cd38537 commit 08fbd47
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
13 changes: 8 additions & 5 deletions examples/jsm/loaders/lwo/IFFParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};

Expand All @@ -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() );

}

Expand Down
Binary file modified examples/screenshots/webgl_loader_lwo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions examples/webgl_loader_lwo.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );

Expand All @@ -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 );
Expand Down

0 comments on commit 08fbd47

Please sign in to comment.