From 6ba244f37b5438e78986f70813448085fbea20d9 Mon Sep 17 00:00:00 2001 From: CrazyH <87752773+CrazyH2@users.noreply.github.com> Date: Sat, 30 Mar 2024 13:31:04 +0000 Subject: [PATCH] remove esm as it breaks it --- index.html | 11 ++ libraries/cardboard-vr-display.js | 10 +- src/main.js | 2 - src/screens/main/SettingsMenu.js | 1 - src/screens/main/appsMenu.js | 1 - src/screens/main/mainMenu.js | 1 - src/screens/screen.js | 2 - src/screens/screenManager.js | 2 - src/screens/start/actionsInfo.js | 1 - src/screens/start/controllerAlign.js | 7 +- src/screens/start/controllerInfo.js | 7 +- src/screens/start/welcome.js | 1 - src/world/render.js | 1 - src/world/scene.js | 8 +- utils/CardboardActions.js | 2 - utils/DeviceOrientationControls.js | 176 ++++++++++++++------------- utils/MTLLoader.js | 20 ++- utils/OBJLoader.js | 6 +- utils/TextBox.js | 2 - utils/VREffect.js | 22 ++-- 20 files changed, 130 insertions(+), 153 deletions(-) diff --git a/index.html b/index.html index 842b6e6..27bba4d 100644 --- a/index.html +++ b/index.html @@ -40,6 +40,17 @@

CardiVR

