-
Notifications
You must be signed in to change notification settings - Fork 0
/
three_test.html
264 lines (141 loc) · 5.08 KB
/
three_test.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
html, body {
margin: 0;
height: 100%;
}
#c {
width: 100%;
height: 100%;
display: block;
}
.container{
position: absolute;
top: 0;
left: 50%;
width: 50px;
height: 50px;
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<div class="container">
<button class="button" id="turncube">turn cube</button>
<button class="button" id="reset">reset</button>
</div>
</body>
<script type="module">
import * as THREE from '../three.js-dev/build/three.module.js';
import {OrbitControls} from 'https://unpkg.com/[email protected]/examples/jsm/controls/OrbitControls.js';
import {DragControls} from 'https://unpkg.com/[email protected]/examples/jsm/controls/DragControls.js';
import Stats from 'https://unpkg.com/[email protected]/examples/jsm/libs/stats.module.js';
import {GLTFLoader} from 'https://threejsfundamentals.org/threejs/resources/threejs/r122/examples/jsm/loaders/GLTFLoader.js';
import {RGBELoader} from '../three.js-dev/examples/jsm/loaders/RGBELoader.js';
import {RoughnessMipmapper} from 'https://threejs.org/examples/jsm/utils/RoughnessMipmapper.js';
import { PMREMGenerator } from './three.js-dev/src/extras/PMREMGenerator.js';
let globalControl = null;
function main() {
const canvas = document.querySelector('#c');
const renderer = new THREE.WebGLRenderer({canvas});
var stats = new Stats();
stats.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom
document.body.appendChild( stats.dom );
stats.update();
const camera = new THREE.PerspectiveCamera(30, 2, 0.1, 16);
camera.position.z = 2;
const controls = new OrbitControls( camera, renderer.domElement );
controls.update();
controls.autoRotate = true;
globalControl = controls;
const scene = new THREE.Scene();
scene.background = new THREE.Color('grey');
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshPhongMaterial({color: 0x44aa88}); // greenish blue
const cube = new THREE.Mesh(geometry, material);
// scene.add(cube);
const gltfLoader = new GLTFLoader();
gltfLoader.load('https://virbikes.s3.us-east-2.amazonaws.com/flexi_project/scene/models/color_1.glb', (gltf) => {
const root = gltf.scene;
scene.add(root);
});
// new RGBELoader()
// .setDataType( THREE.UnsignedByteType )
// .setPath( 'https://virbikes.s3.us-east-2.amazonaws.com/scene/' )
// .load( 'small_rural_road_1k.hdr', function ( texture ) {
// const envMap = PMREMGenerator.fromEquirectangular( texture ).texture;
// scene.background = envMap;
// scene.environment = envMap;
// texture.dispose();
// PMREMGenerator.dispose();
// render();
// // model
// // use of RoughnessMipmapper is optional
// const roughnessMipmapper = new RoughnessMipmapper( renderer );
// const loader = new GLTFLoader().setPath( 'https://virbikes.s3.us-east-2.amazonaws.com/flexi_project/scene/models/' );
// loader.load( 'color_1.glb', function ( gltf ) {
// gltf.scene.traverse( function ( child ) {
// if ( child.isMesh ) {
// // TOFIX RoughnessMipmapper seems to be broken with WebGL 2.0
// // roughnessMipmapper.generateMipmaps( child.material );
// }
// } );
// scene.add( gltf.scene );
// // roughnessMipmapper.dispose();
// render();
// } );
// } );
// const texture = loader.load('https://threejsfundamentals.org/threejs/resources/images/checker.png');
// gltfLoader.load('https://threejsfundamentals.org/threejs/resources/models/cartoon_lowpoly_small_city_free_pack/scene.gltf', (gltf) => {
// const light = new THREE.DirectionalLight();
// light.position.set(-1, 2, 4);
// scene.add(light);
const light2 = new THREE.HemisphereLight(0xFFFFFF,0xcdcdcd,1);
scene.add(light2);
let value=0;
document.getElementById("turncube").addEventListener("click", function() {
value +=0.1;
cube.rotation.x = value;
material.color.set('red');
console.log(value);
});
function render(time) {
stats.begin();
time *= 0.001;
// cube.rotation.x = 4;
// cube.rotation.y = time;
controls.update();
stats.update();
if (resizeRendererToDisplaySize(renderer)) {
const canvas = renderer.domElement;
camera.aspect = canvas.clientWidth / canvas.clientHeight;
camera.updateProjectionMatrix();
}
renderer.render(scene,camera);
requestAnimationFrame(render);
const canvas = renderer.domElement;
camera.aspect = canvas.clientWidth / canvas.clientHeight;
camera.updateProjectionMatrix();
}
function resizeRendererToDisplaySize(renderer) {
const canvas = renderer.domElement;
const width = canvas.clientWidth;
const height = canvas.clientHeight;
const needResize = canvas.width !== width || canvas.height !== height;
if (needResize) {
renderer.setSize(width, height, false);
}
return needResize;
}
stats.end();
requestAnimationFrame(render);
}
document.getElementById("reset").addEventListener("click", function() {
globalControl.reset();
});
main();
</script>
</html>