Skip to content

Commit

Permalink
Merge pull request #4249 from lasalvavida/gltf-1.0.1-uint32-indices
Browse files Browse the repository at this point in the history
glTF 1.0.1 uint32 indices
  • Loading branch information
pjcozzi authored Nov 11, 2016
2 parents 8383f57 + 48aa89d commit 95e541e
Show file tree
Hide file tree
Showing 3 changed files with 272 additions and 1 deletion.
18 changes: 18 additions & 0 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3447,6 +3447,21 @@ define([
}
}

function checkSupportedGlExtensions(model, context) {
var glExtensionsUsed = model.gltf.glExtensionsUsed;
if (defined(glExtensionsUsed)) {
var glExtensionsUsedLength = glExtensionsUsed.length;
for (var i = 0; i < glExtensionsUsedLength; i++) {
var extension = glExtensionsUsed[i];
if (extension !== 'OES_element_index_uint') {
throw new RuntimeError('Unsupported WebGL Extension: ' + extension);
} else if (!context.elementIndexUint) {
throw new RuntimeError('The OES_element_index_uint WebGL extension is required for this glTF model, but it is not supported by this system.');
}
}
}
}

///////////////////////////////////////////////////////////////////////////

function CachedRendererResources(context, cacheKey) {
Expand Down Expand Up @@ -3602,6 +3617,8 @@ define([
* </p>
*
* @exception {RuntimeError} Failed to load external reference.
* @exception {RuntimeError} The glTF model makes use of an unsupported glTF extension.
* @exception {RuntimeError} The glTF model makes use of an unsupported WebGL extension.
*/
Model.prototype.update = function(frameState) {
if (frameState.mode === SceneMode.MORPHING) {
Expand Down Expand Up @@ -3647,6 +3664,7 @@ define([
this._initialRadius = this._boundingSphere.radius;

checkSupportedExtensions(this);
checkSupportedGlExtensions(this, context);
if (this._state !== ModelState.FAILED) {
var extensions = this.gltf.extensions;
if (defined(extensions) && defined(extensions.CESIUM_RTC)) {
Expand Down
233 changes: 233 additions & 0 deletions Specs/Data/Models/Box-Uint32Indices/Box-Uint32Indices.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
{
"accessors": {
"accessor_21": {
"bufferView": "bufferView_1",
"byteOffset": 0,
"byteStride": 0,
"componentType": 5125,
"count": 36,
"type": "SCALAR",
"min": [
0
],
"max": [
23
]
},
"accessor_23": {
"bufferView": "bufferView_0",
"byteOffset": 0,
"byteStride": 0,
"componentType": 5126,
"count": 24,
"max": [
0.5,
0.5,
0.5
],
"min": [
-0.5,
-0.5,
-0.5
],
"type": "VEC3"
},
"accessor_25": {
"bufferView": "bufferView_0",
"byteOffset": 288,
"byteStride": 0,
"componentType": 5126,
"count": 24,
"max": [
1,
1,
1
],
"min": [
-1,
-1,
-1
],
"type": "VEC3"
}
},
"animations": {},
"asset": {
"generator": "collada2gltf@027f74366341d569dea42e9a68b7104cc3892054",
"premultipliedAlpha": true,
"profile": {
"api": "WebGL",
"version": "1.0.2"
},
"version": "1.0"
},
"bufferViews": {
"bufferView_0": {
"buffer": "buffer_0",
"byteLength": 576,
"byteOffset": 0,
"target": 34962
},
"bufferView_1": {
"buffer": "buffer_0",
"byteLength": 144,
"byteOffset": 576,
"target": 34963
}
},
"buffers": {
"buffer_0": {
"type": "arraybuffer",
"byteLength": 720,
"uri": "data:application/octet-stream;base64,AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAvwAAAD8AAAC/AAAAPwAAAD8AAAC/AAAAPwAAAD8AAAA/AAAAvwAAAD8AAAA/AAAAPwAAAL8AAAA/AAAAvwAAAL8AAAA/AAAAPwAAAD8AAAC/AAAAPwAAAD8AAAA/AAAAPwAAAL8AAAC/AAAAPwAAAL8AAAA/AAAAvwAAAD8AAAC/AAAAPwAAAD8AAAC/AAAAvwAAAL8AAAC/AAAAPwAAAL8AAAC/AAAAvwAAAD8AAAA/AAAAvwAAAD8AAAC/AAAAvwAAAL8AAAA/AAAAvwAAAL8AAAC/AAAAvwAAAL8AAAA/AAAAvwAAAL8AAAC/AAAAPwAAAL8AAAA/AAAAPwAAAL8AAAC/AAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAEAAAACAAAAAwAAAAIAAAABAAAABAAAAAUAAAAGAAAABwAAAAYAAAAFAAAACAAAAAkAAAAKAAAACwAAAAoAAAAJAAAADAAAAA0AAAAOAAAADwAAAA4AAAANAAAAEAAAABEAAAASAAAAEwAAABIAAAARAAAAFAAAABUAAAAWAAAAFwAAABYAAAAVAAAA"
}
},
"materials": {
"Effect-Red": {
"name": "Red",
"technique": "technique0",
"values": {
"diffuse": [
0.8,
0,
0,
1
],
"shininess": 256,
"specular": [
0.2,
0.2,
0.2,
1
]
}
}
},
"meshes": {
"Geometry-mesh002": {
"name": "Mesh",
"primitives": [
{
"attributes": {
"NORMAL": "accessor_25",
"POSITION": "accessor_23"
},
"indices": "accessor_21",
"material": "Effect-Red",
"mode": 4
}
]
}
},
"nodes": {
"rootNode": {
"children": [],
"meshes": [
"Geometry-mesh002"
],
"matrix": [
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1,
0,
0,
0,
0,
1
]
}
},
"programs": {
"program_0": {
"attributes": [
"a_normal",
"a_position"
],
"fragmentShader": "Box0FS",
"vertexShader": "Box0VS"
}
},
"scene": "defaultScene",
"scenes": {
"defaultScene": {
"nodes": [
"rootNode"
]
}
},
"shaders": {
"Box0FS": {
"type": 35632,
"uri": "data:text/plain;base64,cHJlY2lzaW9uIGhpZ2hwIGZsb2F0Owp2YXJ5aW5nIHZlYzMgdl9ub3JtYWw7CnVuaWZvcm0gdmVjNCB1X2RpZmZ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ributes": {
"a_normal": "normal",
"a_position": "position"
},
"parameters": {
"diffuse": {
"type": 35666
},
"modelViewMatrix": {
"semantic": "MODELVIEW",
"type": 35676
},
"normal": {
"semantic": "NORMAL",
"type": 35665
},
"normalMatrix": {
"semantic": "MODELVIEWINVERSETRANSPOSE",
"type": 35675
},
"position": {
"semantic": "POSITION",
"type": 35665
},
"projectionMatrix": {
"semantic": "PROJECTION",
"type": 35676
},
"shininess": {
"type": 5126
},
"specular": {
"type": 35666
}
},
"program": "program_0",
"states": {
"enable": [
2929,
2884
],
"disable": []
},
"uniforms": {
"u_diffuse": "diffuse",
"u_modelViewMatrix": "modelViewMatrix",
"u_normalMatrix": "normalMatrix",
"u_projectionMatrix": "projectionMatrix",
"u_shininess": "shininess",
"u_specular": "specular"
}
}
},
"glExtensionsUsed": ["OES_element_index_uint"]
}
22 changes: 21 additions & 1 deletion Specs/Scene/ModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ defineSuite([
var animBoxesUrl = './Data/Models/anim-test-1-boxes/anim-test-1-boxes.gltf';
var riggedFigureUrl = './Data/Models/rigged-figure-test/rigged-figure-test.gltf';
var riggedSimpleUrl = './Data/Models/rigged-simple/rigged-simple.gltf';

var boxConstantUrl = './Data/Models/MaterialsCommon/BoxConstant.gltf';
var boxLambertUrl = './Data/Models/MaterialsCommon/BoxLambert.gltf';
var boxBlinnUrl = './Data/Models/MaterialsCommon/BoxBlinn.gltf';
Expand All @@ -90,6 +89,7 @@ defineSuite([
var boxSpotLightUrl = './Data/Models/MaterialsCommon/BoxSpotLight.gltf';
var boxTransparentUrl = './Data/Models/MaterialsCommon/BoxTransparent.gltf';
var boxColorUrl = './Data/Models/Box-Color/Box-Color.gltf';
var boxUint32Indices = './Data/Models/Box-Uint32Indices/Box-Uint32Indices.gltf';
var boxQuantizedUrl = './Data/Models/WEB3DQuantizedAttributes/Box-Quantized.gltf';
var boxColorQuantizedUrl = './Data/Models/WEB3DQuantizedAttributes/Box-Color-Quantized.gltf';
var boxScalarQuantizedUrl = './Data/Models/WEB3DQuantizedAttributes/Box-Scalar-Quantized.gltf';
Expand Down Expand Up @@ -1724,6 +1724,26 @@ defineSuite([
});
});

it('loads a gltf with uint32 indices', function() {
var context = scene.context;
if (context._elementIndexUint) {
return loadModel(boxUint32Indices).then(function(m) {
verifyRender(m);
primitives.remove(m);
});
}
});

it('throws runtime error when loading a gltf with uint32 indices if OES_element_index_uint is disabled', function() {
var context = scene.context;
var uint32Supported = context._elementIndexUint;
context._elementIndexUint = false;
return loadModel(boxUint32Indices).otherwise(function(e) {
expect(e).toBeDefined();
context._elementIndexUint = uint32Supported;
});
});

it('loads a gltf with WEB3D_quantized_attributes COLOR', function() {
return loadModel(boxColorQuantizedUrl).then(function(m) {
expect(m.ready).toBe(true);
Expand Down

0 comments on commit 95e541e

Please sign in to comment.