Tresjs / tres

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

intersect only objects with events registered #736

Closed kanocence closed 5 months ago

kanocence commented 5 months 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 5 months 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 5 months 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 5 months 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