ImportedMesh doesn't take Raster as texture

Hello everyone

i am trying around a bit with babylonjs and some 3d data. i have a terrain as an stl file and a raster (jpg) that i want to use as texture. i got it working with creategroundfromheight map and the raster on top, but for some reason it doesnt work with my stl file.

Here is the Playgroundlink: Babylon.js Playground

Would be glad if someone has a hint, i search around and tried other ways and the mesh also doesnt take any color. I ended up with stl, because the other fileformats (glb, gltf…) didnt show up, as seen in the playgroundcode.

Thank you in advance

Hello and welcome!

The reason is that your assets are blocked by CORS policy. It is easy to see if you would open the console (it is always useful in case of any errors :slight_smile: ).

In order to use your assets in Playground please follow these docs - Using External Assets In the Playground | Babylon.js Documentation

1 Like

Hey, thank you for the welcome :slight_smile: ,
i have to say im struggeling with this cors in general. it didnt show me this issue before, but maybe cos i was connected the server the raster is saved.
anyway i uploaded everything on dropbox now and console aint showing me any cors issues, but still i dont see the raster on that stl.

Here is the fix: raster_on_ground | Babylon.js Playground (babylonjs.com)

You were missing async/await on ImportMeshAsync and also not using the correct returned value

4 Likes

There are several errors in your PG.
First, if you use ImportMeshAsync() you need to use await as well.
Second, when you import your model, it is imported as Object.
image
But @Deltakosh was faster than me with the corrected Playground :slight_smile:

2 Likes

Thank you, i think i understand. But how come the raster is still not shown on the terrain? Should be this here:

I tried with different material preferences, color change is working but it doesn’t take the texture :thinking:

Your mesh has no uv coordinates :

image

You must create uv coordinates in your DCC tool so that a texture can be applied to it.

1 Like

Thank you everyone for the answers, after I started defining the UV Coordinates in DCC and didn’t really get forward I changed to glb and changed some things there, which made it way easier to get my meshes displayed. Since there where actually three right answers but can only mark one as solution and I guess the first one already solved my asked question I will mark that

Thank you