三。
我正在尝试将一个3D设计文件(GLTF)实现到具有three.js的网站中,并且我一直在遇到此错误:
这是html/javascript/css code:
<!DOCTYPE html>
<html>
<head>
<meta charset=UTF-8 />
<link rel="stylesheet" type="text/css" href="test2.css" />
</head>
<body>
<script src="../three_import/three.min.js"></script>
<script src="../three_import/OrbitControls.js"></script>
<script src="../three_import/GLTFLoader.js"></script>
<script>
let scene, camera, renderer;
function init() {
scene = new THREE.Scene();
scene.background = new THREE.Color(0xdddddd);
controls = new THREE.OrbitControls(camera);
controls.addEventListener('change', renderer);
hlight = new THREE.AmbientLight (0x404040,100);
scene.add(hlight);
let loader = new THREE.GLTFLoader();
loader.load('../Image/USB.gltf', function(gltf){
car = gltf.scene.children[0];
car.scale.set(0.5,0.5,0.5);
scene.add(gltf.scene);
animate();
});
}
function animate() {
renderer.render(scene,camera);
requestAnimationFrame(animate);
}
init();
</script>
</body>
</html>
我不知道这个错误可能来自什么,而且我尝试了其他人提供的一切,但它不起作用。
谢谢
I'm trying to implement a 3d design file (gltf) into a website with three.js and I'm keeping having this error:
Here is the html/Javascript/CSS code :
<!DOCTYPE html>
<html>
<head>
<meta charset=UTF-8 />
<link rel="stylesheet" type="text/css" href="test2.css" />
</head>
<body>
<script src="../three_import/three.min.js"></script>
<script src="../three_import/OrbitControls.js"></script>
<script src="../three_import/GLTFLoader.js"></script>
<script>
let scene, camera, renderer;
function init() {
scene = new THREE.Scene();
scene.background = new THREE.Color(0xdddddd);
controls = new THREE.OrbitControls(camera);
controls.addEventListener('change', renderer);
hlight = new THREE.AmbientLight (0x404040,100);
scene.add(hlight);
let loader = new THREE.GLTFLoader();
loader.load('../Image/USB.gltf', function(gltf){
car = gltf.scene.children[0];
car.scale.set(0.5,0.5,0.5);
scene.add(gltf.scene);
animate();
});
}
function animate() {
renderer.render(scene,camera);
requestAnimationFrame(animate);
}
init();
</script>
</body>
</html>
I have no idea what this error could come from, and I've tried everything given in othersites and it doesn't work.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这是真的:您的主
脚本
标签是类型text/javaScript
,而不是module
。在您的
html
中,您 不要 需要:相反,您将对主脚本 tag:
请记住,由于我们正在这样做,而不是做
new Trix.orbitControls()
或new Trix.gltfloader()
,我们将使用new OrbitControls()< /code>和
new Gltfloader()
。 (没有三个
)就是这样!
Well, this is true: Your main
script
tag is of typetext/javascript
, notmodule
.In your
HTML
, you don't need:Instead, you would do this to your main
script
tag:Remember, since we are doing this, instead of doing
new THREE.OrbitControls()
ornew THREE.GLTFLoader()
, we would usenew OrbitControls()
andnew GLTFLoader()
. (without theTHREE
)That's all!