-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#32 - Refactoring main script file, created additional helpers
- Loading branch information
1 parent
025bd41
commit 42b4bb4
Showing
13 changed files
with
368 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Provides an interface to the core "l" variable, attached to the browser window. | ||
*/ | ||
|
||
// Check if window.l is defined | ||
if (typeof window.l === 'undefined') { | ||
throw new Error('window.l is not defined'); | ||
} | ||
|
||
// Create a shortcut to window.l | ||
const l = window.l; | ||
|
||
export default l; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Set camera FOV based on desired aspect ratio | ||
* | ||
* @param {Float} aspect | ||
* @returns {Float} fov | ||
*/ | ||
export function setCameraFOV( aspect ) { | ||
var fov; | ||
|
||
var threshold = 0.88; | ||
|
||
if ( aspect < threshold ) { | ||
// Portrait or square orientation | ||
fov = mapRange( aspect, 0.5, threshold, 60, 60 ); | ||
} else { | ||
// Widescreen orientation | ||
if ( aspect < 2 ) { | ||
// Tolerance for square to widescreen transition | ||
fov = mapRange( aspect, threshold, 2, 60, 45 ); | ||
} else { | ||
if ( aspect < 2.25 ) { | ||
fov = mapRange( aspect, 2, 2.25, 45, 40 ); | ||
} else { | ||
if ( aspect < 3 ) { | ||
fov = mapRange( aspect, 2.25, 5, 40, 90 ); | ||
} else { | ||
fov = 90; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return fov; | ||
} | ||
|
||
|
||
|
||
/** | ||
* Function to map a value from one range to another | ||
*/ | ||
export function mapRange( value, inMin, inMax, outMin, outMax ) { | ||
return ( ( value - inMin ) * ( outMax - outMin ) ) / ( inMax - inMin ) + outMin; | ||
} | ||
|
||
/** | ||
* Helper to calculate the desired gap size | ||
* | ||
* Used to determine office room dimensions on different screen sizes/aspect ratios. | ||
*/ | ||
export function calculateAdjustedGapSize() { | ||
var width = window.innerWidth; | ||
var height = window.innerHeight; | ||
|
||
// Adjust gap size based on the aspect ratio | ||
var adjustedGapSize = | ||
l.current_scene.settings.gap * l.current_scene.settings.scale; | ||
if ( width < height ) { | ||
adjustedGapSize *= height / width; | ||
} | ||
|
||
return adjustedGapSize; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import l from './l.js'; | ||
|
||
l.select_box = function ( object ) { | ||
// Remove any existing select boxes | ||
if ( l.current_scene.scene_objects.select_box ) { | ||
l.current_scene.scene.remove( l.current_scene.scene_objects.select_box ); | ||
delete l.current_scene.scene_objects.select_box; | ||
} | ||
|
||
const box = new THREE.BoxHelper( object, 0xffff00 ); | ||
l.current_scene.scene_objects.select_box = box; | ||
l.current_scene.scene.add( l.current_scene.scene_objects.select_box ); | ||
|
||
l.current_scene.animation_queue.push( | ||
l.select_box_update | ||
); | ||
} | ||
|
||
l.select_box_update = function () { | ||
l.current_scene.scene_objects.select_box.position.copy( l.current_scene.scene_objects.select_box.object.position ); | ||
l.current_scene.scene_objects.select_box.rotation.copy( l.current_scene.scene_objects.select_box.object.rotation ); | ||
l.current_scene.scene_objects.select_box.update(); | ||
} |
Oops, something went wrong.