浏览代码

Merge pull request #10943 from takahirox/glTFPBR

Add PBR related material primitives into GLTF2Loader
Mr.doob 8 年之前
父节点
当前提交
03b28436c4
共有 21 个文件被更改,包括 563 次插入2 次删除
  1. 91 1
      examples/js/loaders/GLTF2Loader.js
  2. 9 0
      examples/models/gltf/BoomBox/README.md
  3. 二进制
      examples/models/gltf/BoomBox/glTF-Binary/BoomBox.glb
  4. 二进制
      examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox.bin
  5. 240 0
      examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox.gltf
  6. 二进制
      examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_baseColor.png
  7. 二进制
      examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_diffuse.png
  8. 二进制
      examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_emissive.png
  9. 二进制
      examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_metallicRoughness.png
  10. 二进制
      examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_normal.png
  11. 二进制
      examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_occlusion.png
  12. 二进制
      examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_specularGlossiness.png
  13. 二进制
      examples/models/gltf/BoomBox/glTF/BoomBox.bin
  14. 213 0
      examples/models/gltf/BoomBox/glTF/BoomBox.gltf
  15. 二进制
      examples/models/gltf/BoomBox/glTF/BoomBox_baseColor.png
  16. 二进制
      examples/models/gltf/BoomBox/glTF/BoomBox_emissive.png
  17. 二进制
      examples/models/gltf/BoomBox/glTF/BoomBox_metallicRoughness.png
  18. 二进制
      examples/models/gltf/BoomBox/glTF/BoomBox_normal.png
  19. 二进制
      examples/models/gltf/BoomBox/glTF/BoomBox_occlusion.png
  20. 二进制
      examples/models/gltf/BoomBox/screenshot/screenshot.jpg
  21. 10 1
      examples/webgl_loader_gltf.html

+ 91 - 1
examples/js/loaders/GLTF2Loader.js

