Bläddra i källkod

Examples: Format

Mugen87 8 år sedan
förälder
incheckning
91b1beb9ba
1 ändrade filer med 243 tillägg och 243 borttagningar
  1. 243 243
      examples/webgl_loader_x.html

+ 243 - 243
examples/webgl_loader_x.html

@@ -1,333 +1,333 @@
 <!DOCTYPE html>
 <html lang='en'>
 <head>
-    <title>three.js webgl - loaders - X-File loader</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;
-            color: #fff;
-            margin: 0px;
-            overflow: hidden;
-        }
-
-        #info {
-            color: #fff;
-            position: absolute;
-            top: 10px;
-            width: 100%;
-            text-align: center;
-            z-index: -1;
-            display: block;
-        }
-
-        #info a,
-        .button {
-            color: #f00;
-            font-weight: bold;
-            text-decoration: underline;
-            cursor: pointer;
-        }
-    </style>
+		<title>three.js webgl - loaders - X-File loader</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;
+						color: #fff;
+						margin: 0px;
+						overflow: hidden;
+				}
+
+				#info {
+						color: #fff;
+						position: absolute;
+						top: 10px;
+						width: 100%;
+						text-align: center;
+						z-index: -1;
+						display: block;
+				}
+
+				#info a,
+				.button {
+						color: #f00;
+						font-weight: bold;
+						text-decoration: underline;
+						cursor: pointer;
+				}
+		</style>
 </head>
 <body>
 
-    <div id='info'>
-        <a href='http://threejs.org' target='_blank'>three.js</a> - X-File Loader test<br />
-    </div>
+		<div id='info'>
+				<a href='http://threejs.org' target='_blank'>three.js</a> - X-File Loader test<br />
+		</div>
 
-    <script src='../build/three.js'></script>
-    <script src='js/controls/OrbitControls.js'></script>
+		<script src='../build/three.js'></script>
+		<script src='js/controls/OrbitControls.js'></script>
 
-    <script src='js/loaders/XLoader.js'></script>
+		<script src='js/loaders/XLoader.js'></script>
 
-    <script src='js/Detector.js'></script>
-    <script src='js/libs/stats.min.js'></script>
-    <script src='js/libs/dat.gui.min.js'></script>
-    <script>
+		<script src='js/Detector.js'></script>
+		<script src='js/libs/stats.min.js'></script>
+		<script src='js/libs/dat.gui.min.js'></script>
+		<script>
 
-        if (!Detector.webgl) Detector.addGetWebGLMessage();
+				if (!Detector.webgl) Detector.addGetWebGLMessage();
 
-        var container, stats, controls;
-        var camera, scene, renderer;
-        var clock = new THREE.Clock();
-        var gui = new dat.GUI();
-        var mixers = [];
-        var manager = null;
-        var Texloader = null;
-        var ParentList = null;
-        var skeletonHelper = null;
-        var Models = [];
-        var animateInf = null;
-        var DashAnime = null;
-        var d = new Date();
-        var LastDateTime = null;
-        var animates = [];
-        var actions = [];
-        init();
+				var container, stats, controls;
+				var camera, scene, renderer;
+				var clock = new THREE.Clock();
+				var gui = new dat.GUI();
+				var mixers = [];
+				var manager = null;
+				var Texloader = null;
+				var ParentList = null;
+				var skeletonHelper = null;
+				var Models = [];
+				var animateInf = null;
+				var DashAnime = null;
+				var d = new Date();
+				var LastDateTime = null;
+				var animates = [];
+				var actions = [];
+				init();
 
