-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
123 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>=^.^=</title> | ||
<link rel="stylesheet" href="./style.css"> | ||
</head> | ||
<body> | ||
<div class="info"> | ||
<a href="https://github.com/yomotsu/camera-controls">GitHub repo</a><br> | ||
<button onclick="cameraControls.reset( true )">reset</button><br> | ||
<button onclick="rotate45()">rotate 45 deg <b>relatively</b> with easing in 1 sec</button><br> | ||
<button onclick="rotate0To120()">rotate 0 to 120 deg with easing in 3 sec</button><br> | ||
</div> | ||
|
||
<script src="https://unpkg.com/three@0.115.0/build/three.min.js"></script> | ||
<script src="https://unpkg.com/@tweenjs/tween.js@18.5.0/dist/tween.umd.js"></script> | ||
<script src="../dist/camera-controls.js"></script> | ||
<script> | ||
CameraControls.install( { THREE: THREE } ); | ||
|
||
const width = window.innerWidth; | ||
const height = window.innerHeight; | ||
const clock = new THREE.Clock(); | ||
const scene = new THREE.Scene(); | ||
const camera = new THREE.PerspectiveCamera( 60, width / height, 0.01, 100 ); | ||
camera.position.set( 0, 0, 5 ); | ||
const renderer = new THREE.WebGLRenderer( { antialias: true, stencil: false } ); | ||
renderer.setSize( width, height ); | ||
document.body.appendChild( renderer.domElement ); | ||
|
||
const cameraControls = new CameraControls( camera, renderer.domElement ); | ||
|
||
const mesh = new THREE.Mesh( | ||
new THREE.BoxGeometry( 1, 1, 1 ), | ||
new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } ) | ||
); | ||
scene.add( mesh ); | ||
|
||
const gridHelper = new THREE.GridHelper( 50, 50 ); | ||
gridHelper.position.y = - 1; | ||
scene.add( gridHelper ); | ||
|
||
|
||
|
||
const rotate45 = function () { | ||
|
||
// save the start angle | ||
let startAzimuthAngle = cameraControls.azimuthAngle; | ||
new TWEEN.Tween( cameraControls ) | ||
.to( { azimuthAngle: 45 * THREE.Math.DEG2RAD + startAzimuthAngle }, 1000 ) | ||
.easing( TWEEN.Easing.Bounce.Out ) | ||
.onStart( function() { | ||
|
||
// disable user control while the animation | ||
cameraControls.enabled = false; | ||
|
||
} ) | ||
.onComplete( function() { | ||
|
||
cameraControls.enabled = true; | ||
|
||
} ) | ||
.start(); | ||
|
||
} | ||
|
||
|
||
const rotate0To120 = function () { | ||
|
||
cameraControls.azimuthAngle = 0; | ||
|
||
new TWEEN.Tween( cameraControls ) | ||
.to( { azimuthAngle: 120 * THREE.Math.DEG2RAD }, 3000 ) | ||
.easing( TWEEN.Easing.Exponential.Out ) | ||
.onStart( function() { | ||
|
||
// disable user control while the animation | ||
cameraControls.enabled = false; | ||
|
||
} ) | ||
.onComplete( function() { | ||
|
||
cameraControls.enabled = true; | ||
|
||
} ) | ||
.start(); | ||
|
||
} | ||
|
||
|
||
renderer.render( scene, camera ); | ||
|
||
( function anim () { | ||
|
||
const delta = clock.getDelta(); | ||
const elapsed = clock.getElapsedTime(); | ||
const updated = cameraControls.update( delta ); | ||
|
||
// if ( elapsed > 30 ) { return; } | ||
|
||
requestAnimationFrame( anim ); | ||
|
||
TWEEN.update( elapsed * 1000 ); | ||
|
||
if ( updated ) { | ||
|
||
renderer.render( scene, camera ); | ||
console.log( 'rendered' ); | ||
|
||
} | ||
|
||
} )(); | ||
</script> | ||
|
||
</body> | ||
</html> |
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 |
---|---|---|
|
@@ -109,7 +109,7 @@ | |
|
||
requestAnimationFrame( anim ); | ||
|
||
TWEEN.update(); | ||
TWEEN.update( elapsed * 1000 ); | ||
|
||
if ( updated ) { | ||
|
||
|
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