webgl_loader_sea3d_keyframe.html 6.1 KB
Newer Older
J
Jean Carlo Deconto 已提交
1 2 3 4 5 6
<!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">
M
Mr.doob 已提交
7
		<link type="text/css" rel="stylesheet" href="main.css">
J
Jean Carlo Deconto 已提交
8 9 10
	</head>
	<body>
		<div id="info">
M
Mr.doob 已提交
11 12
			<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - Exported by <a href="https://github.com/sunag/sea3d" target="_blank" rel="noopener">SEA3D Exporter</a><br/>
			<div id="description">Click to play</div>
J
Jean Carlo Deconto 已提交
13 14
		</div>

S
sunag 已提交
15
		<script type="module">
J
Jean Carlo Deconto 已提交
16

M
Mr.doob 已提交
17
			import * as THREE from '../build/three.module.js';
J
Jean Carlo Deconto 已提交
18

S
sunag 已提交
19
			import { OrbitControls } from './jsm/controls/OrbitControls.js';
M
Mr.doob 已提交
20

S
sunag 已提交
21 22 23 24 25 26
			import { EffectComposer } from './jsm/postprocessing/EffectComposer.js';
			import { RenderPass } from './jsm/postprocessing/RenderPass.js';
			import { ShaderPass } from './jsm/postprocessing/ShaderPass.js';
			import { CopyShader } from './jsm/shaders/CopyShader.js';
			import { ColorCorrectionShader } from './jsm/shaders/ColorCorrectionShader.js';
			import { VignetteShader } from './jsm/shaders/VignetteShader.js';
J
Jean Carlo Deconto 已提交
27

S
sunag 已提交
28 29
			import { SEA3D } from './jsm/loaders/sea3d/SEA3DLoader.js';
			import './jsm/loaders/sea3d/SEA3DLZMA.js'; // sea3d lzma extension
J
Jean Carlo Deconto 已提交
30

S
sunag 已提交
31
			import Stats from './jsm/libs/stats.module.js';
J
Jean Carlo Deconto 已提交
32

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

J
Jean Carlo Deconto 已提交
35 36
			var container, stats;

S
sunag 已提交
37
			var camera, scene, renderer, composer, demoAt = - 1;
J
Jean Carlo Deconto 已提交
38 39 40 41 42

			var loader;

			// Initialize Three.JS

M
Mr.doob 已提交
43
			init();
J
Jean Carlo Deconto 已提交
44 45 46 47 48

			//
			// SEA3D Loader
			//

S
sunag 已提交
49
			loader = new SEA3D( {
J
Jean Carlo Deconto 已提交
50

S
sunag 已提交
51 52
				autoPlay: false, // Manual play animations
				container: scene // Container to add models
J
Jean Carlo Deconto 已提交
53 54 55

			} );

56
			loader.onComplete = function () {
J
Jean Carlo Deconto 已提交
57 58 59 60

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

S
sunag 已提交
61
				var cam = loader.cameras[ 0 ];
J
Jean Carlo Deconto 已提交
62 63 64
				camera.position.copy( cam.position );
				camera.rotation.copy( cam.rotation );

S
sunag 已提交
65
				new OrbitControls( camera, renderer.domElement );
J
Jean Carlo Deconto 已提交
66

J
Jean Carlo Deconto 已提交
67
				// events
M
Mr.doob 已提交
68

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

J
Jean Carlo Deconto 已提交
71 72 73 74
				animate();

			};

J
Jean Carlo Deconto 已提交
75
			loader.load( './models/sea3d/keyframe.tjs.sea' );
J
Jean Carlo Deconto 已提交
76 77 78 79 80

			//
			//	Animation Functions
			//

S
sunag 已提交
81
			function playAll( id, crossfade, offset ) {
J
Jean Carlo Deconto 已提交
82 83

				// play all animations
S
sunag 已提交
84

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

S
sunag 已提交
87 88
					if ( loader.meshes[ i ].animator )
						loader.meshes[ i ].animator.play( id, crossfade, offset );
S
sunag 已提交
89

J
Jean Carlo Deconto 已提交
90 91 92
				}

			}
M
Mr.doob 已提交
93 94 95

			function setTimeScale( timeScale ) {

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

S
sunag 已提交
98 99
					if ( loader.meshes[ i ].animator )
						loader.meshes[ i ].animator.setTimeScale( timeScale );
S
sunag 已提交
100

J
Jean Carlo Deconto 已提交
101 102 103
				}

			}
M
Mr.doob 已提交
104

J
Jean Carlo Deconto 已提交
105 106
			function stopAll() {

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

S
sunag 已提交
109 110
					if ( loader.meshes[ i ].animator )
						loader.meshes[ i ].animator.stop();
S
sunag 已提交
111 112

				}
M
Mr.doob 已提交
113

J
Jean Carlo Deconto 已提交
114
			}
M
Mr.doob 已提交
115