-        function init() {
+				function init() {
 
-            LastDateTime = Date.now();
-            container = document.createElement('div');
-            document.body.appendChild(container);
-            container.style.zIndex = -10;
-            camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 2000);
-            scene = new THREE.Scene();
-            scene.background = new THREE.Color(0x666666);
-            scene.add(new THREE.AmbientLight(0x999999));
-            // grid
-            var gridHelper = new THREE.GridHelper(14, 1, 0x303030, 0x303030);
-            gridHelper.position.set(0, -0.04, 0);
-            scene.add(gridHelper);
-            // stats
-            stats = new Stats();
-            container.appendChild(stats.dom);
-            // model
-            manager = new THREE.LoadingManager();
-            manager.onProgress = function (item, loaded, total) {
+						LastDateTime = Date.now();
+						container = document.createElement('div');
+						document.body.appendChild(container);
+						container.style.zIndex = -10;
+						camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 2000);
+						scene = new THREE.Scene();
+						scene.background = new THREE.Color(0x666666);
+						scene.add(new THREE.AmbientLight(0x999999));
+						// grid
+						var gridHelper = new THREE.GridHelper(14, 1, 0x303030, 0x303030);
+						gridHelper.position.set(0, -0.04, 0);
+						scene.add(gridHelper);
+						// stats
+						stats = new Stats();
+						container.appendChild(stats.dom);
+						// model
+						manager = new THREE.LoadingManager();
+						manager.onProgress = function (item, loaded, total) {
 
-                console.log(item, loaded, total);
+								console.log(item, loaded, total);
 
-            };
-
-            var onProgress = function (xhr) {
-
-                if (xhr.lengthComputable) {
-
-                    var percentComplete = xhr.loaded / xhr.total * 100;
-                    console.log(Math.round(percentComplete, 2) + '% downloaded');
-
-                }
-
-            };
+						};
+
+						var onProgress = function (xhr) {
+
+								if (xhr.lengthComputable) {
+
+										var percentComplete = xhr.loaded / xhr.total * 100;
+										console.log(Math.round(percentComplete, 2) + '% downloaded');
+
+								}
+
+						};
 
-            var onError = function (xhr) {
+						var onError = function (xhr) {
 
-                console.log('Errror Loading!');
+								console.log('Errror Loading!');
 
-            };
+						};
 
-            Texloader = new THREE.TextureLoader();
-            var loader = new THREE.XLoader(manager, Texloader);
+						Texloader = new THREE.TextureLoader();
+						var loader = new THREE.XLoader(manager, Texloader);
 
-            // ! If [ Texture ] was reversed Y axis, enable the following.
-            // THREE.XLoader.IsUvYReverse = false;
+						// ! If [ Texture ] was reversed Y axis, enable the following.
+						// THREE.XLoader.IsUvYReverse = false;
 
-		    // ! And if [ Model ] was reversed polygons, enable the following.
-            // loader.load([' your model url ', true ], function (object) {
+				// ! And if [ Model ] was reversed polygons, enable the following.
+						// loader.load([' your model url ', true ], function (object) {
 
