ソースを参照

SVGLoader: Fix hole identifier. (#25065)

* SVGLOADER remove paths with a length less than 2 points.

* added extra test

* fix holes

* fix loader
Tom Valkeneers 2 年 前
コミット
580ca9046b

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

@@ -2255,8 +2255,6 @@ class SVGLoader extends Loader {
 		// TODO
 
 		// prepare paths for hole detection
-		let identifier = 0;
-
 		let scanlineMinX = BIGNUMBER;
 		let scanlineMaxX = - BIGNUMBER;
 
@@ -2313,12 +2311,18 @@ class SVGLoader extends Loader {
 
 			}
 
-			return { curves: p.curves, points: points, isCW: ShapeUtils.isClockWise( points ), identifier: identifier ++, boundingBox: new Box2( new Vector2( minX, minY ), new Vector2( maxX, maxY ) ) };
+			return { curves: p.curves, points: points, isCW: ShapeUtils.isClockWise( points ), identifier: -1, boundingBox: new Box2( new Vector2( minX, minY ), new Vector2( maxX, maxY ) ) };
 
 		} );
 
 		simplePaths = simplePaths.filter( sp => sp.points.length > 1 );
 
+		for ( let identifier = 0; identifier < simplePaths.length; identifier++ ) {
+
+			simplePaths[identifier].identifier = identifier;
+
+		}
+
 		// check if path is solid or a hole
 		const isAHole = simplePaths.map( p => isHoleTo( p, simplePaths, scanlineMinX, scanlineMaxX, shapePath.userData?.style.fillRule ) );
 

+ 3 - 0
examples/models/svg/singlePointTest.svg

@@ -0,0 +1,3 @@
+ <svg xmlns="http://www.w3.org/2000/svg">
+    <path d="M 2 -7.3 L 2 -7.3 M 2 -7.2 L 2 -7.4"/>
+  </svg>

+ 5 - 0
examples/models/svg/singlePointTest2.svg

@@ -0,0 +1,5 @@
+<svg xmlns="http://www.w3.org/2000/svg">
+    <g transform="matrix(5.0000,0.0000,0.0000,5.0000,100,100)">
+        <path d="M 5.6 -9.9 L 5.4 -11.9 M 2 -7.3 L 1.7 -6.7 M 2 -7.3 L 2 -7.3 M 2 -7.2 L 2 -7.3 M 2 -7.2 L 2 -7.2 M 2 -7.5 L 2 -7.5 L 1.9 -9.9 L 2.2 -8 L 2.9 -9.6 M 2.4 -8.4 L 2.3 -7.7 L 2.0 -7.2 M 4.4 -6.3 L 4.4 -7.7 L 3.6 -5.4 L 2.7 -2.6 L 3.2 -3.4 L 3.8 -4.7" style="" transform=""/>
+    </g>
+  </svg>

+ 9 - 0
examples/models/svg/singlePointTest3.svg

@@ -0,0 +1,9 @@
+<svg xmlns="http://www.w3.org/2000/svg">
+    <g transform="matrix(5.0000,0.0000,0.0000,5.0000,100,100)">
+        <path d="M 19.236119849058397 17.39499929962357 M 18.779479305038294 15.536343721402552 L 7.861075552403473 19.494468204030596 L 19.61428395903212 13.828702569230778 L 3.599414087449583 5.646679955350668 L 2.43861357223797 2.1757575015276966 M 13.602228390760759 12.928804278027263 M 9.301634244687396 13.954251700835599
+M 6.942641551708241 3.39662501863414 L 12.225782380131871 9.351948415777702 L 18.823865708282256 19.409623721510663 M 19.614023377144257 13.495995025305039 M 16.731027738988868 19.268626257096376 L 10.446250071008858 18.34282797394514 L 17.46629569238116 7.903415848561276 L 13.816801878032518 11.848799982442285 L 18.452186856526602 7.797867818456793
+M 9.256481069281051 5.11094268345523 M 8.631843387794039 2.391037056771407 M 14.73779835068114 17.450993581742953 L 2.7218525185027644 4.023449762366743 L 8.212900415751108 14.708954426300547 M 18.29271259559424 4.310038682901539
+M 14.371547950426525 7.109234927982046 M 19.950306249100436 10.483339050054717 M 5.939529737540385 19.25279733419183 L 15.187835669390303 6.439234331537945 L 20.772513482016727 8.33425652026435
+M 17.986036997832716 7.0810496796789115 M 8.403438874615382 15.015447298863343 L 15.615938624036463 8.939844519927757 L 4.54795856132585 5.344146247518781 L 14.306366934598497 5.308609505459393" style="" transform=""/>
+    </g>
+  </svg>

+ 3 - 0
examples/webgl_loader_svg.html

@@ -121,6 +121,9 @@
 					'Styles in svg tag': 'models/svg/tests/styles.svg',
 					'Round join': 'models/svg/tests/roundJoinPrecisionIssue.svg',
 					'Ellipse Transformations': 'models/svg/tests/ellipseTransform.svg',
+					"singlePointTest": 'models/svg/singlePointTest.svg',
+					"singlePointTest2": 'models/svg/singlePointTest2.svg',
+					"singlePointTest3": 'models/svg/singlePointTest3.svg',
 
 				} ).name( 'SVG File' ).onChange( update );