【发布时间】:2022-01-09 01:17:13
【问题描述】:
我无法让我的 Three.js 场景显示在 HTML 画布上。我正在导入正确导入的 OBJ 文件。它正确显示所有细节,例如网格、材料等。这是我的代码:
export function TestScene() {
const mountRef = useRef(null);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1,
1000);
const renderer = new THREE.WebGLRenderer();
const loader = new THREE.OBJLoader();
renderer.setSize(window.innerWidth, window.innerHeight);
useEffect(() => {
mountRef.current.appendChild(renderer.domElement);
const animate = function () {
requestAnimationFrame(animate);
renderer.render(scene, camera);
};
loader.load(
'object.obj',
function (object) {
scene.add(object);
camera.position.z = 100;
},
function (xhr) {
console.log((xhr.loaded / xhr.total * 100) + '% loaded');
},
function (error) {
console.log(error);
}
);
animate()
}, [])
return <>
<h1 id='test' style={{ color: 'black' }}>blahhh</h1>
<div ref={mountRef} />
</>
}
【问题讨论】:
-
你的场景中有灯光吗?也许这就是问题所在。
-
我做了一个有强度的灯。我现在确实在场景中看到了它,但仍然没有渲染
-
这里是开发服务器在加载40.114.68.103:3000后在控制台中显示场景@
标签: javascript reactjs three.js 3d webgl