浏览代码

Made glTFLoader BufferGeometry only.

Mr.doob 11 年之前
父节点
当前提交
c68e711996
共有 2 个文件被更改,包括 9 次插入78 次删除
  1. 5 55
      examples/js/loaders/gltf/glTFLoader.js
  2. 4 23
      examples/webgl_loader_gltf.html

+ 5 - 55
examples/js/loaders/gltf/glTFLoader.js

@@ -4,8 +4,6 @@
 
 
 THREE.glTFLoader = function (showStatus) {
-	this.useBufferGeometry = (THREE.glTFLoader.useBufferGeometry !== undefined ) ?
-			THREE.glTFLoader.useBufferGeometry : true;
     this.meshesRequested = 0;
     this.meshesLoaded = 0;
     this.pendingMeshes = [];
@@ -86,12 +84,8 @@ THREE.glTFLoader.prototype.load = function( url, callback ) {
 
     var ClassicGeometry = function() {
 
-    	if (theLoader.useBufferGeometry) {
-    		this.geometry = new THREE.BufferGeometry;
-    	}
-    	else {
-    		this.geometry = new THREE.Geometry;
-    	}
+        this.geometry = new THREE.BufferGeometry;
+
         this.totalAttributes = 0;
         this.loadedAttributes = 0;
         this.indicesLoaded = false;
@@ -105,41 +99,6 @@ THREE.glTFLoader.prototype.load = function( url, callback ) {
 
     ClassicGeometry.prototype.constructor = ClassicGeometry;
 
-    ClassicGeometry.prototype.buildArrayGeometry = function() {
-
-    	// Build indexed mesh
-        var geometry = this.geometry;
-        var normals = geometry.normals;
-        var indexArray = this.indexArray;
-        var uvs = this.uvs;
-        var a, b, c;
-        var i, l;
-        var faceNormals = null;
-        var faceTexcoords = null;
-        
-        for(i = 0, l = this.indexArray.length; i < l; i += 3) {
-            a = indexArray[i];
-            b = indexArray[i+1];
-            c = indexArray[i+2];
-            if(normals) {
-                faceNormals = [normals[a], normals[b], normals[c]];
-            }
-            geometry.faces.push( new THREE.Face3( a, b, c, faceNormals, null, null ) );
-            if(uvs) {
-                geometry.faceVertexUvs[0].push([ uvs[a], uvs[b], uvs[c] ]);
-            }
-        }
-
-        // Allow Three.js to calculate some values for us
-        geometry.computeBoundingBox();
-        geometry.computeBoundingSphere();
-        geometry.computeFaceNormals();
-        if(!normals) {
-            geometry.computeVertexNormals();
-        }
-
-    }
-
     ClassicGeometry.prototype.buildBufferGeometry = function() {
         // Build indexed mesh
         var geometry = this.geometry;
@@ -162,12 +121,7 @@ THREE.glTFLoader.prototype.load = function( url, callback ) {
     ClassicGeometry.prototype.checkFinished = function() {
         if(this.indexArray && this.loadedAttributes === this.totalAttributes) {
         	
-        	if (theLoader.useBufferGeometry) {
-        		this.buildBufferGeometry();
-        	}
-        	else {
-        		this.buildArrayGeometry();
-        	}
+        	this.buildBufferGeometry();
         	
             this.finished = true;
 
@@ -314,12 +268,8 @@ THREE.glTFLoader.prototype.load = function( url, callback ) {
     }
     
     VertexAttributeDelegate.prototype.resourceAvailable = function(glResource, ctx) {
-    	if (theLoader.useBufferGeometry) {
-    		this.bufferResourceAvailable(glResource, ctx);
-    	}
-    	else {
-    		this.arrayResourceAvailable(glResource, ctx);
-    	}
+
+    	this.bufferResourceAvailable(glResource, ctx);
     	
         var geom = ctx.geometry;
         geom.loadedAttributes++;

+ 4 - 23
examples/webgl_loader_gltf.html

@@ -35,7 +35,7 @@
             	width:250px;
             	bottom:0%;
             	right:0%;
-            	height:134px;
+            	height:100px;
             	background-color:White;
             	opacity:.9;
             	font: 13px/1.231 "Lucida Grande", Lucida, Verdana, sans-serif;
@@ -78,12 +78,7 @@
             	position:absolute;
             	top:72px;
             }
-            
-            #buffer_geometry_control {
-            	position:absolute;
-            	top:104px;
-            }
-                        
+
             #info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
         </style>
     </head>
@@ -116,12 +111,6 @@
 				Animations
 				<div class="controlValue"><input type="checkbox" checked onclick="toggleAnimations();">Play</input></div>
 			</div>
-			<div class="control" id="buffer_geometry_control">
-				Geometry
-				<div class="controlValue">
-				<input type="checkbox" id="buffer_geometry_checkbox" checked onclick="toggleBufferGeometry();">BufferGeometry</input>
-				</div>
-			</div>
 		</div>
         <script src="../build/three.min.js"></script>
         <script src="js/controls/OrbitControls.js"></script>
@@ -230,7 +219,7 @@
 				}
 				
                 loader = new THREE.glTFLoader;
-                loader.useBufferGeometry = useBufferGeometry;
+
                 var loadStartTime = Date.now();
                 var status = document.getElementById("status");
                 status.innerHTML = "Loading...";
@@ -475,14 +464,6 @@
 				}
 			}
 
-			var usebuf = document.getElementById("buffer_geometry_checkbox");
-			var useBufferGeometry = usebuf.hasAttribute("checked");
-			function toggleBufferGeometry()
-			{
-				useBufferGeometry = !useBufferGeometry;
-				selectScene();
-			}
-			
 			function cleanup() {
 
 				if (container && renderer)
@@ -490,7 +471,7 @@
 					container.removeChild(renderer.domElement);
 				}
 
-	            cameraIndex = 0;
+				cameraIndex = 0;
 				cameras = [];
 				cameraNames = [];
 				defaultCamera = null;