Browse Source

Added example of how to use new version of UTF8 format with UTF8v2Loader.

See #2399
alteredq 13 years ago
parent
commit
1e24a04f6f

+ 107 - 0
examples/models/utf8_r104/ben.js

@@ -0,0 +1,107 @@
+{
+  "materials": {
+    "gums": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "tongue": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "teethbottom": { "Kd": [251, 248, 248] },
+    "teethtop": { "Kd": [251, 248, 248] },
+    "topeyelashes": { "Kd": [66, 52, 42] },
+    "bottomeyelashes": { "Kd": [66, 52, 42] },
+    "head": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "eyetrans": { "Kd": [0, 0, 0] },
+    "pupil": { "Kd": [1, 1, 1] },
+    "iris": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "eyeball": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "pants": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "tshirt3": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "skinbody": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "fingernails": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "soleshoe": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "sole": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "laces": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "bow": { "map_Kd": "../../textures/ash_uvgrid01.jpg" }
+  },
+  "decodeParams": {
+    "decodeOffsets": [-2533,-149,-6225,0,0,-511,-511,-511],
+    "decodeScales": [0.000043,0.000043,0.000043,0.000978,0.000978,0.001957,0.001957,0.001957]
+  },
+  "urls": {
+    "ben.utf8": [
+      { "material": "bottomeyelashes",
+        "attribRange": [0, 130],
+        "codeRange": [1040, 388, 192]
+      },
+      { "material": "bow",
+        "attribRange": [1428, 1848],
+        "codeRange": [16212, 6457, 3224]
+      },
+      { "material": "eyeball",
+        "attribRange": [22669, 3834],
+        "codeRange": [53341, 14697, 7284]
+      },
+      { "material": "eyetrans",
+        "attribRange": [68038, 5248],
+        "codeRange": [110022, 20180, 9964]
+      },
+      { "material": "fingernails",
+        "attribRange": [130202, 1023],
+        "codeRange": [138386, 2669, 1228]
+      },
+      { "material": "gums",
+        "attribRange": [141055, 1446],
+        "codeRange": [152623, 5270, 2624]
+      },
+      { "material": "head",
+        "attribRange": [157893, 2219],
+        "codeRange": [175645, 8353, 4168]
+      },
+      { "material": "iris",
+        "attribRange": [183998, 902],
+        "codeRange": [191214, 3332, 1664]
+      },
+      { "material": "laces",
+        "attribRange": [194546, 1016],
+        "codeRange": [202674, 3590, 1792]
+      },
+      { "material": "pants",
+        "attribRange": [206264, 8200],
+        "codeRange": [271864, 30625, 15293]
+      },
+      { "material": "pupil",
+        "attribRange": [302489, 148],
+        "codeRange": [303673, 581, 288]
+      },
+      { "material": "skinbody",
+        "attribRange": [304254, 4990],
+        "codeRange": [344174, 15770, 7830]
+      },
+      { "material": "sole",
+        "attribRange": [359944, 2588],
+        "codeRange": [380648, 9345, 4668]
+      },
+      { "material": "soleshoe",
+        "attribRange": [389993, 3164],
+        "codeRange": [415305, 10721, 5352]
+      },
+      { "material": "teethbottom",
+        "attribRange": [426026, 1235],
+        "codeRange": [435906, 3513, 1656]
+      },
+      { "material": "teethtop",
+        "attribRange": [439419, 1666],
+        "codeRange": [452747, 3937, 1816]
+      },
+      { "material": "tongue",
+        "attribRange": [456684, 845],
+        "codeRange": [463444, 3162, 1578]
+      },
+      { "material": "topeyelashes",
+        "attribRange": [466606, 130],
+        "codeRange": [467646, 388, 192]
+      },
+      { "material": "tshirt3",
+        "attribRange": [468034, 4283],
+        "codeRange": [502298, 14470, 7216]
+      }
+    ]
+  }
+}

BIN
examples/models/utf8_r104/ben.utf8


+ 27 - 0
examples/models/utf8_r104/hand.js

@@ -0,0 +1,27 @@
+{
+  "materials": {
+    "preview": { "Kd": [184, 136, 234] },
+    "nails": { "map_Kd": "../../textures/ash_uvgrid01.jpg" },
+    "skin": { "map_Kd": "../../textures/ash_uvgrid01.jpg" }
+  },
+  "decodeParams": {
+    "decodeOffsets": [-7473,-239,-8362,0,0,-511,-511,-511],
+    "decodeScales": [0.000050,0.000050,0.000050,0.000978,0.000978,0.001957,0.001957,0.001957]
+  },
+  "urls": {
+    "hand.utf8": [
+      { "material": "nails",
+        "attribRange": [0, 261],
+        "codeRange": [2088, 817, 404]
+      },
+      { "material": "preview",
+        "attribRange": [2905, 688],
+        "codeRange": [8409, 2570, 1280]
+      },
+      { "material": "skin",
+        "attribRange": [10979, 8899],
+        "codeRange": [82171, 31026, 15451]
+      }
+    ]
+  }
+}

