Back to the Shapespark home page

Exchange of textures from a data base

Hi.
I have a question. Is it somehow possible to exchange/load textures from a database? Or to link to a texture on a server that can be overwritten later to be a bit more flexible after a project is done? I know it wouldn’t be compressed in that case.

Yes it is - here some documentation about it: https://github.com/shapespark/shapespark-viewer-api#replace-textures-using-images-from-external-source

Thank you, Kuba.
I don’t want to create a material switcher but load the main texture to from an external source. But this should be possible too. I will have a look at the API.

1 Like

Unfortunately, I am not able to get the code right.

I want to tell the body-end.html to load the texture of an material from the server.
This is what I want to use the give a path to an external resource:

< img src=“https://path to image/a001_img001.jpg”
id=“img001” crossorigin=“anonymous” >

I don’t need any trigger, just to load the image into the material. Do I need some code before/after?
Maybe one of the programmer among us can tell me where the problem lies?

You need a code like this to configure a texture (place it anywhere after the img tag and replace YOUR-MATERIAL-NAME with a valid name):

<script>
  var viewer = WALK.getViewer();
  viewer.setMaterialEditable('YOUR-MATERIAL-NAME');
  viewer.onSceneReadyToDisplay(function() {
    var image = document.getElementById('img001');
    var texture = viewer.createTextureFromHtmlImage(image);
    var material = viewer.findMaterial('YOUR-MATERIAL-NAME');
    material.baseColorTexture = texture;
  });
</script>

Thank you, Jan. Looks nearly similar to my code :grimacing:
I will give it a try!