gwaldron / osgearth

3D Maps for OpenSceneGraph / C++14
https://www.pelicanmapping.com/home-1/opensource
Other
1.52k stars 781 forks source link

Compare with CesiumJS, the osgearth load and render 3DTiles file is very slowly!! #2449

Closed shiner-chen closed 9 months ago

shiner-chen commented 9 months ago

Describe the bug I used osgearth to load local 3DTiles, found the performance of load and render is very slowly. I try to use CesiumJS to load the same 3DTiles, the performance is better than osgearth. How to speed up it?

To Reproduce My main code is below:

#include <iostream>
#include <string>

#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgDB/Options>
#include <osgEarth/MapNode>
#include <osgEarth/ShaderGenerator>

#include <osgEarth/ImageLayer>
#include <osgEarth/Viewpoint>
#include <osgEarth/GeoTransform>
#include <osgEarth/ThreeDTilesLayer>
#include <osgEarth/ModelLayer>
#include <osgEarth/Registry>

#include <osgEarth/EarthManipulator>
#include <osgEarth/TMS>

using namespace std;

void AddModel(osg::ref_ptr<osgEarth::Map> map, osg::ref_ptr<osgEarth::MapNode> mapNode)
{
        // Create a new ThreeDTiles Layer object.
        osg::ref_ptr<osgEarth::Contrib::ThreeDTilesLayer> modelLayer = new osgEarth::Contrib::ThreeDTilesLayer();

        // Set the URL of the 3D Tiles file.
        modelLayer->setURL("/home/chenx/data/3dtiles/lod_3dtiles/tileset.json");
        modelLayer->setName("3DTiles");
        map->addLayer(modelLayer);

}

int main()
{
        osgEarth::initialize();
        osgViewer::Viewer viewer;
        viewer.setUpViewInWindow(0, 100, 800, 600);
        viewer.getCamera()->setClearColor(osg::Vec4(0, 0, 0, 0));

        osg::ref_ptr< osgEarth::EarthManipulator> mainManipulator = new osgEarth::EarthManipulator;
        viewer.setCameraManipulator(mainManipulator);

        //create map
        osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map;

        osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode(map);

        AddModel(map, mapNode);

        viewer.setSceneData(mapNode);

        osgEarth::Viewpoint vp;
        osgEarth::GeoPoint newPoint(map->getSRS(), 121.56241165900519, 25.034966733139754, 500);
        vp.focalPoint() = newPoint;
        vp.heading()->set(0, osgEarth::Units::DEGREES);
        vp.pitch()->set(-90, osgEarth::Units::DEGREES);
        vp.range()->set(1000, osgEarth::Units::METERS);
        mainManipulator->setViewpoint(vp, 5);
        viewer.setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext);
        return viewer.run();
}

Load the 3DTiles with CesiumJS through steps as follows:

  1. Downd the CesiumJS from https://github.com/CesiumGS/cesium/releases/download/1.100/Cesium-1.100.zip, unzip the zip package, and then run npm start to launch the server.
    
    chenx@chenx-rk3588:~/Cesium$ npm start

cesium@1.100.0 start node server.js --production

Cesium development server running locally. Connect to http://localhost:8080/

2. Access the http://localhost:8080, you will get the following screen
![image](https://github.com/gwaldron/osgearth/assets/12945934/4c0324fe-2768-472c-b57a-4f92aa2608cb)

3. Click the link: Sandcastle

4. paste the following code into JavaScript code tab

// San Miguel model created by Guillermo M. Leal Llaguno. Cleaned up and hosted by Morgan McGuire: http://graphics.cs.williams.edu/data/meshes.xml Cesium.Ion.defaultAccessToken ="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkZDUwMzZmYi1jYWRiLTQ2YjEtYjZmMy1jZmRjOTliMjc0NjEiLCJpZCI6OTYwNzAsImlhdCI6MTY4ODYwNzg1MH0.B2oA7SWN2V95xzb1qYTV354j0MoUWeXsXSmsJ4I4vMM"; //this is my token const viewer = new Cesium.Viewer("cesiumContainer", { shadows: true, });

const tileset = new Cesium.Cesium3DTileset({
    url: "../../../lod_3dtiles/tileset.json",
    baseScreenSpaceError:512,
    maximumScreenSpaceError:2,
    skipLevels:1
});
viewer.scene.globe.enableLighting = false; 
   viewer.shadows = false;
viewer.scene.primitives.add(tileset);
viewer.zoomTo(tileset);

![image](https://github.com/gwaldron/osgearth/assets/12945934/ed975ad4-b129-4846-a095-455a4b62fdbd)

Click the Run button to load 3DTiles file!!

5. Compare the speed of render, find the osgearth is slower than CesiumJS

**Expected behavior**
How to optimize the my code to speed up the render?

**Desktop (please complete the following information):**
 - OS: [e.g. iOS] Ubuntu22.04
 - Browser [e.g. chrome, safari] chrome
 - Version [e.g. 22] osgearth version: 3.5.0 build 149 , osgversion: 3.7.0
jasonbeverage commented 9 months ago

The new osgEarthCesium library should have performance that is much closer to CesiumJS than our original 3DTiles implementation, so I'd suggest using that.