Skip to content

Commit 6b8f175

Browse files
committed
Clean up.
1 parent 41db6f6 commit 6b8f175

File tree

1 file changed

+31
-45
lines changed

1 file changed

+31
-45
lines changed

examples/webgl_modifier_subdivision.html

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
var F = function( klass, args ) {
3636

37-
return klass.apply( this, args );
37+
return klass.apply( this, args );
3838

3939
};
4040

@@ -61,7 +61,7 @@
6161

6262
{ type: 'BoxGeometry', args: [ 200, 200, 200, 2, 2, 2, materials ] },
6363
{ 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 },
6565
{ type: 'SphereGeometry', args: [ 100, 3, 3 ], meshScale:2 },
6666
{ type: 'IcosahedronGeometry', args: [ 100, 1 ], meshScale:2 },
6767
{ type: 'CylinderGeometry', args: [ 25, 75, 200, 8, 3 ]} ,
@@ -158,10 +158,10 @@
158158

159159
var dropdown = '<select id="dropdown" onchange="switchGeometry(this.value)">';
160160

161-
for ( i = 0; i < geometriesParams.length; i ++ ) {
161+
for ( var i = 0; i < geometriesParams.length; i ++ ) {
162162
dropdown += '<option value="' + i + '"';
163163

164-
dropdown += (geometryIndex == i) ? ' selected' : '';
164+
dropdown += (geometryIndex == i) ? ' selected' : '';
165165

166166
dropdown += '>' + geometriesParams[i].type + '</option>';
167167
}
@@ -170,27 +170,25 @@
170170

171171
info.innerHTML = 'Drag to spin THREE.' + params.type +
172172

173-
'<br><br>Subdivisions: ' + subdivisions +
173+
'<br><br>Subdivisions: ' + subdivisions +
174174
' <a href="#" onclick="nextSubdivision(1); return false;">more</a>/<a href="#" onclick="nextSubdivision(-1); return false;">less</a>' +
175175
'<br>Geometry: ' + dropdown + ' <a href="#" onclick="nextGeometry();return false;">next</a>' +
176176
'<br><br>Vertices count: before ' + geometry.vertices.length + ' after ' + (smooth.attributes.position.array.length/3) +
177177
'<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+
180179
}
181180

182181
function addStuff() {
183182

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+
191185
geometry.dispose();
186+
material.dispose();
192187
smooth.dispose();
193188

189+
scene.remove( group );
190+
scene.remove( cube );
191+
194192
}
195193

196194

@@ -209,61 +207,48 @@
209207

210208
}
211209

212-
// Cloning original geometry for debuging
210+
smooth = modifier.modify( geometry );
213211

214-
//smooth = geometry.clone(); // removed because the BufferSubdivisionModifier doesn't modify the original object.
212+
updateInfo();
215213

216-
// mergeVertices(); is run in the subdivision modifier
214+
var faceABCD = "abcd";
217215

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' ] );
219218

220-
updateInfo();
219+
for ( var i = 0; i < smooth.attributes.position.array.length / 3; i ++ ) {
221220

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 ] );
233224

234225
}
235-
colors.trim_size();
236-
smooth.addAttribute('color', new THREE.BufferAttribute(colors.buffer,3));
237226

227+
colors.trim_size();
228+
smooth.addAttribute( 'color', new THREE.BufferAttribute( colors.buffer, 3 ) );
238229

239230
group = new THREE.Group();
240231
scene.add( group );
241232

242-
material = new THREE.MeshBasicMaterial( { color: 0xfefefe, wireframe: true, opacity: 0.5 } );
233+
material = new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: true } );
243234
mesh = new THREE.Mesh( geometry, material );
244235
group.add( mesh );
245236

246237
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 } )
249240
];
250241

251242
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 );
259244
scene.add( cube );
260245

261246
group.scale.copy( cube.scale );
262247

263248
}
264249

265250
function init() {
266-
cube = false;
251+
267252
container = document.createElement( 'div' );
268253
document.body.appendChild( container );
269254

@@ -286,7 +271,7 @@
286271

287272
addStuff();
288273

289-
renderer = new THREE.WebGLRenderer( { antialias: true } ); // WebGLRenderer CanvasRenderer
274+
renderer = new THREE.WebGLRenderer( { antialias: true } );
290275
renderer.setClearColor( 0xf0f0f0 );
291276
renderer.setPixelRatio( window.devicePixelRatio );
292277
renderer.setSize( window.innerWidth, window.innerHeight );
@@ -320,8 +305,9 @@
320305

321306
controls.update();
322307

308+
stats.begin();
323309
render();
324-
stats.update();
310+
stats.end();
325311

326312
}
327313

0 commit comments

Comments
 (0)