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

FBXLoader wrong handle the transformed pivot points #13466

Closed
3 of 13 tasks
JochnGst opened this issue Mar 1, 2018 · 6 comments
Closed
3 of 13 tasks

FBXLoader wrong handle the transformed pivot points #13466

JochnGst opened this issue Mar 1, 2018 · 6 comments

Comments

@JochnGst
Copy link

JochnGst commented Mar 1, 2018

Description of the problem

I have tried to load an FBX file with the FBXLoader. I also found the Issues #11895 that descripe a similar problem.

In the Fbx Sdk from Autodesk I solved this kind of Problem bei reset all pivots to the Mesh origin for the TRS-Matrix.

This is how I load the FBX-File. Is a little variation on the FBX-Example

function centerCam(aroundObject3D){

    //calc cam pos from Bounding Box
    var BB = new THREE.Box3().setFromObject(aroundObject3D);
    var centerpoint = BB.getCenter();
    var size = BB.getSize();
    var backup = (size.y / 2) / Math.sin( (camera.fov/2)*(Math.PI/180) );
    var camZpos = BB.max.z + backup + camera.near ;
  
    // Hilfsobject
    const redGeom = new THREE.BoxBufferGeometry( 10, 10, 10 );
    const redMat = new THREE.MeshBasicMaterial( { color: 0xff0000 } );
    const redMesh = new THREE.Mesh( redGeom, redMat );
    redMesh.position.set(centerpoint);
    //scene.add( redMesh);

    //move cam
    camera.position.set(centerpoint.x - 1, centerpoint.y+1, -camZpos);
    camera.far = camera.near + 10*size.z;
    camera.updateProjectionMatrix();
    camera.lookAt(centerpoint);
  
}

function init() {

    container = document.createElement('div');
    document.body.appendChild(container);

    camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 2000);
    //camera.position.set(1, 2, -3);
        

    controls = new THREE.OrbitControls(camera);
    controls.target.set(0, 10, 0);
    controls.update();

    scene = new THREE.Scene();
    scene.background = new THREE.Color(0xa0a0a0);
    scene.fog = new THREE.Fog(0xa0a0a0, 200, 1000);

    light = new THREE.HemisphereLight(0xffffff, 0x444444);
    light.position.set(0, 200, 0);
    scene.add(light);

    light = new THREE.DirectionalLight(0xffffff);
    light.position.set(0, 200, 100);
    light.castShadow = true;
    light.shadow.camera.top = 180;
    light.shadow.camera.bottom = -100;
    light.shadow.camera.left = -120;
    light.shadow.camera.right = 120;
    scene.add(light);

    // scene.add( new THREE.CameraHelper( light.shadow.camera ) );

    // ground
    var mesh = new THREE.Mesh(new THREE.PlaneGeometry(2000, 2000), new THREE.MeshPhongMaterial({ color: 0x999999, depthWrite: false }));
    mesh.rotation.x = - Math.PI / 2;
    mesh.receiveShadow = true;
    //scene.add(mesh);

    var grid = new THREE.GridHelper(2000, 20, 0x000000, 0x000000);
    grid.material.opacity = 0.2;
    grid.material.transparent = true;
    scene.add(grid);

    // model
    var loader = new THREE.FBXLoader();
    // loader.load('models/WerkzeugPump.FBX', function (object) {
    // loader.load('models/Pumpe.FBX', function (object) {
    loader.load('models/Getriebe.FBX', function (object) {


        object.mixer = new THREE.AnimationMixer(object);
        mixers.push(object.mixer);

        //var action = object.mixer.clipAction( object.animations[ 0 ] );
        //action.play();

        object.traverse(function (child) {

            if (child.isMesh) {

                child.castShadow = true;
                child.receiveShadow = true;

            }

        });

        scene.add(object);
        centerCam(object);
        
    });

    renderer = new THREE.WebGLRenderer();
    renderer.setPixelRatio(window.devicePixelRatio);
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.shadowMap.enabled = true;
    container.appendChild(renderer.domElement);

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

    // stats
    stats = new Stats();
    container.appendChild(stats.dom);

}

Three.js viewer
2018-03-01_15-50-22

Windows Viewer
2018-03-01_15-51-11

FBX-File on my OneDrive:
https://1drv.ms/f/s!AtdlOM2GmeG5hKc1e8m-5m5-0SPhSQ

Three.js version
  • Dev
  • r90
  • ...
Browser
  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • macOS
  • Linux
  • Android
  • iOS
Hardware Requirements (graphics card, VR Device, ...)
@looeee
Copy link
Collaborator

looeee commented Mar 1, 2018

Can you make sure that you are using the latest version of the loader? Transformed pivots should work now.

If that doesn't fix it then please share your model and I'll take a look.

@mrdoob
Copy link
Owner

mrdoob commented Mar 2, 2018

I can confirm using the dev branch.

screen shot 2018-03-01 at 4 31 23 pm

Models: https://1drv.ms/f/s!AtdlOM2GmeG5hKc1e8m-5m5-0SPhSQ

@looeee
Copy link
Collaborator

looeee commented Mar 2, 2018

Oh sorry, I missed the model link. I'll take a look later today.

@JochnGst
Copy link
Author

JochnGst commented Mar 2, 2018

Hello,

I have save the file in ASCII and compare the definition to one I have "Reset the Pivots" in 3DS Max.

I have seen that the original (left) has a geometry scaling and the resettet (right) have the scaling translatet in the local scaling value.

2018-03-02_07-36-18

Here is a screenshot how I do this kind of "reset" the Pivots in the Fbx sdk.
I do not know if this is the right way to do this, but for my test models it works.

2018-03-02_07-52-36

I hope it helps you.

@mike-tuxedo
Copy link

I can confirm this problem in fbx-bin-versions (2006 - 2012) and fbx-ascii-format (2017).
I have a complex model with complex animations and when it animates, it seems that the pivot points are at the wrong place. When i convert it to gltf, nearly all is ok, only materials are lost. But since i need materials and have no influence in how the model is made, i can't use gltf.

Unfortunately I'm not allowed to share this model and I have nothing positive to contribute.
I tried to replace "GeometricScaling" with "Lcl Scaling" in my ASCII-file, but didn't work for me.

Just to let you know.

@looeee
Copy link
Collaborator

looeee commented Mar 7, 2018

Fixed in #13513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants