用three.js给我写一个小尺寸的恐龙模型
时间: 2024-05-29 09:03:46 浏览: 154
好的,以下是一个简单的三维恐龙模型代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>恐龙模型</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/loaders/MTLLoader.js"></script>
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/loaders/OBJLoader.js"></script>
<script>
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000
);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const loader = new THREE.MTLLoader();
loader.setPath(
"https://cdn.rawgit.com/mrdoob/three.js/master/examples/models/obj/dinosaur/"
);
loader.load("trex.mtl", function (materials) {
materials.preload();
const objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath(
"https://cdn.rawgit.com/mrdoob/three.js/master/examples/models/obj/dinosaur/"
);
objLoader.load("trex.obj", function (object) {
scene.add(object);
});
});
camera.position.z = 5;
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```
你可以在浏览器中打开这个文件,就可以看到一个小尺寸的恐龙模型了。
阅读全文