2

I've stumbled upon an issue with loading objects into three.js viewport. Tutorials show that it's required to use THREE.ObjectLoader(). As far as I'm concerned, ObjectLoader was removed a few versions ago. What's the way of loading models correctly or what loader (and file format) should I use? I tried GLTFLoader

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

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

It throws me three.module.js:5562 THREE.Object3D.add: object not an instance of THREE.Object3D. CDN loaders can be found here - https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/loaders/


Update: How to import data using ObjectLoader?

import * as THREE from "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js";
import { OrbitControls } from "https://cdn.jsdelivr.net/npm/[email protected]/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
*/

1 Answer 1

1

THREE.ObjectLoader has not been removed from the repository. You can use it for loading three.js custom JSON format.

For loading external models authored in DCC tools like Blender, the recommended 3D format is glTF. Unfortunately, you do not use the loader correctly. It should be:

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

I suggest you have a look at the official documentation page of THREE.GLTFLoader in order to better understand how the gltf parameter of the onLoad() callback is structured.

Sign up to request clarification or add additional context in comments.

9 Comments

Got it. But I can't find the CDN path to ObjectLoader.js . Could u help me with that, please? (If I simply add ObjectLoader.js to my js project folder that will require a lot of other imports)
ObjectLoader is part of the main library. Meaning its sufficient to include three.module.js.
Okay. If I use THREE.ObjectLoader it throws me "three.module.js:39957 THREE.ObjectLoader: Loading "Geometry" is not supported anymore.". How can I load data from JSON instead?
Or simply how to import models with no errors using THREE.ObjectLoader ?
It the message Loading "Geometry" is not supported anymore. appears, that means you are try to load legacy JSON files. In this case, you have to go back to release r98.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.