Skip to content

Conversation

@RenaudRohlinger
Copy link
Collaborator

@RenaudRohlinger RenaudRohlinger commented Nov 27, 2023

Fixed #14921.

Reopening #25933.

This PR introduces two new optional callbacks to the Object3D class in three.js. The onBeforeShadow and onAfterShadow callbacks allow developers to execute custom code immediately before and after the shadow of a 3D object is rendered, respectively. These callbacks provide the following parameters: renderer, scene, camera, shadowCamera, geometry, depthMaterial, and group.

Example usage:

cube.onBeforeShadow = function ( renderer, scene, camera, shadowCamera, geometry, depthMaterial, group ) {

	anothercube.visible = true;
	anothercube.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, anothercube.matrixWorld );
	renderer.renderBufferDirect( shadowCamera, null, anothercube.geometry, depthMaterial, anothercube, group );

};

cube.onAfterShadow = function ( ) {

	anothercube.visible = false;

};

Seems that we would really need it for the newly introduced BatchedMesh /cc @gkjohnson.

#14921 (comment)

@github-actions
Copy link

github-actions bot commented Nov 27, 2023

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
668.4 kB (165.9 kB) 668.6 kB (165.9 kB) +167 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
449.6 kB (108.9 kB) 449.8 kB (108.9 kB) +167 B

@gkjohnson gkjohnson added this to the r159 milestone Nov 27, 2023
@Mugen87 Mugen87 merged commit 6476e2f into mrdoob:dev Nov 27, 2023
AdaRoseCannon pushed a commit to AdaRoseCannon/three.js that referenced this pull request Jan 15, 2024
* added onbeforeShadow and onAfterShadow

* add missing methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Object3D: Introduce onBeforeShadow().

3 participants