void *GodotPrepareRendererResources::prepareInMainThread( Cesium3DTilesSelection::Tile &tile,
                                                          void *pLoadThreadResult_ )
{
...

    std::vector<MeshInstance3D *> meshInstances;
    meshInstances.reserve( meshSize );
    for ( int i = 0; i < meshSize; ++i )
    {
        MeshInstance3D *meshInstance = memnew( MeshInstance3D );
        meshInstance->set_name( godot::String( name.c_str() ) );
        meshInstance->set_mesh( meshes[i] );
        // cesium coordinate axis X is not align godot's, need rotate.
        Quaternion qua( Vector3( 1, 0, 0 ), static_cast<real_t>( -Math_PI / 2 ) );
        Transform3D trans;
        trans.set_basis( qua );
        meshInstance->set_transform( trans );
        meshInstance->hide();
        this->_tileset.add_child( meshInstance );
        meshInstance->set_owner( this->_tileset.get_owner() );
        meshInstances.push_back( meshInstance );
    }
...
}

Cesium3DTileset.cpp

 for ( auto pTile : updateResult.tilesToRenderThisFrame )
    {
        if ( pTile->getState() != TileLoadState::Done )
        {
            continue;
        }
        const Cesium3DTilesSelection::TileContent &content = pTile->getContent();
        const Cesium3DTilesSelection::TileRenderContent *pRenderContent =
            content.getRenderContent();
        if ( pRenderContent )
        {
            CesiumGltfNode *pCesiumGltfNode =
                static_cast<CesiumGltfNode *>( pRenderContent->getRenderResources() );
            if ( pCesiumGltfNode )
            {
                for ( MeshInstance3D *instance3d : pCesiumGltfNode->pNodes )
                {
                    instance3d->show();
                }
            }
        }
    }

Maybe it's about main thread and work thread issues, godot optimize render many MeshInstance3D nodes, but how to let them render asynchronously.
I'm seeking the answer..

  • xyz replied to this.

    xuwzen2024 Interacting with Godot's scene tree is not thread safe. You can safely munch mesh data (including orphaned node subtrees) in worker threads as long as those objects are not a part of the main tree. So do all thread work separately from the tree, and then do the actual insertion of generated stuff into the tree from the main thread. If there is a lot of scene tree interaction that needs to happen at once, spread it through multiple frames to keep the framerate unaffected.