Hi Friends
I am using an api to fetch a png image as follows:
export const getSRXDataBinary = async (obj) => {
const response = await fetch(‘/api’, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/octet-stream’,
},
body: JSON.stringify(obj),
responseType: “arraybuffer”
}).catch((e) => {
return { status: false, data: e.message };
});
if (response.status !== 200) {
return { status: false, data: response.statusText };
}
return response.arrayBuffer();
};
So, because of that i cant use the usual three.TexturLoader() since that requires an image url and i dont have that. I have to get the image raw data from an api in the backend.
When i get the data back i can display it as an image using this code:
const base64 = btoa(
new Uint8Array(rawdata.reduce(
(data, byte) => data + String.fromCharCode(byte),
''
)
)
myimage.src = `data:image/png;base64,${base64}`
But I am stuck trying to create a texture for this image as well.
How can i convert raw data to Texture so i can map that image in 3D as well.
Thanks