Jump to content

Another way of getting picture for new BABYLON.Texture(path, scene)


roman_44
 Share

Recommended Posts

On 2/17/2016 at 0:46 PM, adam said:

There is some code at the beginning of the default LoadImage function to clean the url.  You might need to include that in the new function.


            url = BABYLON.Tools.CleanUrl(url);

Hey Adam, 

I tried your code and it looks like this: 

56c75293a2f70_ScreenShot2016-02-19at9.35

I commented responseType because it is not working with it.

Now the requests are sending fine with my header. But it gets error:

Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.

 

I don't understand why are you trying to put xhr.response to the img.src. Img.src should be path I think. And image data should be somewhere in object. But I don't know where exactly and cannot find any information about it.

 

And probably the interesting question is why another img elements from html are sending with session cookies in headers, and this img elements which created in Babylon are not.

Link to comment
Share on other sites

48 minutes ago, adam said:

You might just want to do something like this:

http://www.babylonjs-playground.com/#1TLCGX

I know that I can manually create diffuseTexture or even download file first and then put in on texture. 

But the problem is that I'm developing a big app. Where I have a lot of scenes exported from 3dMax which already have a lot of textures.

I'm getting scene by SceenLoader.load and I have hundreds of meshes, some of them have diffuse texture some of them not. So it just a big deal to disable downloading pictures when scene loads through sceneLoader from exported babylon file and after that try to manually download all pictures and include them as diffuse textures for appropriate meshes.

So I have to have automated scene upload through SceneLoader.load as well as my session cookies in request headers.

Link to comment
Share on other sites

The code I wanted you to look at isn't disabling anything:

var loadImage = BABYLON.Tools.LoadImage;
	
BABYLON.Tools.LoadImage = function(url, onload, onerror, database) {
        
	var xhr = new XMLHttpRequest();
	
        //xhr.setRequestHeader("[KEY]", "[VALUE]");	
	xhr.open("GET", url);
	xhr.send();
		
	return loadImage(url, onload, onerror, database);
	    
}

It is just overriding the default loadImage so that you can set the header using XMLHttpRequest.

Link to comment
Share on other sites

Sorry, my fault. Missed your top lines....

Yeah. I put this code and it is finally works :)))) It even automatically puts cookies which is awesome :)))

Adam, thank you so much for your time and patience :)

What do you think is it ok to loose all other functionality from default LoadImage function? It is a lot of other stuff there, database and other if's which I dont understand.

Appreciate your help! 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...