Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object3D: Add onBeforeShadow and onAfterShadow callbacks #27250

Merged
merged 2 commits into from
Nov 27, 2023

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)

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
12 checks passed
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
3 participants