2

我想用three.js 加载一个对象“.obj”。

我的代码:

/********** Imports **********/
import React, { PureComponent } from 'react';
import * as THREE from 'three';
import OBJLoader from 'three-obj-loader';
OBJLoader('THREE');

export class Satellites extends PureComponent {

  componentDidMount() {
    // Satellite Sphere
    this.geometry = new THREE.SphereGeometry( 10, 32, 32 );
    // Texture
    this.texture = new THREE.OBJLoader().load
    ('textures/Satellite.obj',
      texture => {
        this.sat = new THREE.MeshBasicMaterial( { map: this.texture } );
        this.sphere = new THREE.Mesh( this.geometry, this.sat );
        this.props.scene.add( this.sphere );
      }
    )
  }

  render() {
    return null;
  }
}

错误 :

Attempted import error: 'OBJLoader' is not exported from 'three' (imported as 'THREE').

所以我使用这个 我添加了这一行import OBJLoader from 'three-obj-loader';

但是什么都没有......我仍然有这个导入的相同错误!

更多细节:https ://github.com/SolenneD/earth-react

Scene.jsSatellite.js (这是第一个版本,所以没有这段代码,但有一个纹理 .obj)

感谢帮助。

4

0 回答 0