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

New Particle System Sandcastle examples #1

Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
Binary file added Apps/SampleData/circular_particle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Apps/SampleData/snowflake_particle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 6 additions & 8 deletions Apps/Sandcastle/gallery/Particle System Fireworks.html
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@

var minimumExplosionSize = 30.0;
var maximumExplosionSize = 100.0;
var particlePixelSize = 7.0;
var particlePixelSize = new Cesium.Cartesian2(7.0, 7.0);
var burstSize = 400.0;
var lifetime = 10.0;
var numberOfFireworks = 20.0;
@@ -90,15 +90,14 @@
image : getImage(),
startColor : color,
endColor : color.withAlpha(0.0),
life : life,
particleLife : life,
speed : 100.0,
width : particlePixelSize,
height : particlePixelSize,
rate : 0,
imageSize : particlePixelSize,
emissionRate : 0,
emitter : new Cesium.SphereEmitter(0.1),
bursts : bursts,
lifeTime : lifetime,
forces : [force],
lifetime : lifetime,
updateCallback : force,
modelMatrix : modelMatrix,
emitterModelMatrix : emitterModelMatrix
}));
@@ -161,7 +160,6 @@
Cesium.Cartesian3.normalize(toFireworks, toFireworks);
var angle = Cesium.Math.PI_OVER_TWO - Math.acos(Cesium.Cartesian3.dot(toFireworks, Cesium.Cartesian3.UNIT_Z));
camera.lookUp(angle);

//Sandcastle_End
Sandcastle.finishedLoading();
}
228 changes: 228 additions & 0 deletions Apps/Sandcastle/gallery/Particle System Tails.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Particle systems for rocket and comet tails.">
<meta name="cesium-sandcastle-labels" content="Beginner, Showcases, Tutorials">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer', {
shouldAnimate : true
});
var planePosition = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883, 800.0);
var particlesOffset = new Cesium.Cartesian3(-8.950115473940969, 34.852766731753945, -30.235411095432937);
var cameraLocation = Cesium.Cartesian3.add(planePosition, particlesOffset, new Cesium.Cartesian3());
var recenterCamera = function() {
viewer.camera.lookAt(cameraLocation, new Cesium.Cartesian3(170, -170, 170));
};
recenterCamera();

// Draw particle image to a canvas
var particleCanvas;
function getImage() {
if (!Cesium.defined(particleCanvas)) {
particleCanvas = document.createElement('canvas');
particleCanvas.width = 20;
particleCanvas.height = 20;
var context2D = particleCanvas.getContext('2d');
context2D.beginPath();
context2D.arc(8, 8, 8, 0, Cesium.Math.TWO_PI, true);
context2D.closePath();
context2D.fillStyle = 'rgb(255, 255, 255)';
context2D.fill();
}
return particleCanvas;
}

// Add plane to scene
var hpr = new Cesium.HeadingPitchRoll(0.0, Cesium.Math.PI_OVER_TWO, 0.0);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(planePosition, hpr);
var entity = viewer.entities.add({
model : {
uri : '../../SampleData/models/CesiumAir/Cesium_Air.gltf',
scale : 3.5
},
position : planePosition,
orientation : orientation
});

// creating particles model matrix
var transl = Cesium.Matrix4.fromTranslation(particlesOffset, new Cesium.Matrix4());
var translPosition = Cesium.Matrix4.fromTranslation(planePosition, new Cesium.Matrix4());
var particlesModelMatrix = Cesium.Matrix4.multiplyTransformation(translPosition, transl, new Cesium.Matrix4());

// creating the particle systems
var rocketOptions = {
numberOfSystems : 50.0,
iterationOffset : 0.1,
cartographicStep : 0.000001,
baseRadius : 0.0005,

colorOptions : [{
minimumRed : 1.0,
green : 0.5,
minimumBlue : 0.05,
alpha : 1.0
}, {
red : 0.9,
minimumGreen : 0.6,
minimumBlue : 0.01,
alpha : 1.0
}, {
red : 0.8,
green : 0.05,
minimumBlue : 0.09,
alpha : 1.0
}, {
minimumRed : 1,
minimumGreen : 0.05,
blue : 0.09,
alpha : 1.0
}]
};

