Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LWOLoader: Fix coordinate system conversion. #28029

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() );
Mugen87 marked this conversation as resolved.
Show resolved Hide resolved

}

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
Loading