-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
143 lines (131 loc) · 4.99 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<title>Document</title>
</head>
<body>
<script src="three.min.js"></script>
<script src="OrbitControls.js"></script>
<script src="DragControls.js"></script>
<script src="GLTFLoader.js"></script>
<script>
// Tentar utilizar arquivos no formato GLB ao invés de GLTF. Aparentemente o resultado é melhor
// Aprender a posiiconar melhor a camera de acordo com os objetos
// Aprender a usar melhor a luz --> threejs documentation Directional Light (Target light)
// Utilizar ROTATE ao inves de ROTATIO, passar valor em radianos
var vlx, vly, vlz , i= 0;
var roll = 0;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x000f00);
//Creating camera
const camera = new THREE.PerspectiveCamera( 25, window.innerWidth / window.innerHeight, 0.1, 1000 );
//Creating Light
var light = new THREE.DirectionalLight(0xffffff, 6);
light.position.set(0,20,10);
//Creating the renderer and appending it to the body of the html
const renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
//Adding plane
var geo = new THREE.PlaneBufferGeometry(2000, 2000, 8, 8);
var mat = new THREE.MeshBasicMaterial({ color: 0xffffff, side: THREE.DoubleSide, transparent: true,opacity: 0 });
var plane = new THREE.Mesh(geo, mat);
plane.rotateX( - Math.PI / 2);
scene.add(plane);
//controls2 = new THREE.OrbitControls(camera, renderer.domElement);
group = new THREE.Object3D();
/*
var cube1 = new THREE.Mesh(new THREE.BoxGeometry(),new THREE.MeshBasicMaterial({
color: 0xffff,
transparent: false,
opacity: 1
}));
*/
const loader = new THREE.GLTFLoader();
loader.load('scene.gltf', function (gltf){
group.add(gltf.scene);
},
function (xhr) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
function (error){
console.log('An error happened');
}
);
camera.position.z = 10;
var cube2 = new THREE.Mesh(
new THREE.BoxGeometry(2,2,2),
new THREE.MeshBasicMaterial({
color: 0x00ff00,
transparent: true,
opacity: 0.0
}));
group.add(cube2);
scene.add(group);
scene.add(light);
const controls = new THREE.DragControls( [scene.children[1]], camera, renderer.domElement );
controls.transformGroup = true;
controls.addEventListener( 'dragstart', function ( event ) {
//roll = false;
roll = 0;
} );
controls.addEventListener( 'dragend', function ( event ) {
//roll = true;
roll=1;
vlx = Math.random()*6.28318531;
vly = Math.random()*6.28318531;
vlz = Math.random()*6.28318531;
} );
/*const rot = () =>{
if(roll==0){
scene.children[1].rotation.x += 0.003;
scene.children[1].rotation.y += 0.003;
scene.children[1].rotation.z += 0.003;
}
if(roll==1){
scene.children[1].rotation.x+= vlx/18;
scene.children[1].rotation.y+= vly/18;
scene.children[1].rotation.z+= vlz/18;
setTimeout(rollStop, 5000);
}
if(roll==3){
scene.children[1].rotation.x+= 0;
scene.children[1].rotation.y+= 0;
scene.children[1].rotation.z+= 0;
}
}*/
const animate = function () {
requestAnimationFrame( animate );
//rot();
if(roll==0){
scene.children[1].rotation.x += 0.003;
scene.children[1].rotation.y += 0.003;
scene.children[1].rotation.z += 0.003;
}
if(roll==1){
vlx -= 0.01;
vly -= 0.01;
vlz -= 0.01;
scene.children[1].rotation.x+= vlx/30;
scene.children[1].rotation.y+= vly/30;
scene.children[1].rotation.z+= vlz/30;
if(vlx < 0 && vly < 0 && vlz <0){
roll=3;
}
}
if(roll==3){
scene.children[1].rotation.x+= 0;
scene.children[1].rotation.y+= 0;
scene.children[1].rotation.z+= 0;
}
renderer.render( scene, camera );
//controls2.update();
};
animate();
</script>
</body>
</html>