var cometOptions = {
numberOfSystems : 100.0,
iterationOffset : 0.003,
cartographicStep : 0.0000001,
baseRadius : 0.0005,

colorOptions : [{
red : 0.6,
green : 0.6,
blue : 0.6,
alpha : 1.0
}, {
red : 0.6,
green : 0.6,
blue : 0.9,
alpha : 0.9
}, {
red : 0.5,
green : 0.5,
blue : 0.7,
alpha : 0.5
}]
};

var scratchCartesian3 = new Cesium.Cartesian3();
var scratchCartographic = new Cesium.Cartographic();
var forceFunction = function(options, iteration) {
var iterationOffset = iteration;
var func = function(particle) {
scratchCartesian3 = Cesium.Cartesian3.normalize(particle.position, new Cesium.Cartesian3());
scratchCartesian3 = Cesium.Cartesian3.multiplyByScalar(scratchCartesian3, -1.0, scratchCartesian3);

particle.position = Cesium.Cartesian3.add(particle.position, scratchCartesian3, particle.position);

scratchCartographic = Cesium.Cartographic.fromCartesian(particle.position, Cesium.Ellipsoid.WGS84, scratchCartographic);

var angle = Cesium.Math.PI * 2.0 * iterationOffset / options.numberOfSystems;
iterationOffset += options.iterationOffset;
scratchCartographic.longitude += Math.cos(angle) * options.cartographicStep;
scratchCartographic.latitude += Math.sin(angle) * options.cartographicStep;

particle.position = Cesium.Cartographic.toCartesian(scratchCartographic);
};
return func;
};

var matrix4Scratch = new Cesium.Matrix4();
var scratchAngleForOffset = 0.0;
var scratchOffset = new Cesium.Cartesian3();
var imageSize = new Cesium.Cartesian2(15.0, 15.0);
function createParticleSystems(options, systemsArray) {
var length = options.numberOfSystems;
for (var i = 0; i < length; ++i) {
scratchAngleForOffset = Math.PI * 2.0 * i / options.numberOfSystems;
scratchOffset.x += options.baseRadius * Math.cos(scratchAngleForOffset);
scratchOffset.y += options.baseRadius * Math.sin(scratchAngleForOffset);

var emitterModelMatrix = Cesium.Matrix4.fromTranslation(scratchOffset, matrix4Scratch);
var color = Cesium.Color.fromRandom(options.colorOptions[i % options.colorOptions.length]);
var force = forceFunction(options, i);

var item = viewer.scene.primitives.add(new Cesium.ParticleSystem({
image : getImage(),
startColor : color,
endColor : color.withAlpha(0.0),
particleLife : 3.5,
speed : 0.00005,
imageSize : imageSize,
emissionRate : 30.0,
emitter : new Cesium.CircleEmitter(0.1),
bursts : [ ],
lifetime : 0.1,
updateCallback : force,
modelMatrix : particlesModelMatrix,
emitterModelMatrix : emitterModelMatrix
}));
systemsArray.push(item);
}
}

var rocketSystems = [];
var cometSystems = [];
createParticleSystems(rocketOptions, rocketSystems);
createParticleSystems(cometOptions, cometSystems);

// toolbar elements
function showAll(systemsArray, show) {
var length = systemsArray.length;
for (var i = 0; i < length; ++i) {
systemsArray[i].show = show;
}
}

var options = [{
text : 'Comet Tail',
onselect : function() {
showAll(rocketSystems, false);
showAll(cometSystems, true);
recenterCamera();

}
}, {
text : 'Rocket Thruster',
onselect : function() {
showAll(cometSystems, false);
showAll(rocketSystems, true);
recenterCamera();
}
}];
Sandcastle.addToolbarMenu(options);
//Sandcastle_End
Sandcastle.finishedLoading();
}

if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>

</body>
</html>
Binary file added Apps/Sandcastle/gallery/Particle System Tails.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
170 changes: 170 additions & 0 deletions Apps/Sandcastle/gallery/Particle System Weather.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Particle systems for rain and snow.">
<meta name="cesium-sandcastle-labels" content="Beginner, Showcases, Tutorials">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar">
</div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer', {
shouldAnimate : true,
terrainProvider: Cesium.createWorldTerrain()
});
var scene = viewer.scene;
scene.globe.depthTestAgainstTerrain = true;
var recenterFunction = function() {
scene.camera.setView({
destination : new Cesium.Cartesian3(277096.634865404, 5647834.481964232, 2985563.7039122293),
orientation : {
heading : 4.731089976107251,
pitch : -0.32003481981370063
}
});
};
recenterFunction();

