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

Add support for point clouds (pnts) #591

Merged
merged 21 commits into from
Feb 6, 2023
Merged

Add support for point clouds (pnts) #591

merged 21 commits into from
Feb 6, 2023

Conversation

j9liu
Copy link
Contributor

@j9liu j9liu commented Jan 24, 2023

WIP, but I'm opening it now to track the tasks involved. This builds off of #334 and will finally close #333 when finished.

TODO

  • Implement support for all point cloud semantics
    • Positions are done (though values being properly stored in buffers still untested)
    • Colors
      • need to convert the different RGB formats into vertex colors appropriately
      • need to convert CONSTANT_RGBA to a PBR material
    • Normals
      • need to decode oct16_p normals
    • Batch IDs
      • need to convert into feature IDs
  • Convert batch table to glTF feature metadata extension
  • Support Draco extension
  • Unit tests

@j9liu j9liu marked this pull request as draft January 24, 2023 20:34
@j9liu j9liu marked this pull request as ready for review February 1, 2023 16:13
@j9liu
Copy link
Contributor Author

j9liu commented Feb 1, 2023

Happy to announce this is ready for review whenever you get a chance @kring !

@timoore
Copy link
Contributor

timoore commented Feb 2, 2023

I tried this branch with the Melbourne Point Cloud and vsgCs and triggered an assertion:

worldviewer: /home/moore/graphics/cesium-native/extern/rapidjson/include/rapidjson/document.h:1253: rapidjson::GenericValue<Encoding, Allocator>::ConstMemberIterator rapidjson::GenericValue<Encoding, Allocator>::MemberBegin() const [with Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>; ConstMemberIterator = rapidjson::GenericMemberIterator<true, rapidjson::UTF8<>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >]: Assertion `IsObject()' failed.

The problem is that the batch table in this tile is of length 0.
Stack trace:

#5  0x0000000000914775 in rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::MemberBegin (this=0x7fffdbedb510) at /home/moore/graphics/cesium-native/extern/rapidjson/include/rapidjson/document.h:1253
#6  0x00000000008ec870 in Cesium3DTilesSelection::(anonymous namespace)::convertBatchTableToGltfFeatureMetadataExtension (
    batchTableJson=..., batchTableBinaryData=..., gltf=..., featureCount=41214, result=...)
    at /home/moore/graphics/cesium-native/Cesium3DTilesSelection/src/BatchTableToGltfFeatureMetadata.cpp:1412
#7  0x00000000008ed4ee in Cesium3DTilesSelection::BatchTableToGltfFeatureMetadata::convertFromPnts (featureTableJson=..., 
    batchTableJson=..., batchTableBinaryData=..., gltf=...)
    at /home/moore/graphics/cesium-native/Cesium3DTilesSelection/src/BatchTableToGltfFeatureMetadata.cpp:1592
#8  0x00000000009876e8 in Cesium3DTilesSelection::(anonymous namespace)::convertPntsContentToGltf (pntsBinary=..., header=..., 
    headerLength=28, result=...) at /home/moore/graphics/cesium-native/Cesium3DTilesSelection/src/PntsToGltfConverter.cpp:1556
#9  0x0000000000987827 in Cesium3DTilesSelection::PntsToGltfConverter::convert (pntsBinary=...)
    at /home/moore/graphics/cesium-native/Cesium3DTilesSelection/src/PntsToGltfConverter.cpp:1576
#10 0x00000000008d9091 in operator() (__closure=0x1e63880, pCompletedRequest=...)
    at /home/moore/graphics/cesium-native/Cesium3DTilesSelection/src/TilesetJsonLoader.cpp:821

The tileUrl is "https://assets.ion.cesium.com/43978/0/0.pnts?v=1".

@j9liu
Copy link
Contributor Author

j9liu commented Feb 2, 2023

Thanks for the catch @timoore. I just pushed a commit to fix it, but let me know if the issue persists.

@timoore
Copy link
Contributor

timoore commented Feb 2, 2023

Thanks for the catch @timoore. I just pushed a commit to fix it, but let me know if the issue persists.

Unfortunately the MemberCount() call fails with the same problem. My stab at fixing the issue is timoore@6fbffd2 .

With that, I can see points in Melbourne. I don't know if vsgCs is doing the right thing with the lighting and point rendering.
Screenshot from 2023-02-03 00-22-11

Copy link
Member

@kring kring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, nice work here @j9liu! This looks very well implemented and tested. I only have minor comments below. Please take a look at @timoore's latest comment as well, of course.

Cesium3DTilesSelection/src/PntsToGltfConverter.cpp Outdated Show resolved Hide resolved
Cesium3DTilesSelection/src/PntsToGltfConverter.cpp Outdated Show resolved Hide resolved
Cesium3DTilesSelection/src/PntsToGltfConverter.cpp Outdated Show resolved Hide resolved
}

template <typename Type>
static void checkBufferContents(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these two checkBufferContents functions be merged into one, with a default value for the epsilon parameter, and the epsilon value is ignored for integer comparisons? Seems like it would eliminate a lot of duplication.

Copy link
Contributor Author

@j9liu j9liu Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I do this, Windows + VS2017 and Linux + GCC are throwing compile errors in Travis because the epsilon parameter isn't used in all branches of the function. Do you know how to address that without code duplication?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add an attribute to the parameter:
https://en.cppreference.com/w/cpp/language/attributes/maybe_unused
You can also use specialization rather than if constexpr, but that's a bigger change.

@j9liu
Copy link
Contributor Author

j9liu commented Feb 3, 2023

@timoore thanks for letting me know your fix. I moved the IsObject check to PntsToGltfConverter so that it doesn't even try to invoke BatchTableToGltfFeatureMetadata if batchTableJson is invalid.

With that, I can see points in Melbourne. I don't know if vsgCs is doing the right thing with the lighting and point rendering.

It seems like the geometry is there but the colors are missing. Or they may just be faded. I have to add a correction that converts the pnts sRGB colors to linear colors for the glTF, as pointed out in CesiumGS/cesium-unity#197.

@j9liu
Copy link
Contributor Author

j9liu commented Feb 3, 2023

Also @timoore, could you sign a CLA here since you found a fix for the rapidjson issue? The CLA forms and relevant info can be found here.

@timoore
Copy link
Contributor

timoore commented Feb 3, 2023

It seems like the geometry is there but the colors are missing. Or they may just be faded. I have to add a correction that converts the pnts sRGB colors to linear colors for the glTF, as pointed out in CesiumGS/cesium-unity#197.

I had a bug where I wasn't doing anything with normals for points, so they were only being lit by ambient lighting. They are looking better now. That's interesting about sRGB colors in points. I followed the comment chain from cesium-unity to cesium. I don't see in the point clouds spec where that's specified, but obviously I would take @lilleyse 's word for it!

@timoore
Copy link
Contributor

timoore commented Feb 3, 2023

Also @timoore, could you sign a CLA here since you found a fix for the rapidjson issue? The CLA forms and relevant info can be found here.

Done.

@kring
Copy link
Member

kring commented Feb 6, 2023

Thanks @j9liu!

@kring kring merged commit 7600488 into main Feb 6, 2023
@kring kring deleted the pnts-support branch February 6, 2023 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Point clouds ("pnts" tile content support)
3 participants