2
0
Эх сурвалжийг харах

Simplified ExtrudeGeometry UV code.

Mr.doob 10 жил өмнө
parent
commit
be75f8a5bb

+ 0 - 1
examples/index.html

@@ -136,7 +136,6 @@
 				"webgl_geometry_extrude_shapes",
 				"webgl_geometry_extrude_shapes",
 				"webgl_geometry_extrude_shapes2",
 				"webgl_geometry_extrude_shapes2",
 				"webgl_geometry_extrude_splines",
 				"webgl_geometry_extrude_splines",
-				"webgl_geometry_extrude_uvs2",
 				"webgl_geometry_hierarchy",
 				"webgl_geometry_hierarchy",
 				"webgl_geometry_hierarchy2",
 				"webgl_geometry_hierarchy2",
 				"webgl_geometry_large_mesh",
 				"webgl_geometry_large_mesh",

+ 0 - 80
examples/js/utils/UVsUtils.js → examples/js/utils/UVsDebug.js

@@ -1,83 +1,3 @@
-/*
- * @author gyuque / http://github.com/gyuque
- * Cylinder Mapping for ExtrudeGeometry
- */
-
-THREE.UVsUtils = {
-
-};
-
-THREE.UVsUtils.CylinderUVGenerator = function() {
-    this.uRepeat = 1;
-    this.targetGeometry = null;
-    this.lengthCache = null;
-};
-
-THREE.UVsUtils.CylinderUVGenerator.prototype = {
-    generateTopUV: THREE.ExtrudeGeometry.WorldUVGenerator.generateTopUV,
-    generateBottomUV: THREE.ExtrudeGeometry.WorldUVGenerator.generateBottomUV,
-    
-    generateSideWallUV: function( geometry, extrudedShape, wallContour, extrudeOptions,
-                                  indexA, indexB, indexC, indexD, stepIndex, stepsLength,
-                                  contourIndex1, contourIndex2 ) {
-        // first call
-        if (this.targetGeometry !== geometry) {
-            this.prepare(geometry, wallContour);
-        }
-
-        // generate uv
-        var u_list = this.lengthCache;
-        var v1 = stepIndex / stepsLength;
-        var v2 = ( stepIndex + 1 ) / stepsLength;
-        
-        var u1 = u_list[contourIndex1];
-        var u2 = u_list[contourIndex2];
-        if (u1 < u2) {u1 += 1.0;}
-        
-        u1 *= this.uRepeat;
-        u2 *= this.uRepeat;
-        return [
-            new THREE.Vector2( u1, v1 ),
-            new THREE.Vector2( u2, v1 ),
-            new THREE.Vector2( u2, v2 ),
-            new THREE.Vector2( u1, v2 )
-        ];
-    },
-    
-    prepare: function(geometry, wallContour) {
-        var p1, p2;
-        var u_list = [];
-        var lengthSum = 0;
-        var len = wallContour.length;
-        for (var i = 0;i < len;i++) {
-            p1 = wallContour[ i ];
-            p2 = wallContour[ (i+1) % len ];
-
-            var dx = p1.x - p2.x;
-            var dy = p1.y - p2.y;
-            var segmentLength = Math.sqrt(dx*dx + dy*dy);
-            
-            u_list.push(lengthSum);
-            lengthSum += segmentLength;
-        }
-        
-        this.normalizeArray(u_list, lengthSum);
-        this.targetGeometry = geometry;
-        this.lengthCache = u_list;
-    },
-    
-    normalizeArray: function(ls, v) {
-        var len = ls.length;
-        for (var i = 0;i < len;i++) {
-            ls[i] /= v;
-        }
-        
-        return ls;
-    }
-};
-
-
-
 /* 
 /* 
  * @author zz85 / http://github.com/zz85
  * @author zz85 / http://github.com/zz85
  * @author WestLangley / http://github.com/WestLangley
  * @author WestLangley / http://github.com/WestLangley

+ 1 - 52
examples/misc_uv_tests.html

@@ -6,7 +6,7 @@
 	</head>
 	</head>
 	<body>
 	<body>
 		<script src="../build/three.min.js"></script>
 		<script src="../build/three.min.js"></script>
-		<script src="js/utils/UVsUtils.js"></script>
+		<script src="js/utils/UVsDebug.js"></script>
 		<script>
 		<script>
 			/* 
 			/* 
 			 * This is to help debug UVs problems in geometry, 
 			 * This is to help debug UVs problems in geometry, 
@@ -42,57 +42,6 @@
 			test('new THREE.LatheGeometry( points, 8 )', new THREE.LatheGeometry( points, 8 ));
 			test('new THREE.LatheGeometry( points, 8 )', new THREE.LatheGeometry( points, 8 ));
 			test('new THREE.TorusGeometry( 50, 20, 8, 8 )', new THREE.TorusGeometry( 50, 20, 8, 8 ));
 			test('new THREE.TorusGeometry( 50, 20, 8, 8 )', new THREE.TorusGeometry( 50, 20, 8, 8 ));
 			test('new THREE.TorusKnotGeometry( 50, 10, 12, 6 )', new THREE.TorusKnotGeometry( 50, 10, 12, 6 ));
 			test('new THREE.TorusKnotGeometry( 50, 10, 12, 6 )', new THREE.TorusKnotGeometry( 50, 10, 12, 6 ));
-
-			/*
-			Not sure how UVs for ExtrudeGeometry are done currently...
-			*/
-
-			var pts = [], starPoints = 5, l;
-			for (i=0; i<starPoints*2;i++) {
-			  if (i%2==1) {
-			    l = 5;
-			  } else {
-			    l = 10;
-			  }
-
-			  var a = i / starPoints * Math.PI;
-			  pts.push(new THREE.Vector2(Math.cos(a) * l,Math.sin(a) * l ));
-			}
-			var starShape = new THREE.Shape(pts);
-			var extrudeSettings = { amount: 200,  bevelEnabled: true, bevelSegments: 2, steps: 10 }; 
-
-			test('new THREE.ExtrudeGeometry(starShape, extrudeSettings);', new THREE.ExtrudeGeometry(starShape, extrudeSettings));
-
-			var uvGenerator = new THREE.UVsUtils.CylinderUVGenerator();
-					testShape = setupShape(8, 3);
-					holeShape = setupShape(8, 2);
-					testShape.holes.push(holeShape);
-
-			function setupShape(n, r) {
-				// Make shape
-				var sh = new THREE.Shape();
-				for (var i = 0; i < n;i++) {
-					var method = i ? 'lineTo' : 'moveTo';
-					var a = (i/n) * Math.PI * 2;
-					var x = Math.cos(a) * r;
-					var y = Math.sin(a) * r;
-					sh[method](x, y);
-				}
-
-				return sh;
-			}
-
-			var exoption = {
-				bevelEnabled: true,
-				bevelSize: 1,
-				amount: 3,
-				extrudeMaterial: 0,
-				material: 1,
-				uvGenerator: uvGenerator
-			};
-
-			var geom = testShape.extrude(exoption);
-			test('new THREE.ExtrudeGeometry with CylinderUVGenerator;', geom);
 		</script>
 		</script>
 	</body>
 	</body>
 </html>
 </html>

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 172
examples/webgl_geometry_extrude_uvs2.html