BIN
examples/models/utf8_r104/hand.utf8


+ 186 - 0
examples/webgl_loader_utf8_r104.html

@@ -0,0 +1,186 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<title>three.js webgl - io - UTF8 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: 100;
+				display:block;
+			}
+			#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
+		</style>
+	</head>
+
+	<body>
+		<div id="info">
+		<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> -
+		<a href="http://code.google.com/p/webgl-loader/" target="_blank">UTF8 format</a> loader test -
+		models from <a href="http://www.sci.utah.edu/~wald/animrep/" target="_blank">The Utah 3D Animation Repository</a>
+		</div>
+
+		<script src="../build/three.min.js"></script>
+		<script src="js/loaders/UTF8v2Loader.js"></script>
+		<script src="js/loaders/MTLLoader.js"></script>
+
+		<script src="js/Detector.js"></script>
+		<script src="js/Stats.js"></script>
+
+		<script>
+
+			var SCREEN_WIDTH = window.innerWidth;
+			var SCREEN_HEIGHT = window.innerHeight;
+
+			var FLOOR = -150;
+
+			var container, stats;
+
+			var camera, scene, renderer;
+
+			var mesh, zmesh, geometry;
+
+			var mouseX = 0, mouseY = 0;
+
+			var windowHalfX = window.innerWidth / 2;
+			var windowHalfY = window.innerHeight / 2;
+
+			document.addEventListener('mousemove', onDocumentMouseMove, false);
+
+			init();
+			animate();
+
+
+			function init() {
+
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
+
+				camera = new THREE.PerspectiveCamera( 20, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 2000 );
+				camera.position.z = 800;
+
+				scene = new THREE.Scene();
+				scene.fog = new THREE.Fog( 0x000000, 800, 2000 );
+
+				var path = "textures/cube/SwedishRoyalCastle/";
+				var format = '.jpg';
+				var urls = [
+					path + 'px' + format, path + 'nx' + format,
+					path + 'py' + format, path + 'ny' + format,
+					path + 'pz' + format, path + 'nz' + format
+				];
+
+				reflectionCube = THREE.ImageUtils.loadTextureCube( urls );
+
+				// LIGHTS
+
+				var ambient = new THREE.AmbientLight( 0x221100 );
+				scene.add( ambient );
+
+				var directionalLight = new THREE.DirectionalLight( 0xffeedd );
+				directionalLight.position.set( 0, 0, 1 ).normalize();
+				scene.add( directionalLight );
+
+				// RENDERER
+
+				renderer = new THREE.WebGLRenderer();
+				renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
+
+				renderer.setClearColor( scene.fog.color, 1 );
+
+				renderer.domElement.style.position = "relative";
+				container.appendChild( renderer.domElement );
+
+				// STATS
+
+				stats = new Stats();
+				stats.domElement.style.position = 'absolute';
+				stats.domElement.style.top = '0px';
+				stats.domElement.style.zIndex = 100;
+				container.appendChild( stats.domElement );
+
+				var loader = new THREE.UTF8v2Loader();
+
+				loader.load( "models/utf8_r104/hand.js", function ( object ) {
+
+					var s = 350;
+					object.scale.set( s, s, s );
+					object.position.x = 125;
+					object.position.y = -125;
+					scene.add( object );
+
+				} );
+
+				loader.load( "models/utf8_r104/ben.js", function ( object ) {
+
+					var s = 350;
+					object.scale.set( s, s, s );
+					object.position.x = -125;
+					object.position.y = -125;
+					scene.add( object );
+
+				} );
+
+				//
+
+				window.addEventListener( 'resize', onWindowResize, false );
+
+			}
+
+			function onWindowResize() {
+
+				windowHalfX = window.innerWidth / 2;
+				windowHalfY = window.innerHeight / 2;
+
+				camera.aspect = window.innerWidth / window.innerHeight;
+				camera.updateProjectionMatrix();
+
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+			}
+
+			function onDocumentMouseMove( event ) {
+
+				mouseX = ( event.clientX - windowHalfX );
+				mouseY = ( event.clientY - windowHalfY );
+
+			}
+
+			//
+
+			function animate() {
+
+				requestAnimationFrame( animate );
+
+				render();
+				stats.update();
+
+			}
+
+			function render() {
+
+				camera.position.x += ( mouseX - camera.position.x ) * .05;
+				camera.position.y += ( - mouseY - camera.position.y ) * .05;
+
+				camera.lookAt( scene.position );
+
+				renderer.render( scene, camera );
+
+			}
+
+		</script>
+
+	</body>
+</html>