Bläddra i källkod

Examples: Clean up.

Mugen87 4 år sedan
förälder
incheckning
b093de6308

+ 3 - 1
examples/js/loaders/SVGLoader.js

@@ -386,7 +386,7 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
 						var numbers = parseFloats( data );
 
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
-							
+
 							// skip command if start point == end point
 							if ( numbers[ j + 5 ] == point.x && numbers[ j + 6 ] == point.y ) continue;
 
@@ -667,9 +667,11 @@ THREE.SVGLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype
 		function parseArcCommand( path, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, start, end ) {
 
 			if ( rx == 0 || ry == 0 ) {
+
 				// draw a line if either of the radii == 0
 				path.lineTo( end.x, end.y );
 				return;
+
 			}
 
 			x_axis_rotation = x_axis_rotation * Math.PI / 180;

+ 69 - 41
examples/js/modifiers/EdgeSplitModifier.js

@@ -1,22 +1,23 @@
 
 THREE.EdgeSplitModifier = function () {
 
-	const A = new THREE.Vector3();
-	const B = new THREE.Vector3();
-	const C = new THREE.Vector3();
+	var A = new THREE.Vector3();
+	var B = new THREE.Vector3();
+	var C = new THREE.Vector3();
 
-	let positions, normals;
-	let indexes;
-	let pointToIndexMap, splitIndexes;
+	var positions, normals;
+	var indexes;
+	var pointToIndexMap, splitIndexes;
 
 
 	function computeNormals() {
 
 		normals = new Float32Array( indexes.length * 3 );
 
-		for ( let i = 0; i < indexes.length; i += 3 ) {
+		for ( var i = 0; i < indexes.length; i += 3 ) {
+
+			var index = indexes[ i ];
 
-			let index = indexes[ i ];
 			A.set(
 				positions[ 3 * index ],
 				positions[ 3 * index + 1 ],
@@ -37,9 +38,9 @@ THREE.EdgeSplitModifier = function () {
 			C.sub( B );
 			A.sub( B );
 
-			const normal = C.cross( A ).normalize();
+			var normal = C.cross( A ).normalize();
 
-			for ( let j = 0; j < 3; j ++ ) {
+			for ( var j = 0; j < 3; j ++ ) {
 
 				normals[ 3 * ( i + j ) ] = normal.x;
 				normals[ 3 * ( i + j ) + 1 ] = normal.y;
@@ -56,13 +57,16 @@ THREE.EdgeSplitModifier = function () {
 
 		pointToIndexMap = Array( positions.length / 3 );
 
-		for ( let i = 0; i < indexes.length; i ++ ) {
+		for ( var i = 0; i < indexes.length; i ++ ) {
+
+			var index = indexes[ i ];
 
-			const index = indexes[ i ];
+			if ( pointToIndexMap[ index ] == null ) {
 
-			if ( pointToIndexMap[ index ] == null )
 				pointToIndexMap[ index ] = [];
 
+			}
+
 			pointToIndexMap[ index ].push( i );
 
 		}
@@ -72,27 +76,29 @@ THREE.EdgeSplitModifier = function () {
 
 	function edgeSplitToGroups( indexes, cutOff, firstIndex ) {
 
-		A.set( normals[ 3 * firstIndex ], normals[ 3 * firstIndex + 1 ], normals[ 3 * firstIndex + 2 ] )
-			.normalize();
+		A.set( normals[ 3 * firstIndex ], normals[ 3 * firstIndex + 1 ], normals[ 3 * firstIndex + 2 ] ).normalize();
 
-		const result = {
+		var result = {
 			splitGroup: [],
 			currentGroup: [ firstIndex ]
 		};
 
-		for ( const j of indexes ) {
+		for ( var j of indexes ) {
 
 			if ( j !== firstIndex ) {
 
-				B.set( normals[ 3 * j ], normals[ 3 * j + 1 ], normals[ 3 * j + 2 ] )
-					.normalize();
+				B.set( normals[ 3 * j ], normals[ 3 * j + 1 ], normals[ 3 * j + 2 ] ).normalize();
+
+				if ( B.dot( A ) < cutOff ) {
 
-				if ( B.dot( A ) < cutOff )
 					result.splitGroup.push( j );
 
-				else
+				} else {
+
 					result.currentGroup.push( j );
 
+				}
+
 			}
 
 		}
@@ -104,27 +110,44 @@ THREE.EdgeSplitModifier = function () {
 
 	function edgeSplit( indexes, cutOff, original = null ) {
 
-		if ( indexes.length === 0 )
-			return;
+		if ( indexes.length === 0 ) return;
+
+		var groupResults = [];
+
+		for ( var index of indexes ) {
 
-		const groupResults = [];
-		for ( const index of indexes )
 			groupResults.push( edgeSplitToGroups( indexes, cutOff, index ) );
 
-		let result = groupResults[ 0 ];
-		for ( const groupResult of groupResults )
-			if ( groupResult.currentGroup.length > result.currentGroup.length )
+		}
+
+		var result = groupResults[ 0 ];
+
+		for ( var groupResult of groupResults ) {
+
+			if ( groupResult.currentGroup.length > result.currentGroup.length ) {
+
 				result = groupResult;
 
-		if ( original != null )
+			}
+
+		}
+
+
+		if ( original != null ) {
+
 			splitIndexes.push( {
 				original: original,
 				indexes: result.currentGroup
 			} );
 
-		if ( result.splitGroup.length )
+		}
+
+		if ( result.splitGroup.length ) {
+
 			edgeSplit( result.splitGroup, cutOff, original || result.currentGroup[ 0 ] );
 
+		}
+
 	}
 
 
@@ -137,44 +160,49 @@ THREE.EdgeSplitModifier = function () {
 		}
 
 
-		if ( geometry.index == null )
+		if ( geometry.index == null ) {
+
 			geometry = THREE.BufferGeometryUtils.mergeVertices( geometry );
 
+		}
 
 		indexes = geometry.index.array;
 		positions = geometry.getAttribute( "position" ).array;
 
 		computeNormals();
-
-
 		mapPositionsToIndexes();
 
 
 		splitIndexes = [];
 
-		for ( const vertexIndexes of pointToIndexMap )
+		for ( var vertexIndexes of pointToIndexMap ) {
+
 			edgeSplit( vertexIndexes, Math.cos( cutOffAngle ) - 0.001 );
 
+		}
 
-		const newPositions = new Float32Array( positions.length + 3 * splitIndexes.length );
+		var newPositions = new Float32Array( positions.length + 3 * splitIndexes.length );
 		newPositions.set( positions );
-		const offset = positions.length;
+		var offset = positions.length;
 
-		const newIndexes = new Uint32Array( indexes.length );
+		var newIndexes = new Uint32Array( indexes.length );
 		newIndexes.set( indexes );
 
-		for ( let i = 0; i < splitIndexes.length; i ++ ) {
+		for ( var i = 0; i < splitIndexes.length; i ++ ) {
 
-			const split = splitIndexes[ i ];
-			const index = indexes[ split.original ];
+			var split = splitIndexes[ i ];
+			var index = indexes[ split.original ];
 
 			newPositions[ offset + 3 * i ] = positions[ 3 * index ];
 			newPositions[ offset + 3 * i + 1 ] = positions[ 3 * index + 1 ];
 			newPositions[ offset + 3 * i + 2 ] = positions[ 3 * index + 2 ];
 
-			for ( const j of split.indexes )
+			for ( var j of split.indexes ) {
+
 				newIndexes[ j ] = offset / 3 + i;
 
+			}
+
 		}
 
 		geometry = new THREE.BufferGeometry();

+ 3 - 1
examples/jsm/loaders/SVGLoader.js

@@ -398,7 +398,7 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 						var numbers = parseFloats( data );
 
 						for ( var j = 0, jl = numbers.length; j < jl; j += 7 ) {
-							
+
 							// skip command if start point == end point
 							if ( numbers[ j + 5 ] == point.x && numbers[ j + 6 ] == point.y ) continue;
 
@@ -679,9 +679,11 @@ SVGLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 		function parseArcCommand( path, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, start, end ) {
 
 			if ( rx == 0 || ry == 0 ) {
+
 				// draw a line if either of the radii == 0
 				path.lineTo( end.x, end.y );
 				return;
+
 			}
 
 			x_axis_rotation = x_axis_rotation * Math.PI / 180;

+ 78 - 44
examples/jsm/modifiers/EdgeSplitModifier.js

@@ -1,25 +1,30 @@
-import { BufferAttribute, BufferGeometry, Vector3 } from "../../../build/three.module.js";
+import {
+	BufferAttribute,
+	BufferGeometry,
+	Vector3
+} from "../../../build/three.module.js";
 import { BufferGeometryUtils } from "../utils/BufferGeometryUtils.js";
 
 
-export function EdgeSplitModifier() {
+var EdgeSplitModifier = function () {
 
-	const A = new Vector3();
-	const B = new Vector3();
-	const C = new Vector3();
+	var A = new Vector3();
+	var B = new Vector3();
+	var C = new Vector3();
 
-	let positions, normals;
-	let indexes;
-	let pointToIndexMap, splitIndexes;
+	var positions, normals;
+	var indexes;
+	var pointToIndexMap, splitIndexes;
 
 
 	function computeNormals() {
 
 		normals = new Float32Array( indexes.length * 3 );
 
-		for ( let i = 0; i < indexes.length; i += 3 ) {
+		for ( var i = 0; i < indexes.length; i += 3 ) {
+
+			var index = indexes[ i ];
 
-			let index = indexes[ i ];
 			A.set(
 				positions[ 3 * index ],
 				positions[ 3 * index + 1 ],
@@ -40,9 +45,9 @@ export function EdgeSplitModifier() {
 			C.sub( B );
 			A.sub( B );
 
-			const normal = C.cross( A ).normalize();
+			var normal = C.cross( A ).normalize();
 
-			for ( let j = 0; j < 3; j ++ ) {
+			for ( var j = 0; j < 3; j ++ ) {
 
 				normals[ 3 * ( i + j ) ] = normal.x;
 				normals[ 3 * ( i + j ) + 1 ] = normal.y;
@@ -59,13 +64,16 @@ export function EdgeSplitModifier() {
 
 		pointToIndexMap = Array( positions.length / 3 );
 
-		for ( let i = 0; i < indexes.length; i ++ ) {
+		for ( var i = 0; i < indexes.length; i ++ ) {
+
+			var index = indexes[ i ];
 
-			const index = indexes[ i ];
+			if ( pointToIndexMap[ index ] == null ) {
 
-			if ( pointToIndexMap[ index ] == null )
 				pointToIndexMap[ index ] = [];
 
+			}
+
 			pointToIndexMap[ index ].push( i );
 
 		}
@@ -75,27 +83,29 @@ export function EdgeSplitModifier() {
 
 	function edgeSplitToGroups( indexes, cutOff, firstIndex ) {
 
-		A.set( normals[ 3 * firstIndex ], normals[ 3 * firstIndex + 1 ], normals[ 3 * firstIndex + 2 ] )
-			.normalize();
+		A.set( normals[ 3 * firstIndex ], normals[ 3 * firstIndex + 1 ], normals[ 3 * firstIndex + 2 ] ).normalize();
 
-		const result = {
+		var result = {
 			splitGroup: [],
 			currentGroup: [ firstIndex ]
 		};
 
-		for ( const j of indexes ) {
+		for ( var j of indexes ) {
 
 			if ( j !== firstIndex ) {
 
-				B.set( normals[ 3 * j ], normals[ 3 * j + 1 ], normals[ 3 * j + 2 ] )
-					.normalize();
+				B.set( normals[ 3 * j ], normals[ 3 * j + 1 ], normals[ 3 * j + 2 ] ).normalize();
+
+				if ( B.dot( A ) < cutOff ) {
 
-				if ( B.dot( A ) < cutOff )
 					result.splitGroup.push( j );
 
-				else
+				} else {
+
 					result.currentGroup.push( j );
 
+				}
+
 			}
 
 		}
@@ -107,27 +117,44 @@ export function EdgeSplitModifier() {
 
 	function edgeSplit( indexes, cutOff, original = null ) {
 
-		if ( indexes.length === 0 )
-			return;
+		if ( indexes.length === 0 ) return;
+
+		var groupResults = [];
+
+		for ( var index of indexes ) {
 
-		const groupResults = [];
-		for ( const index of indexes )
 			groupResults.push( edgeSplitToGroups( indexes, cutOff, index ) );
 
-		let result = groupResults[ 0 ];
-		for ( const groupResult of groupResults )
-			if ( groupResult.currentGroup.length > result.currentGroup.length )
+		}
+
+		var result = groupResults[ 0 ];
+
+		for ( var groupResult of groupResults ) {
+
+			if ( groupResult.currentGroup.length > result.currentGroup.length ) {
+
 				result = groupResult;
 
-		if ( original != null )
+			}
+
+		}
+
+
+		if ( original != null ) {
+
 			splitIndexes.push( {
 				original: original,
 				indexes: result.currentGroup
 			} );
 
-		if ( result.splitGroup.length )
+		}
+
+		if ( result.splitGroup.length ) {
+
 			edgeSplit( result.splitGroup, cutOff, original || result.currentGroup[ 0 ] );
 
+		}
+
 	}
 
 
@@ -140,44 +167,49 @@ export function EdgeSplitModifier() {
 		}
 
 
-		if ( geometry.index == null )
+		if ( geometry.index == null ) {
+
 			geometry = BufferGeometryUtils.mergeVertices( geometry );
 
+		}
 
 		indexes = geometry.index.array;
 		positions = geometry.getAttribute( "position" ).array;
 
 		computeNormals();
-
-
 		mapPositionsToIndexes();
 
 
 		splitIndexes = [];
 
-		for ( const vertexIndexes of pointToIndexMap )
+		for ( var vertexIndexes of pointToIndexMap ) {
+
 			edgeSplit( vertexIndexes, Math.cos( cutOffAngle ) - 0.001 );
 
+		}
 
-		const newPositions = new Float32Array( positions.length + 3 * splitIndexes.length );
+		var newPositions = new Float32Array( positions.length + 3 * splitIndexes.length );
 		newPositions.set( positions );
-		const offset = positions.length;
+		var offset = positions.length;
 
-		const newIndexes = new Uint32Array( indexes.length );
+		var newIndexes = new Uint32Array( indexes.length );
 		newIndexes.set( indexes );
 
-		for ( let i = 0; i < splitIndexes.length; i ++ ) {
+		for ( var i = 0; i < splitIndexes.length; i ++ ) {
 
-			const split = splitIndexes[ i ];
-			const index = indexes[ split.original ];
+			var split = splitIndexes[ i ];
+			var index = indexes[ split.original ];
 
 			newPositions[ offset + 3 * i ] = positions[ 3 * index ];
 			newPositions[ offset + 3 * i + 1 ] = positions[ 3 * index + 1 ];
 			newPositions[ offset + 3 * i + 2 ] = positions[ 3 * index + 2 ];
 
-			for ( const j of split.indexes )
+			for ( var j of split.indexes ) {
+
 				newIndexes[ j ] = offset / 3 + i;
 
+			}
+
 		}
 
 		geometry = new BufferGeometry();
@@ -188,4 +220,6 @@ export function EdgeSplitModifier() {
 
 	};
 
-}
+};
+
+export { EdgeSplitModifier };

+ 1 - 0
utils/modularize.js

@@ -117,6 +117,7 @@ var files = [
 	{ path: 'misc/Volume.js', dependencies: [ { name: 'VolumeSlice', path: 'misc/VolumeSlice.js' } ], ignoreList: [] },
 	{ path: 'misc/VolumeSlice.js', dependencies: [], ignoreList: [] },
 
+	{ path: 'modifiers/EdgeSplitModifier.js', dependencies: [ { name: 'BufferGeometryUtils', path: 'utils/BufferGeometryUtils.js' } ], ignoreList: [] },
 	{ path: 'modifiers/SimplifyModifier.js', dependencies: [], ignoreList: [] },
 	{ path: 'modifiers/SubdivisionModifier.js', dependencies: [], ignoreList: [] },
 	{ path: 'modifiers/TessellateModifier.js', dependencies: [], ignoreList: [] },