Skip to content

Commit 35d690f

Browse files
author
Joshua Bernstein
authored
Merge pull request #1 from AnalyticalGraphicsInc/master
Merge master into my fork
2 parents 3646fef + 2fa9955 commit 35d690f

12 files changed

+285
-201
lines changed

CHANGES.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Change Log
22
==========
3+
### 1.38 - 2017-10-02
4+
5+
* Added ability to add an animation to `ModelAnimationCollection` by its index. [#5815](https://github.com/AnalyticalGraphicsInc/cesium/pull/5815)
6+
* Fixed a bug in `ModelAnimationCollection` that caused adding an animation by its name to throw an error. [#5815](https://github.com/AnalyticalGraphicsInc/cesium/pull/5815)
7+
* Zoom about mouse now maintains camera heading, pitch, and roll [#4639](https://github.com/AnalyticalGraphicsInc/cesium/pull/5603)
8+
39
### 1.37 - 2017-09-01
410

511
* Breaking changes
@@ -24,6 +30,7 @@ Change Log
2430
* Fixed loading of binary glTFs containing CRN or KTX textures. [#5753](https://github.com/AnalyticalGraphicsInc/cesium/pull/5753)
2531
* Fixed specular computation for certain models using the `KHR_materials_common` extension. [#5773](https://github.com/AnalyticalGraphicsInc/cesium/pull/5773)
2632
* Fixed a picking bug in the `3D Tiles Interactivity` Sandcastle demo. [#5703](https://github.com/AnalyticalGraphicsInc/cesium/issues/5703)
33+
* Updated knockout from 3.4.0 to 3.4.2 [#5703](https://github.com/AnalyticalGraphicsInc/cesium/pull/5829)
2734

2835
### 1.36 - 2017-08-01
2936

CONTRIBUTORS.md

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
8686
* [Jason Crow](https://github.com/jason-crow)
8787
* [Flightradar24 AB](https://www.flightradar24.com)
8888
* [Aleksei Kalmykov](https://github.com/kalmykov)
89+
* [BIT Systems](http://www.caci.com/bit-systems)
90+
* [William Wall](https://github.com/wallw-bits)
8991
* [virtualcitySYSTEMS GmbH](https://www.virtualcitysystems.de)
9092
* [Jannes Bolling](https://github.com/jbo023)
9193

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ https://github.com/jrburke/requirejs
356356

357357
http://knockoutjs.com/
358358

359-
> (c) Steven Sanderson - http://knockoutjs.com/
359+
> (c) The Knockout.js team - http://knockoutjs.com/
360360
> License: MIT (http://www.opensource.org/licenses/mit-license.php)
361361
>
362362
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Source/Scene/Model.js

+30-46
Original file line numberDiff line numberDiff line change
@@ -289,20 +289,6 @@ define([
289289
this.ready = true;
290290
};
291291

292-
function getAnimationIds(cachedGltf) {
293-
var animationIds = [];
294-
if (defined(cachedGltf)) {
295-
var animations = cachedGltf.animations;
296-
for (var id in animations) {
297-
if (animations.hasOwnProperty(id)) {
298-
animationIds.push(id);
299-
}
300-
}
301-
}
302-
303-
return animationIds;
304-
}
305-
306292
var gltfCache = {};
307293

308294
///////////////////////////////////////////////////////////////////////////
@@ -368,7 +354,6 @@ define([
368354
this._cacheKey = cacheKey;
369355
this._cachedGltf = undefined;
370356
this._releaseGltfJson = defaultValue(options.releaseGltfJson, false);
371-
this._animationIds = undefined;
372357

373358
var cachedGltf;
374359
if (defined(cacheKey) && defined(gltfCache[cacheKey]) && gltfCache[cacheKey].ready) {
@@ -2523,48 +2508,48 @@ define([
25232508
}
25242509
loadResources.createRuntimeAnimations = false;
25252510

2526-
model._runtime.animations = {};
2511+
model._runtime.animations = [];
25272512

25282513
var runtimeNodes = model._runtime.nodes;
25292514
var animations = model.gltf.animations;
25302515
var accessors = model.gltf.accessors;
25312516

2532-
for (var animationId in animations) {
2533-
if (animations.hasOwnProperty(animationId)) {
2534-
var animation = animations[animationId];
2535-
var channels = animation.channels;
2536-
var samplers = animation.samplers;
2537-
2538-
// Find start and stop time for the entire animation
2539-
var startTime = Number.MAX_VALUE;
2540-
var stopTime = -Number.MAX_VALUE;
2517+
var length = animations.length;
2518+
for (var i = 0; i < length; ++i) {
2519+
var animation = animations[i];
2520+
var channels = animation.channels;
2521+
var samplers = animation.samplers;
25412522

2542-
var length = channels.length;
2543-
var channelEvaluators = new Array(length);
2523+
// Find start and stop time for the entire animation
2524+
var startTime = Number.MAX_VALUE;
2525+
var stopTime = -Number.MAX_VALUE;
25442526

2545-
for (var i = 0; i < length; ++i) {
2546-
var channel = channels[i];
2547-
var target = channel.target;
2548-
var path = target.path;
2549-
var sampler = samplers[channel.sampler];
2550-
var input = ModelAnimationCache.getAnimationParameterValues(model, accessors[sampler.input]);
2551-
var output = ModelAnimationCache.getAnimationParameterValues(model, accessors[sampler.output]);
2527+
var channelsLength = channels.length;
2528+
var channelEvaluators = new Array(channelsLength);
25522529

2553-
startTime = Math.min(startTime, input[0]);
2554-
stopTime = Math.max(stopTime, input[input.length - 1]);
2530+
for (var j = 0; j < channelsLength; ++j) {
2531+
var channel = channels[j];
2532+
var target = channel.target;
2533+
var path = target.path;
2534+
var sampler = samplers[channel.sampler];
2535+
var input = ModelAnimationCache.getAnimationParameterValues(model, accessors[sampler.input]);
2536+
var output = ModelAnimationCache.getAnimationParameterValues(model, accessors[sampler.output]);
25552537

2556-
var spline = ModelAnimationCache.getAnimationSpline(model, animationId, animation, channel.sampler, sampler, input, path, output);
2538+
startTime = Math.min(startTime, input[0]);
2539+
stopTime = Math.max(stopTime, input[input.length - 1]);
25572540

2558-
// GLTF_SPEC: Support more targets like materials. https://github.com/KhronosGroup/glTF/issues/142
2559-
channelEvaluators[i] = getChannelEvaluator(model, runtimeNodes[target.node], target.path, spline);
2560-
}
2541+
var spline = ModelAnimationCache.getAnimationSpline(model, i, animation, channel.sampler, sampler, input, path, output);
25612542

2562-
model._runtime.animations[animationId] = {
2563-
startTime : startTime,
2564-
stopTime : stopTime,
2565-
channelEvaluators : channelEvaluators
2566-
};
2543+
// GLTF_SPEC: Support more targets like materials. https://github.com/KhronosGroup/glTF/issues/142
2544+
channelEvaluators[j] = getChannelEvaluator(model, runtimeNodes[target.node], target.path, spline);
25672545
}
2546+
2547+
model._runtime.animations[i] = {
2548+
name : animation.name,
2549+
startTime : startTime,
2550+
stopTime : stopTime,
2551+
channelEvaluators : channelEvaluators
2552+
};
25682553
}
25692554
}
25702555

@@ -4551,7 +4536,6 @@ define([
45514536
processPbrMetallicRoughness(this.gltf, options);
45524537
// We do this after to make sure that the ids don't change
45534538
addBuffersToLoadResources(this);
4554-
this._animationIds = getAnimationIds(this.gltf);
45554539

45564540
if (!this._loadRendererResourcesFromCache) {
45574541
parseBufferViews(this);

Source/Scene/ModelAnimation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ define([
3030
* @see ModelAnimationCollection#add
3131
*/
3232
function ModelAnimation(options, model, runtimeAnimation) {
33-
this._name = options.name;
33+
this._name = runtimeAnimation.name;
3434
this._startTime = JulianDate.clone(options.startTime);
3535
this._delay = defaultValue(options.delay, 0.0); // in seconds
3636
this._stopTime = options.stopTime;

Source/Scene/ModelAnimationCollection.js

+49-19
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,25 @@ define([
8282
}
8383
});
8484

85+
function add(collection, index, options) {
86+
var model = collection._model;
87+
var animations = model._runtime.animations;
88+
var animation = animations[index];
89+
var scheduledAnimation = new ModelAnimation(options, model, animation);
90+
collection._scheduledAnimations.push(scheduledAnimation);
91+
collection.animationAdded.raiseEvent(model, scheduledAnimation);
92+
return scheduledAnimation;
93+
}
94+
8595
/**
8696
* Creates and adds an animation with the specified initial properties to the collection.
8797
* <p>
8898
* This raises the {@link ModelAnimationCollection#animationAdded} event so, for example, a UI can stay in sync.
8999
* </p>
90100
*
91101
* @param {Object} options Object with the following properties:
92-
* @param {String} options.name The glTF animation name that identifies the animation.
102+
* @param {String} [options.name] The glTF animation name that identifies the animation. Must be defined if <code>options.id</code> is <code>undefined</code>.
103+
* @param {Number} [options.index] The glTF animation index that identifies the animation. Must be defined if <code>options.name</code> is <code>undefined</code>.
93104
* @param {JulianDate} [options.startTime] The scene time to start playing the animation. When this is <code>undefined</code>, the animation starts at the next frame.
94105
* @param {Number} [options.delay=0.0] The delay, in seconds, from <code>startTime</code> to start playing.
95106
* @param {JulianDate} [options.stopTime] The scene time to stop playing the animation. When this is <code>undefined</code>, the animation is played for its full duration.
@@ -101,16 +112,23 @@ define([
101112
*
102113
* @exception {DeveloperError} Animations are not loaded. Wait for the {@link Model#readyPromise} to resolve.
103114
* @exception {DeveloperError} options.name must be a valid animation name.
115+
* @exception {DeveloperError} options.index must be a valid animation index.
116+
* @exception {DeveloperError} Either options.name or options.index must be defined.
104117
* @exception {DeveloperError} options.speedup must be greater than zero.
105118
*
106119
* @example
107-
* // Example 1. Add an animation
120+
* // Example 1. Add an animation by name
108121
* model.activeAnimations.add({
109122
* name : 'animation name'
110123
* });
111124
*
125+
* // Example 2. Add an animation by index
126+
* model.activeAnimations.add({
127+
* index : 0
128+
* });
129+
*
112130
* @example
113-
* // Example 2. Add an animation and provide all properties and events
131+
* // Example 3. Add an animation and provide all properties and events
114132
* var startTime = Cesium.JulianDate.now();
115133
*
116134
* var animation = model.activeAnimations.add({
@@ -144,24 +162,38 @@ define([
144162
if (!defined(animations)) {
145163
throw new DeveloperError('Animations are not loaded. Wait for Model.readyPromise to resolve.');
146164
}
165+
if (!defined(options.name) && !defined(options.index)) {
166+
throw new DeveloperError('Either options.name or options.index must be defined.');
167+
}
168+
if (defined(options.speedup) && (options.speedup <= 0.0)) {
169+
throw new DeveloperError('options.speedup must be greater than zero.');
170+
}
171+
if (defined(options.index) && (options.index >= animations.length || options.index < 0)) {
172+
throw new DeveloperError('options.index must be a valid animation index.');
173+
}
147174
//>>includeEnd('debug');
148175

149-
var animation = animations[options.name];
176+
if (defined(options.index)) {
177+
return add(this, options.index, options);
178+
}
150179

151-
//>>includeStart('debug', pragmas.debug);
152-
if (!defined(animation)) {
153-
throw new DeveloperError('options.name must be a valid animation name.');
180+
// Find the index of the animation with the given name
181+
var index;
182+
var length = animations.length;
183+
for (var i = 0; i < length; ++i) {
184+
if (animations[i].name === options.name) {
185+
index = i;
186+
break;
187+
}
154188
}
155189

156-
if (defined(options.speedup) && (options.speedup <= 0.0)) {
157-
throw new DeveloperError('options.speedup must be greater than zero.');
190+
//>>includeStart('debug', pragmas.debug);
191+
if (!defined(index)) {
192+
throw new DeveloperError('options.name must be a valid animation name.');
158193
}
159194
//>>includeEnd('debug');
160195

161-
var scheduledAnimation = new ModelAnimation(options, model, animation);
162-
this._scheduledAnimations.push(scheduledAnimation);
163-
this.animationAdded.raiseEvent(model, scheduledAnimation);
164-
return scheduledAnimation;
196+
return add(this, index, options);
165197
};
166198

167199
/**
@@ -203,14 +235,12 @@ define([
203235
}
204236
//>>includeEnd('debug');
205237

206-
options = clone(options);
207-
208238
var scheduledAnimations = [];
209-
var animationIds = this._model._animationIds;
210-
var length = animationIds.length;
239+
var model = this._model;
240+
var animations = model._runtime.animations;
241+
var length = animations.length;
211242
for (var i = 0; i < length; ++i) {
212-
options.name = animationIds[i];
213-
scheduledAnimations.push(this.add(options));
243+
scheduledAnimations.push(add(this, i, options));
214244
}
215245
return scheduledAnimations;
216246
};

Source/Scene/ScreenSpaceCameraController.js

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ define([
88
'../Core/destroyObject',
99
'../Core/DeveloperError',
1010
'../Core/Ellipsoid',
11+
'../Core/HeadingPitchRoll',
1112
'../Core/IntersectionTests',
1213
'../Core/isArray',
1314
'../Core/KeyboardEventModifier',
@@ -35,6 +36,7 @@ define([
3536
destroyObject,
3637
DeveloperError,
3738
Ellipsoid,
39+
HeadingPitchRoll,
3840
IntersectionTests,
3941
isArray,
4042
KeyboardEventModifier,
@@ -446,6 +448,9 @@ define([
446448
var scratchCartesian = new Cartesian3();
447449
var scratchCartesianTwo = new Cartesian3();
448450
var scratchCartesianThree = new Cartesian3();
451+
var scratchZoomViewOptions = {
452+
orientation: new HeadingPitchRoll()
453+
};
449454

450455
function handleZoom(object, startPosition, movement, zoomFactor, distanceMeasure, unitPositionDotDirection) {
451456
var percentage = 1.0;
@@ -485,6 +490,11 @@ define([
485490
var camera = scene.camera;
486491
var mode = scene.mode;
487492

493+
var orientation = scratchZoomViewOptions.orientation;
494+
orientation.heading = camera.heading;
495+
orientation.pitch = camera.pitch;
496+
orientation.roll = camera.roll;
497+
488498
if (camera.frustum instanceof OrthographicFrustum) {
489499
if (Math.abs(distance) > 0.0) {
490500
camera.zoomIn(distance);
@@ -646,6 +656,7 @@ define([
646656
Cartesian3.cross(camera.direction, camera.up, camera.right);
647657
Cartesian3.cross(camera.right, camera.direction, camera.up);
648658

659+
camera.setView(scratchZoomViewOptions);
649660
return;
650661
}
651662

@@ -691,6 +702,8 @@ define([
691702
} else {
692703
camera.zoomIn(distance);
693704
}
705+
706+
camera.setView(scratchZoomViewOptions);
694707
}
695708

696709
var translate2DStart = new Ray();

0 commit comments

Comments
 (0)