A camera without gimbal lock
-
Hi all, I'm still learning the ins and outs of JSCAD but enjoying it thus far. Please forgive me if I'm misunderstanding the project structure or purpose here; I would quite like to understand it better.
Is the regl-renderer core package the only "official" way to render and interact with JSCAD models on a webpage? Is there any documentation for it? I don't see any with the rest of the documentation. The regl-renderer camera annoys me quite a bit. I want to move the camera freely around my scene without locking up at the looking-straight-down or looking-straight-up positions. I can understand if not everyone wants this all the time, but it seems like a useful option one can enable, and it's in line with the camera motion in every other piece of modeling software I've seen.
Poking around in the code, it looks like the camera view is a gl-mat4 object calculated using just two spherical coordinate angles, theta and phi. Once the desired camera position is computed, it's turned into a mat4 object using the lookAt() function, which is what's limiting the camera's range of motion. Actually, it looks like it does the lookAt() function twice--once in orbitControls.js and once in the ortho or perspective camera code.
The first thing that comes to my mind is to use gl-quat, and instead of just computing mat4.lookAt() at the new camera position, to use quat.rotationTo() based on the old and new positions. But this would involve changing the structure of the camera view, and require different info to be passed in the camera state, so I don't know how feasible it would be to switch between one camera mode and the other. I have a vague sense of how to implement this, but not enough to work on a pull request. I'm interested to hear others' thoughts on the camera.
-
progress of the mentioned prototype with suport for different wegl libs can be found here:
https://github.com/jscad/OpenJSCAD.org/discussions/944I have just made another step forward: mesh support (but with some quirks ATM)
I have some lighting to fix, and also babylonjs for some weird rason uses left handed system (this adds a bit of complexity to the worker to support it properly)Also when switching viewers, if they are different orioentation currently I need to run the script again manually to get properly oriented triangles
https://user-images.githubusercontent.com/2480762/162638934-7a945625-420d-4041-98fc-5735fcc34c6b.mp4
-
@settinger welcome
I’m not sure how to answer but will try to give some additional information.
Currently, the rendering is pretty basic. There are restrictions on camera view and rotations built into the rendering. This might seem strange but most users like a ‘standard’ viewing angle and rotations. Not a bad choice.
@hrgdavor is working on several new viewers. He’s making some great progress but working alone most of the time. Also, he’s very ambitious about the underlying support for every major WebGL library, including threejs, etc.
So, we know that anything is possible.
Your suggestions on cameras, viewing, lighting, etc. are all welcome. You’re welcome to make improvements, but keep things simple (incremental steps) so we (developers) can follow along.