Browse Source

sea3d polyfill

sunag 8 years ago
parent
commit
87b69d6a24
1 changed files with 32 additions and 88 deletions
  1. 32 88
      examples/js/loaders/sea3d/SEA3DLoader.js

+ 32 - 88
examples/js/loaders/sea3d/SEA3DLoader.js

@@ -5,6 +5,21 @@
 
 'use strict';
 
+//
+//	Polyfills
+//
+
+if (THREE.Float32BufferAttribute === undefined) {
+
+	THREE.Float32BufferAttribute = THREE.Float32Attribute;
+
+}
+
+//
+//
+//	SEA3D
+//
+
 THREE.SEA3D = function ( config ) {
 
 	this.config = {
@@ -1743,19 +1758,8 @@ THREE.SEA3D.prototype.readGeometryBuffer = function ( sea ) {
 
 	if ( sea.joint ) {
 
-		if ( THREE.Float32BufferAttribute ) {
-
-			// three dev
-
-			geo.addAttribute( 'skinIndex', new THREE.Float32BufferAttribute( sea.joint, sea.jointPerVertex ) );
-			geo.addAttribute( 'skinWeight', new THREE.Float32BufferAttribute( sea.weight, sea.jointPerVertex ) );
-
-		} else {
-
-			geo.addAttribute( 'skinIndex', new THREE.Float32Attribute( sea.joint, sea.jointPerVertex ) );
-			geo.addAttribute( 'skinWeight', new THREE.Float32Attribute( sea.weight, sea.jointPerVertex ) );
-
-		}
+		geo.addAttribute( 'skinIndex', new THREE.Float32BufferAttribute( sea.joint, sea.jointPerVertex ) );
+		geo.addAttribute( 'skinWeight', new THREE.Float32BufferAttribute( sea.weight, sea.jointPerVertex ) );
 
 	}
 
@@ -1803,17 +1807,7 @@ THREE.SEA3D.prototype.readLine = function ( sea ) {
 	if ( sea.closed )
 		sea.vertex.push( sea.vertex[ 0 ], sea.vertex[ 1 ], sea.vertex[ 2 ] );
 
-	if ( THREE.Float32BufferAttribute ) {
-
-		// three dev
-
-		geo.addAttribute( 'position', new THREE.Float32BufferAttribute( sea.vertex, 3 ) );
-
-	} else {
-
-		geo.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( sea.vertex ), 3 ) );
-
-	}
+	geo.addAttribute( 'position', new THREE.Float32BufferAttribute( sea.vertex, 3 ) );
 
 	var line = new THREE.Line( geo, new THREE.LineBasicMaterial( { color: THREE.SEA3D.HELPER_COLOR, linewidth: 3 } ) );
 	line.name = sea.name;
@@ -2805,45 +2799,20 @@ THREE.SEA3D.prototype.readMorpher = function ( sea ) {
 
 	var attribs = { position: [] }, targets = [];
 
-	if ( THREE.Float32BufferAttribute ) {
-
-		// three dev
-
-		for ( var i = 0; i < sea.node.length; i ++ ) {
-
-			var node = sea.node[ i ];
-
-			attribs.position[ i ] = new THREE.Float32BufferAttribute( node.vertex, 3 );
+	for ( var i = 0; i < sea.node.length; i ++ ) {
 
-			if ( node.normal ) {
+		var node = sea.node[ i ];
 
-				attribs.normal = attribs.normal || [];
-				attribs.normal[ i ] = new THREE.Float32BufferAttribute( node.normal, 3 );
+		attribs.position[ i ] = new THREE.Float32BufferAttribute( node.vertex, 3 );
 
-			}
+		if ( node.normal ) {
 
-			targets[ i ] = { name: node.name };
+			attribs.normal = attribs.normal || [];
+			attribs.normal[ i ] = new THREE.Float32BufferAttribute( node.normal, 3 );
 
 		}
 
-	} else {
-
-		for ( var i = 0; i < sea.node.length; i ++ ) {
-
-			var node = sea.node[ i ];
-
-			attribs.position[ i ] = new THREE.Float32Attribute( new Float32Array( node.vertex ), 3 );
-
-			if ( node.normal ) {
-
-				attribs.normal = attribs.normal || [];
-				attribs.normal[ i ] = new THREE.Float32Attribute( new Float32Array( node.normal ), 3 );
-
-			}
-
-			targets[ i ] = { name: node.name };
-
-		}
+		targets[ i ] = { name: node.name };
 
 	}
 
@@ -2927,45 +2896,20 @@ THREE.SEA3D.prototype.readVertexAnimation = function ( sea ) {
 
 	var attribs = { position: [] }, targets = [], animations = [], i, j, l;
 
-	if ( THREE.Float32BufferAttribute ) {
-
-		// three dev
-
-		for ( i = 0, l = sea.frame.length; i < l; i ++ ) {
+	for ( i = 0, l = sea.frame.length; i < l; i ++ ) {
 
-			var frame = sea.frame[ i ];
+		var frame = sea.frame[ i ];
 
-			attribs.position[ i ] = new THREE.Float32BufferAttribute( frame.vertex, 3 );
+		attribs.position[ i ] = new THREE.Float32BufferAttribute( frame.vertex, 3 );
 
-			if ( frame.normal ) {
+		if ( frame.normal ) {
 
-				attribs.normal = attribs.normal || [];
-				attribs.normal[ i ] = new THREE.Float32BufferAttribute( frame.normal, 3 );
-
-			}
-
-			targets[ i ] = { name: i };
+			attribs.normal = attribs.normal || [];
+			attribs.normal[ i ] = new THREE.Float32BufferAttribute( frame.normal, 3 );
 
 		}
 
-	} else {
-
-		for ( i = 0, l = sea.frame.length; i < l; i ++ ) {
-
-			var frame = sea.frame[ i ];
-
-			attribs.position[ i ] = new THREE.Float32Attribute( new Float32Array( frame.vertex ), 3 );
-
-			if ( frame.normal ) {
-
-				attribs.normal = attribs.normal || [];
-				attribs.normal[ i ] = new THREE.Float32Attribute( new Float32Array( frame.normal ), 3 );
-
-			}
-
-			targets[ i ] = { name: i };
-
-		}
+		targets[ i ] = { name: i };
 
 	}