What am I missing in .getCameraOrbit return values? #3438
Replies: 2 comments 2 replies
-
I understand your confusion! First problem: If you want a radius of 1m when the auto min-radius is 10m, then you'll need to set Second problem: We zoom with both radius and FoV, so if you want to set one when you click a hotspot, it's best to set both. Try using our editor to zoom and press "save current as initial" to see what radius and FoV you get in the snippet. If you set one to its limit but not the other, then only the unlimited one will change when you zoom with the wheel. |
Beta Was this translation helpful? Give feedback.
-
And so it turns out that what I actually wanted was .getCameraToHotspotDistanceAsPercievedByViewer(); as the pesky zoom radius/fov behavior complicates my otherwise bulletproof plan. |
Beta Was this translation helpful? Give feedback.
-
Hi,
Am I missing something with the .getCameraOrbit=>orbit.radius return value?
After clicking on a hotspot It seems to report the minimum radius value not the current radius value until you scroll wheel out and then you get all sorts of different numbers.
Importantly this is only after you have clicked on a hotspot. Until then the radius is (what I would) expect.
I have a test model which loads up and the initial camera radius comes back at 50.
If I scroll in until I hit my minimum field of view I get a radius of 9.8667.
As I scroll back out the radius gets bigger and in it gets smaller (to the fov limit).
So far so good.
Now click on a hot spot. In the pseudo code below I've put one at (0,0,0) and am looking square on with a requested radius of 1m
Once the view has settled I see a theta and phi of PI/2 (which is what I expect) and a radius of 9.8667!
If I scroll in the fov return changes, but the radius remains at 9.8867.
However if I scroll out then the radius increases. Starting from a hotspot click and scrolling out this time the radius goes up and then scrolling in it goes down.
What am I missing here? I know that the fov and radius (sort of interact), but the reported values are not making sense to me.
And here is the reason I'm worrying about it.
I'm looking at a way to add a routine that controls hotspot visibility as a function of the hotspot's proximity to the camera.
This is a way to remove some hotspot clutter by only showing (for example) those that are less that a given distance from the camera.
I can see that the absolute camera position is cameraTarget (as xyz) + cameraOrbit(turned into xyz), but I'm missing something with the orbit.radius return value.
If the radius is reported reliably then I can't the camera's offset from target reliably.
Or of course I could just put in a feature request to report the camera's absolute position!
Thanks.
Below is a simplistic pseudo example.
<model-viewer
##Add the camera listener after all loaded
onload="addHotspotCameraListener()"
...>
#Add a test hotspot at the centre and set the orbit to be square on with simple unit radius
#button class="hotspot-target" slot="hotspot-4" data-ishotspot=1 data-position="0m 0m 0m" data-normal="0 0 0" data-visibility-attribute="visible" data-orbit="90deg 90deg 1m" data-target="0m 0m 0m">0 #/button>
#Add simple debug watcher event
function addHotspotCameraListener(){
document.querySelector("model-viewer").addEventListener('camera-change', () => validateHotspotProximity());
}
#Report out camera properties, (but only show the orbit)
function validateHotspotProximity() {
const mv = document.querySelector('model-viewer');
let orbit = mv.getCameraOrbit();
let target = mv.getCameraTarget();
let fov = mv.getFieldOfView();
console.log(orbit);
}
Beta Was this translation helpful? Give feedback.
All reactions