trois
trois copied to clipboard
Missing Parent (Scene, Group...)
Hello, thanks for this lib !
I'm trying to use different component for my app, but got this error (Missing Parent (Scene, Group...)
App.vue
<Renderer class="App__canvas" resize="window" :orbit-ctrl="{ enableDamping: true }">
<Camera :position="{ z: 10 }" />
<Scene>
<Test />
</Scene>
</Renderer>
Test.vue
<template>
<Group>
<PointLight :position="{ y: 50, z: 50 }" />
<Sphere>
<LambertMaterial color="red" />
</Sphere>
</Group>
</template>
<script setup>
import { Group, PointLight, Sphere, LambertMaterial } from 'troisjs'
</script>
Don't understand how we can use component inside a Renderer.
If i use Scene
instead of Group
in Test.vue
it work..
But a scene inside a scene is not a good practice ?
Thank !
Thanks, you code looks ok, I will look at this asap
I tried and it works, but I didn't use script setup
syntax
Very weird when i don't use script setup
it work too...
Could be cool to make work with script setup
i will look at it.
thank !
I can make it work with script setup
Object.js -> getParent function
import { getCurrentInstance } from 'vue'
...
// let parent = this.$parent;
const instance = getCurrentInstance()
let parent = instance.parent.ctx
It work good, but not with GltfModel....
If you have an idea i take :)
@klevron I can make it work with this ! On GltfModel too !
import { getCurrentInstance } from 'vue'
...
getParent() {
let parent = this.$parent;
// my 2 cents
const instance = getCurrentInstance()
if(instance && instance.parent)
parent = instance.parent.ctx
//
while (parent) {
if (parent.add)
return parent;
parent = parent.$parent;
}
return void 0;
},
I suck in Typescript, maybe you can add this fix ? I've worked directly in trois.module.js
:)
Thank you !
@klevron any chance to add this fix for script setup
user ?
I will publish a new version with the fix in a few days, thanks for the help 👍