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

Added PointGeometry and PointAppearance #3203

Merged
merged 5 commits into from
Nov 14, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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);
}

var size = pixelScale * collection._maxScale * collection._maxSize * 2.0;
Expand Down
24 changes: 24 additions & 0 deletions Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,30 @@ 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 {Context} context The context.
* @returns {Number} The pixel size in meters.
*/
Camera.prototype.getPixelSize = function(boundingSphere, context) {
//>>includeStart('debug', pragmas.debug);
if (!defined(boundingSphere)) {
throw new DeveloperError('boundingSphere is required.');
}
if (!defined(context)) {
throw new DeveloperError('context is required.');
}
//>>includeEnd('debug');

var distance = this.distanceToBoundingSphere(boundingSphere);
var pixelSize = this.frustum.getPixelDimensions(context.drawingBufferWidth, context.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 @@ -2985,20 +2985,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);
}

var scratchPosition = new Cartesian3();
Expand Down
Loading