How to store terrain in js object

Facing difficulties (an error Failed to execute ‘drawImage’ on ‘CanvasRenderingContext2D’) while converting the terrain i am getting from https://github.com/w3reality/three-geo into an js object using toJSON on mesh, so any one from such a great community help me in this , here i want to store the three-geo terrain into an js object so i can store ti in db

Hi Alex, welcome to our community. Please be patient and give it time till someone replies. Your issue seems to be more related to the project you linked and not THREE itself, it might be a better idea to see if their docs or examples provide information how to serialize it.

Other than that you would have to provide more details in what is passed there causing the error, some more of the log.

@Fyrestar thanks for your response and attention ,
i am trying to convert the mesh into an json object by using toJSON on mesh and the mesh have the texture too like,

terrainData = terrain.toJSON()
terrain is a group than contain lot of meshes that compose a imagery and terrain by three-geo
but while converting i am running into this error
×

TypeError: Failed to execute ‘drawImage’ on ‘CanvasRenderingContext2D’: The provided value is not of type ‘(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)’

in three.module.js

context.drawImage(image, 0, 0, image.width, image.height);
``` is causing issue try to find solution but as if now not able to so thats why if some one help me in this its a great help

What are the assigned textures to the terrain mesh materials? Are they instances of THREE.Texture, THREE.DataTexture or THREE.CanvasTexture etc?

@Fyrestar sir i checked its an datatexture

I don’t use the in-built serialization but it seems DataTexture isn’t handled for it, so it tries to render a object with arraybuffer into the canvas. I assume the buffer also isn’t a Uint8Array, rather Float32Array. It’s better to use another exporter then in that case, like gltf.

i used the gltf exporter but still facing error
TypeError: Cannot convert undefined or null to object

var extras = Object.keys(geometry.userData).length > 0 ? serializeUserData(geometry) : undefined;

even if i use the gltf exporter @Fyrestar i think i cant convert it into JSON to store in db i think gltf is not the solution please put your points on this .

Hello three js community any views on this I want to store the terrain in JSON object please help me

Where is that line of code from and where is the error thrown?

Hello fyrestar you said data texture is not supported for the above error while converting mesh into json by object loader than how i can convert it into the json object i checked with the other exported but they dont give a json object