+ + + + + + + + + + + diff --git a/libraries/cardboard-vr-display.js b/libraries/cardboard-vr-display.js index f451349..b2efbf1 100644 --- a/libraries/cardboard-vr-display.js +++ b/libraries/cardboard-vr-display.js @@ -80,7 +80,11 @@ * THE SOFTWARE. */ -var MainFunc = (function () { 'use strict'; +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.CardboardVRDisplay = factory()); +}(this, (function () { 'use strict'; var asyncGenerator = function () { function AwaitValue(value) { @@ -3462,6 +3466,4 @@ CardboardVRDisplay.VRDisplay = VRDisplay; return CardboardVRDisplay; -})(); - -export default MainFunc; \ No newline at end of file +}))); diff --git a/src/main.js b/src/main.js index 723e546..bbe04be 100644 --- a/src/main.js +++ b/src/main.js @@ -2,8 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../libraries/three.module.min.js"; -import CardboardVRDisplay from "../libraries/cardboard-vr-display.js"; import { Render } from "./world/render.js"; class Main { diff --git a/src/screens/main/SettingsMenu.js b/src/screens/main/SettingsMenu.js index 00080ae..2b7dde0 100644 --- a/src/screens/main/SettingsMenu.js +++ b/src/screens/main/SettingsMenu.js @@ -2,7 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../../../libraries/three.module.min.js"; import { Screen } from "../screen.js"; class SettingsMenu extends Screen { diff --git a/src/screens/main/appsMenu.js b/src/screens/main/appsMenu.js index 263dbc3..fe63553 100644 --- a/src/screens/main/appsMenu.js +++ b/src/screens/main/appsMenu.js @@ -2,7 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../../../libraries/three.module.min.js"; import { Screen } from "../screen.js"; class AppsMenu extends Screen { diff --git a/src/screens/main/mainMenu.js b/src/screens/main/mainMenu.js index 2936f18..6d07986 100644 --- a/src/screens/main/mainMenu.js +++ b/src/screens/main/mainMenu.js @@ -2,7 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../../../libraries/three.module.min.js"; import { Screen } from "../screen.js"; class MainMenu extends Screen { diff --git a/src/screens/screen.js b/src/screens/screen.js index 7bc5447..178a993 100644 --- a/src/screens/screen.js +++ b/src/screens/screen.js @@ -2,8 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../../libraries/three.module.min.js"; - class Screen { constructor(root) { this.root = root; diff --git a/src/screens/screenManager.js b/src/screens/screenManager.js index ea1d776..1d8336d 100644 --- a/src/screens/screenManager.js +++ b/src/screens/screenManager.js @@ -2,8 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../../libraries/three.module.min.js"; - class ScreenManager { constructor(root) { this.root = root; diff --git a/src/screens/start/actionsInfo.js b/src/screens/start/actionsInfo.js index 2e3345b..899bc13 100644 --- a/src/screens/start/actionsInfo.js +++ b/src/screens/start/actionsInfo.js @@ -2,7 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../../../libraries/three.module.min.js"; import { Screen } from "../screen.js"; import { TextBox } from "../../../utils/TextBox.js"; diff --git a/src/screens/start/controllerAlign.js b/src/screens/start/controllerAlign.js index eb36e5d..0947760 100644 --- a/src/screens/start/controllerAlign.js +++ b/src/screens/start/controllerAlign.js @@ -2,9 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../../../libraries/three.module.min.js"; -import { MTLLoader } from "../../../utils/MTLLoader.js"; -import { OBJLoader } from "../../../utils/OBJLoader.js"; import { Screen } from "../screen.js"; import { TextBox } from "../../../utils/TextBox.js"; @@ -46,11 +43,11 @@ class ControllerAlignScreen extends Screen { renderGroup.add( mesh ); - var mtlLoader = new MTLLoader(); + var mtlLoader = new THREE.MTLLoader(); mtlLoader.load("./assets/objects/gear_vr_controller.mtl", function(materials) { materials.preload(); - var objLoader = new OBJLoader(); + var objLoader = new THREE.OBJLoader(); objLoader.setMaterials(materials); objLoader.load("./assets/objects/gear_vr_controller.obj", function(object) { object.position.z = -0.8; diff --git a/src/screens/start/controllerInfo.js b/src/screens/start/controllerInfo.js index c9a7e25..68e67df 100644 --- a/src/screens/start/controllerInfo.js +++ b/src/screens/start/controllerInfo.js @@ -2,9 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../../../libraries/three.module.min.js"; -import { MTLLoader } from "../../../utils/MTLLoader.js"; -import { OBJLoader } from "../../../utils/OBJLoader.js"; import { Screen } from "../screen.js"; import { TextBox } from "../../../utils/TextBox.js"; @@ -46,11 +43,11 @@ class ControllerInfoScreen extends Screen { renderGroup.add( mesh ); - var mtlLoader = new MTLLoader(); + var mtlLoader = new THREE.MTLLoader(); mtlLoader.load("./assets/objects/gear_vr_controller.mtl", function(materials) { materials.preload(); - var objLoader = new OBJLoader(); + var objLoader = new THREE.OBJLoader(); objLoader.setMaterials(materials); objLoader.load("./assets/objects/gear_vr_controller.obj", function(object) { object.position.z = -0.8; diff --git a/src/screens/start/welcome.js b/src/screens/start/welcome.js index 2d3c591..a6698c2 100644 --- a/src/screens/start/welcome.js +++ b/src/screens/start/welcome.js @@ -2,7 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../../../libraries/three.module.min.js"; import { Screen } from "../screen.js"; import { TextBox } from "../../../utils/TextBox.js"; import { ActionsInfoScreen } from "./actionsInfo.js"; diff --git a/src/world/render.js b/src/world/render.js index ba56623..8c5ca2f 100644 --- a/src/world/render.js +++ b/src/world/render.js @@ -2,7 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../../libraries/three.module.min.js"; import { Scene } from "./scene.js"; class Render { diff --git a/src/world/scene.js b/src/world/scene.js index b4a3565..7cf6a4e 100644 --- a/src/world/scene.js +++ b/src/world/scene.js @@ -2,10 +2,6 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../../libraries/three.module.min.js"; -import { DeviceOrientationControls } from "../../utils/DeviceOrientationControls.js"; -import { CardboardActions } from "../../utils/CardboardActions.js"; -import { VREffect } from "../../utils/VREffect.js"; import { WelcomeScreen } from "../screens/start/welcome.js"; import { ScreenManager } from "./../screens/screenManager.js"; @@ -31,10 +27,10 @@ class Scene { var actionControls = new CardboardActions(this.camera); // Apply VR headset rotational data to camera. - var controls = new DeviceOrientationControls(this.camera); + var controls = new THREE.DeviceOrientationControls(this.camera); // Apply VR stereo rendering to renderer. - var effect = new VREffect(this.top.renderer); + var effect = new THREE.VREffect(this.top.renderer); effect.setSize(window.innerWidth, window.innerHeight); // Kick off the render loop. diff --git a/utils/CardboardActions.js b/utils/CardboardActions.js index cc14be1..7ca1551 100644 --- a/utils/CardboardActions.js +++ b/utils/CardboardActions.js @@ -27,5 +27,3 @@ class CardboardActions { } }; }; - -export { CardboardActions }; \ No newline at end of file diff --git a/utils/DeviceOrientationControls.js b/utils/DeviceOrientationControls.js index 10279af..7b5093d 100644 --- a/utils/DeviceOrientationControls.js +++ b/utils/DeviceOrientationControls.js @@ -3,152 +3,154 @@ * @author crazyh / https://github.com/crazyh2 */ -import * as THREE from "../libraries/three.module.min.js"; +( function () { -const _zee = new THREE.Vector3(0, 0, 1); + const _zee = new THREE.Vector3( 0, 0, 1 ); -const _euler = new THREE.Euler(); + const _euler = new THREE.Euler(); -const _q0 = new THREE.Quaternion(); + const _q0 = new THREE.Quaternion(); -const _q1 = new THREE.Quaternion(- Math.sqrt(0.5), 0, 0, Math.sqrt(0.5)); // - PI/2 around the x-axis + const _q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis -const _changeEvent = { - type: 'change' -}; + const _changeEvent = { + type: 'change' + }; -class DeviceOrientationControls extends THREE.EventDispatcher { + class DeviceOrientationControls extends THREE.EventDispatcher { - constructor(object) { + constructor( object ) { - super(); + super(); - if (window.isSecureContext === false) { + if ( window.isSecureContext === false ) { - console.error('THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)'); + console.error( 'THREE.DeviceOrientationControls: DeviceOrientationEvent is only available in secure contexts (https)' ); - } - - const scope = this; - const EPS = 0.000001; - const lastQuaternion = new THREE.Quaternion(); - this.object = object; - this.object.rotation.reorder('YXZ'); - this.enabled = true; - this.deviceOrientation = {}; - this.screenOrientation = 0; - this.alphaOffset = 0; // radians - - const onDeviceOrientationChangeEvent = function (event) { - - scope.deviceOrientation = event; - - }; - - const onScreenOrientationChangeEvent = function () { + } - scope.screenOrientation = window.orientation || 0; + const scope = this; + const EPS = 0.000001; + const lastQuaternion = new THREE.Quaternion(); + this.object = object; + this.object.rotation.reorder( 'YXZ' ); + this.enabled = true; + this.deviceOrientation = {}; + this.screenOrientation = 0; + this.alphaOffset = 0; // radians - }; // The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y'' + const onDeviceOrientationChangeEvent = function ( event ) { + scope.deviceOrientation = event; - const setObjectQuaternion = function (quaternion, alpha, beta, gamma, orient) { + }; - _euler.set(beta, alpha, - gamma, 'YXZ'); // 'ZXY' for the device, but 'YXZ' for us + const onScreenOrientationChangeEvent = function () { + scope.screenOrientation = window.orientation || 0; - quaternion.setFromEuler(_euler); // orient the device + }; // The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y'' - quaternion.multiply(_q1); // camera looks out the back of the device, not the top - quaternion.multiply(_q0.setFromAxisAngle(_zee, - orient)); // adjust for screen orientation + const setObjectQuaternion = function ( quaternion, alpha, beta, gamma, orient ) { - }; + _euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us - this.connect = function () { - onScreenOrientationChangeEvent(); // run once on load - // iOS 13+ + quaternion.setFromEuler( _euler ); // orient the device - if (window.DeviceOrientationEvent && typeof (window.DeviceOrientationEvent.requestPermission) === "function") { - const permissionPrompt = function () { - window.DeviceOrientationEvent.requestPermission().then(function (response) { + quaternion.multiply( _q1 ); // camera looks out the back of the device, not the top - if (response == 'granted') { + quaternion.multiply( _q0.setFromAxisAngle( _zee, - orient ) ); // adjust for screen orientation - window.addEventListener('orientationchange', onScreenOrientationChangeEvent); - window.addEventListener('deviceorientation', onDeviceOrientationChangeEvent); + }; - } + this.connect = function () { - }).catch(function (error) { + onScreenOrientationChangeEvent(); // run once on load + // iOS 13+ - console.error('THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:', error); + if ( window.DeviceOrientationEvent && typeof(window.DeviceOrientationEvent.requestPermission) === "function" ) { + const permissionPrompt = function() { + window.DeviceOrientationEvent.requestPermission().then( function ( response ) { + + if ( response == 'granted' ) { + + window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent ); + window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent ); + + } + + } ).catch( function ( error ) { + + console.error( 'THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:', error ); + + } ); + document.body.removeEventListener("click", permissionPrompt); + }; - }); - document.body.removeEventListener("click", permissionPrompt); - }; + document.body.addEventListener("click", permissionPrompt); - document.body.addEventListener("click", permissionPrompt); + } else { - } else { + window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent ); + window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent ); - window.addEventListener('orientationchange', onScreenOrientationChangeEvent); - window.addEventListener('deviceorientation', onDeviceOrientationChangeEvent); + } - } + scope.enabled = true; - scope.enabled = true; + }; - }; + this.disconnect = function () { - this.disconnect = function () { + window.removeEventListener( 'orientationchange', onScreenOrientationChangeEvent ); + window.removeEventListener( 'deviceorientation', onDeviceOrientationChangeEvent ); + scope.enabled = false; - window.removeEventListener('orientationchange', onScreenOrientationChangeEvent); - window.removeEventListener('deviceorientation', onDeviceOrientationChangeEvent); - scope.enabled = false; + }; - }; + this.update = function () { - this.update = function () { + if ( scope.enabled === false ) return; + const device = scope.deviceOrientation; - if (scope.enabled === false) return; - const device = scope.deviceOrientation; + if ( device ) { - if (device) { + const alpha = device.alpha ? THREE.Math.degToRad( device.alpha ) + scope.alphaOffset : 0; // Z - const alpha = device.alpha ? THREE.Math.degToRad(device.alpha) + scope.alphaOffset : 0; // Z + const beta = device.beta ? THREE.Math.degToRad( device.beta ) : 0; // X' - const beta = device.beta ? THREE.Math.degToRad(device.beta) : 0; // X' + const gamma = device.gamma ? THREE.Math.degToRad( device.gamma ) : 0; // Y'' - const gamma = device.gamma ? THREE.Math.degToRad(device.gamma) : 0; // Y'' + const orient = scope.screenOrientation ? THREE.Math.degToRad( scope.screenOrientation ) : 0; // O - const orient = scope.screenOrientation ? THREE.Math.degToRad(scope.screenOrientation) : 0; // O + setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient ); - setObjectQuaternion(scope.object.quaternion, alpha, beta, gamma, orient); + if ( 8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) { - if (8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) { + lastQuaternion.copy( scope.object.quaternion ); + scope.dispatchEvent( _changeEvent ); - lastQuaternion.copy(scope.object.quaternion); - scope.dispatchEvent(_changeEvent); + } } - } + }; - }; + this.dispose = function () { - this.dispose = function () { + scope.disconnect(); - scope.disconnect(); + }; - }; + this.connect(); - this.connect(); + } } -} + THREE.DeviceOrientationControls = DeviceOrientationControls; -export { DeviceOrientationControls }; \ No newline at end of file +} )(); \ No newline at end of file diff --git a/utils/MTLLoader.js b/utils/MTLLoader.js index b704755..8a495b8 100644 --- a/utils/MTLLoader.js +++ b/utils/MTLLoader.js @@ -4,17 +4,15 @@ * @author angelxuanchang */ -import * as THREE from "../libraries/three.module.min.js"; - -var MTLLoader = function ( manager ) { +THREE.MTLLoader = function ( manager ) { this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; }; -MTLLoader.prototype = { +THREE.MTLLoader.prototype = { - constructor: MTLLoader, + constructor: THREE.MTLLoader, /** * Loads and parses a MTL asset from a URL. @@ -103,7 +101,7 @@ MTLLoader.prototype = { * Parses a MTL file. * * @param {String} text - Content of MTL file - * @return {MTLLoader.MaterialCreator} + * @return {THREE.MTLLoader.MaterialCreator} * * @see setPath setTexturePath * @@ -161,7 +159,7 @@ MTLLoader.prototype = { } - var materialCreator = new MTLLoader.MaterialCreator( this.texturePath || this.path, this.materialOptions ); + var materialCreator = new THREE.MTLLoader.MaterialCreator( this.texturePath || this.path, this.materialOptions ); materialCreator.setCrossOrigin( this.crossOrigin ); materialCreator.setManager( this.manager ); materialCreator.setMaterials( materialsInfo ); @@ -186,7 +184,7 @@ MTLLoader.prototype = { * @constructor */ -MTLLoader.MaterialCreator = function ( baseUrl, options ) { +THREE.MTLLoader.MaterialCreator = function ( baseUrl, options ) { this.baseUrl = baseUrl || ''; this.options = options; @@ -200,9 +198,9 @@ MTLLoader.MaterialCreator = function ( baseUrl, options ) { }; -MTLLoader.MaterialCreator.prototype = { +THREE.MTLLoader.MaterialCreator.prototype = { - constructor: MTLLoader.MaterialCreator, + constructor: THREE.MTLLoader.MaterialCreator, crossOrigin: 'Anonymous', @@ -551,5 +549,3 @@ MTLLoader.MaterialCreator.prototype = { } }; - -export { MTLLoader }; \ No newline at end of file diff --git a/utils/OBJLoader.js b/utils/OBJLoader.js index b22c0c9..2c4845f 100644 --- a/utils/OBJLoader.js +++ b/utils/OBJLoader.js @@ -2,9 +2,7 @@ * @author mrdoob / http://mrdoob.com/ */ -import * as THREE from "../libraries/three.module.min.js"; - -var OBJLoader = ( function () { +THREE.OBJLoader = ( function () { // o object_name | g group_name var object_pattern = /^[og]\s*(.+)?/; @@ -670,5 +668,3 @@ var OBJLoader = ( function () { return OBJLoader; } )(); - -export { OBJLoader }; \ No newline at end of file diff --git a/utils/TextBox.js b/utils/TextBox.js index ccc727f..831e978 100644 --- a/utils/TextBox.js +++ b/utils/TextBox.js @@ -1,5 +1,3 @@ -import * as THREE from "../libraries/three.module.min.js"; - /** * Text = 3D Text * diff --git a/utils/VREffect.js b/utils/VREffect.js index 460bfe0..9a2482e 100644 --- a/utils/VREffect.js +++ b/utils/VREffect.js @@ -8,9 +8,7 @@ * Chromium: https://webvr.info/get-chrome */ -import * as THREE from "../libraries/three.module.min.js"; - -var VREffect = function ( renderer, onError ) { +THREE.VREffect = function ( renderer, onError ) { var vrDisplay, vrDisplays; var eyeTranslationL = new THREE.Vector3(); @@ -60,7 +58,7 @@ var VREffect = function ( renderer, onError ) { var scope = this; - var rendererSize = new THREE.Vector2( 0, 0 ); renderer.getSize(rendererSize); + var rendererSize = renderer.getSize(); var rendererUpdateStyle = false; var rendererPixelRatio = renderer.getPixelRatio(); @@ -123,7 +121,7 @@ var VREffect = function ( renderer, onError ) { if ( ! wasPresenting ) { rendererPixelRatio = renderer.getPixelRatio(); - rendererSize = new THREE.Vector2( 0, 0 ); renderer.getSize(rendererSize); + rendererSize = renderer.getSize(); renderer.setPixelRatio( 1 ); renderer.setSize( eyeWidth * 2, eyeHeight, false ); @@ -237,12 +235,12 @@ var VREffect = function ( renderer, onError ) { if ( vrDisplay && scope.isPresenting ) { - var autoUpdate = scene.matrixWorldAutoUpdate; + var autoUpdate = scene.autoUpdate; if ( autoUpdate ) { scene.updateMatrixWorld(); - scene.matrixWorldAutoUpdate = false; + scene.autoUpdate = false; } @@ -255,7 +253,7 @@ var VREffect = function ( renderer, onError ) { // When rendering we don't care what the recommended size is, only what the actual size // of the backbuffer is. - var size = new THREE.Vector2( 0, 0 ); renderer.getSize(size); + var size = renderer.getSize(); var layers = vrDisplay.getLayers(); var leftBounds; var rightBounds; @@ -389,7 +387,7 @@ var VREffect = function ( renderer, onError ) { if ( autoUpdate ) { - scene.matrixWorldAutoUpdate = true; + scene.autoUpdate = true; } @@ -456,8 +454,8 @@ var VREffect = function ( renderer, onError ) { // The eye's model matrix in head space is the inverse of headToEyeMatrix we calculated above. - eyeMatrixL.invert();//getInverse( eyeMatrixL ); - eyeMatrixR.invert();//getInverse( eyeMatrixR ); + eyeMatrixL.getInverse( eyeMatrixL ); + eyeMatrixR.getInverse( eyeMatrixR ); } @@ -533,5 +531,3 @@ var VREffect = function ( renderer, onError ) { } }; - -export { VREffect }; \ No newline at end of file