-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
182 lines (149 loc) · 6.35 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Trabalho Computação Gráfica</title>
<style>
body {
margin: 0;
overflow: hidden;
font-family: Arial, sans-serif;
}
#controls {
position: absolute;
top: 10px;
left: 10px;
z-index: 1;
background-color: rgba(255, 255, 255, 0.8);
padding: 10px;
border-radius: 5px;
}
#controls label, #controls select, #controls button, #controls input {
margin-bottom: 5px;
font-size: 20px;
}
</style>
</head>
<body>
<div id="controls">
<label for="particleCount">Quantidade de Partículas:</label>
<input type="number" id="particleCount" value="100">
<button onclick="updateParticles()">Atualizar Partículas</button>
<br>
<label for="particleType">Tipo de Partícula:</label>
<select id="particleType" onchange="updateParticleType()">
<option value="1">Tipo 1</option>
<option value="2">Tipo 2</option>
<option value="3">Tipo 3</option>
</select>
</div>
<!-- Inclui a biblioteca Three.js via CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/110/three.min.js"></script>
<!-- Inclui OrbitControls -->
<script src="https://threejsfundamentals.org/threejs/resources/threejs/r119/examples/js/controls/OrbitControls.js"></script>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
camera.position.z = 100;
var controls = new THREE.OrbitControls(camera, renderer.domElement);
// Load textures
var textureLoader = new THREE.TextureLoader();
var burguerTexture = textureLoader.load('./tex/burguer.png');
var sorveteTexture = textureLoader.load('./tex/sorvete.png');
var particleMaterials = [
new THREE.PointsMaterial({ size: 0.3, vertexColors: THREE.VertexColors }), // Tipo 1
new THREE.PointsMaterial({ size: 0.5, map: burguerTexture }), // Tipo 2
new THREE.PointsMaterial({ size: 0.9, map: sorveteTexture }) // Tipo 3
];
var particleSystem;
var finalPositions = [];
initializeScene();
function initializeScene() {
var loader = new THREE.FontLoader();
loader.load('https://threejs.org/examples/fonts/optimer_bold.typeface.json', function (font) {
var textGeometry = new THREE.TextGeometry('PPGEEC', {
font: font,
size: 30,
height: 1,
curveSegments: 24,
bevelEnabled: true,
bevelThickness: 0.15,
bevelSize: 0.3,
bevelSegments: 5
});
finalPositions = [];
textGeometry.vertices.forEach(function(vertex) {
finalPositions.push(vertex.clone());
});
textGeometry.vertices.forEach(function(vertex) {
vertex.x = Math.random() * 200 - 100;
vertex.y = Math.random() * 200 - 100;
vertex.z = Math.random() * 200 - 100;
});
var colors = [];
for (var i = 0; i < textGeometry.vertices.length; i++) {
colors[i] = new THREE.Color(Math.random() * 0xffffff);
}
textGeometry.colors = colors;
particleSystem = new THREE.Points(textGeometry, particleMaterials[0]);
scene.add(particleSystem);
animate();
});
}
function animate() {
requestAnimationFrame(animate);
controls.update();
for (var i = 0; i < particleSystem.geometry.vertices.length; i++) {
var particle = particleSystem.geometry.vertices[i];
var finalPosition = finalPositions[i];
particle.lerp(finalPosition, 0.02);
if (particle.distanceTo(finalPosition) < 0.1) {
particle.set(Math.random() * 100 - 50, Math.random() * 100 - 50, Math.random() * 100 - 50);
}
}
particleSystem.geometry.verticesNeedUpdate = true;
renderer.render(scene, camera);
}
function updateParticles() {
var count = document.getElementById('particleCount').value;
scene.remove(particleSystem); // remove as partículas da cena
var loader = new THREE.FontLoader();
loader.load('https://threejs.org/examples/fonts/optimer_bold.typeface.json', function (font) {
var textGeometry = new THREE.TextGeometry('PPGEEC', {
font: font,
size: 30,
height: 1,
curveSegments: 24,
bevelEnabled: true,
bevelThickness: 0.15,
bevelSize: 0.3,
bevelSegments: 5
});
finalPositions = [];
textGeometry.vertices.forEach(function(vertex) {
finalPositions.push(vertex.clone());
});
textGeometry.vertices.forEach(function(vertex) {
vertex.x = Math.random() * 200 - 100;
vertex.y = Math.random() * 200 - 100;
vertex.z = Math.random() * 200 - 100;
});
var colors = [];
for (var i = 0; i < count; i++) {
colors[i] = new THREE.Color(Math.random() * 0xffffff);
}
textGeometry.colors = colors;
particleSystem = new THREE.Points(textGeometry, particleMaterials[0]);
scene.add(particleSystem);
});
}
function updateParticleType() {
var particleType = document.getElementById('particleType').value;
particleSystem.material = particleMaterials[particleType - 1];
}
</script>
</body>
</html>