Skip to content

Commit

Permalink
Reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Aug 9, 2016
1 parent 58425aa commit c6f2130
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 42 deletions.
21 changes: 19 additions & 2 deletions Source/Scene/Cesium3DTile.js
Expand Up @@ -96,6 +96,8 @@ define([
this.computedTransform = Matrix4.multiply(parentTransform, this.transform, new Matrix4());
this._computedTransform = Matrix4.clone(this.computedTransform);

this._transformDirty = true;

this._boundingVolume = this.createBoundingVolume(header.boundingVolume, this.computedTransform);

var contentBoundingVolume;
Expand Down Expand Up @@ -361,6 +363,20 @@ define([
}
},

/**
* Whether the computedTransform has changed this frame.
*
* @memberof Cesium3DTile.prototype
*
* @type {Boolean}
* @readonly
*/
transformDirty : {
get : function() {
return this._transformDirty;
}
},

/**
* @readonly
* @private
Expand Down Expand Up @@ -613,8 +629,8 @@ define([
}

function updateTransform(tile) {
var transformChanged = !Matrix4.equals(tile.computedTransform, tile._computedTransform);
if (transformChanged) {
var transformDirty = !Matrix4.equals(tile.computedTransform, tile._computedTransform);
if (transformDirty) {
Matrix4.clone(tile.computedTransform, tile._computedTransform);

// Update the bounding volumes
Expand All @@ -629,6 +645,7 @@ define([
tile._debugBoundingVolume = tile._debugBoundingVolume && tile._debugBoundingVolume.destroy();
tile._debugContentBoundingVolume = tile._debugContentBoundingVolume && tile._debugContentBoundingVolume.destroy();
}
tile._transformDirty = transformDirty;
}

/**
Expand Down
109 changes: 69 additions & 40 deletions Source/Scene/Points3DTileContent.js
Expand Up @@ -78,16 +78,17 @@ define([
this._tileset = tileset;
this._tile = tile;

// Hold onto the feature table until the render resources are created
this._featureTableResources = undefined;
this._drawCommand = undefined;
// Hold onto the payload until the render resources are created
this._parsedContent = undefined;

this._drawCommand = undefined;
this._isTranslucent = false;
this._constantColor = Color.clone(Color.WHITE);
this._rtcCenter = undefined;

this._opaqueRenderState = undefined;
this._translucentRenderState = undefined;

this._constantColor = Color.clone(Color.WHITE);

// Uniforms
this._highlightColor = this._constantColor;
this._pointSize = 2.0;
Expand Down Expand Up @@ -214,16 +215,7 @@ define([
var featureTableBinary = new Uint8Array(arrayBuffer, byteOffset, featureTableBinaryByteLength);
byteOffset += featureTableBinaryByteLength;

this._featureTableResources = new Cesium3DTileFeatureTableResources(featureTableJSON, featureTableBinary);

this.state = Cesium3DTileContentState.PROCESSING;
this.contentReadyToProcessPromise.resolve(this);
};

function createResources(content, frameState) {
var context = frameState.context;
var featureTableResources = content._featureTableResources;
var featureTableJSON = featureTableResources.json;
var featureTableResources = new Cesium3DTileFeatureTableResources(featureTableJSON, featureTableBinary);

var pointsLength = featureTableResources.getGlobalProperty('POINTS_LENGTH');
featureTableResources.featuresLength = pointsLength;
Expand All @@ -240,16 +232,29 @@ define([

if (defined(featureTableJSON.POSITION)) {
positions = featureTableResources.getGlobalProperty('POSITION', ComponentDatatype.FLOAT, pointsLength, 3);
var rtcCenter = featureTableResources.getGlobalProperty('RTC_CENTER');
if (defined(rtcCenter)) {
this._rtcCenter = Cartesian3.unpack(rtcCenter);
}
} else if (defined(featureTableJSON.POSITION_QUANTIZED)) {
positions = featureTableResources.getGlobalProperty('POSITION_QUANTIZED', ComponentDatatype.UNSIGNED_SHORT, pointsLength, 3);
isQuantized = true;

var quantizedVolumeScale = featureTableResources.getGlobalProperty('QUANTIZED_VOLUME_SCALE');
content._quantizedVolumeScale = Cartesian3.unpack(quantizedVolumeScale);
//>>includeStart('debug', pragmas.debug);
if (!defined(content._quantizedVolumeScale)) {
if (!defined(quantizedVolumeScale)) {
throw new DeveloperError('Global property: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');
}
//>>includeEnd('debug');
this._quantizedVolumeScale = Cartesian3.unpack(quantizedVolumeScale);

var quantizedVolumeOffset = featureTableResources.getGlobalProperty('QUANTIZED_VOLUME_OFFSET');
//>>includeStart('debug', pragmas.debug);
if (!defined(quantizedVolumeOffset)) {
throw new DeveloperError('Global property: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');
}
//>>includeEnd('debug');
this._rtcCenter = Cartesian3.unpack(quantizedVolumeOffset);
}

//>>includeStart('debug', pragmas.debug);
Expand All @@ -261,21 +266,20 @@ define([
// Get the colors
var colors;
var isTranslucent = false;
var isConstantColor = false;

if (defined(featureTableJSON.RGBA)) {
colors = featureTableResources.getGlobalProperty('RGBA', ComponentDatatype.UNSIGNED_BYTE, pointsLength, 4);
isTranslucent = true;
} else if (defined(featureTableJSON.RGB)) {
colors = featureTableResources.getGlobalProperty('RGB', ComponentDatatype.UNSIGNED_BYTE, pointsLength, 3);
} else if (defined(featureTableJSON.CONSTANT_COLOR)) {
var constantColor = featureTableResources.getGlobalProperty('CONSTANT_COLOR');
content._constantColor = Color.fromBytes(constantColor[0], constantColor[1], constantColor[2], constantColor[3], content._constantColor);
isConstantColor = true;
var constantRGBA = featureTableResources.getGlobalProperty('CONSTANT_RGBA');
this._constantColor = Color.fromBytes(constantRGBA[0], constantRGBA[1], constantRGBA[2], constantRGBA[3], this._constantColor);
} else {
// Use a default constant color
this._constantColor = Color.clone(Color.DARKGRAY, this._constantColor);
}

content._isTranslucent = isTranslucent;

// Get the normals
var normals;
var isOctEncoded16P = false;
Expand All @@ -287,14 +291,34 @@ define([
isOctEncoded16P = true;
}

this._parsedContent = {
pointsLength : pointsLength,
positions : positions,
colors : colors,
normals : normals,
isTranslucent : isTranslucent,
isQuantized : isQuantized,
isOctEncoded16P : isOctEncoded16P
};

this.state = Cesium3DTileContentState.PROCESSING;
this.contentReadyToProcessPromise.resolve(this);
};

function createResources(content, frameState) {
var context = frameState.context;
var parsedContent = content._parsedContent;
var pointsLength = parsedContent.pointsLength;
var positions = parsedContent.positions;
var colors = parsedContent.colors;
var normals = parsedContent.normals;
var isTranslucent = parsedContent.isTranslucent;
var isQuantized = parsedContent.isQuantized;
var isOctEncoded16P = parsedContent.isOctEncoded16P;

var hasColors = defined(colors);
var hasNormals = defined(normals);

if (!hasColors && !isConstantColor) {
// Use a default constant color
content._constantColor = Color.clone(Color.DARKGRAY, content._constantColor);
}

var vs = 'attribute vec3 a_position; \n' +
'varying vec4 v_color; \n' +
'uniform float u_pointSize; \n' +
Expand Down Expand Up @@ -340,7 +364,7 @@ define([
}

vs += ' normal = czm_normal * normal; \n' +
' color *= max(dot(normal, czm_sunDirectionEC), 0.0); \n';
' color *= czm_getLambertDiffuse(czm_sunDirectionEC, normal); \n';
}

if (isQuantized) {
Expand Down Expand Up @@ -521,10 +545,6 @@ define([
pass : isTranslucent ? Pass.TRANSLUCENT : Pass.OPAQUE,
owner : content
});

content.state = Cesium3DTileContentState.READY;
content.readyPromise.resolve(content);
content._featureTableResources = undefined; // Unload
}

/**
Expand All @@ -534,21 +554,30 @@ define([
this._highlightColor = enabled ? color : this._constantColor;
};

var scratchMatrix = new Matrix3();

/**
* Part of the {@link Cesium3DTileContent} interface.
*/
Points3DTileContent.prototype.update = function(tileset, frameState) {
var updateModelMatrix = this._tile.transformDirty;

if (!defined(this._drawCommand)) {
createResources(this, frameState);
updateModelMatrix = true;

// Set state to ready
this.state = Cesium3DTileContentState.READY;
this.readyPromise.resolve(this);
this._parsedContent = undefined; // Unload
}

// Update the model matrix
var boundingSphere = this._tile.contentBoundingVolume.boundingSphere;
var translation = boundingSphere.center;
var rotation = Matrix4.getRotation(this._tile.computedTransform, scratchMatrix);
Matrix4.fromRotationTranslation(rotation, translation, this._drawCommand.modelMatrix);
if (updateModelMatrix) {
var modelMatrix = Matrix4.clone(this._tile.computedTransform, this._drawCommand.modelMatrix);
if (defined(this._rtcCenter)) {
modelMatrix[12] += this._rtcCenter.x;
modelMatrix[13] += this._rtcCenter.y;
modelMatrix[14] += this._rtcCenter.z;
}
}

// Update the render state
var isTranslucent = (this._highlightColor.alpha < 1.0) || this._isTranslucent;
Expand Down

0 comments on commit c6f2130

Please sign in to comment.