-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
74 lines (53 loc) · 2.18 KB
/
main.js
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
import * as THREE from 'three';
import { OBJLoader } from 'three/addons/loaders/OBJLoader.js';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
var camera, scene, renderer, cube;
let object;
await init();
animate();
async function init() {
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
//environment
const path = './textures/skybox/';
const format = '.jpg';
const urls = [
path + 'px' + format, path + 'nx' + format,
path + 'py' + format, path + 'ny' + format,
path + 'pz' + format, path + 'nz' + format
];
const textureCube = new THREE.CubeTextureLoader().load( urls );
scene = new THREE.Scene();
scene.background = textureCube;
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
//var controls = new OrbitControls( camera, renderer.domElement );
// const onProgress = function ( xhr ) {
// if ( xhr.lengthComputable ) {
// const percentComplete = xhr.loaded / xhr.total * 100;
// console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
// }
// };
// const onError = function (e) { console.log(e)};
//load object
const loader = new OBJLoader();
object = await loader.loadAsync('./models/clip.obj');
const geometry = new THREE.BoxGeometry( 1, 1, 1 );
const material = new THREE.MeshBasicMaterial( { color: 0xffffff, envMap: textureCube } );
// cube = new THREE.Mesh( geometry, material );
// scene.add( cube );
object.traverse((mesh) => {
// You can also check for id / name / type here.
mesh.material = material
});
scene.add( object );
camera.position.z = 1.5;
// const axesHelper = new THREE.AxesHelper( 5 );
// scene.add( axesHelper );
}
function animate() {
requestAnimationFrame( animate );
object.rotation.x += 0.01;
object.rotation.y += 0.01;
renderer.render( scene, camera );
}