-
-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OrbitControls #100
Comments
I wrote a component like this: <script>
import {validatePropString} from "vue-gl/src//utils"
import * as VueGL from 'vue-gl'
import OrbitControls from 'orbit-controls-es6'
export default {
mixins: [VueGL.VglObject3d],
name: 'OrbitControls',
inject: ["vglCameras"],
props: {
camera: validatePropString
},
computed: {
inst () {
const cmr = this.vglCameras.forGet[this.camera]
return new OrbitControls(cmr)
}
}
}
</script> But when I give the camera a name and point it to the OrbitControls, the scene get black. <vgl-perspective-camera name="pCamera" orbit-position="200 1 0.5"></vgl-perspective-camera>
<orbit-controls camera="pCamera"></orbit-controls> |
I was on the assumption that the user would change orbit-position property manually by handling mouse event... I guess it should be enable instantly in the future (like by adding directive). So far, the following code should work. export default {
inject: ['vglCameras'],
props: {
camera: validatePropString
},
computed: {
cmr () {
return this.vglCameras.forGet[this.camera]
}
},
watch: {
cmr: {
handler(cmr) {
const controls = new OrbitControls(cmr)
controls.addEventListener('change', () => {
cmr.dispatchEvent({type:'update'})
})
},
immediate: true
}
}
} I don't know why your scene got black. (Getting some error?) You need to inform the renderer when the position of camera changes. We can use THREE's event dispatcher. You don't have to mixin I hope it will help you :) |
Hello, But I had error when I use the OrbitControls component. |
Internal namespace and rendering flow are changed. import { string } from 'vue-gl/src/validators.js'
import OrbitControls from 'orbit-controls-es6'
export default {
inject: ['vglNamespace'],
props: {
camera: string,
},
computed: {
cmr () {
return this.vglNamespace.cameras[this.camera];
}
},
watch: {
cmr: {
handler(cmr) {
const controls = new OrbitControls(cmr)
controls.addEventListener('change', () => {
this.vglNamespace.update();
});
},
immediate: true,
}
},
render(h) {
return h('div');
},
}); example: Injected namespaces are gathered in injected |
Thanks for putting this all together! When using I'm using this within Update
Not saying that's a good or right way to do it - just that it does appear to work. |
@swirlingsand Don't you put components outside |
@h-ikeda how do you constrain the controls to the domElement only ? EDIT: just fixed with : handler(cmr) {
const domElement = this.vglNamespace.renderers[0].inst.domElement;
const controls = new THREE.OrbitControls(cmr, domElement);
controls.addEventListener('change', () => this.vglNamespace.update());
}, |
With the new update, I had trouble accessing properties. So I just do this in my app and it seems to work nicely. this.controls = new OrbitControls(this.$refs.camera.inst, document.querySelector('.renderer'));
this.controls.addEventListener('change', () => {
this.$refs.renderer.requestRender()
}) |
I'm testing this out and have run into issues with the samples on this page. My setup is similar https://codesandbox.io/s/qlpy3, but I'm getting some errors with recent versions of vue-gl (0.21.0):
and
So it seems the camera isn't being passed properly to the component. You can see similar errors in the example posted by @h-ikeda Any ideas how to resolve this? |
@fraguada I was able to solve it by doing this: Vue.component('OrbitControls', {
inject: ['vglNamespace'],
props: ['camera'],
computed: {
cmr () {
return this.vglNamespace.cameras.hash.c
}
},
watch: {
cmr: {
handler(cmr) {
Vue.nextTick(() => {
const controls = new OrbitControls(cmr, this.$parent.$el)
controls.addEventListener('change', () => {
this.$parent.requestRender()
})
})
},
immediate: true,
}
},
render(h) {
return h('div');
},
}); |
Thanks @notchris. That did it! |
Thanks for a really good and extendable repository. I have a question. I have created a custom GridSystem that extends the
VglObject3D
. It works as expected. Now I would like to add OrbitControls. How would you do it? So far I have created a new vue component that importTHREE.OrbitControls
. But how would you instantiate the OrbitControls component with a camera attached?The text was updated successfully, but these errors were encountered: