Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 57 additions & 4 deletions examples/js/loaders/GLTFLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ THREE.GLTFLoader = ( function () {

}

if ( json.extensionsUsed.indexOf( EXTENSIONS.MSFT_TEXTURE_DDS ) >= 0 ) {

extensions[ EXTENSIONS.MSFT_TEXTURE_DDS ] = new GLTFTextureDDSExtension();

}

}

console.time( 'GLTFLoader' );
Expand Down Expand Up @@ -224,9 +230,30 @@ THREE.GLTFLoader = ( function () {
KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
KHR_LIGHTS: 'KHR_lights',
KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
KHR_MATERIALS_UNLIT: 'KHR_materials_unlit'
KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
MSFT_TEXTURE_DDS: 'MSFT_texture_dds'
};

/**
* DDS Texture Extension
*
* Specification:
* https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_texture_dds
*
*/
function GLTFTextureDDSExtension() {

if (!THREE.DDSLoader) {

throw new Error( 'THREE.GLTFLoader: Attempting to load .dds texture without importing THREE.DDSLoader' );

}

this.name = EXTENSIONS.MSFT_TEXTURE_DDS;
this.ddsLoader = new THREE.DDSLoader();

}

/**
* Lights Extension
*
Expand Down Expand Up @@ -1789,7 +1816,21 @@ THREE.GLTFLoader = ( function () {
var URL = window.URL || window.webkitURL;

var textureDef = json.textures[ textureIndex ];
var source = json.images[ textureDef.source ];

var textureExtensions = textureDef.extensions || {};

var source;

if ( textureExtensions[ EXTENSIONS.MSFT_TEXTURE_DDS ] ) {

source = json.images[ textureExtensions[ EXTENSIONS.MSFT_TEXTURE_DDS ].source ];

} else {

source = json.images[ textureDef.source ];

}

var sourceURI = source.uri;
var isObjectURL = false;

Expand All @@ -1812,7 +1853,15 @@ THREE.GLTFLoader = ( function () {

// Load Texture resource.

var loader = THREE.Loader.Handlers.get( sourceURI ) || textureLoader;
var loader = THREE.Loader.Handlers.get( sourceURI );

if ( ! loader ) {

loader = textureExtensions[ EXTENSIONS.MSFT_TEXTURE_DDS ]
? parser.extensions[ EXTENSIONS.MSFT_TEXTURE_DDS ].ddsLoader
: textureLoader;

}

return new Promise( function ( resolve, reject ) {

Expand All @@ -1834,7 +1883,11 @@ THREE.GLTFLoader = ( function () {

if ( textureDef.name !== undefined ) texture.name = textureDef.name;

texture.format = textureDef.format !== undefined ? WEBGL_TEXTURE_FORMATS[ textureDef.format ] : THREE.RGBAFormat;
if ( ! textureExtensions[ EXTENSIONS.MSFT_TEXTURE_DDS ] ) {

texture.format = textureDef.format !== undefined ? WEBGL_TEXTURE_FORMATS[ textureDef.format ] : THREE.RGBAFormat;

}

if ( textureDef.internalFormat !== undefined && texture.format !== WEBGL_TEXTURE_FORMATS[ textureDef.internalFormat ] ) {

Expand Down
Binary file not shown.
237 changes: 237 additions & 0 deletions examples/models/gltf/BoomBox/glTF-dds/BoomBox.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
{
"accessors": [
{
"bufferView": 0,
"componentType": 5126,
"count": 3575,
"type": "VEC2",
"max": [
0.9999003,
-0.0221377648
],
"min": [
0.0006585993,
-0.996773958
]
},
{
"bufferView": 1,
"componentType": 5126,
"count": 3575,
"type": "VEC3",
"max": [
1.0,
1.0,
0.9999782
],
"min": [
-1.0,
-1.0,
-0.9980823
]
},
{
"bufferView": 2,
"componentType": 5126,
"count": 3575,
"type": "VEC4",
"max": [
1.0,
0.9999976,
1.0,
1.0
],
"min": [
-0.9991289,
-0.999907851,
-1.0,
1.0
]
},
{
"bufferView": 3,
"componentType": 5126,
"count": 3575,
"type": "VEC3",
"max": [
0.009921154,
0.00977163,
0.0100762453
],
"min": [
-0.009921154,
-0.00977163,
-0.0100762453
]
},
{
"bufferView": 4,
"componentType": 5123,
"count": 18108,
"type": "SCALAR",
"max": [
3574
],
"min": [
0
]
}
],
"asset": {
"generator": "glTF Tools for Unity",
"version": "2.0"
},
"bufferViews": [
{
"buffer": 0,
"byteLength": 28600
},
{
"buffer": 0,
"byteOffset": 28600,
"byteLength": 42900
},
{
"buffer": 0,
"byteOffset": 71500,
"byteLength": 57200
},
{
"buffer": 0,
"byteOffset": 128700,
"byteLength": 42900
},
{
"buffer": 0,
"byteOffset": 171600,
"byteLength": 36216
}
],
"buffers": [
{
"uri": "BoomBox.bin",
"byteLength": 207816
}
],
"images": [
{
"uri": "BoomBox_baseColor.png"
},
{
"uri": "BoomBox_occlusionRoughnessMetallic.png"
},
{
"uri": "BoomBox_normal.png"
},
{
"uri": "BoomBox_emissive.png"
},
{
"uri": "BoomBox_baseColor.dds"
},
{
"uri": "BoomBox_occlusionRoughnessMetallic.dds"
},
{
"uri": "BoomBox_normal.dds"
},
{
"uri": "BoomBox_emissive.dds"
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"TEXCOORD_0": 0,
"NORMAL": 1,
"TANGENT": 2,
"POSITION": 3
},
"indices": 4,
"material": 0
}
],
"name": "BoomBox"
}
],
"materials": [
{
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 0
},
"metallicRoughnessTexture": {
"index": 1
}
},
"normalTexture": {
"index": 2
},
"occlusionTexture": {
"index": 1
},
"emissiveFactor": [
1.0,
1.0,
1.0
],
"emissiveTexture": {
"index": 3
},
"name": "BoomBox_Mat"
}
],
"nodes": [
{
"mesh": 0,
"name": "BoomBox"
}
],
"scene": 0,
"scenes": [
{
"nodes": [
0
]
}
],
"textures": [
{
"source": 0,
"extensions": {
"MSFT_texture_dds": {
"source": 4
}
}
},
{
"source": 1,
"extensions": {
"MSFT_texture_dds": {
"source": 5
}
}
},
{
"source": 2,
"extensions": {
"MSFT_texture_dds": {
"source": 6
}
}
},
{
"source": 3,
"extensions": {
"MSFT_texture_dds": {
"source": 7
}
}
}
],
"extensionsUsed": [
"MSFT_texture_dds"
]
}
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion examples/webgl_loader_gltf_extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<script src="js/libs/dat.gui.min.js"></script>
<script src="js/controls/OrbitControls.js"></script>
<script src="js/loaders/DRACOLoader.js"></script>
<script src="js/loaders/DDSLoader.js"></script>
<script src="js/loaders/GLTFLoader.js"></script>

<script>
Expand All @@ -71,7 +72,7 @@
cameraPos: new THREE.Vector3( 0.02, 0.01, 0.03 ),
objectRotation: new THREE.Euler( 0, Math.PI, 0 ),
addLights: true,
extensions: [ 'glTF', 'glTF-pbrSpecularGlossiness', 'glTF-Binary' ],
extensions: [ 'glTF', 'glTF-pbrSpecularGlossiness', 'glTF-Binary', 'glTF-dds' ],
addEnvMap: true
},
'Bot Skinned': {
Expand Down