Skip to content

fix(MeshReflectorMaterial): avoid updates when possible #2372

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davcri
Copy link
Contributor

@davcri davcri commented Feb 24, 2025

Why

These changes avoids unnecessary updates for MeshReflectorMaterial.
Previously it was updating even with visible=false on the material or on the parent mesh.

A couple of notes:

  1. I had to update three and @types/three package because onBeforeRender() method was not typed correctly up til Material: Add onBeforeRender() back. three-types/three-ts-types#1169 and it was causing errors
  2. sorry I disabled Husky locally as I was getting a lot of errors that were not related to these changes

Copy link

vercel bot commented Feb 24, 2025

@davcri is attempting to deploy a commit to the Poimandres Team on Vercel.

A member of the Team first needs to authorize it.

@@ -194,12 +192,12 @@ export const MeshReflectorMaterial: ForwardRefComponent<MeshReflectorMaterialPro

useFrame(() => {
const parent = (materialRef.current as any).parent || (materialRef.current as any)?.__r3f.parent?.object
if (!parent) return
if (!parent || !materialRef.current.visible || !parent.visible || !shouldUpdate.current) return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used shouldUpdate to avoid unnecessary instructions in useFrame which is called unconditionally.

Three's onBeforeRender instead is called only when the renderer needs it (EG: it shouldn't be called if the mesh isn't part of the scene being rendered).

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.

1 participant