Replit 上的 Three.js 库未显示在文档中

发布于 2025-01-10 17:40:50 字数 744 浏览 0 评论 0原文

const scene = new THREE.Scene();

const camera = new THREE.PerspectiveCamera(120, window.innerwidth / window.innerheight, 0.1, 1000);

const renderer = new THREE.WebGLRenderer();

renderer.setSize(window.innerwidth, window.innerheight);

document.body.appendChild(renderer.domElement);

const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({color: 0x000fff});
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);

camera.position.z = 5;

function animate() {
  requestAnimationFrame(animate);

  renderer.render(scene, camera);

}

animate();

我正在使用 Replit 来执行此操作,但是当我运行它时没有显示任何内容,并且没有错误消息。我已经尝试过 replit 上的人的其他代码,他们的代码工作得很好,但他们的代码几乎与我的相同,我也在我的项目中尝试了代码,它工作得很好。

const scene = new THREE.Scene();

const camera = new THREE.PerspectiveCamera(120, window.innerwidth / window.innerheight, 0.1, 1000);

const renderer = new THREE.WebGLRenderer();

renderer.setSize(window.innerwidth, window.innerheight);

document.body.appendChild(renderer.domElement);

const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({color: 0x000fff});
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);

camera.position.z = 5;

function animate() {
  requestAnimationFrame(animate);

  renderer.render(scene, camera);

}

animate();

I am using Replit to do this but nothing is showing when i run it and there is no error message. I have tried other code from people on replit and theirs works fine but their code is almost identical to mine, I also tried there code in my project and it works fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦上情书 2025-01-17 17:40:50

const 相机 = new THREE.PerspectiveCamera(120, window.innerwidth / window.innerheight, 0.1, 1000);
renderer.setSize(window.innerwidth, window.innerheight);

两行都有错别字。应该是:

const camera = new THREE.PerspectiveCamera(120, window.innerWidth / window.innerHeight, 0.1, 1000);

renderer.setSize(window.innerWidth, window.innerHeight);

const camera = new THREE.PerspectiveCamera(120, window.innerwidth / window.innerheight, 0.1, 1000);
renderer.setSize(window.innerwidth, window.innerheight);

There are typos in both lines. It should be:

const camera = new THREE.PerspectiveCamera(120, window.innerWidth / window.innerHeight, 0.1, 1000);

and

renderer.setSize(window.innerWidth, window.innerHeight);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文