|
34 | 34 |
|
35 | 35 | var F = function( klass, args ) {
|
36 | 36 |
|
37 |
| - return klass.apply( this, args ); |
| 37 | + return klass.apply( this, args ); |
38 | 38 |
|
39 | 39 | };
|
40 | 40 |
|
|
61 | 61 |
|
62 | 62 | { type: 'BoxGeometry', args: [ 200, 200, 200, 2, 2, 2, materials ] },
|
63 | 63 | { type: 'TorusGeometry', args: [ 100, 60, 4, 8, Math.PI*2 ] },
|
64 |
| - { type: 'TorusKnotGeometry', args: [ ], scale:0.25, meshScale:4 }, |
| 64 | + { type: 'TorusKnotGeometry', args: [], scale:0.25, meshScale:4 }, |
65 | 65 | { type: 'SphereGeometry', args: [ 100, 3, 3 ], meshScale:2 },
|
66 | 66 | { type: 'IcosahedronGeometry', args: [ 100, 1 ], meshScale:2 },
|
67 | 67 | { type: 'CylinderGeometry', args: [ 25, 75, 200, 8, 3 ]} ,
|
|
158 | 158 |
|
159 | 159 | var dropdown = '<select id="dropdown" onchange="switchGeometry(this.value)">';
|
160 | 160 |
|
161 |
| - for ( i = 0; i < geometriesParams.length; i ++ ) { |
| 161 | + for ( var i = 0; i < geometriesParams.length; i ++ ) { |
162 | 162 | dropdown += '<option value="' + i + '"';
|
163 | 163 |
|
164 |
| - dropdown += (geometryIndex == i) ? ' selected' : ''; |
| 164 | + dropdown += (geometryIndex == i) ? ' selected' : ''; |
165 | 165 |
|
166 | 166 | dropdown += '>' + geometriesParams[i].type + '</option>';
|
167 | 167 | }
|
|
170 | 170 |
|
171 | 171 | info.innerHTML = 'Drag to spin THREE.' + params.type +
|
172 | 172 |
|
173 |
| - '<br><br>Subdivisions: ' + subdivisions + |
| 173 | + '<br><br>Subdivisions: ' + subdivisions + |
174 | 174 | ' <a href="#" onclick="nextSubdivision(1); return false;">more</a>/<a href="#" onclick="nextSubdivision(-1); return false;">less</a>' +
|
175 | 175 | '<br>Geometry: ' + dropdown + ' <a href="#" onclick="nextGeometry();return false;">next</a>' +
|
176 | 176 | '<br><br>Vertices count: before ' + geometry.vertices.length + ' after ' + (smooth.attributes.position.array.length/3) +
|
177 | 177 | '<br>Face count: before ' + geometry.faces.length + ' after ' + (smooth.attributes.position.array.length / 3)
|
178 |
| - /* since the result is unindex'd the face count will always be directly related to the vertice count */ |
179 |
| - ; //+ params.args; |
| 178 | + |
180 | 179 | }
|
181 | 180 |
|
182 | 181 | function addStuff() {
|
183 | 182 |
|
184 |
| - if ( cube != false ) { |
185 |
| - |
186 |
| - scene.remove( group ); |
187 |
| - scene.remove(cube); |
188 |
| - scene.remove(mesh); |
189 |
| - //mesh.dispose(); |
190 |
| - material.dispose(); |
| 183 | + if ( cube !== undefined ) { |
| 184 | + |
191 | 185 | geometry.dispose();
|
| 186 | + material.dispose(); |
192 | 187 | smooth.dispose();
|
193 | 188 |
|
| 189 | + scene.remove( group ); |
| 190 | + scene.remove( cube ); |
| 191 | + |
194 | 192 | }
|
195 | 193 |
|
196 | 194 |
|
|
209 | 207 |
|
210 | 208 | }
|
211 | 209 |
|
212 |
| - // Cloning original geometry for debuging |
| 210 | + smooth = modifier.modify( geometry ); |
213 | 211 |
|
214 |
| - //smooth = geometry.clone(); // removed because the BufferSubdivisionModifier doesn't modify the original object. |
| 212 | + updateInfo(); |
215 | 213 |
|
216 |
| - // mergeVertices(); is run in the subdivision modifier |
| 214 | + var faceABCD = "abcd"; |
217 | 215 |
|
218 |
| - smooth = modifier.modify( geometry ); |
| 216 | + // var TypedArrayHelper = function (size, registers, register_type, array_type, unit_size, accessors) |
| 217 | + var colors = new TypedArrayHelper( 0, 1, THREE.Color, Float32Array, 3, [ 'r', 'g', 'b' ] ); |
219 | 218 |
|
220 |
| - updateInfo(); |
| 219 | + for ( var i = 0; i < smooth.attributes.position.array.length / 3; i ++ ) { |
221 | 220 |
|
222 |
| - var faceABCD = "abcd"; |
223 |
| - |
224 |
| - var i; |
225 |
| - // var tmp_v = new THREE.Vector3(); |
226 |
| - var colors = new TypedArrayHelper(0, 1, THREE.Color, Float32Array, 3, ['r', 'g', 'b']); // var TypedArrayHelper = function (size, registers, register_type, array_type, unit_size, accessors) |
227 |
| - for (i = 0; i < smooth.attributes.position.array.length / 3; i++) { |
228 |
| - // tmp_v.x = smooth.attributes.position.array[i * 3]; |
229 |
| - // tmp_v.y = smooth.attributes.position.array[(i * 3)+1]; |
230 |
| - // tmp_v.z = smooth.attributes.position.array[(i * 3) + 2]; |
231 |
| - colors.register[0].setHSL((smooth.attributes.position.array[(i * 3) + 1] / 200) + 0.5, 1, 0.5); |
232 |
| - colors.push_element(colors.register[0]); |
| 221 | + var hue = ( smooth.attributes.position.array[ ( i * 3 ) + 1 ] / 200 ) + 0.5; |
| 222 | + colors.register[ 0 ].setHSL( hue, 1, 0.5 ); |
| 223 | + colors.push_element( colors.register[ 0 ] ); |
233 | 224 |
|
234 | 225 | }
|
235 |
| - colors.trim_size(); |
236 |
| - smooth.addAttribute('color', new THREE.BufferAttribute(colors.buffer,3)); |
237 | 226 |
|
| 227 | + colors.trim_size(); |
| 228 | + smooth.addAttribute( 'color', new THREE.BufferAttribute( colors.buffer, 3 ) ); |
238 | 229 |
|
239 | 230 | group = new THREE.Group();
|
240 | 231 | scene.add( group );
|
241 | 232 |
|
242 |
| - material = new THREE.MeshBasicMaterial( { color: 0xfefefe, wireframe: true, opacity: 0.5 } ); |
| 233 | + material = new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: true } ); |
243 | 234 | mesh = new THREE.Mesh( geometry, material );
|
244 | 235 | group.add( mesh );
|
245 | 236 |
|
246 | 237 | var meshmaterials = [
|
247 |
| - new THREE.MeshPhongMaterial({ color: 0xffffff, shading: THREE.FlatShading, vertexColors: THREE.VertexColors, shininess: 0 }), |
248 |
| - new THREE.MeshBasicMaterial( { color: 0x405040, wireframe: true, opacity: 0.8, transparent: true } ) |
| 238 | + new THREE.MeshPhongMaterial( { color: 0xffffff, shading: THREE.FlatShading, vertexColors: THREE.VertexColors } ), |
| 239 | + new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true, opacity: 0.15, transparent: true } ) |
249 | 240 | ];
|
250 | 241 |
|
251 | 242 | cube = THREE.SceneUtils.createMultiMaterialObject( smooth, meshmaterials );
|
252 |
| - |
253 |
| - var meshScale = params.meshScale ? params.meshScale : 1; |
254 |
| - |
255 |
| - cube.scale.x = meshScale; |
256 |
| - cube.scale.y = meshScale; |
257 |
| - cube.scale.z = meshScale; |
258 |
| - |
| 243 | + cube.scale.setScalar( params.meshScale ? params.meshScale : 1 ); |
259 | 244 | scene.add( cube );
|
260 | 245 |
|
261 | 246 | group.scale.copy( cube.scale );
|
262 | 247 |
|
263 | 248 | }
|
264 | 249 |
|
265 | 250 | function init() {
|
266 |
| - cube = false; |
| 251 | + |
267 | 252 | container = document.createElement( 'div' );
|
268 | 253 | document.body.appendChild( container );
|
269 | 254 |
|
|
286 | 271 |
|
287 | 272 | addStuff();
|
288 | 273 |
|
289 |
| - renderer = new THREE.WebGLRenderer( { antialias: true } ); // WebGLRenderer CanvasRenderer |
| 274 | + renderer = new THREE.WebGLRenderer( { antialias: true } ); |
290 | 275 | renderer.setClearColor( 0xf0f0f0 );
|
291 | 276 | renderer.setPixelRatio( window.devicePixelRatio );
|
292 | 277 | renderer.setSize( window.innerWidth, window.innerHeight );
|
|
320 | 305 |
|
321 | 306 | controls.update();
|
322 | 307 |
|
| 308 | + stats.begin(); |
323 | 309 | render();
|
324 |
| - stats.update(); |
| 310 | + stats.end(); |
325 | 311 |
|
326 | 312 | }
|
327 | 313 |
|
|
0 commit comments