Skip to content

Commit

Permalink
TB screen non spherical
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-repo committed Oct 23, 2024
1 parent a86a24b commit fbd939f
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/index.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion scripts/generate_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@

if "_TB" in title[-3:]:
screen_type = "tb"
elif "_TB_SCREEN" in title[-10:]:
screen_type = "tb_screen"
elif "_SCREEN" in title[-7:]:
screen_type = "screen"
elif "_2D_180" in title[-7:]:
Expand All @@ -109,7 +111,7 @@
else:
screen_type = "sbs"

if screen_type == "screen":
if screen_type == "screen" or screen_type == "tb_screen":
out_files[subDir]["list"].append(
{"name": title,
"src": urllib.parse.quote(fullfile),
Expand Down
18 changes: 14 additions & 4 deletions src/FileBrowser/FileBrowserPanelUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class FileBrowserPanel {
sortByDateColorRef = this.sortInactiveColor;
activeSorting = "name";
sortDirectionBlock;
sortDirection = "ASC";
sortDirection;

buttonLeft;
buttonRight;
Expand Down Expand Up @@ -834,11 +834,11 @@ export class FileBrowserPanel {
justifyContent: "center",
contentDirection: "row",
padding: 0.02,
borderRadius: 0.06,
borderRadius: 0.12,
backgroundOpacity: 1,
backgroundColor: new Color(0x5c5c5c),
width: this.PANELMAXWIDTH / 3,
height: 0.1,
width: this.PANELMAXWIDTH / 2,
height: 0.2,
});

MAIN.scene.add(this.draggingBox);
Expand Down Expand Up @@ -1614,6 +1614,16 @@ export class FileBrowserPanel {
this.folderPageIndex = 0;
this.currentFolderPageIndex = 0;
this.CURRENT_PAGE = 0;
this.sortByName.setState('selected');
this.sortByName.setState('idle');
this.sortDirection.set({
content: Helpers.getWordFromLang("ascending"),
});
this.sortDirection.sortDirection = "asc";
this.sortFiles(
this.activeSorting,
this.sortDirection.sortDirection
);
this.TOTAL_PAGES =
Math.ceil(
this.FILES.length / (this.FILES_PER_ROW * this.FILES_ROWS)
Expand Down
8 changes: 8 additions & 0 deletions src/FileBrowser/ThumbnailBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export default class ThumbnailBlock extends Block {
MAIN.scaleScreenMesh(
this.frame_width / this.frame_height
);
if (screen_type === "tb_screen")
MAIN.scaleTBScreenMesh(
this.frame_width / this.frame_height
);
Helpers.setVideoSrc(this.fileSRC);
fileBrowserPanel.hideFileMenuPanel(this.screen_type);
} else {
Expand All @@ -64,6 +68,10 @@ export default class ThumbnailBlock extends Block {
MAIN.scaleScreenMesh(
this.frame_width / this.frame_height
);
if (screen_type === "tb_screen")
MAIN.scaleTBScreenMesh(
this.frame_width / this.frame_height
);
Helpers.setVideoSrc(this.fileSRC);
fileBrowserPanel.hideFileMenuPanel(this.screen_type);
},
Expand Down
12 changes: 8 additions & 4 deletions src/ScreenManager/ScreenManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function zoom(in_or_out, step = 10) {
}
if (oldZoom !== currentZoom) {
for (let mesh in MAIN.meshes) {
if (in_or_out === "reset"){
if (in_or_out === "reset") {
const temp = panels.meshes.panels
.find((element) => element.ui_name === mesh)
.position.clone();
Expand All @@ -97,16 +97,16 @@ export function zoom(in_or_out, step = 10) {
}
}

export function tilt(up_or_down) {
export function tilt(up_or_down, value = 0.01) {
switch (up_or_down) {
case "up":
for (let mesh in MAIN.meshes) {
MAIN.meshes[mesh].rotation.x -= 0.01;
MAIN.meshes[mesh].rotation.x -= value;
}
break;
case "down":
for (let mesh in MAIN.meshes) {
MAIN.meshes[mesh].rotation.x += 0.01;
MAIN.meshes[mesh].rotation.x += value;
}
break;
case "reset":
Expand Down Expand Up @@ -156,6 +156,10 @@ export function switchModeVRScreen(vr_or_screen) {
case "screen":
isVRModeUsed = false;
break;
case "tb_screen":
VRMode = "tb_screen";
isVRModeUsed = true;
break;
}
}

Expand Down
143 changes: 132 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import * as UI from "./UI.js";
import * as Helpers from "./Helpers.js";
import SourcesSelectorPanel from "./sourceSelector.js";

import FontJSON from "../assets/fonts/Roboto-Regular-msdf.json";
import FontImage from "../assets/fonts/Roboto-Regular.png";

export let scene,
camera,
cameras,
Expand All @@ -27,28 +30,29 @@ export let scene,
videoTexture,
meshLeftSBS,
meshLeftTB,
meshLeftTBScreen,
meshRightSBS,
meshRightTB,
meshRightTBScreen,
mesh2dSBS,
mesh2dTB,
mesh2dTBScreen,
meshForScreenMode,
meshes,
meshLeft360,
meshRight360,
mesh2d360,
mesh1802D,
mesh3602D;
mesh3602D,
playMenuPanel,
fileBrowserPanel,
sourcesSelectorPanel,
hiddenSphere;
export let clickedButton = undefined;
export let playMenuPanel;
export let fileBrowserPanel;
export let sourcesSelectorPanel;
export let camToSave = {};

let popupMessage, popupContainer;
import FontJSON from "../assets/fonts/Roboto-Regular-msdf.json";
import FontImage from "../assets/fonts/Roboto-Regular.png";

export let hiddenSphere;
const CAMERAPOSITIONY = 1.6;

// compute mouse position in normalized device coordinates
Expand Down Expand Up @@ -121,7 +125,7 @@ function init() {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.xr.enabled = true;
document.body.appendChild(VRButton.createButton(renderer));
document.body.appendChild(renderer.domElement);
document.getElementById("three_scene").appendChild(renderer.domElement);

// Orbit controls for no-vr

Expand Down Expand Up @@ -160,12 +164,14 @@ function init() {
120,
60,
40,
Math.PI / 2 + Math.PI / 4,
Math.PI + Math.PI / 2
(Math.PI / 4) * 3,
(Math.PI / 2) * 3
);
geometryLeftTB.scale(-1, 1, 1);
const geometryRightSBS = geometryLeftSBS.clone();
const geometryRightTB = geometryLeftTB.clone();
const geometryLeftTBScreen = new THREE.PlaneGeometry(120, 120);
const geometryRightTBScreen = geometryLeftTBScreen.clone();
const geometryLeft360 = new THREE.SphereGeometry(240, 120, 80, Math.PI / 2);
geometryLeft360.scale(-1, 1, 1);
const geometryRight360 = geometryLeft360.clone();
Expand Down Expand Up @@ -244,6 +250,28 @@ function init() {
mesh2d360.visible = false;
scene.add(mesh2d360);


// TBScreen
const uvsLeftTBScreen = geometryLeftTBScreen.attributes.uv.array;
for (let i = 1; i < uvsLeftTBScreen.length; i += 2) {
uvsLeftTBScreen[i] *= 0.5;
uvsLeftTBScreen[i] += 0.5;
}

meshLeftTBScreen = new THREE.Mesh(geometryLeftTBScreen, material);
meshLeftTBScreen.layers.set(1); // display in left eye only
meshLeftTBScreen.visible = false;
meshLeftTBScreen.position.setZ(-240);
meshLeftTBScreen.position.setY(CAMERAPOSITIONY);
scene.add(meshLeftTBScreen);

// mesh for 2d mode

mesh2dTBScreen = meshLeftTBScreen.clone();
mesh2dTBScreen.layers.set(2);
mesh2dTBScreen.visible = false;
scene.add(mesh2dTBScreen);

//// right eye
// SBS
const uvsRightSBS = geometryRightSBS.attributes.uv.array;
Expand Down Expand Up @@ -283,6 +311,21 @@ function init() {
meshRight360.position.setZ(-120);
scene.add(meshRight360);


// TBScreen
const uvsRightTBScreen = geometryRightTBScreen.attributes.uv.array;
for (let i = 1; i < uvsRightTBScreen.length; i += 2) {
uvsRightTBScreen[i] *= 0.5;
}

meshRightTBScreen = new THREE.Mesh(geometryRightTBScreen, material);
meshRightTBScreen.layers.set(2); // display in left eye only
meshRightTBScreen.visible = false;
meshRightTBScreen.position.setZ(-240);
meshRightTBScreen.position.setY(CAMERAPOSITIONY);
scene.add(meshRightTBScreen);


ScreenManager.registerMeshPanel(
meshLeftSBS,
"meshLeftSBS",
Expand All @@ -299,6 +342,14 @@ function init() {
"tb",
"left"
);
ScreenManager.registerMeshPanel(
meshLeftTBScreen,
"meshLeftTBScreen",
"meshLeftTBScreen",
"3d",
"tb_screen",
"left"
);
ScreenManager.registerMeshPanel(
meshRightSBS,
"meshRightSBS",
Expand All @@ -315,6 +366,14 @@ function init() {
"tb",
"right"
);
ScreenManager.registerMeshPanel(
meshRightTBScreen,
"meshRightTBScreen",
"meshRightTBScreen",
"3d",
"tb_screen",
"right"
);
ScreenManager.registerMeshPanel(
mesh2dSBS,
"mesh2dSBS",
Expand All @@ -331,6 +390,14 @@ function init() {
"tb",
"right"
);
ScreenManager.registerMeshPanel(
mesh2dTBScreen,
"mesh2dTBScreen",
"mesh2dTBScreen",
"2d",
"tb_screen",
"right"
);
ScreenManager.registerMeshPanel(
meshForScreenMode,
"meshForScreenMode",
Expand Down Expand Up @@ -392,6 +459,9 @@ function init() {
ScreenManager.registerObjectToDrag(mesh2d360, "player", "meshes");
ScreenManager.registerObjectToDrag(mesh1802D, "player", "meshes");
ScreenManager.registerObjectToDrag(mesh3602D, "player", "meshes");
ScreenManager.registerObjectToDrag(meshLeftTBScreen, "player", "meshes");
ScreenManager.registerObjectToDrag(meshRightTBScreen, "player", "meshes");
ScreenManager.registerObjectToDrag(mesh2dTBScreen, "player", "meshes");
meshes = {
meshLeftSBS: meshLeftSBS,
meshRightSBS: meshRightSBS,
Expand All @@ -405,6 +475,9 @@ function init() {
mesh2d360: mesh2d360,
mesh1802D: mesh1802D,
mesh3602D: mesh3602D,
meshLeftTBScreen: meshLeftTBScreen,
meshRightTBScreen: meshRightTBScreen,
mesh2dTBScreen: mesh2dTBScreen,
};

//////////
Expand Down Expand Up @@ -630,6 +703,26 @@ function gamepadControlsUpdate() {
if (typeof gamepad !== "undefined" && gamepad !== null) {
if (gamepad.mapping === "xr-standard") {
if (
gamepad.buttons[1].pressed &&
gamepad.axes[3] < -0.35 &&
(gamepadAxisActive === false ||
gamepadAxisActive === "up")
) {
if (playbackIsActive) {
ScreenManager.tilt("up", 0.005);
}
gamepadAxisActive = "up";
} else if (
gamepad.buttons[1].pressed &&
gamepad.axes[3] > 0.35 &&
(gamepadAxisActive === false ||
gamepadAxisActive === "down")
) {
if (playbackIsActive) {
ScreenManager.tilt("down", 0.005);
}
gamepadAxisActive = "down";
} else if (
gamepad.axes[2] > 0.35 &&
gamepadAxisActive === false
) {
Expand Down Expand Up @@ -683,9 +776,30 @@ function gamepadControlsUpdate() {
}

let buttonABXYpressed = false;
let buttonABXYexitVR = false;
let buttonABXYexitVRstart = null;

function gamepadButtonsCheck(buttons) {
if (buttons[4].pressed && playbackIsActive && buttonABXYpressed === false) {
if (
buttons[1].pressed &&
buttons[5].pressed &&
!playbackIsActive &&
(buttonABXYpressed === false || buttonABXYexitVR)
) {
if (buttonABXYexitVRstart === null) {
buttonABXYexitVRstart = Date.now();
showPopupMessage("Hold Grip + B for 3 seconds to exit.");
} else if (Date.now() - buttonABXYexitVRstart > 3000) {
let session = renderer.xr.getSession();
session.end();
}
buttonABXYexitVR = true;
buttonABXYpressed = true;
} else if (
buttons[4].pressed &&
playbackIsActive &&
buttonABXYpressed === false
) {
playMenuPanel.playPause();
buttonABXYpressed = true;
} else if (
Expand All @@ -697,6 +811,8 @@ function gamepadButtonsCheck(buttons) {
buttonABXYpressed = true;
} else if (!buttons[4].pressed && !buttons[5].pressed) {
buttonABXYpressed = false;
buttonABXYexitVR = false;
buttonABXYexitVRstart = null;
}
}

Expand Down Expand Up @@ -821,6 +937,11 @@ function raycast() {
export function scaleScreenMesh(x_scale) {
meshForScreenMode.scale.x = x_scale;
}
export function scaleTBScreenMesh(x_scale) {
mesh2dTBScreen.scale.x = x_scale;
meshLeftTBScreen.scale.x = x_scale;
meshRightTBScreen.scale.x = x_scale;
}

if (WebGL.isWebGLAvailable()) {
window.addEventListener("resize", onWindowResize);
Expand Down
Loading

0 comments on commit fbd939f

Please sign in to comment.