Skip to content

Commit

Permalink
Merge pull request #1 from AnalyticalGraphicsInc/master
Browse files Browse the repository at this point in the history
Merge master into my fork
  • Loading branch information
Joshua Bernstein committed Sep 14, 2017
2 parents 3646fef + 2fa9955 commit 35d690f
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 201 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Change Log
==========
### 1.38 - 2017-10-02

* Added ability to add an animation to `ModelAnimationCollection` by its index. [#5815](https://github.com/AnalyticalGraphicsInc/cesium/pull/5815)
* 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)
* Zoom about mouse now maintains camera heading, pitch, and roll [#4639](https://github.com/AnalyticalGraphicsInc/cesium/pull/5603)

### 1.37 - 2017-09-01

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

### 1.36 - 2017-08-01

Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [Jason Crow](https://github.com/jason-crow)
* [Flightradar24 AB](https://www.flightradar24.com)
* [Aleksei Kalmykov](https://github.com/kalmykov)
* [BIT Systems](http://www.caci.com/bit-systems)
* [William Wall](https://github.com/wallw-bits)
* [virtualcitySYSTEMS GmbH](https://www.virtualcitysystems.de)
* [Jannes Bolling](https://github.com/jbo023)

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ https://github.com/jrburke/requirejs

http://knockoutjs.com/

> (c) Steven Sanderson - http://knockoutjs.com/
> (c) The Knockout.js team - http://knockoutjs.com/
> License: MIT (http://www.opensource.org/licenses/mit-license.php)
>
> 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:
Expand Down
76 changes: 30 additions & 46 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,6 @@ define([
this.ready = true;
};

function getAnimationIds(cachedGltf) {
var animationIds = [];
if (defined(cachedGltf)) {
var animations = cachedGltf.animations;
for (var id in animations) {
if (animations.hasOwnProperty(id)) {
animationIds.push(id);
}
}
}

return animationIds;
}

var gltfCache = {};

///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -368,7 +354,6 @@ define([
this._cacheKey = cacheKey;
this._cachedGltf = undefined;
this._releaseGltfJson = defaultValue(options.releaseGltfJson, false);
this._animationIds = undefined;

var cachedGltf;
if (defined(cacheKey) && defined(gltfCache[cacheKey]) && gltfCache[cacheKey].ready) {
Expand Down Expand Up @@ -2523,48 +2508,48 @@ define([
}
loadResources.createRuntimeAnimations = false;

model._runtime.animations = {};
model._runtime.animations = [];

var runtimeNodes = model._runtime.nodes;
var animations = model.gltf.animations;
var accessors = model.gltf.accessors;

for (var animationId in animations) {
if (animations.hasOwnProperty(animationId)) {
var animation = animations[animationId];
var channels = animation.channels;
var samplers = animation.samplers;

// Find start and stop time for the entire animation
var startTime = Number.MAX_VALUE;
var stopTime = -Number.MAX_VALUE;
var length = animations.length;
for (var i = 0; i < length; ++i) {
var animation = animations[i];
var channels = animation.channels;
var samplers = animation.samplers;

var length = channels.length;
var channelEvaluators = new Array(length);
// Find start and stop time for the entire animation
var startTime = Number.MAX_VALUE;
var stopTime = -Number.MAX_VALUE;

for (var i = 0; i < length; ++i) {
var channel = channels[i];
var target = channel.target;
var path = target.path;
var sampler = samplers[channel.sampler];
var input = ModelAnimationCache.getAnimationParameterValues(model, accessors[sampler.input]);
var output = ModelAnimationCache.getAnimationParameterValues(model, accessors[sampler.output]);
var channelsLength = channels.length;
var channelEvaluators = new Array(channelsLength);

startTime = Math.min(startTime, input[0]);
stopTime = Math.max(stopTime, input[input.length - 1]);
for (var j = 0; j < channelsLength; ++j) {
var channel = channels[j];
var target = channel.target;
var path = target.path;
var sampler = samplers[channel.sampler];
var input = ModelAnimationCache.getAnimationParameterValues(model, accessors[sampler.input]);
var output = ModelAnimationCache.getAnimationParameterValues(model, accessors[sampler.output]);

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

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

model._runtime.animations[animationId] = {
startTime : startTime,
stopTime : stopTime,
channelEvaluators : channelEvaluators
};
// GLTF_SPEC: Support more targets like materials. https://github.com/KhronosGroup/glTF/issues/142
channelEvaluators[j] = getChannelEvaluator(model, runtimeNodes[target.node], target.path, spline);
}

model._runtime.animations[i] = {
name : animation.name,
startTime : startTime,
stopTime : stopTime,
channelEvaluators : channelEvaluators
};
}
}

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

if (!this._loadRendererResourcesFromCache) {
parseBufferViews(this);
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/ModelAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ define([
* @see ModelAnimationCollection#add
*/
function ModelAnimation(options, model, runtimeAnimation) {
this._name = options.name;
this._name = runtimeAnimation.name;
this._startTime = JulianDate.clone(options.startTime);
this._delay = defaultValue(options.delay, 0.0); // in seconds
this._stopTime = options.stopTime;
Expand Down
68 changes: 49 additions & 19 deletions Source/Scene/ModelAnimationCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,25 @@ define([
}
});

function add(collection, index, options) {
var model = collection._model;
var animations = model._runtime.animations;
var animation = animations[index];
var scheduledAnimation = new ModelAnimation(options, model, animation);
collection._scheduledAnimations.push(scheduledAnimation);
collection.animationAdded.raiseEvent(model, scheduledAnimation);
return scheduledAnimation;
}

/**
* Creates and adds an animation with the specified initial properties to the collection.
* <p>
* This raises the {@link ModelAnimationCollection#animationAdded} event so, for example, a UI can stay in sync.
* </p>
*
* @param {Object} options Object with the following properties:
* @param {String} options.name The glTF animation name that identifies the animation.
* @param {String} [options.name] The glTF animation name that identifies the animation. Must be defined if <code>options.id</code> is <code>undefined</code>.
* @param {Number} [options.index] The glTF animation index that identifies the animation. Must be defined if <code>options.name</code> is <code>undefined</code>.
* @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.
* @param {Number} [options.delay=0.0] The delay, in seconds, from <code>startTime</code> to start playing.
* @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.
Expand All @@ -101,16 +112,23 @@ define([
*
* @exception {DeveloperError} Animations are not loaded. Wait for the {@link Model#readyPromise} to resolve.
* @exception {DeveloperError} options.name must be a valid animation name.
* @exception {DeveloperError} options.index must be a valid animation index.
* @exception {DeveloperError} Either options.name or options.index must be defined.
* @exception {DeveloperError} options.speedup must be greater than zero.
*
* @example
* // Example 1. Add an animation
* // Example 1. Add an animation by name
* model.activeAnimations.add({
* name : 'animation name'
* });
*
* // Example 2. Add an animation by index
* model.activeAnimations.add({
* index : 0
* });
*
* @example
* // Example 2. Add an animation and provide all properties and events
* // Example 3. Add an animation and provide all properties and events
* var startTime = Cesium.JulianDate.now();
*
* var animation = model.activeAnimations.add({
Expand Down Expand Up @@ -144,24 +162,38 @@ define([
if (!defined(animations)) {
throw new DeveloperError('Animations are not loaded. Wait for Model.readyPromise to resolve.');
}
if (!defined(options.name) && !defined(options.index)) {
throw new DeveloperError('Either options.name or options.index must be defined.');
}
if (defined(options.speedup) && (options.speedup <= 0.0)) {
throw new DeveloperError('options.speedup must be greater than zero.');
}
if (defined(options.index) && (options.index >= animations.length || options.index < 0)) {
throw new DeveloperError('options.index must be a valid animation index.');
}
//>>includeEnd('debug');

var animation = animations[options.name];
if (defined(options.index)) {
return add(this, options.index, options);
}

//>>includeStart('debug', pragmas.debug);
if (!defined(animation)) {
throw new DeveloperError('options.name must be a valid animation name.');
// Find the index of the animation with the given name
var index;
var length = animations.length;
for (var i = 0; i < length; ++i) {
if (animations[i].name === options.name) {
index = i;
break;
}
}

if (defined(options.speedup) && (options.speedup <= 0.0)) {
throw new DeveloperError('options.speedup must be greater than zero.');
//>>includeStart('debug', pragmas.debug);
if (!defined(index)) {
throw new DeveloperError('options.name must be a valid animation name.');
}
//>>includeEnd('debug');

var scheduledAnimation = new ModelAnimation(options, model, animation);
this._scheduledAnimations.push(scheduledAnimation);
this.animationAdded.raiseEvent(model, scheduledAnimation);
return scheduledAnimation;
return add(this, index, options);
};

/**
Expand Down Expand Up @@ -203,14 +235,12 @@ define([
}
//>>includeEnd('debug');

options = clone(options);

var scheduledAnimations = [];
var animationIds = this._model._animationIds;
var length = animationIds.length;
var model = this._model;
var animations = model._runtime.animations;
var length = animations.length;
for (var i = 0; i < length; ++i) {
options.name = animationIds[i];
scheduledAnimations.push(this.add(options));
scheduledAnimations.push(add(this, i, options));
}
return scheduledAnimations;
};
Expand Down
13 changes: 13 additions & 0 deletions Source/Scene/ScreenSpaceCameraController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ define([
'../Core/destroyObject',
'../Core/DeveloperError',
'../Core/Ellipsoid',
'../Core/HeadingPitchRoll',
'../Core/IntersectionTests',
'../Core/isArray',
'../Core/KeyboardEventModifier',
Expand Down Expand Up @@ -35,6 +36,7 @@ define([
destroyObject,
DeveloperError,
Ellipsoid,
HeadingPitchRoll,
IntersectionTests,
isArray,
KeyboardEventModifier,
Expand Down Expand Up @@ -446,6 +448,9 @@ define([
var scratchCartesian = new Cartesian3();
var scratchCartesianTwo = new Cartesian3();
var scratchCartesianThree = new Cartesian3();
var scratchZoomViewOptions = {
orientation: new HeadingPitchRoll()
};

function handleZoom(object, startPosition, movement, zoomFactor, distanceMeasure, unitPositionDotDirection) {
var percentage = 1.0;
Expand Down Expand Up @@ -485,6 +490,11 @@ define([
var camera = scene.camera;
var mode = scene.mode;

var orientation = scratchZoomViewOptions.orientation;
orientation.heading = camera.heading;
orientation.pitch = camera.pitch;
orientation.roll = camera.roll;

if (camera.frustum instanceof OrthographicFrustum) {
if (Math.abs(distance) > 0.0) {
camera.zoomIn(distance);
Expand Down Expand Up @@ -646,6 +656,7 @@ define([
Cartesian3.cross(camera.direction, camera.up, camera.right);
Cartesian3.cross(camera.right, camera.direction, camera.up);

camera.setView(scratchZoomViewOptions);
return;
}

Expand Down Expand Up @@ -691,6 +702,8 @@ define([
} else {
camera.zoomIn(distance);
}

camera.setView(scratchZoomViewOptions);
}

var translate2DStart = new Ray();
Expand Down
Loading

0 comments on commit 35d690f

Please sign in to comment.