J
Jean Carlo Deconto 已提交
116 117 118 119
			//

			function init() {

M
Mr.doob 已提交
120 121
				scene = new THREE.Scene();
				scene.background = new THREE.Color( 0x333333 );
J
Jean Carlo Deconto 已提交
122 123 124 125

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

M
Mr.doob 已提交
126
				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
J
Jean Carlo Deconto 已提交
127 128
				camera.position.set( 1000, - 300, 1000 );

M
Mr.doob 已提交
129
				renderer = new THREE.WebGLRenderer();
J
Jean Carlo Deconto 已提交
130 131 132 133 134
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				container.appendChild( renderer.domElement );

				stats = new Stats();
M
Mr.doob 已提交
135
				container.appendChild( stats.dom );
J
Jean Carlo Deconto 已提交
136 137 138

				// post-processing

S
sunag 已提交
139
				composer = new EffectComposer( renderer );
J
Jean Carlo Deconto 已提交
140

S
sunag 已提交
141 142
				var renderPass = new RenderPass( scene, camera );
				var copyPass = new ShaderPass( CopyShader );
J
Jean Carlo Deconto 已提交
143 144 145 146
				composer.addPass( renderPass );

				var vh = 1.4, vl = 1.2;

S
sunag 已提交
147
				var colorCorrectionPass = new ShaderPass( ColorCorrectionShader );
M
Mr.doob 已提交
148 149
				colorCorrectionPass.uniforms[ "powRGB" ].value = new THREE.Vector3( vh, vh, vh );
				colorCorrectionPass.uniforms[ "mulRGB" ].value = new THREE.Vector3( vl, vl, vl );
J
Jean Carlo Deconto 已提交
150 151
				composer.addPass( colorCorrectionPass );

S
sunag 已提交
152
				var vignettePass = new ShaderPass( VignetteShader );
J
Jean Carlo Deconto 已提交
153 154 155 156 157 158
				vignettePass.uniforms[ "darkness" ].value = 1.0;
				composer.addPass( vignettePass );

				composer.addPass( copyPass );

				// events
M
Mr.doob 已提交
159

J
Jean Carlo Deconto 已提交
160 161 162 163 164 165 166 167 168 169
				window.addEventListener( 'resize', onWindowResize, false );

			}


			function onWindowResize() {

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

M
Mr.doob 已提交
170
				composer.setSize( window.innerWidth, window.innerHeight );
J
Jean Carlo Deconto 已提交
171 172 173 174 175 176
				renderer.setSize( window.innerWidth, window.innerHeight );

			}

			//

S
sunag 已提交
177
			function description( msg ) {
J
Jean Carlo Deconto 已提交
178

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

			}
M
Mr.doob 已提交
182

183
			function onMouseClick() {
J
Jean Carlo Deconto 已提交
184 185 186

				// 0 at 3 demos

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

189
					// play all animation to sequence "crash#1"
J
Jean Carlo Deconto 已提交
190 191 192

					case 0:

S
sunag 已提交
193 194
						playAll( "crash#1", .5 );
						setTimeScale( 1 );
J
Jean Carlo Deconto 已提交
195

S
sunag 已提交
196
						description( "crash#1 - crossfade 0.5 seconds" );
J
Jean Carlo Deconto 已提交
197 198 199

						break;

S
sunag 已提交
200
						// play all animation to sequence "crash#2"
J
Jean Carlo Deconto 已提交
201 202 203

					case 1:

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

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

M
Mr.doob 已提交
208
						break;
J
Jean Carlo Deconto 已提交
209

S
sunag 已提交
210
						// play animation in single object
J
Jean Carlo Deconto 已提交
211 212 213 214 215

					case 2:

						stopAll();

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

218 219 220 221
						//fracture99.animator.setTimeScale( 1 );
						//fracture99.animator.playing
						//fracture99.animator.currentAnimation
						//fracture99.animator.previousAnimation
J
Jean Carlo Deconto 已提交
222

S
sunag 已提交
223
						fracture99.animator.play( "crash#2", .5, 0 );
224 225 226
						//fracture99.animator.stop();
						//fracture99.animator.pause();
						//fracture99.animator.resume();
J
Jean Carlo Deconto 已提交
227

S
sunag 已提交
228
						description( "crash#2 in single object - crossfade 0.5 seconds" );
J
Jean Carlo Deconto 已提交
229 230 231

						break;

S
sunag 已提交
232
						// set time scale
J
Jean Carlo Deconto 已提交
233 234 235

					case 3:

S
sunag 已提交
236 237
						playAll( "crash#2", .5 );
						setTimeScale( .1 );
J
Jean Carlo Deconto 已提交
238

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

M
Mr.doob 已提交
241
						break;
S
sunag 已提交
242

J
Jean Carlo Deconto 已提交
243
				}
S
sunag 已提交
244

J
Jean Carlo Deconto 已提交
245
			}
J
Jean Carlo Deconto 已提交
246 247 248

			//

M
Mr.doob 已提交
249
			var clock = new THREE.Clock();
J
Jean Carlo Deconto 已提交
250

J
Jean Carlo Deconto 已提交
251 252
			function animate() {

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

J
Jean Carlo Deconto 已提交
255 256
				requestAnimationFrame( animate );

J
Jean Carlo Deconto 已提交
257
				// Update SEA3D Animations
S
sunag 已提交
258
				SEA3D.AnimationHandler.update( delta );
J
Jean Carlo Deconto 已提交
259

J
Jean Carlo Deconto 已提交
260
				render( delta );
J
Jean Carlo Deconto 已提交
261 262 263 264 265

				stats.update();

			}

J
Jean Carlo Deconto 已提交
266
			function render( dlt ) {
J
Jean Carlo Deconto 已提交
267 268

				//renderer.render( scene, camera );
J
Jean Carlo Deconto 已提交
269
				composer.render( dlt );
J
Jean Carlo Deconto 已提交
270 271 272 273 274 275

			}

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