-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtown.html
187 lines (157 loc) · 6.81 KB
/
town.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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html>
<head>
<title>KT 융합기술원 - 타운홀 / TED 참가</title>
<meta name="author" content="Sean Bradley" />
<link rel="stylesheet" href="/stylesheets/style.css" />
<style>
body {
overflow: hidden;
margin: 0px;
}
a {
color: #ffffff;
}
#progressBar {
width: 500px;
height: 24px;
position: absolute;
left: 50%;
top: 25px;
margin-left: -250px;
}
#instructions {
color: white;
position: absolute;
left: 50%;
top: 10px;
margin-left: -120px;
font-family: monospace;
}
</style>
</head>
<body>
<a href="/view_source/loader-fbx.html" id="vwSrcLink" target="_blank"><></a>
<progress value="0" max="100" id="progressBar"></progress>
<div id="instructions">
Model from <a href="https://www.mixamo.com" target="_blank" rel="nofollow noopener">Mixamo</a>
</div>
<script type="module">
import * as THREE from 'https://cdn.skypack.dev/[email protected]/build/three.module.js'
import { OrbitControls } from 'https://cdn.skypack.dev/[email protected]/examples/jsm/controls/OrbitControls.js'
import { FBXLoader } from 'https://cdn.skypack.dev/[email protected]/examples/jsm/loaders/FBXLoader.js'
import Stats from 'https://cdn.skypack.dev/[email protected]/examples/jsm/libs/stats.module.js'
const scene = new THREE.Scene()
scene.background = new THREE.Color( 0xFFFFFF );
scene.add(new THREE.AxesHelper(5))
/*
const light = new THREE.PointLight()
light.position.set(0,0,0)
scene.add(light)
const directionalLight = new THREE.DirectionalLight( 0x111111, 0.1 );
scene.add( directionalLight );
*/
const ambientLight = new THREE.AmbientLight( 0xffffff, 1.0 )
scene.add(ambientLight)
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000)
camera.position.set(0.001, 0, 0)
const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
let rot = 0.0;
// PICKING ------------------------------------------
//ground
var ground_texture, ground_material;
ground_texture = THREE.ImageUtils.loadTexture( "./asset/kt_logo.png" );
ground_material = new THREE.MeshLambertMaterial({ map : ground_texture });
//BoxGeometry (makes a geometry)
const boxgeometry = new THREE.BoxGeometry( 0.1,0.1,0.1);
const cube1 = new THREE.Mesh( boxgeometry, ground_material );
cube1.position.set(0.5,0.1,0.5);
cube1.rotation.set(Math.PI / 4,Math.PI / 4,0);
cube1.name = "cube1";
//Adds cube to the scene
scene.add( cube1 );
// PICKING
window.addEventListener('click', onPkCheck, false)
function onPkCheck() {
var mouseVector = new THREE.Vector3();
var raycaster = new THREE.Raycaster();
mouseVector.set((event.clientX / window.innerWidth) * 2 - 1, -(event.clientY / window.innerHeight) * 2 + 1, 0.5);
mouseVector.unproject(camera);
raycaster.set(camera.position, mouseVector.sub(camera.position).normalize());
var interTarget = [];
interTarget.push(cube1);
var intersects = raycaster.intersectObjects(interTarget, true);
if (intersects.length > 0) {
console.log(intersects[0]);
if(intersects[0].object.name=='cube1')
window.open("https://teams.microsoft.com/l/meetup-join/19%3ameeting_YjU1YjIzMmUtOTNlYS00OTk0LWJiZDEtMzg5MGU2Nzc2MGI5%40thread.v2/0?context=%7b%22Tid%22%3a%22e6c9ec09-8430-4a99-bf15-242bc089b409%22%2c%22Oid%22%3a%22772de039-aaa9-4cf9-97f5-22472c2bd375%22%7d");
}
}
const controls = new OrbitControls(camera, renderer.domElement)
controls.enableDamping = true
controls.target.set(0, 0, 0)
const material = new THREE.MeshNormalMaterial()
const fbxLoader = new FBXLoader()
fbxLoader.load(
'asset/town/cafe.fbx',
(object) => {
/*
object.traverse(function (child) {
if (child.isMesh) {
//child.material = material
if (child.material) {
child.material.transparent = false
}
}
})
*/
object.scale.set(0.01, 0.01, 0.01)
scene.add(object)
progressBar.style.display = 'none'
},
(xhr) => {
if (xhr.lengthComputable) {
var percentComplete = (xhr.loaded / xhr.total) * 100
progressBar.value = percentComplete
progressBar.style.display = 'block'
}
},
(error) => {
console.log(error)
}
)
window.addEventListener('resize', onWindowResize, false)
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight
camera.updateProjectionMatrix()
renderer.setSize(window.innerWidth, window.innerHeight)
render()
}
// Add event listener on keydown
document.addEventListener('keydown', (event) => {
var name = event.key;
var code = event.code;
if (name === 'Control') {
window.location = "index.html"
return;
}
}, false);
const stats = Stats()
document.body.appendChild(stats.dom)
function animate() {
requestAnimationFrame(animate)
controls.update()
rot = rot + 0.01;
cube1.rotation.set(Math.PI / 4 + rot,Math.PI / 4 + rot, rot);
render()
stats.update()
}
function render() {
renderer.render(scene, camera)
}
animate()
</script>
</body>
</html>