// snow
var snowParticleSize = scene.drawingBufferWidth / 100.0;
var snowRadius = 100000.0;
var minimumSnowImageSize = new Cesium.Cartesian2(snowParticleSize, snowParticleSize);
var maximumSnowImageSize = new Cesium.Cartesian2(snowParticleSize * 2.0, snowParticleSize * 2.0);
var snowSystem;

var snowGravityScratch = new Cesium.Cartesian3();
var snowUpdate = function(particle, dt) {
snowGravityScratch = Cesium.Cartesian3.normalize(particle.position, snowGravityScratch);
Cesium.Cartesian3.multiplyByScalar(snowGravityScratch, Cesium.Math.randomBetween(-30.0, -300.0), snowGravityScratch);
particle.velocity = Cesium.Cartesian3.add(particle.velocity, snowGravityScratch, particle.velocity);

var distance = Cesium.Cartesian3.distance(scene.camera.position, particle.position);
if (distance > (snowRadius)) {
particle.endColor.alpha = 0.0;
} else {
particle.endColor.alpha = snowSystem.endColor.alpha / (distance / snowRadius + 0.1);
}
};

snowSystem = new Cesium.ParticleSystem({
modelMatrix : new Cesium.Matrix4.fromTranslation(scene.camera.position),
minimumSpeed : -1.0,
maximumSpeed : 0.0,
lifetime : 15.0,
emitter : new Cesium.SphereEmitter(snowRadius),
startScale : 0.5,
endScale : 1.0,
image : "../../SampleData/snowflake_particle.png",
emissionRate : 7000.0,
startColor : Cesium.Color.WHITE.withAlpha(0.0),
endColor : Cesium.Color.WHITE.withAlpha(1.0),
minimumImageSize : minimumSnowImageSize,
maximumImageSize : maximumSnowImageSize,
updateCallback : snowUpdate
});
scene.primitives.add(snowSystem);

// rain
var rainParticleSize = scene.drawingBufferWidth / 80.0;
var rainRadius = 100000.0;
var rainImageSize = new Cesium.Cartesian2(rainParticleSize, rainParticleSize * 2.0);

var rainSystem;

var rainGravityScratch = new Cesium.Cartesian3();
var rainUpdate = function(particle, dt) {
rainGravityScratch = Cesium.Cartesian3.normalize(particle.position, rainGravityScratch);
rainGravityScratch = Cesium.Cartesian3.multiplyByScalar(rainGravityScratch, -1050.0, rainGravityScratch);

particle.position = Cesium.Cartesian3.add(particle.position, rainGravityScratch, particle.position);

var distance = Cesium.Cartesian3.distance(scene.camera.position, particle.position);
if (distance > (rainRadius)) {
particle.endColor.alpha = 0.0;
} else {
particle.endColor.alpha = rainSystem.endColor.alpha / (distance / rainRadius + 0.1);
}
};

rainSystem = new Cesium.ParticleSystem({
modelMatrix : new Cesium.Matrix4.fromTranslation(scene.camera.position),
speed : -1.0,
lifetime : 15.0,
emitter : new Cesium.SphereEmitter(rainRadius),
startScale : 1.0,
endScale : 0.0,
image : "../../SampleData/circular_particle.png",
emissionRate : 9000.0,
startColor :new Cesium.Color(0.27, 0.5, 0.70, 0.0),
endColor : new Cesium.Color(0.27, 0.5, 0.70, 0.98),
imageSize : rainImageSize,
updateCallback : rainUpdate
});
scene.primitives.add(rainSystem);

// button
Sandcastle.addToolbarButton("Recenter", recenterFunction);

// drop down
var options = [{
text : "Snow",
onselect : function() {
rainSystem.show = false;
snowSystem.show = true;

scene.skyAtmosphere.hueShift = -0.8;
scene.skyAtmosphere.saturationShift = -0.7;
scene.skyAtmosphere.brightnessShift = -0.33;

scene.fog.density = 0.001;
scene.fog.minimumBrightness = 0.8;
}
}, {
text : "Rain",
onselect : function() {
rainSystem.show = true;
snowSystem.show = false;

scene.skyAtmosphere.hueShift = -0.97;
scene.skyAtmosphere.saturationShift = 0.25;
scene.skyAtmosphere.brightnessShift = -0.4;

scene.fog.density = 0.00025;
scene.fog.minimumBrightness = 0.01;
}
}];
Sandcastle.addToolbarMenu(options);
//Sandcastle_End
Sandcastle.finishedLoading();
}