+ 20 - 25
src/extras/geometries/ExtrudeGeometry.js

@@ -495,7 +495,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 			for ( i = 0; i < flen; i ++ ) {
 			for ( i = 0; i < flen; i ++ ) {
 
 
 				face = faces[ i ];
 				face = faces[ i ];
-				f3( face[ 2 ]+ offset, face[ 1 ]+ offset, face[ 0 ] + offset, true );
+				f3( face[ 2 ]+ offset, face[ 1 ]+ offset, face[ 0 ] + offset );
 
 
 			}
 			}
 
 
@@ -507,7 +507,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 			for ( i = 0; i < flen; i ++ ) {
 			for ( i = 0; i < flen; i ++ ) {
 
 
 				face = faces[ i ];
 				face = faces[ i ];
-				f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset, false );
+				f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
 
 
 			}
 			}
 
 
@@ -518,7 +518,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 			for ( i = 0; i < flen; i ++ ) {
 			for ( i = 0; i < flen; i ++ ) {
 
 
 				face = faces[ i ];
 				face = faces[ i ];
-				f3( face[ 2 ], face[ 1 ], face[ 0 ], true );
+				f3( face[ 2 ], face[ 1 ], face[ 0 ] );
 
 
 			}
 			}
 
 
@@ -527,7 +527,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 			for ( i = 0; i < flen; i ++ ) {
 			for ( i = 0; i < flen; i ++ ) {
 
 
 				face = faces[ i ];
 				face = faces[ i ];
-				f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps, false );
+				f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
 
 
 			}
 			}
 		}
 		}
