Browse Source

Add default material technique support to glTFLoader.js (#9726)

Rich Tibbett 9 years ago
parent
commit
c1d87e3d7d
1 changed files with 34 additions and 10 deletions
  1. 34 10
      examples/js/loaders/gltf/glTFLoader.js

+ 34 - 10
examples/js/loaders/gltf/glTFLoader.js

@@ -987,13 +987,36 @@ THREE.glTFLoader.prototype.load = function( url, callback ) {
 						values[prop] = khr_material.values[prop];
 					}
 
+				}
+				else if (material.technique === undefined) {
+
+					materialType = THREE.MeshPhongMaterial;
+
+					if (material.doubleSided)
+					{
+						params.side = THREE.DoubleSide;
+					}
+
+					if (material.transparent)
+					{
+						params.transparent = true;
+					}
+
+					values = {};
+					for (var prop in material.values) {
+						values[prop] = material.values[prop];
+					}
+
 				}
 				else {
-					var technique = material.technique ?
-						this.resources.getEntry(material.technique) :
-						null;
 
-					values = material.values;
+					var technique = this.resources.getEntry(material.technique);
+
+					values = {};
+					for (var prop in material.values) {
+						values[prop] = material.values[prop];
+					}
+
 					var description = technique.description;
 
 					if (++description.refCount > 1) {
@@ -1008,6 +1031,7 @@ THREE.glTFLoader.prototype.load = function( url, callback ) {
 					if (loadshaders) {
 						materialType = Material;
 					}
+
 				}
 
 				if (values.diffuse && typeof(values.diffuse) == 'string') {
@@ -1876,16 +1900,16 @@ THREE.glTFLoader.prototype.load = function( url, callback ) {
 
 	var self = this;
 
-	var loader = Object.create(ThreeGLTFLoader);
-	loader.initWithPath(url);
-	loader.load(new Context(rootObj,
+	this.callback = callback;
+	this.rootObj = rootObj;
+
+	this.loader = Object.create(ThreeGLTFLoader);
+	this.loader.initWithPath(url);
+	this.loader.load(new Context(rootObj,
 						function(obj) {
 						}),
 				null);
 
-	this.loader = loader;
-	this.callback = callback;
-	this.rootObj = rootObj;
 	return rootObj;
 }