Tresjs / tres

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

intersect only objects with events registered #736

Closed kanocence closed 2 weeks ago

kanocence commented 3 weeks ago

Description

I created a mesh using Three.js and added it to the scene with context.scene.add(). How can I add a click event to it? Initially, I could directly write mesh.onClick = clickMesh, but the #714 submission restricted this behavior.

Suggested solution

Maybe you could extend the context.scene.

Alternative

No response

Additional context

@tresjs/core@4.0.2

Validations

JakobHock commented 2 weeks ago

Event's can be added via the template like shown in the docs.

I'm not quite sure what issue you are experiencing. Can you provide a reproduction?

kanocence commented 2 weeks ago

Playground

Two boxes were added in MyComp.vue. Although both have onClick events in the console, only the box added through tres can be triggered.

image

alvarosabu commented 2 weeks ago

Hi @kanocence the way to add event handlers is through the template by passing the event handlers like you would do in vue. We don't provide an interface to add event handlers programmatically to objects because is not the normal flow of a TresJS app.

You could add your object to the scene graph by using primitives and add the event handler there https://docs.tresjs.org/advanced/primitive