浏览代码

Fixed CTMLoader.

Mr.doob 11 年之前
父节点
当前提交
52438ae582
共有 1 个文件被更改,包括 31 次插入15 次删除
  1. 31 15
      examples/js/loaders/ctm/CTMLoader.js

+ 31 - 15
examples/js/loaders/ctm/CTMLoader.js

@@ -190,38 +190,54 @@ THREE.CTMLoader.prototype.load = function( url, callback, parameters ) {
 
 THREE.CTMLoader.prototype.createModel = function ( file, callback ) {
 
-	var Model = function ( ) {
+	var Model = function () {
 
 		THREE.BufferGeometry.call( this );
 
 		this.materials = [];
 
-		// init GL buffers
 		var indices = file.body.indices,
 		positions = file.body.vertices,
 		normals = file.body.normals;
 
 		var uvs, colors;
 
-		if ( file.body.uvMaps !== undefined && file.body.uvMaps.length > 0 ) {
-			uvs = file.body.uvMaps[ 0 ].uv;
+		var uvMaps = file.body.uvMaps;
+
+		if ( uvMaps !== undefined && uvMaps.length > 0 ) {
+
+			uvs = uvMaps[ 0 ].uv;
+
+		}
+
+		var attrMaps = file.body.attrMaps;
+
+		if ( attrMaps !== undefined && attrMaps.length > 0 && attrMaps[ 0 ].name === 'Color' ) {
+
+			colors = attrMaps[ 0 ].attr;
+
 		}
 
-		if ( file.body.attrMaps !== undefined && file.body.attrMaps.length > 0 && file.body.attrMaps[ 0 ].name === "Color" ) {
-			colors = file.body.attrMaps[ 0 ].attr;
+		this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
+		this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
+
+		if ( normals !== undefined ) {
+
+			this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
+
 		}
 
-		this.addAttribute( 'index', new THREE.Uint32Attribute( indices, 1 ) );
-		this.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
+		if ( uvs !== undefined ) {
+
+			this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
 
-		if ( normals !== undefined ) 
-			this.addAttribute( 'normal', new THREE.Float32Attribute( normals, 3 ) );
+		}
+
+		if ( colors !== undefined ) {
 
-		if ( uvs !== undefined ) 
-			this.addAttribute( 'uv', new THREE.Float32Attribute( uvs, 2 ) );
+			this.addAttribute( 'color', new THREE.BufferAttribute( colors, 4 ) );
 
-		if ( colors !== undefined ) 
-			this.addAttribute( 'color', new THREE.Float32Attribute( colors, 4 ) );
+		}
 
 	}
 
@@ -238,4 +254,4 @@ THREE.CTMLoader.prototype.createModel = function ( file, callback ) {
 
 	callback( geometry );
 
-};
+};