THREE.ObjectLoader的Three.js错误 [英] Three.js Error with THREE.ObjectLoader
问题描述
我似乎对Three.ObjectLoader有问题.我正在以JSON格式4.3导出场景.该场景包括几何形状,材质和灯光.场景将在Three.js编辑器中打开,并且没有任何错误.
I seem to be having issues with Three.ObjectLoader. I am exporting a scene in JSON Format 4.3. This scene includes geometries, materials, and lights. The scene opens in the Three.js Editor just fine without any errors.
我正在使用Three.js r70 master开发Firefox. 这是生成的json的链接: https://gist.github.com/fraguada/d86637f7987096b361ea
I am working on firefox with Three.js r70 master. Here is a link to the generated json: https://gist.github.com/fraguada/d86637f7987096b361ea
在查看器中,我试图编写代码,并且正在使用以下代码进行加载:
In the viewer I am trying to write I am using the following code for the loading:
var manager = new THREE.LoadingManager();
manager.onProgress = function ( item, loaded, total ) {
console.log( item, loaded, total );
};
// instantiate a loader
var loader = new THREE.ObjectLoader(manager);
loader.load(
// resource URL coming from other file
Name,
// Function when resource is loaded
function ( result )
{ scene.add( result.scene ); },
// Function called when download progresses
function ( xhr )
{ console.log( (xhr.loaded / xhr.total * 100) + '% loaded' ); },
// Function called when download errors
function ( xhr )
{ console.log( 'An error happened' ); }
);
在控制台中,我看到以下内容:
In the console I see the following:
THREE.WebGLRenderer 70 three.min.js (line 513)
100% loaded content.js (line 117)
THREE.Object3D.add: undefined is not an instance of THREE.Object3D. three.min.js (line 164)
js/Test83.js 1 1 content.js (line 86)
错误也出现在7674行的未缩小的three.js中
The error also appears in the unminified three.js in line 7674
如果我在Three.js编辑器中创建几何图形和其他对象并将其导出为场景,也会出现此问题.
This issue also appears if I create geometry and other objects in the Three.js editor and export it as a scene.
问题似乎在这里:scene.add( result.scene );
假设THREE.ObjectLoader可以使用文件中的JSON是不正确的吗?在我发布的代码中,如果删除scene.add( result.scene );
,似乎文件至少加载了(数据加载,没有可视化的几何图形),因为没有错误出现.如果我的场景具有多个网格,则进度将输出到控制台(已加载10%,已加载20%等).
The issue seems to be here: scene.add( result.scene );
Am incorrect in assuming the THREE.ObjectLoader can consume JSON from a file? In the code I post, if I remove scene.add( result.scene );
it seems the file loads at least (data loads, no geometry is visualized), as no errors appear. If I have scenes with many meshes, the progress gets output to the console (10% loaded, 20%loaded, etc).
任何见解将不胜感激.
推荐答案
我认为您应该改为scene.add( result )
.
这篇关于THREE.ObjectLoader的Three.js错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!