question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use OBJLoader?

See original GitHub issue

Forgive me if this is a trivial question, but I am trying to load an OBJ from within the three-seed structure, in a similar way to how the standard examples use ObjectLoader, but can’t quite figure out how to get it done.

I import what I assume is the correct loader:

import { Group, OBJLoader } from 'three';

But if I try

const loader = new OBJLoader();

Then I get the error:

TypeError: _threeObjLoader.OBJLoader is not a constructor

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
edwinwebbcommented, Mar 21, 2018

Try this 😃

import { Group, ObjectLoader  } from 'three';
import MODEL from './flower.json';

import * as THREE from 'three';
import OBJLoader from 'three-obj-loader';

export default class Flower extends Group {
  constructor() {
    const loader = new ObjectLoader();
    
    super();

    this.name = 'flower';

    const x = OBJLoader(THREE);
    const y = new THREE.OBJLoader();

    console.log(y.load)

    loader.load(MODEL, (mesh)=>{
      this.add(mesh);
    });
  }
}

logs…

      load(url, onLoad, onProgress, onError) {

      var scope = this;
      this.onError = onError || defaultOnError;

      var loader = new THREE.FileLoader(scope.manager);
      loader.setPath(this.pa…```
0reactions
anselanzacommented, Mar 28, 2018

Wonderful, thank you!

(I had thought somehow that importing from a non-JS file would throw parsing errors, but it seems my understanding of Webpack might be a little deficient.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

OBJLoader – three.js docs
Returns an Object3D. It contains the parsed meshes as Mesh and lines as LineSegments. All geometry is created as BufferGeometry. Default materials are...
Read more >
OBJ Model Loader - Three.js Tutorials - sbcode.net
The 3D models used in this lesson can be easily created using Blender. If you don't want to use blender to create the...
Read more >
Three.js Loading a .OBJ File
The .OBJ loader can be passed an object of name / material pairs. When it loads the .OBJ file, any material name it...
Read more >
Trying to load an object with OBJLoader locally | Three.js
I am testing how three.js works with 3d objects in a web page with a .obj file, I am using OBJLoader to load...
Read more >
Example of loading a Three JS object with OBJLoader as well ...
Still learning observable, JS and Three Js so might not have done it the best way. I want to put limitations on how...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found