ObjectLoader.parse()
是three.js中的一个函数,用于解析JSON格式的物体模型,并将其转化为three.js中的Object3D对象。
ObjectLoader.parse(json: Object, onLoad: Function, onProgress: Function, onError: Function): Object3D
json
:必填,需要解析的JSON格式的物体模型。onLoad
:选填,当解析完成时执行的回调函数。onProgress
:选填,当解析过程中执行的回调函数,用于显示进度。onError
:选填,当解析发生错误时执行的回调函数。Object3D
:返回一个Object3D对象。import { ObjectLoader } from 'three';
const loader = new ObjectLoader();
loader.load(
'models/model.json',
function ( object ) {
scene.add( object );
},
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
function ( error ) {
console.error( 'Error loading model', error );
}
);