question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allows loadTexture to load encoded data

See original GitHub issue

Currently loadTexture loads data from an url. It could be nice to let it loads data from base64 encoded data (something like data:image/png;base64,XXXXX for eg).

It nearly works with the current implementation, only that we get a Cross-origin image load denied by Cross-Origin Resource Sharing policy. error (in Chrome) because of this: loader.crossOrigin = this.crossOrigin;.

Also, the url is put in texture.sourceFile, something that we would avoid to do when the url is really raw data.

So, in the current implementation, I would replace:

loader.crossOrigin = this.crossOrigin;
loader.load( url, image );
texture.sourceFile = url;

by

var isRawData = url.substr(0, 5) == 'data:';
if (!isRawData) {
    loader.crossOrigin = this.crossOrigin;
    texture.sourceFile = url;
} else {
    texture.sourceFile = '';
}
loader.load( url, image );

What do you think ?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mrdoobcommented, May 4, 2013

And just to be safe…

var image = document.createElement( 'img' );
var texture = new THREE.Texture( image );
image.onload = function()  {
    texture.needsUpdate = true;
        ...
};
image.src = 'data:image/png;base64,XXXXX';
1reaction
WestLangleycommented, May 4, 2013

Or…

var image = document.createElement( 'img' );
image.src = 'data:image/png;base64,XXXXX';
var texture = new THREE.Texture( image );
image.onload = function()  {
    texture.needsUpdate = true;
        ...
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Three.JS - How to load textures of material from data URL?
var json = JSON.parse(myJSON); var _loadTexture = THREE.MTLLoader.MaterialCreator.prototype.loadTexture; THREE.MTLLoader.MaterialCreator.
Read more >
Texture Loading in LWJGL3 | Coding a 2D Game ... - YouTube
Join the Discord: https://discord.gg/4tHeAkxNg7In this video I go over how to load textures in LWJGL3 using OpenGL. I go over what UV ...
Read more >
Facebook Playable Ads - how to load Texture Atlas? - Phaser 3
To clarify, loading normal images is working just fine using base64 encoded ... atlases to load, given the restrictions Facebook provides?
Read more >
Scripting API: Texture2D.LoadRawTextureData - Unity - Manual
This function fills texture pixel memory with raw data. This is mostly useful for loading compressed texture format data into a texture.
Read more >
Load Texture from GPU - Unity Answers
I want to know if it's possible to load a texture from data stored in ... In my project, I have a server...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found