Skip to content

Commit

Permalink
Added a runAnimations property to ModelGraphics.js to allow the user …
Browse files Browse the repository at this point in the history
…to specify if glTF animations should be started
  • Loading branch information
gbeatty committed Sep 14, 2015
1 parent 06ad0e8 commit 9359a01
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Source/DataSources/ModelGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ define([
* @param {Property} [options.show=true] A boolean Property specifying the visibility of the model.
* @param {Property} [options.scale=1.0] A numeric Property specifying a uniform linear scale.
* @param {Property} [options.minimumPixelSize=0.0] A numeric Property specifying the approximate minimum pixel size of the model regardless of zoom.
* @param {Property} [options.runAnimations=true] A boolean Property specifying if glTF animations specified in the model should be started.
*
* @see {@link http://cesiumjs.org/2014/03/03/Cesium-3D-Models-Tutorial/|3D Models Tutorial}
* @demo {@link http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=3D%20Models.html|Cesium Sandcastle 3D Models Demo}
Expand All @@ -46,6 +47,8 @@ define([
this._minimumPixelSizeSubscription = undefined;
this._uri = undefined;
this._uriSubscription = undefined;
this._runAnimations = undefined;
this._runAnimationsSubscription = undefined;
this._nodeTransformations = undefined;
this._nodeTransformationsSubscription = undefined;
this._definitionChanged = new Event();
Expand Down Expand Up @@ -102,6 +105,14 @@ define([
*/
uri : createPropertyDescriptor('uri'),

/**
* Gets or sets the boolean Property specifying if glTF animations should be run.
* @memberof ModelGraphics.prototype
* @type {Property}
* @default true
*/
runAnimations : createPropertyDescriptor('runAnimations'),

/**
* Gets or sets the object Property specifying the 3D transformations to apply to glTF asset nodes.
* @memberof ModelGraphics.prototype
Expand All @@ -124,6 +135,7 @@ define([
result.scale = this.scale;
result.minimumPixelSize = this.minimumPixelSize;
result.uri = this.uri;
result.runAnimations = this.runAnimations;
result.nodeTransformations = this.nodeTransformations;

return result;
Expand All @@ -146,6 +158,7 @@ define([
this.scale = defaultValue(this.scale, source.scale);
this.minimumPixelSize = defaultValue(this.minimumPixelSize, source.minimumPixelSize);
this.uri = defaultValue(this.uri, source.uri);
this.runAnimations = defaultValue(this.runAnimations, source.runAnimations);
this.nodeTransformations = defaultValue(this.nodeTransformations, source.nodeTransformations);
};

Expand Down
17 changes: 16 additions & 1 deletion Source/DataSources/ModelVisualizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ define([

modelData = {
modelPrimitive : model,
uri : uri
uri : uri,
animationsRunning : false
};
modelHash[entity.id] = modelData;
}
Expand All @@ -134,6 +135,20 @@ define([
model.minimumPixelSize = Property.getValueOrDefault(modelGraphics._minimumPixelSize, time, defaultMinimumPixelSize);
model.modelMatrix = Matrix4.clone(modelMatrix, model.modelMatrix);

var runAnimations = Property.getValueOrDefault(modelGraphics._runAnimations, time, true);
if (model.ready && modelData.animationsRunning !== runAnimations) {
if (runAnimations === true) {
model.activeAnimations.addAll({
loop : ModelAnimationLoop.REPEAT
});
modelData.animationsRunning = true;
}
else {
model.activeAnimations.removeAll();
modelData.animationsRunning = false;
}
}

// Apply node transformations
var nodeTransformations = Property.getValueOrDefault(modelGraphics._nodeTransformations, time, undefined);
if (defined(nodeTransformations) && model.ready === true) {
Expand Down
11 changes: 11 additions & 0 deletions Specs/DataSources/ModelGraphicsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defineSuite([
scale : 1,
show : false,
minimumPixelSize : 2,
runAnimations : false,
nodeTransformations : {
node1 : new ModelTransformProperty()
}
Expand All @@ -26,11 +27,13 @@ defineSuite([
expect(model.scale).toBeInstanceOf(ConstantProperty);
expect(model.show).toBeInstanceOf(ConstantProperty);
expect(model.minimumPixelSize).toBeInstanceOf(ConstantProperty);
expect(model.runAnimations).toBeInstanceOf(ConstantProperty);
expect(model.nodeTransformations).toBeInstanceOf(ConstantProperty);

expect(model.uri.getValue()).toEqual(options.uri);
expect(model.scale.getValue()).toEqual(options.scale);
expect(model.show.getValue()).toEqual(options.show);
expect(model.runAnimations.getValue()).toEqual(options.runAnimations);
expect(model.minimumPixelSize.getValue()).toEqual(options.minimumPixelSize);
expect(model.nodeTransformations.getValue()).toEqual(options.nodeTransformations);
});
Expand All @@ -47,6 +50,7 @@ defineSuite([
var source = new ModelGraphics();
source.uri = new ConstantProperty('');
source.show = new ConstantProperty(true);
source.runAnimations = new ConstantProperty(true);
source.scale = new ConstantProperty(1.0);
source.minimumPixelSize = new ConstantProperty(2.0);
source.nodeTransformations = nodeTransforms;
Expand All @@ -57,6 +61,7 @@ defineSuite([
expect(target.uri).toBe(source.uri);
expect(target.show).toBe(source.show);
expect(target.scale).toBe(source.scale);
expect(target.runAnimations).toBe(source.runAnimations);
expect(target.minimumPixelSize).toBe(source.minimumPixelSize);
expect(target.nodeTransformations).toBe(source.nodeTransformations);
});
Expand All @@ -69,6 +74,7 @@ defineSuite([
source.uri = new ConstantProperty('');
source.show = new ConstantProperty(true);
source.scale = new ConstantProperty(1.0);
source.runAnimations = new ConstantProperty(true);
source.minimumPixelSize = new ConstantProperty(2.0);
source.nodeTransformations = new ConstantProperty({
transform : node1Transforms
Expand All @@ -77,6 +83,7 @@ defineSuite([
var uri = new ConstantProperty('');
var show = new ConstantProperty(true);
var scale = new ConstantProperty(1.0);
var runAnimations = new ConstantProperty(true);
var minimumPixelSize = new ConstantProperty(2.0);
var nodeTransformations = new ConstantProperty({
transform : node2Transforms
Expand All @@ -86,6 +93,7 @@ defineSuite([
target.uri = uri;
target.show = show;
target.scale = scale;
target.runAnimations = runAnimations;
target.minimumPixelSize = minimumPixelSize;
target.nodeTransformations = nodeTransformations;

Expand All @@ -94,6 +102,7 @@ defineSuite([
expect(target.uri).toBe(uri);
expect(target.show).toBe(show);
expect(target.scale).toBe(scale);
expect(target.runAnimations).toBe(runAnimations);
expect(target.minimumPixelSize).toBe(minimumPixelSize);
expect(target.nodeTransformations).toBe(nodeTransformations);
});
Expand All @@ -102,6 +111,7 @@ defineSuite([
var source = new ModelGraphics();
source.uri = new ConstantProperty('');
source.show = new ConstantProperty(true);
source.runAnimations = new ConstantProperty(true);
source.scale = new ConstantProperty(1.0);
source.minimumPixelSize = new ConstantProperty(2.0);
source.nodeTransformations = {
Expand All @@ -112,6 +122,7 @@ defineSuite([
var result = source.clone();
expect(result.uri).toBe(source.uri);
expect(result.show).toBe(source.show);
expect(result.runAnimations).toBe(source.runAnimations);
expect(result.scale).toBe(source.scale);
expect(result.minimumPixelSize).toBe(source.minimumPixelSize);
expect(result.nodeTransformations).toBe(source.nodeTransformations);
Expand Down

0 comments on commit 9359a01

Please sign in to comment.