How to use the ObjectLoader function from three

Find comprehensive JavaScript three.ObjectLoader code examples handpicked from public code repositorys.

The three.ObjectLoader is a class that is used to load and parse object data in Three.js.

112
113
114
115
116
117
118
119
120
121
        }
    }
    return null;
}

// The ExtensibleObjectLoader extends the THREE.ObjectLoader
// interface, while providing some hooks for us to perform some
// custom loading for things other than three.js native JSON.
//
// We currently use this class to support some extensions to
fork icon35
star icon0
watch icon1

117
118
119
120
121
122
123
124
125
126

    return deferred.promise;
};

var postProcessWorld = function (json) {
    var loader = new THREE.ObjectLoader();

    var obj = loader.parse(json);

    var mergedMeshesGeometry = new THREE.Geometry();
fork icon13
star icon30
watch icon17

How does three.ObjectLoader work?

three.ObjectLoader is a class in the Three.js library that provides a way to load 3D models from external files in various formats and convert them into Three.js scene objects, using the JSON data format. It is capable of asynchronously loading multiple models and can handle animations, materials, and textures. The class exposes methods for loading different types of assets such as geometry, materials, and animations, and can be customized with options such as loading manager and URL modifier.

22
23
24
25
26
27
28
29
30
31
this.camera = State.get('camera');
this.scene = State.get('scene');

this.counter = 0;

var objectLoader = new THREE.ObjectLoader();
var self = this;
objectLoader.load('models/ground.json', function (obj) {
  obj.children.forEach(function (value) {
    if (value instanceof THREE.Mesh) {
fork icon10
star icon33
watch icon10

+ 3 other calls in file

367
368
369
370
371
372
373
374
375
376
// everything is loaded.
this.loadingManager = new THREE.LoadingManager();
this.loadingManager.onLoad = this.onLoad.bind(this);

// Load the Android model by fetching it from the server.
const loader = new THREE.ObjectLoader(this.loadingManager);
loader.load("assets/android.json", object => {

  // Save a reference to the loaded android model.
  this.android = object;
fork icon1
star icon11
watch icon1

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import * as THREE from "three";

const loader = new THREE.ObjectLoader();
loader.load(
  "models/mymodel.json",
  function (object) {
    scene.add(object);
  },
  function (xhr) {
    console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
  },
  function (error) {
    console.log("An error happened");
  }
);

In this example, a new ObjectLoader is created from the three library. The load() method is then called on the loader with the path to the JSON file to load, a callback function to run when the model has been loaded, a progress function to report on the load progress, and an error function to handle any loading errors. Once the model has been loaded, it is added to the scene.

78
79
80
81
82
83
84
85
86
87
// )

// box.name = 'box'
scene.add(customWave)

const loader = new THREE.ObjectLoader()
loader.load('./model.json', (object) => {
  console.log('geometry', object.geometry)
  const something = new THREE.Mesh(object.geometry, material)
  something.position.z = 60
fork icon0
star icon1
watch icon2

2
3
4
5
6
7
8
9
10
11
//import * as THREE from 'https://unpkg.com/three@0.126.1/build/three.module.js';
//import { OrbitControls } from 'https://unpkg.com/three@0.126.1/examples/jsm/controls/OrbitControls.js';
//const THREE = require('three');
import * as THREE from 'three'

const loader = new THREE.ObjectLoader();
const scene = new THREE.Scene();
loader.load(
        // resource URL
        '../models/json/human.json',
fork icon719
star icon0
watch icon0

19
20
21
22
23
24
25
26
27
28
29
30
// obj 加载器
const objLoader = new THREE.OBJLoader();
objLoader.setPath(MODEL_PATH);


// json 模型加载器
const objectLoader = new THREE.ObjectLoader();
objectLoader.setTexturePath(MODEL_PATH);


// prefab 数据加载器
const prefLoader = new THREE.FileLoader();
fork icon1
star icon0
watch icon1

540
541
542
543
544
545
546
547
548
549
550
};


var onError = function( xhr ) {
	console.error( xhr );
};
//var loader = new THREE.ObjectLoader();
var loader = new THREE.ColladaLoader( manager );
//var loader = new THREE.FBXLoader( manager ); // create a new loader to load collada files and use the download manager
loader.load( myScene.fileToLoad , 
function( object ) {
fork icon0
star icon0
watch icon0

+ 2 other calls in file

321
322
323
324
325
326
327
328
329
330

this.inv = data.inv;

for (let key in data.stats) this[key] = data.stats[key];

let loader = new THREE.ObjectLoader();

loader.load(`/assets/3d/${data.path}.json`, (object) => {

    G.get('cache').json[data.path] = object;
fork icon0
star icon0
watch icon0

+ 3 other calls in file

134
135
136
137
138
139
140
141
142
143
144
    !(event.keyCode == 69) || interact(event); // E
    !(event.keyCode == 81) || attack(event); // Q
    !(event.keyCode == 82) || attackAlt(event); // R
});


new THREE.ObjectLoader().load('/assets/3d/sword/sword.json', (weapon) => {
    G.get('camera').add(weapon);
    weapon.scale.set(0.1, 0.1, 0.1);
    weapon.position.x++;
    weapon.position.y -= 1.2;
fork icon0
star icon0
watch icon0

38
39
40
41
42
43
44
45
46
47
)
this.renderer.setClearColor(0x444444, 1.0)
this.renderer.shadowMap.enabled = true
this.renderer.shadowMap.type = THREE.PSCFSoftShadowMap

let loader = new THREE.ObjectLoader()
this.scene = loader.parse(baseScene)

this.camera = new THREE.PerspectiveCamera(this.VIEW_ANGLE, this.ASPECT, this.NEAR, this.FAR)
this.camera.position.set(-200, 200, -200)
fork icon0
star icon0
watch icon1

Other functions in three

Sorted by popularity

function icon

three.Vector3 is the most popular function in three (22341 examples)