Skip to content

Commit

Permalink
DecalGeometry: Transform normal with normal matrix (#29476)
Browse files Browse the repository at this point in the history
* Transform normal with normal matrix

* Transform normal with normal matrix
  • Loading branch information
WestLangley authored Sep 24, 2024
1 parent 12bcf60 commit 8f765f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion examples/jsm/geometries/DecalGeometry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
BufferGeometry,
Float32BufferAttribute,
Matrix3,
Matrix4,
Vector3
} from 'three';
Expand Down Expand Up @@ -36,6 +37,8 @@ class DecalGeometry extends BufferGeometry {

const plane = new Vector3();

const normalMatrix = new Matrix3().getNormalMatrix( mesh.matrixWorld );

// this matrix represents the transformation of the decal projector

const projectorMatrix = new Matrix4();
Expand Down Expand Up @@ -146,7 +149,7 @@ class DecalGeometry extends BufferGeometry {
vertex.applyMatrix4( mesh.matrixWorld );
vertex.applyMatrix4( projectorMatrixInverse );

normal.transformDirection( mesh.matrixWorld );
normal.applyNormalMatrix( normalMatrix );

decalVertices.push( new DecalVertex( vertex.clone(), normal.clone() ) );

Expand Down
4 changes: 3 additions & 1 deletion examples/webgl_decals.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@
mouseHelper.position.copy( p );
intersection.point.copy( p );

const normalMatrix = new THREE.Matrix3().getNormalMatrix( mesh.matrixWorld );

const n = intersects[ 0 ].face.normal.clone();
n.transformDirection( mesh.matrixWorld );
n.applyNormalMatrix( normalMatrix );
n.multiplyScalar( 10 );
n.add( intersects[ 0 ].point );

Expand Down

0 comments on commit 8f765f9

Please sign in to comment.