Move Environment Image with Camera #3078
Replies: 2 comments 5 replies
-
By default, the model is fixed in the environment and the camera moves relative to both. This example shows how you can turn the environment instead. You should be able to adjust that example to get the behavior you want. However, I'd recommend doing a quick test with that sample first; we use environment lighting, so the self shadowing comes from your AO channel. You may not see much difference either way. |
Beta Was this translation helpful? Give feedback.
-
We are wanting to do the same, which we managed to get working using the following code: modelViewer.dataset.lastX = false;
modelViewer.dataset.lastY = false;
modelViewer.dataset.lastTheta = false;
modelViewer.dataset.panning = false;
modelViewer.dataset.skyboxAngle = 0;
modelViewer.dataset.radiansPerPixel = 0;
function startPan() {
const orbit = modelViewer.getCameraOrbit();
const radius = orbit.radius;
modelViewer.dataset.radiansPerPixel = radius / modelViewer.getBoundingClientRect().height;
modelViewer.interactionPrompt = 'none';
};
function updatePan(thisX, thisY) {
const deltaX = (thisX - parseFloat(modelViewer.dataset.lastX)) * parseFloat(modelViewer.dataset.radiansPerPixel);
const deltaY = -1 * (thisY - parseFloat(modelViewer.dataset.lastY)) * parseFloat(modelViewer.dataset.radiansPerPixel);
modelViewer.dataset.lastX = thisX;
modelViewer.dataset.lastY = thisY;
// modelViewer.dataset.skyboxAngle += deltaX;
modelViewer.dataset.skyboxAngle = parseFloat(modelViewer.dataset.skyboxAngle) + deltaX;
const orbit = modelViewer.getCameraOrbit();
orbit.theta += deltaX;
orbit.phi += deltaY;
modelViewer.resetTurntableRotation(parseFloat(modelViewer.dataset.skyboxAngle));
modelViewer.cameraOrbit = orbit.toString();
}
modelViewer.addEventListener('mousedown', function (event) {
modelViewer.dataset.panning = true;
if (modelViewer.dataset.panning == "false")
return;
modelViewer.dataset.lastX = event.clientX;
modelViewer.dataset.lastY = event.clientY;
startPan();
}, true);
modelViewer.addEventListener('touchstart', function (event) {
const targetTouches = event.targetTouches;
modelViewer.dataset.panning = true;
if (modelViewer.dataset.panning == "false")
return;
modelViewer.dataset.lastX = 0.5 * (targetTouches[0].clientX + targetTouches[1].clientX);
modelViewer.dataset.lastY = 0.5 * (targetTouches[0].clientY + targetTouches[1].clienty);
startPan();
}, true);
self.addEventListener('mousemove', function (event) {
if (modelViewer.dataset.panning == "false")
return;
updatePan(event.clientX, event.clientY);
}, true);
modelViewer.addEventListener('touchmove', function (event) {
if (modelViewer.dataset.panning == "false")
return;
const targetTouches = event.targetTouches;
const thisX = 0.5 * (targetTouches[0].clientX + targetTouches[1].clientX);
const thisY = 0.5 * (targetTouches[0].clientY + targetTouches[1].clientY);
updatePan(thisX, thisY);
}, true);
self.addEventListener('mouseup', function (event) {
modelViewer.dataset.panning = false;
}, true);
modelViewer.addEventListener('touchend', function (event) {
modelViewer.dataset.panning = false;
}, true); The issue we have now is that we have buttons that the user can click that animates to a preset cameraOrbit & cameraTarget using the following code const orientation = $(e.target).attr('data-orientation');
const target = $(e.target).attr('data-camera-target');
const maxCameraOrbit = $(e.target).attr('data-max-camera-orbit');
modelViewer.cameraTarget = target;
modelViewer.cameraOrbit = orientation;
modelViewer.fieldOfView = "auto"; Unfortunately due to the fact that the example only works on drag, this does not work with the automatic movement that happens when setting the cameraOrbit. We have tried hooking into the camera-change event only when the event source is "none", though as expected this got stuck in an infinite loop as it triggers the camera-change event when changing the cameraOrbit as part of the update function. Are you aware of any way to handle this? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to move the environment image along with the camera as a user rotates around the model? I want the user to see how the shadows fall across the surface of the model as they rotate around it. Can anybody advise?
Beta Was this translation helpful? Give feedback.
All reactions