提交 03b28436 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #10943 from takahirox/glTFPBR

Add PBR related material primitives into GLTF2Loader
......@@ -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 );
......
# Boom Box
## Screenshot
![screenshot](screenshot/screenshot.jpg)
## License Information
Donated by Microsoft for glTF testing.
\ No newline at end of file
{
"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
}
]
}
\ No newline at end of file
{
"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
}
]
}
\ No newline at end of file
......@@ -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),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册