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 2.0 #4808

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
97c1a0d
Update CHANGES.md
pjcozzi Aug 30, 2016
2471b03
Update CHANGES.md
pjcozzi Aug 30, 2016
a8afa5e
Added support for normalized accessors
lasalvavida Aug 30, 2016
2170ac5
Modified Box-Color to use normalized property
lasalvavida Aug 30, 2016
20cef47
Clarified normalized in test
lasalvavida Aug 30, 2016
e4f4240
SCISSOR_TEST is no longer required in glTF 1.0.1
lasalvavida Aug 31, 2016
34b63c1
Merge pull request #4247 from lasalvavida/gltf-1.0.1-normalized
pjcozzi Aug 31, 2016
b20e8c4
Merge branch 'gltf-1.0.1' of github.com:AnalyticalGraphicsInc/cesium …
lasalvavida Aug 31, 2016
ad83614
Merge pull request #4248 from lasalvavida/gltf-1.0.1-remove-scissor-test
pjcozzi Aug 31, 2016
246a848
Added uint32 indices support for glTF 1.0.1
lasalvavida Sep 1, 2016
b4fd22a
Fix jsHint error
lasalvavida Sep 1, 2016
c143152
Test glTF for required extensions.
emackey Sep 26, 2016
9d8f635
Merge pull request #4371 from AnalyticalGraphicsInc/required-extensio…
pjcozzi Nov 10, 2016
ff84031
Merge branch 'master' of https://github.com/lasalvavida/cesium into g…
lasalvavida Nov 11, 2016
b9f304c
Merge branch 'gltf-1.0.1' of https://github.com/lasalvavida/cesium in…
lasalvavida Nov 11, 2016
12b18cb
Made suggested changes
lasalvavida Nov 11, 2016
8383f57
Merge pull request #4636 from lasalvavida/gltf-1.0.1
lilleyse Nov 11, 2016
07f9f44
Merge branch 'gltf-1.0.1' of https://github.com/AnalyticalGraphicsInc…
lasalvavida Nov 11, 2016
48aa89d
Check for _elementIndexUint before testing
lasalvavida Nov 11, 2016
95e541e
Merge pull request #4249 from lasalvavida/gltf-1.0.1-uint32-indices
pjcozzi Nov 11, 2016
47f3631
Added initial pipeline build
lasalvavida Jan 2, 2017
3355a84
Merge branch 'gltf-1.0.1' of https://github.com/AnalyticalGraphicsInc…
lasalvavida Jan 2, 2017
56cea8c
Added amdifyed pipeline files
lasalvavida Jan 3, 2017
ee2fca2
Some of the model changes (not done yet)
lasalvavida Jan 3, 2017
9d4fbde
Checkpoint: Geometry only models render
Jan 4, 2017
8c0c7e4
Fixed promise code
Jan 4, 2017
92a9696
Fixed textures and skinning
lasalvavida Jan 4, 2017
2d337b4
Removed getBinaryAccessor
lasalvavida Jan 4, 2017
e6aafe4
Enabled gltf-1.1
lasalvavida Jan 4, 2017
cf05283
Removed gltfDefaults from ThirdParty
lasalvavida Jan 4, 2017
80c9786
Reverting model changes
Jan 10, 2017
5901bde
Switch workspaces
Jan 12, 2017
860d56f
Fixed skeleton hierarchy issues
Jan 12, 2017
ebb29ca
Merge branch 'master' of https://github.com/AnalyticalGraphicsInc/ces…
lasalvavida Jan 13, 2017
b70b357
addDefaults and processModelMaterialsCommon post-updateVersion
lasalvavida Jan 13, 2017
d959f46
Merge branch 'master' of github.com:AnalyticalGraphicsInc/cesium into…
Jan 26, 2017
a7ec3c8
Pulled latest changes from gltf-pipeline
Jan 26, 2017
8135029
Create runtimeNodes from skeleton nodes even if they aren't part of
Jan 26, 2017
c912f87
Update from small pipeline changes
Jan 26, 2017
4c0054b
RemovePipelineExtras
Jan 26, 2017
6ec4ed8
Last pull of changes from gltf-pipeline
Jan 26, 2017
cad8794
A few test fixes
Jan 27, 2017
b4a4b16
Added back some lost 1.0.1 changes and fixes for tests
lasalvavida Jan 27, 2017
5ed44c3
Update from pipeline changes
Mar 22, 2017
298a203
Merge branch 'master' of github.com:AnalyticalGraphicsInc/cesium into…
Mar 22, 2017
b1e7f89
A few fixes from the merge
Mar 22, 2017
c9c20a6
Added missing pipeline files
Mar 22, 2017
29149db
Fix most failing tests, still a few left
Mar 22, 2017
b6a1d9d
A few more fixed tests
lasalvavida Mar 26, 2017
b99554d
Added KHR_technique_webgl to supported extensions
Apr 3, 2017
39514ee
Updated GltfPipeline built files
Apr 3, 2017
a69ffd1
Merge branch 'gltf-1.1' of github.com:lasalvavida/cesium into gltf-1.1
Apr 3, 2017
2d6aac6
Fix all failing tests
Apr 3, 2017
99ad146
Merge branch 'master' of github.com:AnalyticalGraphicsInc/cesium into…
Apr 3, 2017
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
273 changes: 111 additions & 162 deletions Source/Scene/Model.js