@@ -1190,7 +1190,97 @@ THREE.GLTF2Loader = ( function () {
 
 				} else if ( material.technique === undefined ) {
 
-					materialType = THREE.MeshPhongMaterial;
+					if ( material.pbrMetallicRoughness !== undefined )  {
+
+						// specification
+						// https://github.com/sbtron/glTF/blob/30de0b365d1566b1bbd8b9c140f9e995d3203226/specification/2.0/README.md#metallic-roughness-material
+
+						materialType = THREE.MeshStandardMaterial;
+
+						if ( material.pbrMetallicRoughness !== undefined ) {
+
+							var metallicRoughness = material.pbrMetallicRoughness;
+
+							materialParams.color = new THREE.Color( 1.0, 1.0, 1.0 );
+							materialParams.opacity = 1.0;
+
+							if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
+
+								var array = metallicRoughness.baseColorFactor;
+
+								materialParams.color.fromArray( array );
+								materialParams.opacity = array[ 3 ];
+
+							}
+
+							if ( metallicRoughness.baseColorTexture !== undefined ) {
+
+								materialParams.map = dependencies.textures[ metallicRoughness.baseColorTexture.index ];
+
+							}
+
+							if ( materialParams.opacity < 1.0 ||
+							     ( materialParams.map !== undefined &&
+							       ( materialParams.map.format === THREE.AlphaFormat ||
+							         materialParams.map.format === THREE.RGBAFormat ||
+							         materialParams.map.format === THREE.LuminanceAlphaFormat ) ) ) {
+
+								materialParams.transparent = true;
+
+							}
+
+							materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
+							materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
+
+							if ( metallicRoughness.metallicRoughnessTexture !== undefined ) {
+
+								var textureIndex = metallicRoughness.metallicRoughnessTexture.index;
+
+								// Note that currently metalnessMap would be entirely ignored because
+								// Three.js and glTF specification use different texture channels for metalness
+								// (Blue: Three.js, Red: glTF).
+								// But glTF specification team is discussing if they can change.
+								// Let's keep an eye on it so far.
+								//
+								// https://github.com/KhronosGroup/glTF/issues/857
+								materialParams.metalnessMap = dependencies.textures[ textureIndex ];
+								materialParams.roughnessMap = dependencies.textures[ textureIndex ];
+
+							}
+
+						}
+
+					} else {
+
+						materialType = THREE.MeshPhongMaterial;
+
+					}
+
+					if ( material.normalTexture !== undefined ) {
+
+						materialParams.normalMap = dependencies.textures[ material.normalTexture.index ];
+
+					}
+
+					if ( material.occlusionTexture !== undefined ) {
+
+						materialParams.aoMap = dependencies.textures[ material.occlusionTexture.index ];
+
+					}
+
+					if ( material.emissiveTexture !== undefined ) {
+
+						materialParams.emissiveMap = dependencies.textures[ material.emissiveTexture.index ];
+
+					}
+
+					materialParams.emissive = new THREE.Color( 0.0, 0.0, 0.0 );
+
+					if ( material.emissiveFactor !== undefined ) {
+
+						materialParams.emissive.fromArray( material.emissiveFactor );
+
+					}
 
 					Object.assign( materialValues, material.values );
 

+ 9 - 0
examples/models/gltf/BoomBox/README.md

@@ -0,0 +1,9 @@
+# Boom Box
+## Screenshot
+
+![screenshot](screenshot/screenshot.jpg)
+
+
+## License Information
+
+Donated by Microsoft for glTF testing.

二进制
examples/models/gltf/BoomBox/glTF-Binary/BoomBox.glb


二进制
examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox.bin


+ 240 - 0
examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox.gltf

@@ -0,0 +1,240 @@
+{
+  "accessors": [
+    {
+      "bufferView": 0,
+      "byteOffset": 0,
+      "componentType": 5126,
+      "count": 3575,
+      "type": "VEC2",
+      "max": [
+        0.9999003,
+        -0.0221377648
+      ],
+      "min": [
+        0.0006585993,
+        -0.996773958
+      ]
+    },
+    {
+      "bufferView": 1,
+      "byteOffset": 0,
+      "componentType": 5126,
+      "count": 3575,
+      "type": "VEC3",
+      "max": [
+        1.0,
+        1.0,
+        0.9999782
+      ],
+      "min": [
+        -1.0,
+        -1.0,
+        -0.9980823
+      ]
+    },
+    {
+      "bufferView": 2,
+      "byteOffset": 0,
+      "componentType": 5126,
+      "count": 3575,
+      "type": "VEC3",
+      "max": [
+        0.009921154,
+        0.00977163,
+        0.0100762453
+      ],
+      "min": [
+        -0.009921154,
+        -0.00977163,
+        -0.0100762453
+      ]
+    },
+    {
+      "bufferView": 3,
+      "byteOffset": 0,
+      "componentType": 5123,
+      "count": 18108,
+      "type": "SCALAR",
+      "max": [
+        3574
+      ],
+      "min": [
+        0
+      ]
+    }
+  ],
+  "asset": {
+    "generator": "glTF Tools for Unity",
+    "version": "2.0"
+  },
+  "bufferViews": [
+    {
+      "buffer": 0,
+      "byteOffset": 0,
+      "byteLength": 28600,
+      "target": 34962
+    },
+    {
+      "buffer": 0,
+      "byteOffset": 28600,
+      "byteLength": 42900,
+      "target": 34962
+    },
+    {
+      "buffer": 0,
+      "byteOffset": 71500,
+      "byteLength": 42900,
+      "target": 34962
+    },
+    {
+      "buffer": 0,
+      "byteOffset": 114400,
+      "byteLength": 36216,
+      "target": 34963
+    }
+  ],
+  "buffers": [
+    {
+      "uri": "BoomBox.bin",
+      "byteLength": 150616
+    }
+  ],
+  "extensionsUsed": [
+    "KHR_materials_pbrSpecularGlossiness"
+  ],
+  "images": [
+    {
+      "uri": "BoomBox_baseColor.png"
+    },
+    {
+      "uri": "BoomBox_metallicRoughness.png"
+    },
+    {
+      "uri": "BoomBox_normal.png"
+    },
+    {
+      "uri": "BoomBox_occlusion.png"
+    },
+    {
+      "uri": "BoomBox_emissive.png"
+    },
+    {
+      "uri": "BoomBox_diffuse.png"
+    },
+    {
+      "uri": "BoomBox_specularGlossiness.png"
+    }
+  ],
+  "meshes": [
+    {
+      "primitives": [
+        {
+          "attributes": {
+            "TEXCOORD_0": 0,
+            "NORMAL": 1,
+            "POSITION": 2
+          },
+          "indices": 3,
+          "material": 0,
+          "mode": 4
+        }
+      ],
+      "name": "BoomBox"
+    }
+  ],
+  "materials": [
+    {
+      "pbrMetallicRoughness": {
+        "baseColorTexture": {
+          "index": 0
+        },
+        "metallicRoughnessTexture": {
+          "index": 1
+        }
+      },
+      "normalTexture": {
+        "index": 2
+      },
+      "occlusionTexture": {
+        "index": 3
+      },
+      "emissiveFactor": [
+        1.0,
+        1.0,
+        1.0
+      ],
+      "emissiveTexture": {
+        "index": 4
+      },
+      "name": "BoomBox_Mat",
+      "extensions": {
+        "KHR_materials_pbrSpecularGlossiness": {
+          "diffuseTexture": {
+            "index": 5
+          },
+          "specularGlossinessTexture": {
+            "index": 6
+          }
+        }
+      }
+    }
+  ],
+  "nodes": [
+    {
+      "children": [],
+      "mesh": 0,
+      "scale": [
+        80.0,
+        80.0,
+        80.0
+      ],
+      "translation": [
+        0.0,
+        0.163,
+        0.053
+      ],
+      "name": "BoomBox"
+    }
+  ],
+  "samplers": [
+    {}
+  ],
+  "scene": 0,
+  "scenes": [
+    {
+      "nodes": [
+        0
+      ]
+    }
+  ],
+  "textures": [
+    {
+      "sampler": 0,
+      "source": 0
+    },
+    {
+      "sampler": 0,
+      "source": 1
+    },
+    {
+      "sampler": 0,
+      "source": 2
+    },
+    {
+      "sampler": 0,
+      "source": 3
+    },
+    {
+      "sampler": 0,
+      "source": 4
+    },
+    {
+      "sampler": 0,
+      "source": 5
+    },
+    {
+      "sampler": 0,
+      "source": 6
+    }
+  ]
+}

二进制
examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_baseColor.png


二进制
examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_diffuse.png


二进制
examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_emissive.png


二进制
examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_metallicRoughness.png


二进制
examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_normal.png


二进制
examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_occlusion.png


二进制
examples/models/gltf/BoomBox/glTF-pbrSpecularGlossiness/BoomBox_specularGlossiness.png


二进制
examples/models/gltf/BoomBox/glTF/BoomBox.bin


+ 213 - 0
examples/models/gltf/BoomBox/glTF/BoomBox.gltf

@@ -0,0 +1,213 @@
+{
+  "accessors": [
+    {
+      "bufferView": 0,
+      "byteOffset": 0,
+      "componentType": 5126,
+      "count": 3575,
+      "type": "VEC2",
+      "max": [
+        0.9999003,
+        -0.0221377648
+      ],
+      "min": [
+        0.0006585993,
+        -0.996773958
+      ]
+    },
+    {
+      "bufferView": 1,
+      "byteOffset": 0,
+      "componentType": 5126,
+      "count": 3575,
+      "type": "VEC3",
+      "max": [
+        1.0,
+        1.0,
+        0.9999782
+      ],
+      "min": [
+        -1.0,
+        -1.0,
+        -0.9980823
+      ]
+    },
+    {
+      "bufferView": 2,
+      "byteOffset": 0,
+      "componentType": 5126,
+      "count": 3575,
+      "type": "VEC3",
+      "max": [
+        0.009921154,
+        0.00977163,
+        0.0100762453
+      ],
+      "min": [
+        -0.009921154,
+        -0.00977163,
+        -0.0100762453
+      ]
+    },
+    {
+      "bufferView": 3,
+      "byteOffset": 0,
+      "componentType": 5123,
+      "count": 18108,
+      "type": "SCALAR",
+      "max": [
+        3574
+      ],
+      "min": [
+        0
+      ]
+    }
+  ],
+  "asset": {
+    "generator": "glTF Tools for Unity",
+    "version": "2.0"
+  },
+  "bufferViews": [
+    {
+      "buffer": 0,
+      "byteOffset": 0,
+      "byteLength": 28600,
+      "target": 34962
+    },
+    {
+      "buffer": 0,
+      "byteOffset": 28600,
+      "byteLength": 42900,
+      "target": 34962
+    },
+    {
+      "buffer": 0,
+      "byteOffset": 71500,
+      "byteLength": 42900,
+      "target": 34962
+    },
+    {
+      "buffer": 0,
+      "byteOffset": 114400,
+      "byteLength": 36216,
+      "target": 34963
+    }
+  ],
+  "buffers": [
+    {
+      "uri": "BoomBox.bin",
+      "byteLength": 150616
+    }
+  ],
+  "images": [
+    {
+      "uri": "BoomBox_baseColor.png"
+    },
+    {
+      "uri": "BoomBox_metallicRoughness.png"
+    },
+    {
+      "uri": "BoomBox_normal.png"
+    },
+    {
+      "uri": "BoomBox_occlusion.png"
+    },
+    {
+      "uri": "BoomBox_emissive.png"
+    }
+  ],
+  "meshes": [
+    {
+      "primitives": [
+        {
+          "attributes": {
+            "TEXCOORD_0": 0,
+            "NORMAL": 1,
+            "POSITION": 2
+          },
+          "indices": 3,
+          "material": 0,
+          "mode": 4
+        }
+      ],
+      "name": "BoomBox"
+    }
+  ],
+  "materials": [
+    {
+      "pbrMetallicRoughness": {
+        "baseColorTexture": {
+          "index": 0
+        },
+        "metallicRoughnessTexture": {
+          "index": 1
+        }
+      },
+      "normalTexture": {
+        "index": 2
+      },
+      "occlusionTexture": {
+        "index": 3
+      },
+      "emissiveFactor": [
+        1.0,
+        1.0,
+        1.0
+      ],
+      "emissiveTexture": {
+        "index": 4
+      },
+      "name": "BoomBox_Mat"
+    }
+  ],
+  "nodes": [
+    {
+      "children": [],
+      "mesh": 0,
+      "scale": [
+        80.0,
+        80.0,
+        80.0
+      ],
+      "translation": [
+        0.0,
+        0.163,
+        0.053
+      ],
+      "name": "BoomBox"
+    }
+  ],
+  "samplers": [
+    {}
+  ],
+  "scene": 0,
+  "scenes": [
+    {
+      "nodes": [
+        0
+      ]
+    }
+  ],
+  "textures": [
+    {
+      "sampler": 0,
+      "source": 0
+    },
+    {
+      "sampler": 0,
+      "source": 1
+    },
+    {
+      "sampler": 0,
+      "source": 2
+    },
+    {
+      "sampler": 0,
+      "source": 3
+    },
+    {
+      "sampler": 0,
+      "source": 4
+    }
+  ]
+}

二进制
examples/models/gltf/BoomBox/glTF/BoomBox_baseColor.png


二进制
examples/models/gltf/BoomBox/glTF/BoomBox_emissive.png


二进制
examples/models/gltf/BoomBox/glTF/BoomBox_metallicRoughness.png


二进制
examples/models/gltf/BoomBox/glTF/BoomBox_normal.png


二进制
examples/models/gltf/BoomBox/glTF/BoomBox_occlusion.png


二进制
examples/models/gltf/BoomBox/screenshot/screenshot.jpg


+ 10 - 1
examples/webgl_loader_gltf.html

@@ -66,7 +66,8 @@
 		<a href="https://github.com/KhronosGroup/glTF" target="_blank">glTF</a> loader
 		<br>
 		monster by <a href="http://www.3drt.com/downloads.htm" target="_blank">3drt</a> - COLLADA duck by Sony -
-		Cesium models by <a href="http://cesiumjs.org/" target="_blank">Cesium</a>
+		Cesium models by <a href="http://cesiumjs.org/" target="_blank">Cesium</a> -
+		BoomBox by <a href="https://www.microsoft.com/" target="_blank">Microsoft</a>
 		</div>
 	<div id="container"></div>
 	<div id="controls">
@@ -381,6 +382,14 @@
 					addGround:true,
 					extensions: ["glTF", "glTF-MaterialsCommon", "glTF-Binary"]
 				},
+				{
+					name : "BoomBox (PBR)", url : "./models/gltf/BoomBox/%s/BoomBox.gltf",
+					cameraPos: new THREE.Vector3(2, 1, 3),
+					objectRotation: new THREE.Euler(0, Math.PI, 0),
+					addLights:true,
+					extensions: ["glTF"]
+				},
+
 				{
 					name : "Duck", url : "./models/gltf/duck/%s/duck.gltf",
 					cameraPos: new THREE.Vector3(0, 3, 5),