load model from external url (CORS?)

883 views
Skip to first unread message

Gergely Padányi-Gulyás

unread,
Nov 19, 2015, 7:58:09 AM11/19/15
to cesium-dev
Dear All!

I would like to add a glb/gltf model to my scene. Everything works fine when the model is on the same server than the app itself. But I wish to store the individual models on a different server. In this case, Cesium is unable to download the models and the corresponding textures.

If I simply insert the url into a new browser window, it is accessible with no problem. I guess this is because of CORS, but I have no idea how I could solve it.

My code looks like this:

    var viewer = new Cesium.Viewer('cesiumContainer');
    
    var czml = [
     {
         "id": "document",
         "name": "CZML Model",
         "version": "1.0"
     },
     {
         "id": "varoshaz",
         "name": "2534_1_Varoshaz_ter_9a_E94E_georef3",
         "position": {
             "cartographicDegrees": [20.775372, 48.102767, 0]
         },
         "model": {
             "gltf": "https://myserver/models/collada/varoshaz.glb",
             "scale": 1,
             "minimumPixelSize": 128
         }
     }
    ];
    
    viewer.dataSources.add(Cesium.CzmlDataSource.load(czml)).then(function(dataSource){
        viewer.zoomTo(dataSource);
    }).otherwise(function(error){
        window.alert(error);
    });   

I actually provided a solution, but it makes everything quite slow: I built a Java proxy for the glb file; in that case, the model is downloaded, but the textures are again not loaded. I had to modify the model itself, and the texture reference url-s were manually replaced to a proxied url. After that, the models could be downloaded, but so much slower than it was when the models were stored locally. 

I would like to avoid proxying everything if it is possible in some ways.

Any help is highly appreciated! 

        Gergely


falc...@gmail.com

unread,
Nov 19, 2015, 9:34:57 PM11/19/15
to cesium-dev
Your other server needs to send the Access-Control-Origin-Allow header. How that is done varies based on the server.

Matthew Amato

unread,
Nov 19, 2015, 9:43:09 PM11/19/15
to cesiu...@googlegroups.com
http://enable-cors.org/ is a good resource for learning about CORS and enabling it on different servers.

--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gergely Padányi-Gulyás

unread,
Nov 20, 2015, 7:36:13 AM11/20/15
to cesium-dev
Thank you for the answers!

Unfortunately modifying the remote server to send the Access-Control-Origin-Allow header was not an option in my case, I don't have admin rights. Therefore I stayed at the solution of using my Java proxy. 

However, I managed to optimize the number of downloads by embedding all the textures as "data:image/jpeg;base64" into the gltf file itself (I used czml-writer for that). Although the file size became bigger, there are no extra downloads, and the scene loading time became much much better as a result.

Best,
      Gergely
Reply all
Reply to author
Forward
0 new messages