Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Three.js 加载模型-threejs_Three.js - Fatal编程技术网

Three.js 加载模型-threejs

Three.js 加载模型-threejs,three.js,Three.js,我偶然发现了一个将对象加载到three.js视口的问题。教程显示需要使用THREE.ObjectLoader()。就我而言,ObjectLoader在几个版本之前就被删除了。正确加载模型的方法是什么?我应该使用什么加载程序(和文件格式)? 我试过GLTFLoader import * as THREE from "https://cdn.jsdelivr.net/npm/three@0.114/build/three.module.js"; import { OrbitCon

我偶然发现了一个将对象加载到three.js视口的问题。教程显示需要使用THREE.ObjectLoader()。就我而言,ObjectLoader在几个版本之前就被删除了。正确加载模型的方法是什么?我应该使用什么加载程序(和文件格式)? 我试过GLTFLoader

import * as THREE from "https://cdn.jsdelivr.net/npm/three@0.114/build/three.module.js";
import { OrbitControls } from "https://cdn.jsdelivr.net/npm/three@0.114/examples/jsm/controls/OrbitControls.js";
import { GLTFLoader } from 'https://cdn.jsdelivr.net/npm/three@0.114.0/examples/jsm/loaders/GLTFLoader.js';
...
let loader = new GLTFLoader();

loader.load('./models/object.gltf',
    (obj) => {
        scene.add(obj);
    }
);
它向我抛出three.module.js:5562 three.Object3D.add:object不是three.Object3D的实例。 CDN加载程序可在此处找到-


更新:如何使用ObjectLoader导入数据

import * as THREE from "https://cdn.jsdelivr.net/npm/three@0.114/build/three.module.js";
import { OrbitControls } from "https://cdn.jsdelivr.net/npm/three@0.114/examples/jsm/controls/OrbitControls.js;
...
let loader = new THREE.ObjectLoader();

loader.load('./models/object.json',
    (obj) => {
        scene.add(obj);
    }
);

/* throws
   three.module.js:39957 THREE.ObjectLoader: Loading "Geometry"
   is not supported anymore
*/
尚未从存储库中删除。您可以使用它加载
three.js
自定义JSON格式

对于加载在Blender等DCC工具中编写的外部模型,建议使用glTF格式。不幸的是,您没有正确使用加载程序。应该是:

loader.load('./models/object.gltf',
(gltf)=>{
scene.add(gltf.scene);
}
);

为了更好地理解
onLoad()
回调函数的
gltf
参数是如何构造的,我建议您看看
THREE.GLTFLoader
的函数。

明白了。但是我找不到ObjectLoader.js的CDN路径。你能帮我吗?(如果我只是将ObjectLoader.js添加到我的js项目文件夹中,这将需要大量其他导入)
ObjectLoader
是主库的一部分。这意味着包含
three.module.js
就足够了。如果我使用THREE.ObjectLoader,它会抛出“THREE.module.js:39957 THREE.ObjectLoader:不再支持加载“几何体”。如何从JSON加载数据?或者简单地说,如何使用THREE.ObjectLoader导入没有错误的模型?如果消息
加载“几何体”不再受支持。
出现,则表示您正在尝试加载旧的JSON文件。在这种情况下,您必须返回release
r98