-            // read (download) model file
-            loader.load(['models/xfile/SSR06_Born2.x', false], function (object) {
+						// read (download) model file
+						loader.load(['models/xfile/SSR06_Born2.x', false], function (object) {
 
-                for (var i = 0; i < object.FrameInfo.length; i++) {
+								for (var i = 0; i < object.FrameInfo.length; i++) {
 
-                    Models.push(object.FrameInfo[i]);
-                    scene.add(Models[i]);
+										Models.push(object.FrameInfo[i]);
+										scene.add(Models[i]);
 
-                    if (Models[i] instanceof THREE.SkinnedMesh) {
+										if (Models[i] instanceof THREE.SkinnedMesh) {
 
-                        skeletonHelper = new THREE.SkeletonHelper(Models[i]);
-                        scene.add(skeletonHelper);
+												skeletonHelper = new THREE.SkeletonHelper(Models[i]);
+												scene.add(skeletonHelper);
 
-                        if (object.XAnimationObj !== undefined && object.XAnimationObj.length !== 0) {
+												if (object.XAnimationObj !== undefined && object.XAnimationObj.length !== 0) {
 
-                            Models[i].geometry.animations = [];
+														Models[i].geometry.animations = [];
 
-                            /*
-                            *  ↓ that is BASIC animation data code.
-                            *  Usually, please use this.
-                            *  Because of the data I have, I use a different code
-                            *
-                           for (var a = 0; a < object.XAnimationObj.length; a++) {
-                               Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(object.XAnimationObj[a], Models[i].skeleton.bones));
-                           }
-                           Models[i].mixer = new THREE.AnimationMixer(Models[i]);
-                           animates.push(Models[i].mixer);
+														/*
+														*	↓ that is BASIC animation data code.
+														*	Usually, please use this.
+														*	Because of the data I have, I use a different code
+														*
+													 for (var a = 0; a < object.XAnimationObj.length; a++) {
+															 Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(object.XAnimationObj[a], Models[i].skeleton.bones));
+													 }
+													 Models[i].mixer = new THREE.AnimationMixer(Models[i]);
+													 animates.push(Models[i].mixer);
 
-                           var action = Models[i].mixer.clipAction(Models[i].geometry.animations[0]);
-                           action.play();
-                           */
-
-                            // ↓ that is a code for [ All animation-keyframes are connected data ]. output from 'LightWave3D'
-                            {
+													 var action = Models[i].mixer.clipAction(Models[i].geometry.animations[0]);
+													 action.play();
+													 */
+
+														// ↓ that is a code for [ All animation-keyframes are connected data ]. output from 'LightWave3D'
+														{
 
-                                Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(splitAnimation(object.XAnimationObj[0], 'stand', 10 * object.XAnimationObj[0].fps, 11 * object.XAnimationObj[0].fps), Models[i].skeleton.bones));
-                                Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(splitAnimation(object.XAnimationObj[0], 'walk', 50 * object.XAnimationObj[0].fps, 80 * object.XAnimationObj[0].fps), Models[i].skeleton.bones));
-                                Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(splitAnimation(object.XAnimationObj[0], 'dash', 140 * object.XAnimationObj[0].fps, 160 * object.XAnimationObj[0].fps), Models[i].skeleton.bones));
-                                Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(splitAnimation(object.XAnimationObj[0], 'dashing', 160 * object.XAnimationObj[0].fps, 165 * object.XAnimationObj[0].fps), Models[i].skeleton.bones));
-                                Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(splitAnimation(object.XAnimationObj[0], 'damage', 500 * object.XAnimationObj[0].fps, 530 * object.XAnimationObj[0].fps), Models[i].skeleton.bones));
+																Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(splitAnimation(object.XAnimationObj[0], 'stand', 10 * object.XAnimationObj[0].fps, 11 * object.XAnimationObj[0].fps), Models[i].skeleton.bones));
+																Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(splitAnimation(object.XAnimationObj[0], 'walk', 50 * object.XAnimationObj[0].fps, 80 * object.XAnimationObj[0].fps), Models[i].skeleton.bones));
+																Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(splitAnimation(object.XAnimationObj[0], 'dash', 140 * object.XAnimationObj[0].fps, 160 * object.XAnimationObj[0].fps), Models[i].skeleton.bones));
+																Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(splitAnimation(object.XAnimationObj[0], 'dashing', 160 * object.XAnimationObj[0].fps, 165 * object.XAnimationObj[0].fps), Models[i].skeleton.bones));
+																Models[i].geometry.animations.push(THREE.AnimationClip.parseAnimation(splitAnimation(object.XAnimationObj[0], 'damage', 500 * object.XAnimationObj[0].fps, 530 * object.XAnimationObj[0].fps), Models[i].skeleton.bones));
 
-                                Models[i].mixer = new THREE.AnimationMixer(Models[i]);
-                                animates.push(Models[i].mixer);
+																Models[i].mixer = new THREE.AnimationMixer(Models[i]);
+																animates.push(Models[i].mixer);
 
-                                var stand = Models[i].mixer.clipAction('stand');
-                                // stand.play();
-                                stand.setLoop(THREE.LoopRepeat);
-                                actions['stand'] = stand;
+																var stand = Models[i].mixer.clipAction('stand');
+																// stand.play();
+																stand.setLoop(THREE.LoopRepeat);
+																actions['stand'] = stand;
 
-                                var walk = Models[i].mixer.clipAction('walk');
-                                walk.setLoop(THREE.LoopRepeat);
-                                walk.play();
-                                actions['walk'] = walk;
+																var walk = Models[i].mixer.clipAction('walk');
+																walk.setLoop(THREE.LoopRepeat);
+																walk.play();
+																actions['walk'] = walk;
 
-                                var dash = Models[i].mixer.clipAction('dash');
-                                dash.setLoop(THREE.LoopOnce);
-                                //dash.play();
-                                actions['dash'] = dash;
+																var dash = Models[i].mixer.clipAction('dash');
+																dash.setLoop(THREE.LoopOnce);
+																//dash.play();
+																actions['dash'] = dash;
 
-                                var dashing = Models[i].mixer.clipAction('dashing');
-                                dashing.setLoop(THREE.LoopPingPong);
-                                // dashing.play();
-                                actions['dashing'] = dashing;
+																var dashing = Models[i].mixer.clipAction('dashing');
+																dashing.setLoop(THREE.LoopPingPong);
+																// dashing.play();
+																actions['dashing'] = dashing;
 
-                                var damage = Models[i].mixer.clipAction('damage');
-                                damage.setLoop(THREE.LoopRepeat);
-                                //damage.play();
-                                actions['damage'] = damage;
+																var damage = Models[i].mixer.clipAction('damage');
+																damage.setLoop(THREE.LoopRepeat);
+																//damage.play();
+																actions['damage'] = damage;
 
-                                var ActionKeys = Object.keys(actions);
-                                var dmy = {};
-                                dmy.gui = '';
-                                dmy.action = '';
-                                gui.add(dmy, 'action', ActionKeys).onChange(function (v) {
-                                    animates[0].stopAllAction();
-                                    actions[v].play();
-                                });
+																var ActionKeys = Object.keys(actions);
+																var dmy = {};
+																dmy.gui = '';
+																dmy.action = '';
+																gui.add(dmy, 'action', ActionKeys).onChange(function (v) {
+																		animates[0].stopAllAction();
+																		actions[v].play();
+																});
 
-                            }
-                            ///////////
-                        }
+														}
+														///////////
+												}
 
