【发布时间】:2021-06-22 03:19:00
【问题描述】:
我正在尝试使用 https 链接/文件中的 react-three-fiber 和 threejs 显示 STL 文件。
问题:
- CORS(本地主机 -> https 问题)
- 也无法加载本地文件
我也知道我可以定期使用threejs加载文件(没有尝试过这种方式,也不知道react-3和3之间的正确集成)但我不打算使用它,因为我将全部加载我的模型通过链接,我只是假设在我的情况下使用 react-three-fiber 更好?
我的尝试
import React from 'react';
import {STLLoader} from 'three/examples/jsm/loaders/STLLoader';
import {useLoader} from 'react-three-fiber';
export const Model = ({url}) => {
const res = useLoader(STLLoader,url);
return (
<primitive object={res}/>
)
}
class Layout extends Component {
render() {
const {project} = this.props;
return (
<Canvas>
<Model url={project.tdFiles}/>
</Canvas>
)
}
//project.tDFiles is a string thats a URL to my STL file location
//I've also tired './model.stl' , 'model.stl' to try and load a file locally
}
模型更新
export const Model = (props) => {
const geom = useLoader(STLLoader, './book.stl')
return (
<Canvas>
<mesh args={[geom]}>
<bufferGeometry ref={geom} attach="geometry"/>
<meshStandardMaterial color="hotpink"/>
</mesh>
<ambientLight/>
<pointLight position={[10, 10, 10]}/>
</Canvas>
)
}
我收到错误Error: failure loading ./book.stl
最新更新
import React from 'react';
import {STLLoader} from "three/examples/jsm/loaders/STLLoader";
import {Canvas, useLoader} from "react-three-fiber";
import book from './book.stl'
export const Model = ({url}) => {
const geom = useLoader(STLLoader, book)
return (
<Canvas>
<mesh>
<primitive object={geom}/>
<meshStandardMaterial color="hotpink"/>
</mesh>
<ambientLight/>
<pointLight position={[10, 10, 10]}/>
</Canvas>
)
}
我是这样导入的,现在我没有错误但没有加载任何内容。
【问题讨论】:
标签: reactjs three.js react-three-fiber