webgl_loader_sea3d_keyframe.html 6.6 KB
Newer Older
J
Jean Carlo Deconto 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js webgl - sea3d / keyframe</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				font-family: Monospace;
				background-color: #000;
				margin: 0px;
				overflow: hidden;
			}

			#info {
				color: #fff;
				position: absolute;
				top: 10px;
				width: 100%;
				text-align: center;
				z-index: 100;
				display:block;

			}

			a { color: white }
		</style>
	</head>
	<body>
		<div id="info">
31
			<a href="http://threejs.org" target="_blank" rel="noopener">Three.JS</a> - Exported by <a href="https://github.com/sunag/sea3d" style="color:#FFFFFF" target="_blank" rel="noopener">SEA3D Exporter</a>
S
sunag 已提交
32 33
			<br/>
			<br/><div id="description">Click to play</div>
J
Jean Carlo Deconto 已提交
34 35
		</div>

W
WestLangley 已提交
36
		<script src="../build/three.js"></script>
J
Jean Carlo Deconto 已提交
37

J
Jean Carlo Deconto 已提交
38
		<script src="js/controls/OrbitControls.js"></script>
J
Jean Carlo Deconto 已提交
39 40 41 42

		<script src="js/postprocessing/EffectComposer.js"></script>
		<script src="js/postprocessing/RenderPass.js"></script>
		<script src="js/postprocessing/ShaderPass.js"></script>
M
Mr.doob 已提交
43
		<script src="js/postprocessing/MaskPass.js"></script>
J
Jean Carlo Deconto 已提交
44 45 46
		<script src="js/shaders/CopyShader.js"></script>
		<script src="js/shaders/ColorCorrectionShader.js"></script>
		<script src="js/shaders/VignetteShader.js"></script>
M
Mr.doob 已提交
47

J
Jean Carlo Deconto 已提交
48 49 50 51
		<script src="js/loaders/sea3d/SEA3D.js"></script>
		<script src="js/loaders/sea3d/SEA3DLZMA.js"></script>
		<script src="js/loaders/sea3d/SEA3DLoader.js"></script>

M
Mr.doob 已提交
52
		<script src="js/WebGL.js"></script>
J
Jean Carlo Deconto 已提交
53 54 55 56
		<script src="js/libs/stats.min.js"></script>

		<script>

M
Mr.doob 已提交
57 58 59 60 61
			if ( WEBGL.isWebGLAvailable() === false ) {

				document.body.appendChild( WEBGL.getWebGLErrorMessage() );

			}
J
Jean Carlo Deconto 已提交
62

S
sunag 已提交
63
			console.log( "Visit https://github.com/sunag/sea3d to all codes and builds under development." );
S
sunag 已提交
64

J
Jean Carlo Deconto 已提交
65 66
			var container, stats;

S
sunag 已提交
67
			var camera, scene, renderer, composer, demoAt = - 1;
J
Jean Carlo Deconto 已提交
68 69 70 71 72

			var loader;

			// Initialize Three.JS

M
Mr.doob 已提交
73
			init();
J
Jean Carlo Deconto 已提交
74 75 76 77 78 79 80

			//
			// SEA3D Loader
			//

			loader = new THREE.SEA3D( {

S
sunag 已提交
81 82
				autoPlay: false, // Manual play animations
				container: scene // Container to add models
J
Jean Carlo Deconto 已提交
83 84 85

			} );

86
			loader.onComplete = function () {
J
Jean Carlo Deconto 已提交
87 88 89 90

				// Get the first camera from 3ds Max
				// use loader.get... to get others objects

S
sunag 已提交
91
				var cam = loader.cameras[ 0 ];
J
Jean Carlo Deconto 已提交
92 93 94
				camera.position.copy( cam.position );
				camera.rotation.copy( cam.rotation );

S
sunag 已提交
95
				new THREE.OrbitControls( camera );
J
Jean Carlo Deconto 已提交
96

J
Jean Carlo Deconto 已提交
97
				// events
M
Mr.doob 已提交
98

S
sunag 已提交
99
				window.addEventListener( 'click', onMouseClick, false );
M
Mr.doob 已提交
100

J
Jean Carlo Deconto 已提交
101 102 103 104
				animate();

			};

