trois icon indicating copy to clipboard operation
trois copied to clipboard

Using ref is not handy

Open klevron opened this issue 4 years ago • 3 comments

We should maybe find another way to get access to renderer and threejs objects.

klevron avatar Nov 16 '21 19:11 klevron

At least with a reference to <Renderer>, we have getObjectByName method to access children objects? https://threejs.org/docs/index.html#api/en/core/Object3D.getObjectByName

Amar-Gill avatar Dec 22 '21 00:12 Amar-Gill

To get access to object id that took some time to find the troisjs has it. I didn't see some docs examples. Looking that src files.

This is vuejs 3 setup but the old version should work.

<script setup>
import { RendererInjectionKey, SceneInjectionKey } from 'troisjs'
import {inject, onMounted, onUnmounted} from "vue";
const renderer = inject(RendererInjectionKey);
console.log(renderer)
const scene = inject(SceneInjectionKey);
console.log(scene)
</script>

You can read more about it vuejs docs.

https://vuejs.org/guide/components/provide-inject.html#prop-drilling

Lightnet avatar Mar 22 '22 19:03 Lightnet

Thanks @Lightnet, sorry for this late answer, I am quite busy lately.

I think the main problem is how to normalize the way to access components (and threejs objects), e.g.:

If I want to set positions on an instanced mesh, I can use 'created' event : https://github.com/troisjs/trois/blob/0.3.4/src/core/Object3D.ts#L115

If I want to animate this instanced mesh I'll have to use renderer.onBeforeRender and a ref, do you see what I mean ?

klevron avatar Mar 28 '22 20:03 klevron