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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
<html>
<head>
<style>
body { margin: 0; }
canvas { width: 100%; height: 100% }
</style>
</head>
<body>
<script src="three.min.js"></script>
<script src="CSG.js"></script>
<script>
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( drawFrame );
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild( renderer.domElement );
var scene = new THREE.Scene();
var aspect = window.innerWidth/window.innerHeight;
var camera = new THREE.PerspectiveCamera( 30, aspect );
// camera.position.set( 0, 1200, 0 );
// camera.lookAt( new THREE.Vector3(0, 0, -1) );
camera.position.set(0, 10, 0);
var cameraLook = new THREE.Vector3(0, 10, 1);
var groundShape = new THREE.Shape();
groundShape.moveTo(-31, 142);
groundShape.lineTo(8, 142);
groundShape.lineTo(38, 164);
groundShape.lineTo(65, 151);
groundShape.lineTo(103, 204);
groundShape.lineTo(152, 214);
groundShape.lineTo(154, 201);
groundShape.lineTo(189, 152);
groundShape.lineTo(208, 123);
groundShape.lineTo(162, 111);
groundShape.lineTo(168, 91);
groundShape.lineTo(136, 90);
groundShape.lineTo(154, 30);
groundShape.lineTo(146, 6);
groundShape.lineTo(197, -38);
groundShape.lineTo(194, -95);
groundShape.lineTo(175, -74);
groundShape.lineTo(142, -88);
groundShape.lineTo(150, -112);
groundShape.lineTo(138, -121);
groundShape.lineTo(132, -142);
groundShape.lineTo(150, -152);
groundShape.lineTo(52, -246);
groundShape.lineTo(-11, -226);
groundShape.lineTo(-86, -276);
groundShape.lineTo(-100, -314);
groundShape.lineTo(-163, -286);
groundShape.lineTo(-116, -242);
groundShape.lineTo(-129, -213);
groundShape.lineTo(-70, -132);
groundShape.lineTo(-56, -136);
groundShape.lineTo(-26, -93);
groundShape.lineTo(-55, -87);
groundShape.lineTo(-80, -62);
groundShape.lineTo(-141, -92);
groundShape.lineTo(-162, -64);
groundShape.lineTo(-106, -20);
groundShape.lineTo(-142, 5);
groundShape.lineTo(-236, -8);
groundShape.lineTo(-252, 146);
groundShape.lineTo(-240, 169);
groundShape.lineTo(-106, 266);
groundShape.lineTo(-112, 162);
groundShape.lineTo(-64, 175);
groundShape.lineTo(-62, 201);
groundShape.lineTo(-24, 197);
var extrudeSettings = { depth: 3, bevelEnabled: true, bevelSegments: 2, steps: 2, bevelSize: 0.1, bevelThickness: 0.1 };
var ground = new THREE.Mesh(new THREE.ExtrudeGeometry( groundShape, extrudeSettings ),
new THREE.MeshPhongMaterial({ color: 'green' }));
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
var uni = new THREE.Mesh(new THREE.BoxGeometry(28, 10, 20),
new THREE.MeshPhongMaterial({ color: 'gray' }));
uni.position.set(42, 5, -111);
uni.rotation.y = Math.PI / 4;
uni.castShadow = true;
scene.add(uni);
var mosque = new THREE.Mesh(new THREE.BoxGeometry(10, 12, 10),
new THREE.MeshPhongMaterial({ color: 0xdec687 }));
mosque.position.set(-181, 6, -30);
mosque.castShadow = true;
scene.add(mosque);
var founders = new THREE.Mesh(new THREE.BoxGeometry(30, 20, 30),
new THREE.MeshPhongMaterial({ color: 0xcdc1c1 }));
founders.position.set(-101, 10, 47);
founders.rotation.y = Math.PI / 4;
founders.castShadow = true;
scene.add(founders);
var lake = new THREE.Mesh(new THREE.BoxGeometry(40, 3, 50),
new THREE.MeshPhongMaterial({ color: 0x9cc0f9 }));
lake.position.set(66, 2, 159);
lake.rotation.y = -Math.PI / 4;
scene.add(lake);
scene.add(ground);
var light = new THREE.PointLight(0xffffff, 0.5);
light.position.set(0,200,0);
light.castShadow = true;
light.target = ground;
scene.add(light);
var ambient = new THREE.AmbientLight(0xffffff, 0.25);
scene.add(ambient);
const MOVE_SPEED = 1.5;
const ROTATION_SPEED = 0.05;
addEventListener("keydown", (event) => {
switch (event.key) {
case 'ArrowUp':
camera.position.x -= MOVE_SPEED * Math.sin(camera.rotation.y);
camera.position.z -= MOVE_SPEED * Math.cos(camera.rotation.y);
break;
case 'ArrowDown':
camera.position.x += MOVE_SPEED * Math.sin(camera.rotation.y);
camera.position.z += MOVE_SPEED * Math.cos(camera.rotation.y);
break;
case 'ArrowLeft':
camera.rotation.y += ROTATION_SPEED;
break;
case 'ArrowRight':
camera.rotation.y -= ROTATION_SPEED;
break;
}
});
function drawFrame()
{
renderer.render( scene, camera );
}
</script>
</body>
</html>
|