J
Jean Carlo Deconto 已提交
105
			loader.load( './models/sea3d/keyframe.tjs.sea' );
J
Jean Carlo Deconto 已提交
106 107 108 109 110

			//
			//	Animation Functions
			//

S
sunag 已提交
111
			function playAll( id, crossfade, offset ) {
J
Jean Carlo Deconto 已提交
112 113

				// play all animations
S
sunag 已提交
114

S
sunag 已提交
115
				for ( var i = 0; i < loader.meshes.length; i ++ ) {
S
sunag 已提交
116

S
sunag 已提交
117 118
					if ( loader.meshes[ i ].animator )
						loader.meshes[ i ].animator.play( id, crossfade, offset );
S
sunag 已提交
119

J
Jean Carlo Deconto 已提交
120 121 122
				}

			}
M
Mr.doob 已提交
123 124 125

			function setTimeScale( timeScale ) {

S
sunag 已提交
126
				for ( var i = 0; i < loader.meshes.length; i ++ ) {
S
sunag 已提交
127

S
sunag 已提交
128 129
					if ( loader.meshes[ i ].animator )
						loader.meshes[ i ].animator.setTimeScale( timeScale );
S
sunag 已提交
130

J
Jean Carlo Deconto 已提交
131 132 133
				}

			}
M
Mr.doob 已提交
134

J
Jean Carlo Deconto 已提交
135 136
			function stopAll() {

S
sunag 已提交
137
				for ( var i = 0; i < loader.meshes.length; i ++ ) {
M
Mr.doob 已提交
138

S
sunag 已提交
139 140
					if ( loader.meshes[ i ].animator )
						loader.meshes[ i ].animator.stop();
S
sunag 已提交
141 142

				}
M
Mr.doob 已提交
143

J
Jean Carlo Deconto 已提交
144
			}
M
Mr.doob 已提交
145

J
Jean Carlo Deconto 已提交
146 147 148 149 150
			//

			function init() {

				scene = new THREE.Scene();
151
				scene.background = new THREE.Color( 0x333333 );
J
Jean Carlo Deconto 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164

				container = document.createElement( 'div' );
				document.body.appendChild( container );

				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
				camera.position.set( 1000, - 300, 1000 );

				renderer = new THREE.WebGLRenderer();
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				container.appendChild( renderer.domElement );

				stats = new Stats();
M
Mr.doob 已提交
165
				container.appendChild( stats.dom );
J
Jean Carlo Deconto 已提交
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188

				// post-processing

				composer = new THREE.EffectComposer( renderer );

				var renderPass = new THREE.RenderPass( scene, camera );
				var copyPass = new THREE.ShaderPass( THREE.CopyShader );
				composer.addPass( renderPass );

				var vh = 1.4, vl = 1.2;

				var colorCorrectionPass = new THREE.ShaderPass( THREE.ColorCorrectionShader );
				colorCorrectionPass.uniforms[ "powRGB" ].value = new THREE.Vector3( vh, vh, vh );
				colorCorrectionPass.uniforms[ "mulRGB" ].value = new THREE.Vector3( vl, vl, vl );
				composer.addPass( colorCorrectionPass );

				var vignettePass = new THREE.ShaderPass( THREE.VignetteShader );
				vignettePass.uniforms[ "darkness" ].value = 1.0;
				composer.addPass( vignettePass );

				composer.addPass( copyPass );

				// events
M
Mr.doob 已提交
189

J
Jean Carlo Deconto 已提交
190 191 192 193 194 195 196 197 198 199
				window.addEventListener( 'resize', onWindowResize, false );

			}


			function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

M
Mr.doob 已提交
200
				composer.setSize( window.innerWidth, window.innerHeight );
J
Jean Carlo Deconto 已提交
201 202 203 204 205 206
				renderer.setSize( window.innerWidth, window.innerHeight );

			}

			//

S
sunag 已提交
207
			function description( msg ) {
J
Jean Carlo Deconto 已提交
208

S
sunag 已提交
209
				document.getElementById( 'description' ).innerHTML = ( demoAt + 1 ) + " - " + msg;
J
Jean Carlo Deconto 已提交
210 211

			}
