-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.html
71 lines (61 loc) · 2.37 KB
/
1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Three.js Car Movement</title>
<style>
body { margin: 0; }
canvas { display: block; }
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/OBJLoader.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js"></script>
<script>
const serverAdress = 'http://47.108.186.214:8082/Files/3DEditor'; // 替换为你的服务器地址
// 初始化场景、相机和渲染器
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 light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(10, 10, 10).normalize();
scene.add(light);
// 创建地面
const groundGeometry = new THREE.PlaneGeometry(200, 200);
const groundMaterial = new THREE.MeshStandardMaterial({ color: 0x00ff00 });
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotation.x = -Math.PI / 2;
scene.add(ground);
// 加载警车模型
const loader = new THREE.OBJLoader();
let car;
loader.load(`${serverAdress}/3Dstatic/model3D/警车/警车/obj/policeCar.obj`, function (obj) {
car = obj;
car.scale.set(0.5, 0.5, 0.5); // 根据需要缩放模型
car.position.set(0, 0.5, 0);
scene.add(car);
// 初始化相机位置
camera.position.set(0, 5, 10);
camera.lookAt(car.position);
// GSAP 动画控制
const timeline = gsap.timeline();
// 小车朝一个方向移动
timeline.to(car.position, { x: 10, duration: 2 });
// 小车转弯
timeline.to(car.rotation, { y: Math.PI / 2, duration: 1 });
// 小车再向前移动
timeline.to(car.position, { z: -10, duration: 2 });
});
const animate = () => {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>