if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>

</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 7 additions & 12 deletions Apps/Sandcastle/gallery/Particle System.html
Original file line number Diff line number Diff line change
@@ -263,20 +263,16 @@
startScale : viewModel.startScale,
endScale : viewModel.endScale,

minimumLife : viewModel.minimumLife,
maximumLife : viewModel.maximumLife,
minimumParticleLife : viewModel.minimumLife,
maximumParticleLife : viewModel.maximumLife,

minimumSpeed : viewModel.minimumSpeed,
maximumSpeed : viewModel.maximumSpeed,

minimumWidth : viewModel.particleSize,
minimumHeight : viewModel.particleSize,

maximumWidth : viewModel.particleSize,
maximumHeight : viewModel.particleSize,
imageSize : new Cesium.Cartesian2(viewModel.particleSize, viewModel.particleSize),

// Particles per second.
rate : viewModel.rate,
emissionRate : viewModel.rate,

bursts : [
// these burst will occasionally sync to create a multicolored effect
@@ -285,13 +281,13 @@
new Cesium.ParticleBurst({time : 15.0, minimum : 200, maximum : 300})
],

lifeTime : 16.0,
lifetime : 16.0,

emitter : new Cesium.CircleEmitter(2.0),

emitterModelMatrix : computeEmitterModelMatrix(),

forces : [applyGravity]
updateCallback : applyGravity
}));

var gravityScratch = new Cesium.Cartesian3();
@@ -422,8 +418,7 @@
}];

Sandcastle.addToolbarMenu(options);

//Sandcastle_End
//Sandcastle_End
Sandcastle.finishedLoading();
}

