Quellcode durchsuchen

DecalGeometry: Transform normal with normal matrix (#29476)

* Transform normal with normal matrix

* Transform normal with normal matrix
WestLangley vor 1 Jahr
Ursprung
Commit
8f765f9e19
2 geänderte Dateien mit 7 neuen und 2 gelöschten Zeilen
  1. 4 1
      examples/jsm/geometries/DecalGeometry.js
  2. 3 1
      examples/webgl_decals.html

+ 4 - 1
examples/jsm/geometries/DecalGeometry.js

@@ -1,6 +1,7 @@
 import {
 import {
 	BufferGeometry,
 	BufferGeometry,
 	Float32BufferAttribute,
 	Float32BufferAttribute,
+	Matrix3,
 	Matrix4,
 	Matrix4,
 	Vector3
 	Vector3
 } from 'three';
 } from 'three';
@@ -36,6 +37,8 @@ class DecalGeometry extends BufferGeometry {
 
 
 		const plane = new Vector3();
 		const plane = new Vector3();
 
 
+		const normalMatrix = new Matrix3().getNormalMatrix( mesh.matrixWorld );
+
 		// this matrix represents the transformation of the decal projector
 		// this matrix represents the transformation of the decal projector
 
 
 		const projectorMatrix = new Matrix4();
 		const projectorMatrix = new Matrix4();
@@ -146,7 +149,7 @@ class DecalGeometry extends BufferGeometry {
 			vertex.applyMatrix4( mesh.matrixWorld );
 			vertex.applyMatrix4( mesh.matrixWorld );
 			vertex.applyMatrix4( projectorMatrixInverse );
 			vertex.applyMatrix4( projectorMatrixInverse );
 
 
-			normal.transformDirection( mesh.matrixWorld );
+			normal.applyNormalMatrix( normalMatrix );
 
 
 			decalVertices.push( new DecalVertex( vertex.clone(), normal.clone() ) );
 			decalVertices.push( new DecalVertex( vertex.clone(), normal.clone() ) );
 
 

+ 3 - 1
examples/webgl_decals.html

@@ -187,8 +187,10 @@
 						mouseHelper.position.copy( p );
 						mouseHelper.position.copy( p );
 						intersection.point.copy( p );
 						intersection.point.copy( p );
 
 
+						const normalMatrix = new THREE.Matrix3().getNormalMatrix( mesh.matrixWorld );
+
 						const n = intersects[ 0 ].face.normal.clone();
 						const n = intersects[ 0 ].face.normal.clone();
-						n.transformDirection( mesh.matrixWorld );
+						n.applyNormalMatrix( normalMatrix );
 						n.multiplyScalar( 10 );
 						n.multiplyScalar( 10 );
 						n.add( intersects[ 0 ].point );
 						n.add( intersects[ 0 ].point );
 
 

粤ICP备19079148号