Tresjs / tres

Declarative ThreeJS using Vue Components
https://tresjs.org
MIT License
1.91k stars 85 forks source link

fix: make on* callbacks settable #672

Closed andretchen0 closed 2 months ago

andretchen0 commented 2 months ago

Problem

on* callbacks – e.g., onBeforeRender – are methods on THREE Objects. In plain THREE, these can be overridden by users.

Currently in TresJS, a prop like on-before-render="..." calls the default function – which does nothing:

It should instead set the function.

Solution

Add a predicate in src/core/nodeOps.ts where, for prop-name="value":

In this limited case, value will replace object[propName].

A unit test and a playground were also added.

Context

This is a more targeted approach than R3F. There's a good chance that this could be absorbed into a more general predicate in a future refactor.

But the predicate is kept tight here to avoid unexpected behavior elsewhere.

Closes #360

netlify[bot] commented 2 months ago

Deploy Preview for tresjs-docs ready!

Name Link
Latest commit c7e111cb0f24e7527bab865bcc1fd00288611ec2
Latest deploy log https://app.netlify.com/sites/tresjs-docs/deploys/6632cb78113cde00084836ac
Deploy Preview https://deploy-preview-672--tresjs-docs.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.