-                    }
+										}
 
-                }
+								}
 
-                object = null;
-            }, onProgress, onError);
+								object = null;
+						}, onProgress, onError);
 
 
-            renderer = new THREE.WebGLRenderer();
-            renderer.setPixelRatio(window.devicePixelRatio);
-            renderer.setSize(window.innerWidth, window.innerHeight);
-            container.appendChild(renderer.domElement);
+						renderer = new THREE.WebGLRenderer();
+						renderer.setPixelRatio(window.devicePixelRatio);
+						renderer.setSize(window.innerWidth, window.innerHeight);
+						container.appendChild(renderer.domElement);
 
-            controls = new THREE.OrbitControls(camera, renderer.domElement);
-            controls.target.set(0, 12, 0);
+						controls = new THREE.OrbitControls(camera, renderer.domElement);
+						controls.target.set(0, 12, 0);
 						controls.update();
 
-            camera.position.set(2, 18, 28);
-            camera.up.set(0, 1, 0);
+						camera.position.set(2, 18, 28);
+						camera.up.set(0, 1, 0);
 
-            var light = new THREE.DirectionalLight(0xeeeeff, 2);
-            light.position.set(10, 100, 1).normalize();
-            scene.add(light);
+						var light = new THREE.DirectionalLight(0xeeeeff, 2);
+						light.position.set(10, 100, 1).normalize();
+						scene.add(light);
 
-            light = new THREE.DirectionalLight(0x555588);
-            light.position.set(-1, -1, -1).normalize();
-            scene.add(light);
+						light = new THREE.DirectionalLight(0x555588);
+						light.position.set(-1, -1, -1).normalize();
+						scene.add(light);
 
 
-            window.addEventListener('resize', onWindowResize, false);
-            animate();
+						window.addEventListener('resize', onWindowResize, false);
+						animate();
 
-        }
+				}
 
