Getting an {“isTrusted”:true} error when using GLTFLoader

烂漫一生 提交于 2019-12-11 08:59:57

问题


QUESTION:

Everything was working fine: I converted my FBX files to GLTF inside my /GLTF/ subfolder.

Sadly, some geometry was missing from some of the converted files, so I tried to convert again my FBX files, this time to /TEST/.

Suddenly, the models don't load and from my console.log statement:

console.log( 'An error happened: '+JSON.stringify(error) );

I get this strange useless error:

An error happened: {"isTrusted":true}

So I try to convert my FBX files to .glb instead, this time to /TEST2/ and add an additional console.log statement:

console.log( 'An error happened: '+JSON.stringify(error, ["message", "arguments", "type", "name"]) );

I still get the same error:

An error happened: {"isTrusted":true}
An error happened: {"type":"error"}

Loading the first converted gltf files still works (those from /GLTF/), but as mentioned, some seem to have improperly converted: some of their geometry is missing.

What are those errors and how can I make my models load ?


CODE:

<script src="../public/js/3DVisualizer/three.js"></script>
<script src="../public/js/3DVisualizer/inflate.min.js"></script>
<script src="../public/js/3DVisualizer/GLTFLoader.js"></script>
<script src="../public/js/3DVisualizer/DracoLoader.js"></script>

<script src="../public/js/3DVisualizer/OrbitControls.js"></script>
<script src="../public/js/3DVisualizer/Detector.js"></script>
<script src="../public/js/3DVisualizer/stats.min.js"></script>

<script src="../public/js/3DVisualizer/TGALoader.js"></script>

//SOME MORE CODE

<script>

// Instantiate a loader
var loader = new THREE.GLTFLoader();

// Optional: Provide a DRACOLoader instance to decode compressed mesh data
THREE.DRACOLoader.setDecoderPath( '../public/js/3DVisualizer/' );
THREE.DRACOLoader.setDecoderConfig( { type: 'js' } );
loader.setDRACOLoader( new THREE.DRACOLoader() );

// Load a glTF resource
    loader.load(
        // resource URL
        '../public/3D/TEST2/'+name+'.glb',
        // called when the resource is loaded
        function ( gltf ) {

            scene.add( gltf.scene );

            gltf.animations; // Array<THREE.AnimationClip>
            gltf.scene; // THREE.Scene
            gltf.scenes; // Array<THREE.Scene>
            gltf.cameras; // Array<THREE.Camera>
            gltf.asset; // Object

            gltf.scene.traverse(function(node) {
                if (node instanceof THREE.Mesh) {
                    frontObject = node;
                    node.geometry.computeFaceNormals();
                    node.geometry.computeVertexNormals();
                }
            });

            if (name.includes("...")) {
                backObject = gltf.scene;
            }
            else {
                frontObject = gltf.scene;
            }

            console.log("LOADED")

            frontObject.scale.set(45, 45, 45);
            backObject.scale.set(45, 45, 45);


            let box = new THREE.Box3().setFromObject(frontObject);
            let sphere = box.getBoundingSphere();
            let centerPoint = sphere.center;

            console.log("CENTER POINT X: " + centerPoint.x);
            console.log("CENTER POINT Y: " + centerPoint.y);
            console.log("CENTER POINT Z: " + centerPoint.z);

            centerPoint.y = 150;

            var newCoordinate = shootRay(centerPoint, frontObject);

            console.log("NEW POINT X: " + newCoordinate.x);
            console.log("NEW POINT Y: " + newCoordinate.y);
            console.log("NEW POINT Z: " + newCoordinate.z);

            backObject.position.set(newCoordinate.x, newCoordinate.y, (newCoordinate.z - 0));

        },
        // called while loading is progressing
        function ( xhr ) {

        },
        // called when loading has errors
        function ( error ) {
            console.log( 'An error happened: '+JSON.stringify(error) );
            console.log( 'An error happened: '+JSON.stringify(error, ["message", "arguments", "type", "name"]) );

        }
    );

    </script>

NPM PACKAGE I USED TO CONVERT FROM FBX TO GLTF:

https://www.npmjs.com/package/fbx2gltf


ERROR:


WHAT I LOOKED AT:

Log shows Error object: {"isTrusted":true} instead of actual error data

.NET Cors isTrusted: true error with Angular 5 app

{"isTrusted":true} exception in core.umd.js


EDIT:


回答1:


To debug this, you can drag the model into my debugging viewer and you'll see this message:

Missing texture: M_Med_Soldier_Body_BLACKKNIGHT_n.tga

Neither glTF nor web browsers support TGA textures, so the fact that it's referenced is a bug in the tool used to create this file. I'd recommend filing a bug on FBX2glTF.

However, if you look in the model folder, you'll see that same image is already there as a PNG (perhaps FBX2glTF converted it?). If you open the .gltf file in a text editor (I used Sublime Text) and search for "images", you'll find that incorrect TGA image reference. Rename it to .png and you'll see what I assume is the correct result:



来源:https://stackoverflow.com/questions/51839039/getting-an-istrustedtrue-error-when-using-gltfloader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!