Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glTF 1.0.1 uint32 indices #4249

Merged
merged 6 commits into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 16 additions & 0 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3115,6 +3115,7 @@ define([
var context = frameState.context;
var scene3DOnly = frameState.scene3DOnly;

checkSupportedGlExtensions(model, context);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this call to be next to checkSupportedExtensions in update?

if (model._loadRendererResourcesFromCache) {
var resources = model._rendererResources;
var cachedResources = model._cachedRendererResources;
Expand Down Expand Up @@ -3475,6 +3476,21 @@ define([
}
}

function checkSupportedGlExtensions(model, context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document this exception in the update function reference doc? Also add the exception from checkSupportedExtensions which is missing.

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('OES_element_index_uint WebGL extension is not enabled.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps '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
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"
]
}
},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vcm1hbCA9IHVfbm9ybWFsTWF0cml4ICogYV9ub3JtYWw7CmdsX1Bvc2l0aW9uID0gdV9wcm9qZWN0aW9uTWF0cml4ICogcG9zOwp9Cg=="
}
},
"skins": {},
"techniques": {
"technique0": {
"attributes": {
"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"]
}
18 changes: 17 additions & 1 deletion Specs/Scene/ModelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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 @@ -88,6 +87,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 @@ -1679,6 +1679,22 @@ defineSuite([
});
});

it('loads a gltf with uint32 indices', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should check for Context.elementIndexUint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lasalvavida did you see this comment:

The test should check for 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;
context._elementIndexUint = false;
return loadModel(boxUint32Indices).otherwise(function(e) {
expect(e).toBeDefined();
context._elementIndexUint = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save and restore the original value; it could be false on some systems in theory.

});
});

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