superframe icon indicating copy to clipboard operation
superframe copied to clipboard

[orbit-controls and look-at] make them work together

Open mattrei opened this issue 5 years ago • 6 comments

Hi,

I ran into an issue which I currently do not know how to solve properly. I want that an entity always looks at the camera when using the orbit-controls.

This does not work because the THREE.OrbitControls object takes a THREE Camera and does its transforms directly on that camera object (PerspectivceCamera or OrthographicCamera). But in A-Frame the camera is technically a child of a THREE.Group (because it is wrapped inside an entity) and so the transforms are not applied to the entity itself.

Now when I pass the cameras selector to the look-at component it 'watches' the orientation of the entity and not the camera object and of course nothing happens...

See the example here: https://lookat-orbitcontrols-aframe.glitch.me/

I could imagine how to fix it, but I am not sure where: at the look-at component or at the orbit-controls?

Thx for any advices. Best

mattrei avatar Oct 24 '18 06:10 mattrei

Hi. I took a closer look at your post because I've been playing with look-at and orbit-controls myself. I'm a little unsure about what you are trying to achieve? But here are a couple of alternatives I've posted to Codepen:

https://codepen.io/beebabba/pen/YJRwrV

https://codepen.io/beebabba/pen/ReqrOM

Hope fully these are helpful.

B.

bizzell avatar Oct 24 '18 13:10 bizzell

hi @bizzell ,

thx for your input, but the examples do not help, because they do not address the issue i tried to point out above.

Maybe @ngokevin can chime in.

Best

mattrei avatar Oct 29 '18 09:10 mattrei

@mattrei Im sure there's a better way to do this but this is a quick solution i put together that uses orbit-controls and look-at.

https://periodic-hardcover.glitch.me/

allancozart avatar Oct 29 '18 16:10 allancozart

@allancozart thx for helping out. that's indeed a valid workaround and helps for now! Instead of the posiiton attribute i would also use the getWorldPosition if the camera gets further transformed.

Maybe we come up with an idea how to make it work by changing one of the libraries without this workaround. Because there are also other THREEJs example controls that might be implemented in the future.

mattrei avatar Oct 30 '18 07:10 mattrei

@mattrei What about anding a boolean option to the look-at schema. for example "orbitcamera: true". We can then use that to create a condition that pulls the entity orbit camera values.

i'm assuming it could go here. https://github.com/ngokevin/kframe/blob/master/components/look-at/dist/aframe-look-at-component.js#L107

allancozart avatar Oct 30 '18 14:10 allancozart

@mattrei Im sure there's a better way to do this but this is a quick solution i put together that uses orbit-controls and look-at.

https://periodic-hardcover.glitch.me/

Wonderful solution. It helped me 2 years later. I have a newbie question, I saw you used lookCube.setAttribute() without defining lookCube, but threeJs recognize it. Does threeJs support using element ids directly as object?

EricHsuYC avatar Oct 23 '20 02:10 EricHsuYC