@@ -593,7 +593,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 
 	}
 	}
 
 
-	function f3( a, b, c, isBottom ) {
+	function f3( a, b, c ) {
 
 
 		a += shapesOffset;
 		a += shapesOffset;
 		b += shapesOffset;
 		b += shapesOffset;
@@ -602,7 +602,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 		// normal, color, material
 		// normal, color, material
 		scope.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
 		scope.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
 
 
-		var uvs = isBottom ? uvgen.generateBottomUV( scope, shape, options, a, b, c ) : uvgen.generateTopUV( scope, shape, options, a, b, c );
+		var uvs = uvgen.generateTopUV( scope, a, b, c );
 
 
  		scope.faceVertexUvs[ 0 ].push( uvs );
  		scope.faceVertexUvs[ 0 ].push( uvs );
 
 
@@ -618,8 +618,7 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  		scope.faces.push( new THREE.Face3( a, b, d, null, null, extrudeMaterial ) );
  		scope.faces.push( new THREE.Face3( a, b, d, null, null, extrudeMaterial ) );
  		scope.faces.push( new THREE.Face3( b, c, d, null, null, extrudeMaterial ) );
  		scope.faces.push( new THREE.Face3( b, c, d, null, null, extrudeMaterial ) );
 
 
- 		var uvs = uvgen.generateSideWallUV( scope, shape, wallContour, options, a, b, c, d,
- 		                                    stepIndex, stepsLength, contourIndex1, contourIndex2 );
+ 		var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
 
 
  		scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  		scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  		scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  		scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
@@ -630,11 +629,13 @@ THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 
 THREE.ExtrudeGeometry.WorldUVGenerator = {
 THREE.ExtrudeGeometry.WorldUVGenerator = {
 
 
-	generateTopUV: function( geometry, extrudedShape, extrudeOptions, indexA, indexB, indexC ) {
-	
-		var a = geometry.vertices[ indexA ];
-		var b = geometry.vertices[ indexB ];
-		var c = geometry.vertices[ indexC ];
+	generateTopUV: function ( geometry, indexA, indexB, indexC ) {
+
+		var vertices = geometry.vertices;
+
+		var a = vertices[ indexA ];
+		var b = vertices[ indexB ];
+		var c = vertices[ indexC ];
 
 
 		return [
 		return [
 			new THREE.Vector2( a.x, a.y ),
 			new THREE.Vector2( a.x, a.y ),
@@ -644,20 +645,14 @@ THREE.ExtrudeGeometry.WorldUVGenerator = {
 
 
 	},
 	},
 
 
-	generateBottomUV: function( geometry, extrudedShape, extrudeOptions, indexA, indexB, indexC ) {
-
-		return this.generateTopUV( geometry, extrudedShape, extrudeOptions, indexA, indexB, indexC );
-
-	},
+	generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
 
 
-	generateSideWallUV: function( geometry, extrudedShape, wallContour, extrudeOptions,
-	                              indexA, indexB, indexC, indexD, stepIndex, stepsLength,
-	                              contourIndex1, contourIndex2 ) {
+		var vertices = geometry.vertices;
 
 
-		var a = geometry.vertices[ indexA ];
-		var b = geometry.vertices[ indexB ];
-		var c = geometry.vertices[ indexC ];
-		var d = geometry.vertices[ indexD ];
+		var a = vertices[ indexA ];
+		var b = vertices[ indexB ];
+		var c = vertices[ indexC ];
+		var d = vertices[ indexD ];
 
 
 		if ( Math.abs( a.y - b.y ) < 0.01 ) {
 		if ( Math.abs( a.y - b.y ) < 0.01 ) {
 			return [
 			return [

+ 1 - 1
src/extras/geometries/ShapeGeometry.js

@@ -126,7 +126,7 @@ THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
 		var c = face[ 2 ] + shapesOffset;
 		var c = face[ 2 ] + shapesOffset;
 
 
 		this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
 		this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
-		this.faceVertexUvs[ 0 ].push( uvgen.generateBottomUV( this, shape, options, a, b, c ) );
+		this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
 
 
 	}
 	}
 
 

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно