gpt4 book ai didi

javascript - three.js OBJLoader 没有加载 react

转载 作者:数据小太阳 更新时间:2023-10-29 04:41:41 27 4
gpt4 key购买 nike

我正在尝试加载一个对象 (.obj) 文件以与 three.js 一起使用并使用react(使用 react-three-renderer),但得到一个我的代码如下所示:

import React from 'react';
import ReactDOM from 'react-dom';
import React3 from 'react-three-renderer';
import TrackballControls from './TrackballControls';
import * as THREE from 'three';
import * as OBJLoader from 'three-obj-loader';
OBJLoader(THREE);

class MyClass extends React.Component {
...
render() {
...
const objLoader = new THREE.OBJLoader();
}
}

但是,我不断收到:“在‘三’中找不到导出‘OBJLoader’(导入为‘三’)有人有想法吗?

最佳答案

所以似乎将 this.THREE = THREE 添加到 React 组件就可以了(很奇怪,嗯?)。所以我的代码目前看起来像:

import React from 'react';
import ReactDOM from 'react-dom';
import React3 from 'react-three-renderer';
import TrackballControls from './TrackballControls';
import * as THREE from 'three';
import * as OBJLoader from 'three-obj-loader';
OBJLoader(THREE);

class MyClass extends React.Component {
...
render() {
...
this.THREE = THREE;
const objLoader = new this.THREE.OBJLoader();
}
}

关于javascript - three.js OBJLoader 没有加载 react ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45191676/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com