Skip to content

Commit

Permalink
Merge pull request #3203 from AnalyticalGraphicsInc/point-geometry-ap…
Browse files Browse the repository at this point in the history
…pearance

Added PointGeometry and PointAppearance
  • Loading branch information
pjcozzi committed Nov 14, 2015
2 parents 0cfb29d + 12451a3 commit 015b0b3
Show file tree
Hide file tree
Showing 14 changed files with 679 additions and 33 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Change Log
* Added `Camera.distanceToBoundingSphere` function.
* Added utility function `getBaseUri`, which given a URI with or without query parameters, returns the base path of the URI.
* Added support for incrementally loading textures after a Model is ready. This allows the Model to be visible as soon as possible while its textures are loaded in the background.
* Added 'Cartographic.fromCartesian' function.
* Added `Cartographic.fromCartesian` function.
* Added `Camera.getPixelSize` function to get the size of a pixel in meters based on the current view.

### 1.15 - 2015-11-02

Expand Down
104 changes: 104 additions & 0 deletions Source/Core/PointGeometry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*global define*/
define([
'./BoundingSphere',
'./ComponentDatatype',
'./defaultValue',
'./defined',
'./DeveloperError',
'./Geometry',
'./GeometryAttribute',
'./GeometryAttributes',
'./PrimitiveType'
], function(
BoundingSphere,
ComponentDatatype,
defaultValue,
defined,
DeveloperError,
Geometry,
GeometryAttribute,
GeometryAttributes,
PrimitiveType) {
"use strict";

/**
* Describes a collection of points made up of positions and colors.
*
* @alias PointGeometry
* @constructor
*
* @param {Object} options Object with the following properties:
* @param {TypedArray} options.positionsTypedArray The position values of the points stored in a typed array. Positions are stored as packed (x, y, z) floats.
* @param {TypedArray} options.colorsTypedArray The color values of the points stored in a typed array. Colors are stored as packed (r, g, b) unsigned bytes.
* @param {BoundingSphere} [options.boundingSphere] Optional precomputed bounding sphere to save computation time.
*
* @example
* // Create a PointGeometry with two points
* var points = new Cesium.PointGeometry({
* positionsTypedArray : new Float32Array([0.0, 0.0, 0.0, 1.0, 1.0, 1.0]),
* colorsTypedArray : new Uint8Array([255, 0, 0, 127, 127, 127]),
* boundingSphere : boundingSphere
* });
* var geometry = Cesium.PointGeometry.createGeometry(points);
*
* @private
*/
var PointGeometry = function(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);

//>>includeStart('debug', pragmas.debug);
if (!defined(options.positionsTypedArray)) {
throw new DeveloperError('options.positionsTypedArray is required.');
}
if (!defined(options.colorsTypedArray)) {
throw new DeveloperError('options.colorsTypedArray is required');
}
//>>includeEnd('debug');

this._positionsTypedArray = options.positionsTypedArray;
this._colorsTypedArray = options.colorsTypedArray;
this._boundingSphere = BoundingSphere.clone(options.boundingSphere);

this._workerName = 'createPointGeometry';
};

/**
* Computes the geometric representation a point collection, including its vertices and a bounding sphere.
*
* @param {PointGeometry} pointGeometry A description of the points.
* @returns {Geometry} The computed vertices.
*/
PointGeometry.createGeometry = function(pointGeometry) {
var positions = pointGeometry._positionsTypedArray;
var componentByteLength = positions.byteLength / positions.length;
var componentDatatype = componentByteLength === 4 ? ComponentDatatype.FLOAT : ComponentDatatype.DOUBLE;

var attributes = new GeometryAttributes();
attributes.position = new GeometryAttribute({
componentDatatype : componentDatatype,
componentsPerAttribute : 3,
values : positions
});

attributes.color = new GeometryAttribute({
componentDatatype : ComponentDatatype.UNSIGNED_BYTE,
componentsPerAttribute : 3,
values : pointGeometry._colorsTypedArray,
normalize : true
});

// User provided bounding sphere to save computation time.
var boundingSphere = pointGeometry._boundingSphere;
if (!defined(boundingSphere)) {
boundingSphere = BoundingSphere.fromVertices(positions);
}

return new Geometry({
attributes : attributes,
primitiveType : PrimitiveType.POINTS,
boundingSphere : boundingSphere
});
};

return PointGeometry;
});
9 changes: 1 addition & 8 deletions Source/Scene/BillboardCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -1135,17 +1135,10 @@ define([
}
}