-        function onWindowResize() {
+				function onWindowResize() {
 
-            camera.aspect = window.innerWidth / window.innerHeight;
-            camera.updateProjectionMatrix();
-            renderer.setSize(window.innerWidth, window.innerHeight);
+						camera.aspect = window.innerWidth / window.innerHeight;
+						camera.updateProjectionMatrix();
+						renderer.setSize(window.innerWidth, window.innerHeight);
 
-        }
-        //
-        function animate() {
+				}
+				//
+				function animate() {
 
-            requestAnimationFrame(animate);
-            var nowTime = Date.now();
-            var dulTime = nowTime - LastDateTime;
-            LastDateTime = nowTime;
+						requestAnimationFrame(animate);
+						var nowTime = Date.now();
+						var dulTime = nowTime - LastDateTime;
+						LastDateTime = nowTime;
 
-            if (animates != null && animates.length > 0) {
+						if (animates != null && animates.length > 0) {
 
-                for (var i = 0; i < animates.length; i++) {
+								for (var i = 0; i < animates.length; i++) {
 
-                    animates[i].update(dulTime);
+										animates[i].update(dulTime);
 
-                }
+								}
 
-            }
+						}
 
-            stats.update();
-            render();
+						stats.update();
+						render();
 
-        }
+				}
 
-        function render() {
+				function render() {
 
-            renderer.render(scene, camera);
+						renderer.render(scene, camera);
 
-        }
+				}
 
-        /////////////////
-        /// this is not must mount codes.
-        // split  One and Long Animation, for time
-        function splitAnimation(_baseAnime, _name, _beginTime, _endTime) {
+				/////////////////
+				/// this is not must mount codes.
+				// split	One and Long Animation, for time
+				function splitAnimation(_baseAnime, _name, _beginTime, _endTime) {
 
-            var Animation = {};
-            Animation.fps = _baseAnime.fps;
-            Animation.name = _name;
-            Animation.length = _endTime - _beginTime;
-            Animation.hierarchy = [];
+						var Animation = {};
+						Animation.fps = _baseAnime.fps;
+						Animation.name = _name;
+						Animation.length = _endTime - _beginTime;
+						Animation.hierarchy = [];
 
-            for (var i = 0; i < _baseAnime.hierarchy.length; i++) {
+						for (var i = 0; i < _baseAnime.hierarchy.length; i++) {
 
-                var firstKey = -1;
-                var lastKey = -1;
-                var frame = {};
-                frame.name = _baseAnime.hierarchy[i].name;
-                frame.parent = _baseAnime.hierarchy[i].parent;
-                frame.keys = [];
+								var firstKey = -1;
+								var lastKey = -1;
+								var frame = {};
+								frame.name = _baseAnime.hierarchy[i].name;
+								frame.parent = _baseAnime.hierarchy[i].parent;
+								frame.keys = [];
 
-                for (var m = 1; m < _baseAnime.hierarchy[i].keys.length; m++) {
+								for (var m = 1; m < _baseAnime.hierarchy[i].keys.length; m++) {
 
-                    if (_baseAnime.hierarchy[i].keys[m].time > _beginTime) {
+										if (_baseAnime.hierarchy[i].keys[m].time > _beginTime) {
 
-                        if (firstKey === -1) {
+												if (firstKey === -1) {
 
-                            firstKey = m - 1;
-                            frame.keys.push(_baseAnime.hierarchy[i].keys[m - 1]);
+														firstKey = m - 1;
+														frame.keys.push(_baseAnime.hierarchy[i].keys[m - 1]);
 
-                        }
+												}
 
-                        frame.keys.push(_baseAnime.hierarchy[i].keys[m]);
+												frame.keys.push(_baseAnime.hierarchy[i].keys[m]);
 
-                    }
+										}
 
-                    if (_endTime <= _baseAnime.hierarchy[i].keys[m].time || m >= _baseAnime.hierarchy[i].keys.length - 1) {
+										if (_endTime <= _baseAnime.hierarchy[i].keys[m].time || m >= _baseAnime.hierarchy[i].keys.length - 1) {
 
-                        break;
-                    }
+												break;
+										}
 
-                }
+								}
 
-                for (var m = 0; m < frame.keys.length; m++) {
+								for (var m = 0; m < frame.keys.length; m++) {
 
-                    frame.keys[m].time -= _beginTime;
+										frame.keys[m].time -= _beginTime;
 
-                }
+								}
 
-                Animation.hierarchy.push(frame);
+								Animation.hierarchy.push(frame);
 
-            }
+						}
 
-            return Animation;
+						return Animation;
 
-        }
-    </script>
+				}
+		</script>
 
 </body>