175 lines
4.7 KiB
JavaScript
175 lines
4.7 KiB
JavaScript
"use strict";
|
|
/*jslint vars:true, plusplus:true, forin:true*/
|
|
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
|
|
//
|
|
// generateCubemapImages.js
|
|
//
|
|
// **********************
|
|
// *****START README*****
|
|
// **********************
|
|
// Deselect "Developer > Avatar > Draw Mesh" so that your avatar doesn't show
|
|
// up in your capture.
|
|
//
|
|
// Here is the expected layout for the faces in an image with the 1/6 aspect ratio:
|
|
//
|
|
// WIDTH
|
|
// <------>
|
|
// ^ +------+
|
|
// | | |
|
|
// | | +X |
|
|
// | | |
|
|
// H +------+
|
|
// E | |
|
|
// I | -X |
|
|
// G | |
|
|
// H +------+
|
|
// T | |
|
|
// | | +Y |
|
|
// | | |
|
|
// | +------+
|
|
// | | |
|
|
// | | -Y |
|
|
// | | |
|
|
// H +------+
|
|
// E | |
|
|
// I | +Z |
|
|
// G | |
|
|
// H +------+
|
|
// T | |
|
|
// | | -Z |
|
|
// | | |
|
|
// V +------+
|
|
//
|
|
// FaceWidth = width = height / 6
|
|
// **********************
|
|
// ******END README******
|
|
// **********************
|
|
//
|
|
// Created by Zach Fox on 2017-08-16
|
|
// Copyright 2017 High Fidelity, Inc
|
|
//
|
|
// Distributed under the Apache License, Version 2.0
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
|
|
/*global Tablet, MyAvatar, Window, Menu */
|
|
|
|
(function() { // BEGIN LOCAL_SCOPE
|
|
|
|
var counter = 0,
|
|
spectatorCameraConfig = Render.getConfig("SecondaryCamera");
|
|
|
|
function resetAvatarPitchRoll() {
|
|
print("Resetting avatar pitch/yaw/roll...");
|
|
MyAvatar.bodyPitch = 0;
|
|
MyAvatar.bodyYaw = 0;
|
|
MyAvatar.bodyRoll = 0;
|
|
MyAvatar.headPitch = 0;
|
|
MyAvatar.headYaw = 0;
|
|
MyAvatar.headRoll = 0;
|
|
}
|
|
|
|
function cleanup() {
|
|
resetAvatarPitchRoll();
|
|
counter = 0;
|
|
}
|
|
|
|
function snapshotLoop() {
|
|
print("Starting cubemap photo capture!");
|
|
var cameraPitch = -90,
|
|
cameraYaw = 0,
|
|
numSnapsPerRow = [1, 4, 1],
|
|
numSnapsTotal = numSnapsPerRow.reduce(function(pv, cv) { return pv + cv; }, 0),
|
|
currentRowIndex = 0,
|
|
currentRowSnapsTaken = 0;
|
|
|
|
function tick() {
|
|
spectatorCameraConfig.orientation = Quat.fromPitchYawRollDegrees(cameraPitch, cameraYaw, 0.0);
|
|
|
|
Script.setTimeout(function() {
|
|
if (counter < numSnapsTotal) {
|
|
print("Taking Snapshot " + (counter + 1) + "/" + numSnapsTotal);
|
|
Window.takeSecondaryCameraSnapshot();
|
|
cameraYaw += 360/numSnapsPerRow[currentRowIndex];
|
|
currentRowSnapsTaken++;
|
|
if (currentRowSnapsTaken === numSnapsPerRow[currentRowIndex]) {
|
|
currentRowIndex++;
|
|
currentRowSnapsTaken = 0;
|
|
cameraYaw = 0;
|
|
cameraPitch += 180/(numSnapsPerRow.length-1);
|
|
print("Pitching camera to capture row " + (currentRowIndex + 1));
|
|
}
|
|
} else {
|
|
cleanup();
|
|
return;
|
|
}
|
|
counter++;
|
|
Script.setTimeout(tick, 500);
|
|
}, 500);
|
|
}
|
|
tick();
|
|
}
|
|
|
|
function commenceSnapshotProcess() {
|
|
resetAvatarPitchRoll();
|
|
snapshotLoop();
|
|
}
|
|
|
|
function twirlAvatar(callback) {
|
|
// Spin to load
|
|
print("Spinning avatar to ensure content loaded...");
|
|
resetAvatarPitchRoll();
|
|
var bodyYaw = 0;
|
|
function tick() {
|
|
MyAvatar.bodyYaw = bodyYaw;
|
|
bodyYaw += 15;
|
|
if (bodyYaw >= 360) {
|
|
return callback();
|
|
}
|
|
Script.setTimeout(tick, 90);
|
|
}
|
|
tick();
|
|
}
|
|
|
|
function generateCubemapImages(){
|
|
if (counter > 0) {
|
|
cleanup();
|
|
} else {
|
|
twirlAvatar(commenceSnapshotProcess);
|
|
spectatorCameraConfig.enableSecondaryCameraRenderConfigs(true);
|
|
spectatorCameraConfig.resetSizeSpectatorCamera(2048, 2048);
|
|
spectatorCameraConfig.position = MyAvatar.getHeadPosition();
|
|
spectatorCameraConfig.orientation = {x: 0, y: 0, z: 0, w: 1};
|
|
spectatorCameraConfig.vFoV = 90;
|
|
spectatorCameraConfig.nearClipPlaneDistance = 1.0;
|
|
spectatorCameraConfig.farClipPlaneDistance = 1000.0;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Manage the connection between the button and the window.
|
|
//
|
|
var button;
|
|
var buttonName = "CUBEMAP";
|
|
var tablet = null;
|
|
|
|
function startup() {
|
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
|
button = tablet.addButton({
|
|
text: buttonName
|
|
});
|
|
button.clicked.connect(generateCubemapImages);
|
|
}
|
|
|
|
function shutdown() {
|
|
button.clicked.disconnect(generateCubemapImages);
|
|
tablet.removeButton(button);
|
|
}
|
|
|
|
//
|
|
// Run the functions.
|
|
//
|
|
startup();
|
|
Script.scriptEnding.connect(shutdown);
|
|
|
|
}()); // END LOCAL_SCOPE
|