Locally generated gltf object

Hi there,

Currently I can import a gltf object by providing a uri. That implies that the object is acquired from some (file) resource.

.add(Cesium.Model.fromGltf({
url: “resource here”

Is it possible to ‘import’ a locally generated gltf object from a local variable? I get the data in json format and generate gltf inside the code.

.add(Cesium.Model.fromGltf({
url: local_variable

While on the topic, how can I retain the gltf colors and the brightness. Gltf loaded from a file is much darker.

Cheers!

Hi, it was possible before because I was loading gltf from a variable with Cesium versions up to Cesium 1.96.

I am also looking for the syntax that will work for recent Cesium versions. I hope not, but maybe it went file only starting from Cesium 1.97, the version with huge model architectural changes. I would like to find a solution without having to modify Cesium’s source code.

I have resorted to debugging fromGltf function and discovered that the gltf option is still supported.

ribbonC = cViewer.scene.primitives.add(Cesium.Model.fromGltf({
//url : ‘./gltf/object.gltf’,
gltf : my_gltf_json,

Here is a work-around that worked for me (Cesium 1.101) !

var blob = new Blob([local_variable], { type: "text/json;charset=utf-8" });
var blobUrl = URL.createObjectURL(blob);

var model = Cesium.Model.fromGltf({
	url: blobUrl
});

// run this when the model's readyPromise fires
URL.revokeObjectURL(blobUrl);

Good job! pretty generic, can be used anywhere…