2

问题:

一切正常:我在 /GLTF/ 子文件夹中将我的 FBX 文件转换为 GLTF。

遗憾的是,一些转换后的文件中缺少一些几何图形,所以我尝试再次转换我的 FBX 文件,这次是 /TEST/。

突然,模型没有加载并且来自我的 console.log 语句:

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

我收到这个奇怪的无用错误:

An error happened: {"isTrusted":true}

所以我尝试将我的 FBX 文件转换为 .glb,这次转换为 /TEST2/ 并添加一个额外的 console.log 语句:

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

我仍然得到同样的错误:

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

加载第一个转换的 gltf 文件仍然有效(来自 /GLTF/ 的文件),但如前所述,有些似乎转换不正确:它们的一些几何形状丢失了。

这些错误是什么?如何让我的模型加载?


代码:

<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>

我用来从 FBX 转换为 GLTF 的 NPM 包:

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


错误:

在此处输入图像描述


我看到了什么:

日志显示错误对象:{"isTrusted":true} 而不是实际的错误数据

.NET Cors isTrusted:Angular 5 应用程序的真正错误

core.umd.js 中的 {"isTrusted":true} 异常


编辑:

在此处输入图像描述

4

1 回答 1

1

要对此进行调试,您可以将模型拖到我的调试查看器中,您将看到以下消息:

缺少纹理:M_Med_Soldier_Body_BLACKKNIGHT_n.tga

glTF 和 Web 浏览器都不支持 TGA 纹理,因此引用它的事实是用于创建此文件的工具中的错误。我建议在 FBX2glTF 上提交一个错误。

但是,如果您查看模型文件夹,您会看到相同的图像已经作为 PNG 存在(也许是 FBX2glTF 转换的?)。如果您.gltf在文本编辑器(我使用 Sublime Text)中打开文件并搜索“图像”,您会发现不正确的 TGA 图像参考。将其重命名为.png,您会看到我认为是正确的结果:

工作骑士模型截图

于 2018-08-20T21:17:38.147 回答