-
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
Support batch table binary section for pnts #4112
Changes from all commits
6728f06
45e6a94
926bedf
2ea85e0
1ed28c4
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ define([ | |
'../Core/DeveloperError', | ||
'../Core/GeometryInstance', | ||
'../Core/getMagic', | ||
'../Core/getStringFromTypedArray', | ||
'../Core/loadArrayBuffer', | ||
'../Core/PointGeometry', | ||
'../Core/Request', | ||
|
@@ -30,6 +31,7 @@ define([ | |
DeveloperError, | ||
GeometryInstance, | ||
getMagic, | ||
getStringFromTypedArray, | ||
loadArrayBuffer, | ||
PointGeometry, | ||
Request, | ||
|
@@ -56,6 +58,7 @@ define([ | |
this._url = url; | ||
this._tileset = tileset; | ||
this._tile = tile; | ||
this._constantColor = Color.clone(Color.WHITE); | ||
|
||
/** | ||
* The following properties are part of the {@link Cesium3DTileContent} interface. | ||
|
@@ -66,8 +69,6 @@ define([ | |
this.batchTableResources = undefined; | ||
this.featurePropertiesDirty = false; | ||
this.boundingSphere = tile.contentBoundingVolume.boundingSphere; | ||
this._debugColor = Color.fromRandom({ alpha : 1.0 }); | ||
this._debugColorizeTiles = false; | ||
} | ||
|
||
defineProperties(Points3DTileContent.prototype, { | ||
|
@@ -108,6 +109,7 @@ define([ | |
}; | ||
|
||
var sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; | ||
var sizeOfFloat32 = Float32Array.BYTES_PER_ELEMENT; | ||
|
||
/** | ||
* Part of the {@link Cesium3DTileContent} interface. | ||
|
@@ -166,11 +168,97 @@ define([ | |
var pointsLength = view.getUint32(byteOffset, true); | ||
byteOffset += sizeOfUint32; | ||
|
||
var positionsOffsetInBytes = byteOffset; | ||
var positions = new Float32Array(arrayBuffer, positionsOffsetInBytes, pointsLength * 3); | ||
var batchTableJSONByteLength = view.getUint32(byteOffset, true); | ||
byteOffset += sizeOfUint32; | ||
|
||
var batchTableBinaryByteLength = view.getUint32(byteOffset, true); | ||
byteOffset += sizeOfUint32; | ||
|
||
var positions = new Float32Array(arrayBuffer, byteOffset, pointsLength * 3); | ||
byteOffset += pointsLength * 3 * sizeOfFloat32; | ||
|
||
var colors; | ||
var translucent = false; | ||
var hasConstantColor = false; | ||
|
||
if (batchTableJSONByteLength > 0) { | ||
// Get the batch table JSON | ||
var batchTableString = getStringFromTypedArray(uint8Array, byteOffset, batchTableJSONByteLength); | ||
var batchTableJSON = JSON.parse(batchTableString); | ||
byteOffset += batchTableJSONByteLength; | ||
|
||
// Get the batch table binary | ||
var batchTableBinary; | ||
if (batchTableBinaryByteLength > 0) { | ||
batchTableBinary = new Uint8Array(arrayBuffer, byteOffset, batchTableBinaryByteLength); | ||
} | ||
byteOffset += batchTableBinaryByteLength; | ||
|
||
// Get the point colors | ||
var tiles3DRGB = batchTableJSON.TILES3D_RGB; | ||
var tiles3DRGBA = batchTableJSON.TILES3D_RGBA; | ||
var tiles3DColor = batchTableJSON.TILES3D_COLOR; | ||
|
||
if (defined(tiles3DRGBA)) { | ||
colors = new Uint8Array(batchTableBinary, tiles3DRGBA.byteOffset, pointsLength * 4); | ||
translucent = true; | ||
} else if (defined(tiles3DRGB)) { | ||
colors = new Uint8Array(batchTableBinary, tiles3DRGB.byteOffset, pointsLength * 3); | ||
} else if (defined(tiles3DColor)) { | ||
this._constantColor = Color.fromBytes(tiles3DColor[0], tiles3DColor[1], tiles3DColor[2], tiles3DColor[3], this._constantColor); | ||
hasConstantColor = true; | ||
} | ||
} | ||
|
||
var hasColors = defined(colors); | ||
|
||
if (!hasColors && !hasConstantColor) { | ||
this._constantColor = Color.DARKGRAY; | ||
} | ||
|
||
var vs = 'attribute vec3 position3DHigh; \n' + | ||
'attribute vec3 position3DLow; \n' + | ||
'uniform float pointSize; \n'; | ||
if (hasColors) { | ||
if (translucent) { | ||
vs += 'attribute vec4 color; \n' + | ||
'varying vec4 v_color; \n'; | ||
} else { | ||
vs += 'attribute vec3 color; \n' + | ||
'varying vec3 v_color; \n'; | ||
} | ||
} | ||
vs += 'void main() \n' + | ||
'{ \n' + | ||
' gl_Position = czm_modelViewProjectionRelativeToEye * czm_computePosition(); \n' + | ||
' gl_PointSize = pointSize; \n'; | ||
if (hasColors) { | ||
vs += ' v_color = color; \n'; | ||
} | ||
vs += '}'; | ||
|
||
var fs = 'uniform vec4 highlightColor; \n'; | ||
if (hasColors) { | ||
if (translucent) { | ||
fs += 'varying vec4 v_color; \n'; | ||
} else { | ||
fs += 'varying vec3 v_color; \n'; | ||
} | ||
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. Hm I think I'm going to fix this so the attribute is just a single value. 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 this won't work easily 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. Can't we provide a uniform using an appearance? Otherwise put a 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'll try that. |
||
} | ||
fs += 'void main() \n' + | ||
'{ \n'; | ||
|
||
if (hasColors) { | ||
if (translucent) { | ||
fs += ' gl_FragColor = v_color * highlightColor; \n'; | ||
} else { | ||
fs += ' gl_FragColor = vec4(v_color * highlightColor.rgb, highlightColor.a); \n'; | ||
} | ||
} else { | ||
fs += ' gl_FragColor = highlightColor; \n'; | ||
} | ||
|
||
var colorsOffsetInBytes = positionsOffsetInBytes + (pointsLength * (3 * Float32Array.BYTES_PER_ELEMENT)); | ||
var colors = new Uint8Array(arrayBuffer, colorsOffsetInBytes, pointsLength * 3); | ||
fs += '} \n'; | ||
|
||
// TODO: performance test with 'interleave : true' | ||
var instance = new GeometryInstance({ | ||
|
@@ -180,9 +268,17 @@ define([ | |
boundingSphere : this.boundingSphere | ||
}) | ||
}); | ||
|
||
var appearance = new PointAppearance({ | ||
highlightColor : this._constantColor, | ||
translucent : translucent, | ||
vertexShaderSource : vs, | ||
fragmentShaderSource : fs | ||
}); | ||
|
||
var primitive = new Primitive({ | ||
geometryInstances : instance, | ||
appearance : new PointAppearance(), | ||
appearance : appearance, | ||
asynchronous : false, | ||
allowPicking : false, | ||
cull : false, | ||
|
@@ -208,7 +304,7 @@ define([ | |
* Part of the {@link Cesium3DTileContent} interface. | ||
*/ | ||
Points3DTileContent.prototype.applyDebugSettings = function(enabled, color) { | ||
color = enabled ? color : Color.WHITE; | ||
color = enabled ? color : this._constantColor; | ||
this._primitive.appearance.uniforms.highlightColor = color; | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"asset": { | ||
"version": "0.0" | ||
}, | ||
"geometricError": 346.4, | ||
"refine": "add", | ||
"root": { | ||
"boundingVolume": { | ||
"sphere": [ | ||
1215011.9317263428, | ||
-4736309.3434217675, | ||
4081602.0044800863, | ||
100 | ||
] | ||
}, | ||
"geometricError": 0, | ||
"content": { | ||
"url": "pointsConstantColor.pnts" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"asset": { | ||
"version": "0.0" | ||
}, | ||
"geometricError": 346.4, | ||
"refine": "add", | ||
"root": { | ||
"boundingVolume": { | ||
"sphere": [ | ||
1215011.9317263428, | ||
-4736309.3434217675, | ||
4081602.0044800863, | ||
100 | ||
] | ||
}, | ||
"geometricError": 0, | ||
"content": { | ||
"url": "pointsNoColor.pnts" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
}, | ||
"geometricError": 0, | ||
"content": { | ||
"url": "points.pnts" | ||
"url": "pointsRGB.pnts" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"asset": { | ||
"version": "0.0" | ||
}, | ||
"geometricError": 346.4, | ||
"refine": "add", | ||
"root": { | ||
"boundingVolume": { | ||
"sphere": [ | ||
1215011.9317263428, | ||
-4736309.3434217675, | ||
4081602.0044800863, | ||
100 | ||
] | ||
}, | ||
"geometricError": 0, | ||
"content": { | ||
"url": "pointsRGBA.pnts" | ||
} | ||
} | ||
} |
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.
Actually, in b3dm and i3dm, the batch table comes before glTF. We should be consistent here for now and move the positions payload after the batch table; however, we might want to switch them all later if there is a benefit, e.g., to avoid parsing it in some cases?
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.
Ah that's true, I'll make the change in a new PR.
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.
I'm surprised we haven't run into this before, but TypedArray constructors expect their byte offset to be aligned to the type. For two of the points tilesets, the byte length of the batch table is odd and this causes problems when creating a
Float32Array
of the positions. Do we want to require byte alignment in the spec?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.
Yes, definitely need to say this in the spec. @tfili and I have ran into this before and I know some of the work we did included the padding
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.
glTF spec guarantees this btw. https://github.com/KhronosGroup/glTF/tree/master/specification#bufferview-and-accessor-byte-alignment