Hi,
Here is a sample + instruction of my implemenation:
First: You need two pictures: The authors of the day/night scene used two pictures; a day picture and a night picture. Since I don't have those kind of pictures i'm using two of my pictures that show the inside of a virtual bunker. One picture has the door OPEN, the other picture has the door CLOSED.
Second: Upon changing the picture, you want use the same pitch, yaw and FOV values.
Third: I did this quick & dirty and place javascript/css in the index.html file. You can also make seperate files for this to make it more clean.
Instructions of recreating demo:
Add a button to the pano in index.html:
I added the following code for the button style
<style>
.button {
z-index: 1;
position:absolute;
top: 110px;
left: 10px;
display: inline-block;
padding: 15px 25px;
font-size: 24px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
}
.button:hover {background-color: #3e8e41}
.button:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
</style>
Add a button to the pano in index.html:
<button class="button" id="mybutton" onclick="changeDoor()">Press to open</button>
Here I also added a function that actually changes the image.
Add the changeDoor() script to index.html, and in the switchDoor function set the scenes to switch to
<script>
function changeDoor() {
if (document.getElementById("mybutton").innerHTML == "Press to open")
{
document.getElementById("mybutton").innerHTML = "Press to close";
switchDoor("1-room1_main_dooropen");
}
else
{
document.getElementById("mybutton").innerHTML = "Press to open";
switchDoor("0-room1_main_doorclosed");
}
}
</script>
Changes in index.js
1) Make the index.js accessible from the index.html file
Comment the first and last line of code of the index.js file;
//(function() {
//})();
2) Add the italic line to the function to make the viewer accesible;
function updateSceneName(scene) {
sceneNameElement.innerHTML = sanitize(
scene.data.name);
window.marzipano_viewer = viewer; //!@#$ }
3) Add the new function to switch the image. It actually grabs the current yaw/pitch/fov, gets the target scene, sets the initialViewParameters of the target, and switches the scene.
function switchDoor(scene) { //THIS IS AN ACTUAL COPY OF switchScene
stopAutorotate();
var lmyScene = findSceneById(scene);
var lYaw = marzipano_viewer.view().yaw();
var lPitch = marzipano_viewer.view().pitch();
var lFOV = marzipano_viewer.view().fov();
var lTarget = findSceneById(scene).
data.id ;
lmyScene.data.initialViewParameters.yaw = lYaw;
lmyScene.data.initialViewParameters.pitch = lPitch;
lmyScene.data.initialViewParameters.fov = lFOV;
switchScene(lmyScene);
lmyScene.scene.switchTo();
startAutorotate();
updateSceneName(lmyScene);
updateSceneList(lmyScene);
}
Good luck in creating your day/night pano.
greetings
Joost