Large diffs are not rendered by default.

91 changes: 44 additions & 47 deletions Source/Scene/ModelAnimationCache.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
/*global define*/
define([
'../Core/Cartesian3',
'../Core/ComponentDatatype',
'../Core/defaultValue',
'../Core/defined',
'../Core/LinearSpline',
'../Core/Matrix4',
'../Core/Quaternion',
'../Core/QuaternionSpline',
'../Core/WebGLConstants',
'./getBinaryAccessor'
'../ThirdParty/GltfPipeline/getAccessorByteStride',
'../ThirdParty/GltfPipeline/numberOfComponentsForType',
], function(
Cartesian3,
ComponentDatatype,
defaultValue,
defined,
LinearSpline,
Matrix4,
Quaternion,
QuaternionSpline,
WebGLConstants,
getBinaryAccessor) {
getAccessorByteStride,
numberOfComponentsForType) {
'use strict';

/**
Expand All @@ -36,7 +40,7 @@ define([
var buffer = buffers[bufferView.buffer];

var byteOffset = bufferView.byteOffset + accessor.byteOffset;
var byteLength = accessor.count * getBinaryAccessor(accessor).componentsPerAttribute;
var byteLength = accessor.count * numberOfComponentsForType(accessor.type);

// buffer.path will be undefined when animations are embedded.
return model.cacheKey + '//' + defaultValue(buffer.path, '') + '/' + byteOffset + '/' + byteLength;
Expand All @@ -45,50 +49,40 @@ define([
var cachedAnimationParameters = {
};

var axisScratch = new Cartesian3();

ModelAnimationCache.getAnimationParameterValues = function(model, accessor) {
var key = getAccessorKey(model, accessor);
var values = cachedAnimationParameters[key];

if (!defined(values)) {
// Cache miss
var loadResources = model._loadResources;
var gltf = model.gltf;
var hasAxisAngle = (parseFloat(gltf.asset.version) < 1.0);

var buffers = gltf.buffers;
var bufferViews = gltf.bufferViews;

var bufferView = bufferViews[accessor.bufferView];
var bufferId = bufferView.buffer;
var buffer = buffers[bufferId];
var source = buffer.extras._pipeline.source;

var componentType = accessor.componentType;
var type = accessor.type;
var numberOfComponents = numberOfComponentsForType(type);
var count = accessor.count;

// Convert typed array to Cesium types
var buffer = loadResources.getBuffer(bufferView);
var typedArray = getBinaryAccessor(accessor).createArrayBufferView(buffer.buffer, buffer.byteOffset + accessor.byteOffset, count);
var i;

if ((componentType === WebGLConstants.FLOAT) && (type === 'SCALAR')) {
values = typedArray;
}
else if ((componentType === WebGLConstants.FLOAT) && (type === 'VEC3')) {
values = new Array(count);
for (i = 0; i < count; ++i) {
values[i] = Cartesian3.fromArray(typedArray, 3 * i);
}
} else if ((componentType === WebGLConstants.FLOAT) && (type === 'VEC4')) {
values = new Array(count);
for (i = 0; i < count; ++i) {
var byteOffset = 4 * i;
if (hasAxisAngle) {
values[i] = Quaternion.fromAxisAngle(Cartesian3.fromArray(typedArray, byteOffset, axisScratch), typedArray[byteOffset + 3]);
}
else {
values[i] = Quaternion.unpack(typedArray, byteOffset);
}
var byteStride = getAccessorByteStride(accessor);

values = new Array(count);
var byteOffset = bufferView.byteOffset + accessor.byteOffset;
for (var i = 0; i < count; i++) {
var typedArrayView = ComponentDatatype.createArrayBufferView(componentType, source.buffer, byteOffset, numberOfComponents);
if (type === 'SCALAR') {
values[i] = typedArrayView[0];
} else if (type === 'VEC3') {
values[i] = Cartesian3.fromArray(typedArrayView);
} else if (type === 'VEC4') {
values[i] = Quaternion.unpack(typedArrayView);
}
byteOffset += byteStride;
}
// GLTF_SPEC: Support more parameter types when glTF supports targeting materials. https://github.com/KhronosGroup/glTF/issues/142

Expand Down Expand Up @@ -117,30 +111,26 @@ define([
};
// END GLTF_SPEC

ModelAnimationCache.getAnimationSpline = function(model, animationName, animation, samplerName, sampler, parameterValues) {
ModelAnimationCache.getAnimationSpline = function(model, animationName, animation, samplerName, sampler, input, path, output) {
var key = getAnimationSplineKey(model, animationName, samplerName);
var spline = cachedAnimationSplines[key];

if (!defined(spline)) {
var times = parameterValues[sampler.input];
var accessor = model.gltf.accessors[animation.parameters[sampler.output]];
var controlPoints = parameterValues[sampler.output];
var times = input;
var controlPoints = output;

// GLTF_SPEC: https://github.com/KhronosGroup/glTF/issues/185
if ((times.length === 1) && (controlPoints.length === 1)) {
spline = new ConstantSpline(controlPoints[0]);
} else {
// END GLTF_SPEC
var componentType = accessor.componentType;
var type = accessor.type;

if (sampler.interpolation === 'LINEAR') {
if ((componentType === WebGLConstants.FLOAT) && (type === 'VEC3')) {
if (path === 'translation' || path === 'scale') {
spline = new LinearSpline({
times : times,
points : controlPoints
});
} else if ((componentType === WebGLConstants.FLOAT) && (type === 'VEC4')) {
} else if (path === 'rotation') {
spline = new QuaternionSpline({
times : times,
points : controlPoints
Expand Down Expand Up @@ -169,23 +159,30 @@ define([

if (!defined(matrices)) {
// Cache miss

var loadResources = model._loadResources;
var gltf = model.gltf;
var buffers = gltf.buffers;
var bufferViews = gltf.bufferViews;

var bufferView = bufferViews[accessor.bufferView];
var bufferViewId = accessor.bufferView;
var bufferView = bufferViews[bufferViewId];
var bufferId = bufferView.buffer;
var buffer = buffers[bufferId];
var source = buffer.extras._pipeline.source;

var componentType = accessor.componentType;
var type = accessor.type;
var count = accessor.count;
var buffer = loadResources.getBuffer(bufferView);
var typedArray = getBinaryAccessor(accessor).createArrayBufferView(buffer.buffer, buffer.byteOffset + accessor.byteOffset, count);
matrices = new Array(count);
var byteStride = getAccessorByteStride(accessor);
var byteOffset = bufferView.byteOffset + accessor.byteOffset;
var numberOfComponents = numberOfComponentsForType(type);

matrices = new Array(count);

if ((componentType === WebGLConstants.FLOAT) && (type === 'MAT4')) {
for (var i = 0; i < count; ++i) {
matrices[i] = Matrix4.fromArray(typedArray, 16 * i);
var typedArrayView = ComponentDatatype.createArrayBufferView(componentType, source.buffer, byteOffset, numberOfComponents);
matrices[i] = Matrix4.fromArray(typedArrayView);
byteOffset += byteStride;
}
}

Expand Down
1 change: 0 additions & 1 deletion Source/Scene/ModelAnimationCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ define([
options.name = animationIds[i];
scheduledAnimations.push(this.add(options));
}

return scheduledAnimations;
};

Expand Down
12 changes: 9 additions & 3 deletions Source/Scene/getAttributeOrUniformBySemantic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/*global define*/
define([], function() {
define([
'../Core/defined'
], function(
defined) {
'use strict';

/**
Expand All @@ -9,6 +12,7 @@ define([], function() {
*/
function getAttributeOrUniformBySemantic(gltf, semantic) {
var techniques = gltf.techniques;
var parameter;
for (var techniqueName in techniques) {
if (techniques.hasOwnProperty(techniqueName)) {
var technique = techniques[techniqueName];
Expand All @@ -17,14 +21,16 @@ define([], function() {
var uniforms = technique.uniforms;
for (var attributeName in attributes) {
if (attributes.hasOwnProperty(attributeName)) {
if (parameters[attributes[attributeName]].semantic === semantic) {
parameter = parameters[attributes[attributeName]];
if (defined(parameter) && parameter.semantic === semantic) {
return attributeName;
}
}
}
for (var uniformName in uniforms) {
if (uniforms.hasOwnProperty(uniformName)) {
if (parameters[uniforms[uniformName]].semantic === semantic) {
parameter = parameters[uniforms[uniformName]];
if (defined(parameter) && parameter.semantic === semantic) {
return uniformName;
}
}
Expand Down
64 changes: 0 additions & 64 deletions Source/Scene/getBinaryAccessor.js

This file was deleted.

Loading