-
Notifications
You must be signed in to change notification settings - Fork 25
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
dynamically changing camera position #14
Comments
Hey @weddingdj, sounds like a solid idea to me and like a bug on my side. Thanks for the catch! cheers Till |
Hey @weddingdj, i'm currently looking into this and was able to reproduce the issue. I will now try to fix this. I have one question, though: Can you explain why you are moving the camera around? Maybe this might be a good feature :) Cheers Till |
Great! First I am moving (animating) the model from the background to the origin, like on Sketchfab when you look at models. But that has no influence on your component. But then I calculate the distance of the camera according to the model size, so that the 3D model fits on the screen. And that's why I position the camera. The whole thing will be a IdeaSpaceVR theme. :-) |
Ah, i thought you might be doing something like this. We already have the rotateTo functionality. Maybe i can build something like moveTo as well. Cheers |
Hey @weddingdj, can you tell me how you achieve the animations in the beginning? I tried to implement this using an a-animation entity as a child of the camera. This works ok, but it only works flawless when the camera is disabled during the animation. Do you follow the same principle, or do you use aome animation library? Edit: Sorry, i got that all wrong :D Ignore that request. Cheers Till |
Hey @weddingdj, i dove into the issue again and have some news! Funnily the changed attributes of the camera never make it into the orbit-controls. So there it is not to have a lifecycle method inside the component handle outside manipulation, apart from an event listener looking for changes. I'm reluctant to add something like this, as it would always fire when moving the orbit controls, as i update the camera properties from the component. Nevertheless i found a way to accomplish what you are looking for that is a little less hackish than setting distance. You simply disable the orbit-controls on the camera, then set the new camera attributes and enable the orbit controls. This will trigger the orbit-control's lifecycle update() method, where i now update the controls position from the camera's position. You can also see this in action in the basic example.
Hope you are fine with this. :) Cheers Till |
Hi Till, that sounds great, I will play with it. Thanks! Cheers! |
It works great, there is just one little issue. Since I am animating the model (the target in your code) as well, moving towards the camera, I have to update the target position as well. What do you think of adding this line of code to the update function as well?
If I don't add this line, the rotation is wrong (I am not sure though why...). |
Yep, that should definitely fix this issue. Cheers Till |
Hey @weddingdj, now i'm able to come back to my earlier question, that was totally nonsensical back then :D Do you use some library? Cheers Till |
I just thought of an easy-peasy workaround for this. Cheers Till |
I am just using the basic a-frame animation system. I disable orbit controls, then I move the target from the background to 0, 0, 0, then I enable orbit controls. But if I rotate the target it is wrong, like there would be an offset from 0, 0, 0. But if I set the target position in your update method, it works fine. |
I'm a litte unsure how to proceed. I just played around a little and simply referenced the target object in the orbit-controls, which makes the camera rotation always follow the target. This is quite nice, because it allows to use a separate target entity without any geometry and move that around to different areas of interest. Also i feel this the expected behavior. But... This also interferes with what you want to accomplish. Say the object should fly in from the top. The camera then would look at the item floating in the air and follow it as it animates to e.g. 0 0 0. For you this would mean you had to use the workaround with the separate target entity i mentioned. What do you think? |
you could then do something like this:
|
I see you point, and that workaround is a possibility. Thanks! Btw, I saw on your website that you live in Hamburg, I lived there for 4 years until 2006, close to the Schanze, in der Eimsbüttelerstrasse 13 ;-) Cheers! |
I'm encountering a similar issue. In my web app, I'm using
This works fine but recently rotating the camera offsets the target, so the animated zoom is off-centre. I'll try using the workarounds above but wanted to highlight in case it helps with a more permanent fix. |
Hey @codemacabre , i will look into this tomorrow, as i got some spare time. Cheers |
do you by any chance have a minimal example i can play around with? Thanks and cheers, Till |
I have a use case where I dynamically set the position of the camera after the scene and a model is loaded. I realised that the orbit controls component still thinks that the camera is at the original position when the component was initialised. So the camera jumps back to its original position because of
this.dolly.position.copy(this.object.position);
in the init function.
I did a workaround and added this line of code to the update function and trigger an update event by calling
camera.setAttribute('orbit-controls', 'distance', '2');
in order to get the dolly position updated with the new values.Would you consider putting
this.dolly.position.copy(this.object.position);
into the update function or do you have a better solution?Thanks!
The text was updated successfully, but these errors were encountered: