Render Obj, MTL and JPG

Hello, I’m new using Cesium, so far the platform looks great.

My issue is that i need to render a 3D model which is a .obj and has .mtl and .jpg for textures, i tried with the sandcastle example just to place my object by doing this:

{
            text: "Monument",
            onselect: function () {
              createModel(
                "../../SampleData/models/Monument/monument.obj",
                0
              );
            },
          },

but got an error:

RuntimeError: Failed to load model: ../../SampleData/models/Monument/monument.obj
undefined
Error
    at new RuntimeError (http://localhost:8080/Source/Core/RuntimeError.js:38:11)
    at http://localhost:8080/Source/Scene/ModelUtility.js:166:32
    at Promise.then (http://localhost:8080/Source/ThirdParty/when.js:217:33)
    at http://localhost:8080/Source/ThirdParty/when.js:297:13
    at processQueue (http://localhost:8080/Source/ThirdParty/when.js:647:4)
    at _resolve (http://localhost:8080/Source/ThirdParty/when.js:333:4)
    at promiseReject (http://localhost:8080/Source/ThirdParty/when.js:366:11)
    at Promise.then (http://localhost:8080/Source/ThirdParty/when.js:217:33)
    at http://localhost:8080/Source/ThirdParty/when.js:298:7
    at processQueue (http://localhost:8080/Source/ThirdParty/when.js:647:4)

Is there any way to load my assets?

As far as I know, OBJ files are not directly supported by CesiumJS.

The most sensible approach would probably be to convert the model into a glTF asset - usually, into a .GLB file, which is a “binary glTF”.

There are many tools that can do this. There are command-line tools for this (for example, GitHub - CesiumGS/obj2gltf: Convert OBJ assets to glTF ), but it should also be possible to load the OBJ in any modeling tool (like Blender) and then export it as glTF. There even are some online drag-and-drop OBJ-to-glTF converters, but I cannot say much about how good they are. More generally: All these tools may differ in terms of configurability, simplicity of use, and quality of the resulting model. (Additionally, there are many, many OBJ loaders that cannot properly load some OBJ files, but most of them can load most files, fortunately…)

(Is the model that you are using publicly available somewhere?)

1 Like