-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·230 lines (147 loc) · 5.32 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
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
body{
background-color: grey;
margin: 0;
padding: 0;
text-align: center;
}
</style>
</head>
<body>
<div id="container">
</div>
<script type="x-shader/x-vertex" id="vertex-Shader">
varying vec2 vUv;
varying vec3 vPosModel;
varying vec3 vPosWorld;
uniform float t; // tiempo en segundos
uniform float frame; // numero de frame (60 frames x segundo)
void main() {
vec4 aux = vec4(position,1.0);
vPosWorld = (modelMatrix * vec4(aux.xyz, 1.0 )).xyz;
vec2 auxUv=uv;
/*
Objetivo
--------
Aplicar modificaciones a auxUv para que se reproduzcan los 16 cuadros de animacion
cubriendo cada cara completa del cubo;
Las variables t y frame son dependientes del tiempo.
Suegerencias:
1) Verificar que efecto tiene multiplicar auxUv por un factor de escala
2) Verificar que efecto tiene sumar o restar un delta a auxUv.x o auxUv.y
3) Pensar en que modificaciones deben hacerse para que mostrar un cuadro especifico en las caras del cubo.
4) Incluir la variable tiempo
tip: las funciones floor() y mod() pueden ser de utilizada
*/
auxUv *= .25;
auxUv.x += .25 * floor(mod(t * 10., 4.));
auxUv.y += .25 * (3. - mod(floor(t * 10. / 4.), 4.));
vUv = auxUv;
gl_Position = projectionMatrix * modelViewMatrix * aux;
}
</script>
<script type="x-shader/x-fragment" id="fragment-Shader">
precision highp float;
uniform sampler2D textura;
varying vec2 vUv;
varying vec3 vPosModel;
varying vec3 vPosWorld;
uniform float t;
void main() {
vec4 color = vec4(1.0,0.0,0.0, 1.0);
vec4 texColor=texture2D(textura, vUv);
color.x=texColor.x;
color.y=texColor.y;
color.z=texColor.z;
gl_FragColor = color;
}
</script>
<script src="js/three.min.js"></script>
<script src="js/jquery-1.9.1.js"></script>
<script src="js/controls/OrbitControls.js"></script>
<script>
var scene, camera, renderer;
var tex=THREE.ImageUtils.loadTexture( "img/horse.jpg");
tex.wrapS = THREE.RepeatWrapping;
tex.wrapT = THREE.RepeatWrapping;
var attributes = {
};
var uniforms = {
t: {
type: 'f', // a float
value: 0
},
frame: {
type: 'f', // a float
value: 0
},
textura: {
type: "t",
value:tex
}
};
var shaderMaterial = new THREE.ShaderMaterial({
attributes: attributes,
uniforms: uniforms,
vertexShader: $('#vertex-Shader').text(),
fragmentShader: $('#fragment-Shader').text(),
});
function configurarEcena() {
var RENDER_WIDTH = 1200, RENDER_HEIGHT = 900;
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, RENDER_WIDTH / RENDER_HEIGHT, 0.1, 1000);
camera.position.set(5, 5, 5);
renderer = new THREE.WebGLRenderer({preserveDrawingBuffer: true, autoClear: false});
renderer.setSize(RENDER_WIDTH, RENDER_HEIGHT);
renderer.setClearColor(0xffffff, 1);
var container = document.getElementById('container'); //esto vincula Three.js con el Canvas
container.appendChild(renderer.domElement);
controls = new THREE.OrbitControls(camera, container);
controls.target.x = 0;
controls.target.y = 0;
controls.target.z = 0;
}
function agregarLuces()
{
var ambientLight = new THREE.AmbientLight( 0x404040 );
scene.add( ambientLight );
var pointLight = new THREE.PointLight( 0xffffff, 1, 1000 ); // definimos una fuente de Luz puntual de color blanco
pointLight.position.set( 200, 500, 200 ); // definimos su posicion
scene.add( pointLight ); // agregamos la luz a la escena
var pointLight = new THREE.PointLight( 0xffffff, 1, 1000 );
pointLight.position.set( -500, 500, 0 );
scene.add( pointLight );
var pointLight = new THREE.PointLight( 0xffffff, 1, 1000 );
pointLight.position.set( -200, 500, 200 );
scene.add( pointLight );
}
var modelo;
var frame=0;
function render() {
controls.update();
requestAnimationFrame(render);
uniforms.t.value += 1/60;
uniforms.frame.value += 1;
renderer.render(scene, camera,false,false);
frame++;
};
configurarEcena();
agregarLuces();
var geometry = new THREE.BoxGeometry( 5, 5, 5 );
var material = new THREE.MeshBasicMaterial( {color: 0x00ff00} );
var cube = new THREE.Mesh( geometry, shaderMaterial );
//cube.position.y=4;
scene.add( cube );
var size = 10;
var step = 4;
var gridHelper = new THREE.GridHelper( size, step );
//scene.add( gridHelper );
render();
</script>
</body>
</html>