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

HtmlMesh doesn't handle html comment (#23657)

* HTMLMesh fix html comment, constants and basic html example
HTMLMesh was not working when the html has a comment (see err below). And use Node constants https://developer.mozilla.org/fr/docs/Web/API/Node/nodeType. Add basic example of html with list in webxr_vr_sandbox

```
HTMLMesh.js:258 Uncaught TypeError: Cannot read properties of undefined (reading 'display')
    at drawElement (HTMLMesh.js:258)
    at drawElement (HTMLMesh.js:307)
    at html2canvas (HTMLMesh.js:337)
    at new HTMLTexture (HTMLMesh.js:54)
    at new HTMLMesh (HTMLMesh.js:14)
    at init (webxr_vr_sandbox.html:224)
    at webxr_vr_sandbox.html:62
```

* Update webxr_vr_sandbox.html

* Update webxr_vr_sandbox.html

Co-authored-by: mrdoob <[email protected]>
Remy Mellet 3 жил өмнө
parent
commit
bac57daa33

+ 6 - 2
examples/js/interactive/HTMLMesh.js

@@ -210,7 +210,7 @@
 				width = 0,
 				height = 0;
 
-			if ( element.nodeType === 3 ) {
+			if ( element.nodeType === Node.TEXT_NODE ) {
 
 				// text
 				range.selectNode( element );
@@ -221,6 +221,10 @@
 				height = rect.height;
 				drawText( style, x, y, element.nodeValue.trim() );
 
+			} else if ( element.nodeType === Node.COMMENT_NODE ) {
+
+				return;
+
 			} else if ( element instanceof HTMLCanvasElement ) {
 
 				// Canvas element
@@ -333,7 +337,7 @@
 
 		function traverse( element ) {
 
-			if ( element.nodeType !== 3 ) {
+			if ( element.nodeType !== Node.TEXT_NODE && element.nodeType !== Node.COMMENT_NODE ) {
 
 				const rect = element.getBoundingClientRect();
 

+ 6 - 2
examples/jsm/interactive/HTMLMesh.js

@@ -223,7 +223,7 @@ function html2canvas( element ) {
 
 		let x = 0, y = 0, width = 0, height = 0;
 
-		if ( element.nodeType === 3 ) {
+		if ( element.nodeType === Node.TEXT_NODE ) {
 
 			// text
 
@@ -238,6 +238,10 @@ function html2canvas( element ) {
 
 			drawText( style, x, y, element.nodeValue.trim() );
 
+		} else if ( element.nodeType === Node.COMMENT_NODE ) {
+
+			return;
+
 		} else if ( element instanceof HTMLCanvasElement ) {
 
 			// Canvas element
@@ -355,7 +359,7 @@ function htmlevent( element, event, x, y ) {
 
 	function traverse( element ) {
 
-		if ( element.nodeType !== 3 ) {
+		if ( element.nodeType !== Node.TEXT_NODE && element.nodeType !== Node.COMMENT_NODE ) {
 
 			const rect = element.getBoundingClientRect();