-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
I3dm updates #4101
I3dm updates #4101
Changes from all commits
99f6f38
12edc38
dedbdae
b067c1b
f4f9232
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*global define*/ | ||
define([ | ||
'../Core/ComponentDatatype', | ||
'../Core/defaultValue', | ||
'../Core/defined', | ||
'../Core/DeveloperError' | ||
], function( | ||
ComponentDatatype, | ||
defaultValue, | ||
defined, | ||
DeveloperError) { | ||
'use strict'; | ||
|
||
/** | ||
* @private | ||
*/ | ||
function Cesium3DTileFeatureTableResources(featureTableJSON, featureTableBinary) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now the approach of generating a JS array that holds onto the property's binary data just seems too expensive. I think it would be easier if this class stored a TypedArray view for each property, and then when getting an instance's property it just indexes into the typed array. To avoid allocations, the getter can take an optional This is also make it easier to work with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see this comment: #4101 (comment) kind of alludes to that too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lasalvavida can we write unit tests that test this file in isolation without an entire tile? |
||
this.json = featureTableJSON; | ||
this.buffer = featureTableBinary; | ||
this._cachedArrayBufferViews = {}; | ||
this.featuresLength = 0; | ||
} | ||
|
||
Cesium3DTileFeatureTableResources.prototype.getTypedArrayForSemantic = function(semantic, byteOffset, componentType, count, featureSize) { | ||
//>>includeStart('debug', pragmas.debug); | ||
if (!defined(byteOffset)) { | ||
throw new DeveloperError('byteOffset must be defined to read from binary data for semantic: ' + semantic); | ||
} | ||
if (!defined(componentType)) { | ||
throw new DeveloperError('componentType must be defined to read from binary data for semantic: ' + semantic); | ||
} | ||
if (!defined(count)) { | ||
throw new DeveloperError('count must be defined to read from binary data for semantic: ' + semantic); | ||
} | ||
//>>includeEnd('debug'); | ||
var cachedArrayBufferViews = this._cachedArrayBufferViews; | ||
var arrayBuffer = cachedArrayBufferViews[semantic]; | ||
if (!defined(arrayBuffer)) { | ||
arrayBuffer = ComponentDatatype.createArrayBufferView(componentType, this.buffer.buffer, this.buffer.byteOffset + byteOffset, count * featureSize); | ||
cachedArrayBufferViews[semantic] = arrayBuffer; | ||
} | ||
return arrayBuffer; | ||
}; | ||
|
||
Cesium3DTileFeatureTableResources.prototype.getGlobalProperty = function(semantic, componentType, count) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure that "global" is the best word here; it's not really about scope. It just means apply to all instances, not individual instances. I don't have anything better right now though. Will let you know if I think of something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it will be cleaner to split this implementation into separate global and non-global getters. There may be some duplication, but the logic and parameters will be decoupled. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would a global property ever need to be stored in binary? If not, this function could just return the JSON. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not; I think that's probably better for making the implementation more streamlined There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should assume it will always be JSON. A global property could be a big array, even if it isn't per-feature data, so we shouldn't make the spec this limited unless there is a significant implementation reason, which I do not see here since we already need to handle binary for the other properties. |
||
var jsonValue = this.json[semantic]; | ||
if (defined(jsonValue)) { | ||
var byteOffset = jsonValue.byteOffset; | ||
if (defined(byteOffset)) { | ||
// This is a reference to the binary | ||
count = defaultValue(count, 1); | ||
var typedArray = this.getTypedArrayForSemantic(semantic, byteOffset, componentType, count, 1); | ||
var subArray = typedArray.subarray(0, count); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lilleyse can you confirm that this is a fast operation, e.g., just a pointer splice, not a copy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it's fine, it creates a view of the array buffer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, is the subarray needed in this case? The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind, it may be cached. |
||
if (subArray.length === 1) { | ||
return subArray[0]; | ||
} | ||
return subArray; | ||
} | ||
} | ||
return jsonValue; | ||
}; | ||
|
||
Cesium3DTileFeatureTableResources.prototype.getProperty = function(semantic, featureId, componentType, featureSize) { | ||
var jsonValue = this.json[semantic]; | ||
if (defined(jsonValue)) { | ||
var byteOffset = jsonValue.byteOffset; | ||
if (defined(byteOffset)) { | ||
// This is a reference to the binary | ||
featureSize = defaultValue(featureSize, 1); | ||
var typedArray = this.getTypedArrayForSemantic(semantic, byteOffset, componentType, this.featuresLength, featureSize); | ||
var subArray = typedArray.subarray(featureId * featureSize, featureId * featureSize + featureSize); | ||
if (subArray.length === 1) { | ||
return subArray[0]; | ||
} | ||
return subArray; | ||
} | ||
} | ||
if (Array.isArray(jsonValue)) { | ||
return jsonValue.slice(featureId * featureSize, featureId * featureSize + featureSize); | ||
} | ||
return jsonValue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it should, my mistake. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the comment above, it should return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I missed that. |
||
}; | ||
|
||
return Cesium3DTileFeatureTableResources; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bagnell did you look at this file to see if you can use it for vector data?