M
Mr.doob 已提交
212

213
			function onMouseClick() {
J
Jean Carlo Deconto 已提交
214 215 216

				// 0 at 3 demos

S
sunag 已提交
217
				switch ( demoAt = ++ demoAt % 4 ) {
J
Jean Carlo Deconto 已提交
218

219
					// play all animation to sequence "crash#1"
J
Jean Carlo Deconto 已提交
220 221 222

					case 0:

S
sunag 已提交
223 224
						playAll( "crash#1", .5 );
						setTimeScale( 1 );
J
Jean Carlo Deconto 已提交
225

S
sunag 已提交
226
						description( "crash#1 - crossfade 0.5 seconds" );
J
Jean Carlo Deconto 已提交
227 228 229

						break;

S
sunag 已提交
230
						// play all animation to sequence "crash#2"
J
Jean Carlo Deconto 已提交
231 232 233

					case 1:

S
sunag 已提交
234
						playAll( "crash#2", .5 );
M
Mr.doob 已提交
235

S
sunag 已提交
236
						description( "crash#2 - crossfade 0.5 seconds" );
J
Jean Carlo Deconto 已提交
237

M
Mr.doob 已提交
238
						break;
J
Jean Carlo Deconto 已提交
239

S
sunag 已提交
240
						// play animation in single object
J
Jean Carlo Deconto 已提交
241 242 243 244 245

					case 2:

						stopAll();

S
sunag 已提交
246
						var fracture99 = loader.getMesh( "Object099" );
J
Jean Carlo Deconto 已提交
247

248 249 250 251
						//fracture99.animator.setTimeScale( 1 );
						//fracture99.animator.playing
						//fracture99.animator.currentAnimation
						//fracture99.animator.previousAnimation
J
Jean Carlo Deconto 已提交
252

S
sunag 已提交
253
						fracture99.animator.play( "crash#2", .5, 0 );
254 255 256
						//fracture99.animator.stop();
						//fracture99.animator.pause();
						//fracture99.animator.resume();
J
Jean Carlo Deconto 已提交
257

S
sunag 已提交
258
						description( "crash#2 in single object - crossfade 0.5 seconds" );
J
Jean Carlo Deconto 已提交
259 260 261

						break;

S
sunag 已提交
262
						// set time scale
J
Jean Carlo Deconto 已提交
263 264 265

					case 3:

S
sunag 已提交
266 267
						playAll( "crash#2", .5 );
						setTimeScale( .1 );
J
Jean Carlo Deconto 已提交
268

S
sunag 已提交
269
						description( "time scale / 10 - crossfade 0.5 seconds" );
J
Jean Carlo Deconto 已提交
270

M
Mr.doob 已提交
271
						break;
S
sunag 已提交
272

J
Jean Carlo Deconto 已提交
273
				}
S
sunag 已提交
274

J
Jean Carlo Deconto 已提交
275
			}
J
Jean Carlo Deconto 已提交
276 277 278 279 280

			//

			var clock = new THREE.Clock();

J
Jean Carlo Deconto 已提交
281 282
			function animate() {

J
Jean Carlo Deconto 已提交
283
				var delta = clock.getDelta();
M
Mr.doob 已提交
284

J
Jean Carlo Deconto 已提交
285 286
				requestAnimationFrame( animate );

J
Jean Carlo Deconto 已提交
287
				// Update SEA3D Animations
J
Jean Carlo Deconto 已提交
288
				THREE.SEA3D.AnimationHandler.update( delta );
J
Jean Carlo Deconto 已提交
289

J
Jean Carlo Deconto 已提交
290
				render( delta );
J
Jean Carlo Deconto 已提交
291 292 293 294 295

				stats.update();

			}

J
Jean Carlo Deconto 已提交
296
			function render( dlt ) {
J
Jean Carlo Deconto 已提交
297 298

				//renderer.render( scene, camera );
J
Jean Carlo Deconto 已提交
299
				composer.render( dlt );
J
Jean Carlo Deconto 已提交
300 301 302 303 304 305

			}

		</script>
	</body>
</html>