1

I'm using THREE.js r98. I have to make POST request with some payload that returns an image or texture in response and I want to use this API URL with ImageLoader, render the image onto canvas. I'm not sure ImageLoader supports this. Any workaround to use image response from POST request and load that onto mesh, add to scene. I'm using the below code which works for static image URL

var imgLoader = new THREE.ImageLoader();
  imgLoader.load(imgPath, function(image) {
    //do stuff with image like loading onto mesh etc    
  });

I tried calling that API with ajax, tried converting to base64 to load onto canvas but doesn't work(Weird characters in image response of POST request)

1 Answers1

2

What you are trying to do does not work with three.js. THREE.ImageLoader assign the given URL to the src attribute of an HTML5 image element which triggers always a GET request. Apart from that, THREE.FileLoader also performs just GET requests.

So it looks like you have to write your own custom loader in order to accommodate your needs.

Mugen87
  • 28,829
  • 4
  • 27
  • 50
  • I've tried with HTML5 Image element once I receive response from API. onload isn't even getting triggered. Tried converting base64 and blob, no success. – lifetimeLearner007 Dec 20 '18 at 11:09
  • Can you share your code as a live example? https://jsfiddle.net/f2Lommf5/ – Mugen87 Dec 20 '18 at 11:21
  • The POST request requires authorization id and other data to work. I can't simulate the weird characters in response in fiddle. The API won't work outside the application. – lifetimeLearner007 Dec 20 '18 at 11:35
  • Too bad. I suggest you accept the answer since the issue with the "weird characters" is tracked in a different post. Your problem is unrelated to `three.js`. – Mugen87 Dec 20 '18 at 12:07
  • I was hoping for workarounds or add-ons or utilities in three.js that can handle post requests. Someone might have a solution else I'll accept your answer. – lifetimeLearner007 Dec 20 '18 at 12:12
  • 1
    I'm one of the collaborators and I can tell you for sure there is no API for your use case ;) – Mugen87 Dec 20 '18 at 12:30