var scratchPixelSize = new Cartesian2();

function updateBoundingVolume(collection, frameState, boundingVolume) {
var pixelScale = 1.0;
if (!collection._allSizedInMeters || collection._maxPixelOffset !== 0.0) {
var camera = frameState.camera;
var distance = camera.distanceToBoundingSphere(boundingVolume);

var context = frameState.context;
var pixelSize = frameState.camera.frustum.getPixelDimensions(context.drawingBufferWidth, context.drawingBufferHeight, distance, scratchPixelSize);
pixelScale = Math.max(pixelSize.x, pixelSize.y);
pixelScale = frameState.camera.getPixelSize(boundingVolume, frameState.context.drawingBufferWidth, frameState.context.drawingBufferHeight);
}

var size = pixelScale * collection._maxScale * collection._maxSize * 2.0;
Expand Down
28 changes: 28 additions & 0 deletions Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,34 @@ define([
return Math.max(0.0, Cartesian3.magnitude(proj) - boundingSphere.radius);
};

var scratchPixelSize = new Cartesian2();

/**
* Return the pixel size in meters.
*
* @param {BoundingSphere} boundingSphere The bounding sphere in world coordinates.
* @param {Number} drawingBufferWidth The drawing buffer width.
* @param {Number} drawingBufferHeight The drawing buffer height.
* @returns {Number} The pixel size in meters.
*/
Camera.prototype.getPixelSize = function(boundingSphere, drawingBufferWidth, drawingBufferHeight) {
//>>includeStart('debug', pragmas.debug);
if (!defined(boundingSphere)) {
throw new DeveloperError('boundingSphere is required.');
}
if (!defined(drawingBufferWidth)) {
throw new DeveloperError('drawingBufferWidth is required.');
}
if (!defined(drawingBufferHeight)) {
throw new DeveloperError('drawingBufferHeight is required.');
}
//>>includeEnd('debug');

var distance = this.distanceToBoundingSphere(boundingSphere);
var pixelSize = this.frustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, scratchPixelSize);
return Math.max(pixelSize.x, pixelSize.y);
};

function createAnimation2D(camera, duration) {
var position = camera.position;
var translateX = position.x < -camera._maxCoord.x || position.x > camera._maxCoord.x;
Expand Down
10 changes: 1 addition & 9 deletions Source/Scene/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2978,20 +2978,12 @@ define([
}
}

var scratchPixelSize = new Cartesian2();
var scratchBoundingSphere = new BoundingSphere();

function scaleInPixels(positionWC, radius, frameState) {
scratchBoundingSphere.center = positionWC;
scratchBoundingSphere.radius = radius;
var camera = frameState.camera;
var distance = camera.distanceToBoundingSphere(scratchBoundingSphere);

var context = frameState.context;
var pixelSize = camera.frustum.getPixelDimensions(context.drawingBufferWidth, context.drawingBufferHeight, distance, scratchPixelSize);
var pixelScale = Math.max(pixelSize.x, pixelSize.y);

return pixelScale;
return frameState.camera.getPixelSize(scratchBoundingSphere, frameState.context.drawingBufferWidth, frameState.context.drawingBufferHeight);
}

var scratchPosition = new Cartesian3();
Expand Down
Loading

0 comments on commit 015b0b3

Please sign in to comment.