9 changes: 7 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -12,6 +12,9 @@ Change Log
* Added `Math.log2` to compute the base 2 logarithm of a number.
* Added 'PeliasGeocoderService', which provides geocoding via a [Pelias](https://pelias.io) server.
* Added `GeocodeType` enum and use it as an optional parameter to all `GeocoderService` instances to differentiate between autocomplete and search requests.
* Improved `MapboxImageryProvider` performance by 300% via `tiles.mapbox.com` subdomain switching. [#6426](https://github.com/AnalyticalGraphicsInc/cesium/issues/6426)
* Added ability to invoke `sampleTerrain` from node.js to enable offline terrain sampling
* Added more ParticleSystem Sandcastle examples for rocket and comet tails and weather. [#6375](https://github.com/AnalyticalGraphicsInc/cesium/pull/6375)

##### Fixes :wrench:
* Fixed bugs in `TimeIntervalCollection.removeInterval`. [#6418](https://github.com/AnalyticalGraphicsInc/cesium/pull/6418).
@@ -22,8 +25,6 @@ Change Log
* Fix Firefox WebGL console warnings. [#5912](https://github.com/AnalyticalGraphicsInc/cesium/issues/5912)
* Fix parsing Cesium.js in older browsers that do not support all TypedArray types. [#6396](https://github.com/AnalyticalGraphicsInc/cesium/pull/6396)
* Fix flicker when adding, removing, or modifiying entities. [#3945](https://github.com/AnalyticalGraphicsInc/cesium/issues/3945)
##### Additions :tada:
* Improved `MapboxImageryProvider` performance by 300% via `tiles.mapbox.com` subdomain switching. [#6426](https://github.com/AnalyticalGraphicsInc/cesium/issues/6426)

### 1.44 - 2018-04-02

@@ -63,6 +64,10 @@ Change Log
* `sourceType` specifies the type of data source if the URL doesn't have a known file extension.
* `flyTo=false` optionally disables the automatic `flyTo` after loading the data source.
* Added a multi-part CZML example to Sandcastle. [#6320](https://github.com/AnalyticalGraphicsInc/cesium/pull/6320)
* `Credit` has been modified to take an HTML string as the credit content [#6331](https://github.com/AnalyticalGraphicsInc/cesium/pull/6331)
* Added support for ordering in `DataSourceCollection` [#6316](https://github.com/AnalyticalGraphicsInc/cesium/pull/6316)
* All ground geometry from one `DataSource` will render in front of all ground geometry from another `DataSource` in the same collection with a lower index.
* Use `DataSourceCollection.raise`, `DataSourceCollection.lower`, `DataSourceCollection.raiseToTop` and `DataSourceCollection.lowerToBottom` functions to change the ordering of a `DataSource` in the collection.
* Improved processing order of 3D tiles. [#6364](https://github.com/AnalyticalGraphicsInc/cesium/pull/6364)

##### Fixes :wrench:
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -177,3 +177,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [Tamar Cohen](https://github.com/tamarmot)
* [Stephen Wiseman](https://github.com/srwiseman)
* [Gabriel Macario](https://github.com/gabriel-macario)
* [Jonathan Puckey](https://github.com/puckey)
9 changes: 9 additions & 0 deletions Source/Core/FeatureDetection.js
Original file line number Diff line number Diff line change
@@ -163,6 +163,14 @@ define([
return isFirefox() && firefoxVersionResult;
}

var isNodeJsResult;
function isNodeJs() {
if (!defined(isNodeJsResult)) {
isNodeJsResult = typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]'; // eslint-disable-line
}
return isNodeJsResult;
}

var hasPointerEvents;
function supportsPointerEvents() {
if (!defined(hasPointerEvents)) {
@@ -230,6 +238,7 @@ define([
isFirefox : isFirefox,
firefoxVersion : firefoxVersion,
isWindows : isWindows,
isNodeJs: isNodeJs,
hardwareConcurrency : defaultValue(theNavigator.hardwareConcurrency, 3),
supportsPointerEvents : supportsPointerEvents,
supportsImageRenderingPixelated: supportsImageRenderingPixelated,
64 changes: 64 additions & 0 deletions Source/Core/Resource.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ define([
'./defineProperties',
'./deprecationWarning',
'./DeveloperError',
'./FeatureDetection',
'./freezeObject',
'./getAbsoluteUri',
'./getBaseUri',
@@ -37,6 +38,7 @@ define([
defineProperties,
deprecationWarning,
DeveloperError,
FeatureDetection,
freezeObject,
getAbsoluteUri,
getBaseUri,
@@ -1772,13 +1774,75 @@ define([
image.src = url;
};

function decodeResponse(loadWithHttpResponse, responseType) {
switch (responseType) {
case 'text':
return loadWithHttpResponse.toString('utf8');
case 'json':
return JSON.parse(loadWithHttpResponse.toString('utf8'));
default:
return new Uint8Array(loadWithHttpResponse).buffer;
}
}

function loadWithHttpRequest(url, responseType, method, data, headers, deferred, overrideMimeType) {
// Note: only the 'json' and 'text' responseTypes transforms the loaded buffer
var URL = require('url').parse(url);
var http = URL.protocol === 'https:' ? require('https') : require('http');
var zlib = require('zlib');
var options = {
protocol : URL.protocol,
hostname : URL.hostname,
port : URL.port,
path : URL.path,
query : URL.query,
method : method,
headers : headers
};

http.request(options)
.on('response', function(res) {
if (res.statusCode < 200 || res.statusCode >= 300) {
deferred.reject(new RequestErrorEvent(res.statusCode, res, res.headers));
return;
}

var chunkArray = [];
res.on('data', function(chunk) {
chunkArray.push(chunk);
});

res.on('end', function() {
var result = Buffer.concat(chunkArray); // eslint-disable-line
if (res.headers['content-encoding'] === 'gzip') {
zlib.gunzip(result, function(error, resultUnzipped) {
if (error) {
deferred.reject(new RuntimeError('Error decompressing response.'));
} else {
deferred.resolve(decodeResponse(resultUnzipped, responseType));
}
});
} else {
deferred.resolve(decodeResponse(result, responseType));
}
});
}).on('error', function(e) {
deferred.reject(new RequestErrorEvent());
}).end();
}

Resource._Implementations.loadWithXhr = function(url, responseType, method, data, headers, deferred, overrideMimeType) {
var dataUriRegexResult = dataUriRegex.exec(url);
if (dataUriRegexResult !== null) {
deferred.resolve(decodeDataUri(dataUriRegexResult, responseType));
return;
}

if (FeatureDetection.isNodeJs()) {
loadWithHttpRequest(url, responseType, method, data, headers, deferred, overrideMimeType);
return;
}

var xhr = new XMLHttpRequest();

if (TrustedServers.contains(url)) {
16 changes: 14 additions & 2 deletions Source/Core/getAbsoluteUri.js
Original file line number Diff line number Diff line change
@@ -23,7 +23,12 @@ define([
* var absoluteUri = Cesium.getAbsoluteUri('awesome.png', 'https://test.com');
*/
function getAbsoluteUri(relative, base) {
return getAbsoluteUri._implementation(relative, base, document);
var documentObject;
if (typeof document !== 'undefined') {
documentObject = document;
}

return getAbsoluteUri._implementation(relative, base, documentObject);
}

getAbsoluteUri._implementation = function(relative, base, documentObject) {
@@ -32,7 +37,14 @@ define([
throw new DeveloperError('relative uri is required.');
}
//>>includeEnd('debug');
base = defaultValue(base, defaultValue(documentObject.baseURI, documentObject.location.href));

if (!defined(base)) {
if (typeof documentObject === 'undefined') {
return relative;
}
base = defaultValue(documentObject.baseURI, documentObject.location.href);
}

var baseUri = new Uri(base);
var relativeUri = new Uri(relative);
return relativeUri.resolve(baseUri).toString();
4 changes: 2 additions & 2 deletions Source/Scene/BillboardCollection.js
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@ define([
* @param {Scene} [options.scene] Must be passed in for billboards that use the height reference property or will be depth tested against the globe.
* @param {BlendOption} [options.blendOption=BlendOption.OPAQUE_AND_TRANSLUCENT] The billboard blending option. The default
* is used for rendering both opaque and translucent billboards. However, if either all of the billboards are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve performance by up to 2x.
* setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve performance by up to 2x.
*
* @performance For best performance, prefer a few collections, each with many billboards, to
* many collections with only a few billboards each. Organize collections so that billboards
@@ -285,7 +285,7 @@ define([
/**
* The billboard blending option. The default is used for rendering both opaque and translucent billboards.
* However, if either all of the billboards are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve
* setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve
* performance by up to 2x.
* @type {BlendOption}
* @default BlendOption.OPAQUE_AND_TRANSLUCENT
2 changes: 0 additions & 2 deletions Source/Scene/Globe.js
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ define([
'./GlobeSurfaceShaderSet',
'./GlobeSurfaceTileProvider',
'./ImageryLayerCollection',
'./Material',
'./QuadtreePrimitive',
'./SceneMode',
'./ShadowMode'
@@ -54,7 +53,6 @@ define([
GlobeSurfaceShaderSet,
GlobeSurfaceTileProvider,
ImageryLayerCollection,
Material,
QuadtreePrimitive,
SceneMode,
ShadowMode) {
4 changes: 2 additions & 2 deletions Source/Scene/LabelCollection.js
Original file line number Diff line number Diff line change
@@ -450,7 +450,7 @@ define([
* @param {Scene} [options.scene] Must be passed in for labels that use the height reference property or will be depth tested against the globe.
* @param {BlendOption} [options.blendOption=BlendOption.OPAQUE_AND_TRANSLUCENT] The label blending option. The default
* is used for rendering both opaque and translucent labels. However, if either all of the labels are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve performance by up to 2x.
* setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve performance by up to 2x.
*
* @performance For best performance, prefer a few collections, each with many labels, to
* many collections with only a few labels each. Avoid having collections where some
@@ -552,7 +552,7 @@ define([
/**
* The label blending option. The default is used for rendering both opaque and translucent labels.
* However, if either all of the labels are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve
* setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve
* performance by up to 2x.
* @type {BlendOption}
* @default BlendOption.OPAQUE_AND_TRANSLUCENT
4 changes: 2 additions & 2 deletions Source/Scene/PointPrimitiveCollection.js
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ define([
* @param {Boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.
* @param {BlendOption} [options.blendOption=BlendOption.OPAQUE_AND_TRANSLUCENT] The point blending option. The default
* is used for rendering both opaque and translucent points. However, if either all of the points are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve performance by up to 2x.
* setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve performance by up to 2x.
*
* @performance For best performance, prefer a few collections, each with many points, to
* many collections with only a few points each. Organize collections so that points
@@ -211,7 +211,7 @@ define([
/**
* The point blending option. The default is used for rendering both opaque and translucent points.
* However, if either all of the points are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve
* setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve
* performance by up to 2x.
* @type {BlendOption}
* @default BlendOption.OPAQUE_AND_TRANSLUCENT
4 changes: 4 additions & 0 deletions Specs/Core/FeatureDetectionSpec.js
Original file line number Diff line number Diff line change
@@ -110,4 +110,8 @@ defineSuite([
expect(FeatureDetection.imageRenderingValue()).not.toBeDefined();
}
});

it('detects Node.js', function() {
expect(FeatureDetection.isNodeJs()).toBe(false);
});
});