- Home /
GetPixel error on downloaded texture even with crossdomain.xml
Hi,
I am trying to download a texture hosted on my domain and apply it as a normal map to my model.
Here is my function that takes in the URL of the normal map, does the required operation on it and applies it.
I am stumped as to why its not working. It works (is able to load the map and perform GetPixel on it) in the editor when I put http://werplay.com (which is my domain) in WWW Security Emulation(under project settings\editor) in the project. Though when I build for web and run, it does not work. I have now put the crossdomain.xml file at the hosting root as well. It is the same xml that unity3d.com uses, just saved it and put it up on my domain.
(actual) location of crossdomain.xml http://werplay.com/crossdomain.xml (sample) location of texture to load, manipulate and apply http://werplay.com/folder1/folder2/normalmap_xx.jpg
Any help would be greatly appreciated :)
function setNormal(n: String){
var myNormal : WWW = new WWW (n);
yield myNormal;
var normalTexture : Texture2D = new Texture2D(myNormal.texture.width,myNormal.texture.height,TextureFormat.ARGB32,false);
var loadedTexture : Texture2D = myNormal.texture;
var x : int;
var y : int;
var theColour: Color = new Color();
for (x = 0; x<loadedTexture.width; x++)
{
for (y = 0; y<loadedTexture.height; y++)
{
theColour.r = loadedTexture.GetPixel(x,y).g;
theColour.g = theColour.r;
theColour.b = theColour.r;
theColour.a = loadedTexture.GetPixel(x,y).r;
normalTexture.SetPixel(x,y, theColour);
}
}
normalTexture.Apply();
normal = normalTexture;
renderer.material.SetTexture("_BumpMap", normal);
}
I have edited the post now.
It works (is able to load the map and perform GetPixel on it) in the editor when I put http://werplay.com (which is my domain) in WWW Security Emulation(under project settingseditor) in the project. Though when I build for web and run, it does not work.
When building for web, is there anything/anywhere I need to specify where to fetch/check crossdomain policy from? (since WWW security emulation I assume is limited to editor testing only)?
Where do you test your webbuild? On your actual server or locally?
I've tried both locally or putting the built unity + html file on the same server from where it is downloading the image.
Answer by Bunny83 · May 07, 2012 at 01:32 PM
Your explanation is very confusing. Does it work or not? And what's the exact question? Do you want it to work without setting the emulation settings?
You need to set the hosting url if you want to access files on your server when you emulating in the editor. This pretends that the webplayer is run on your website.
See the Security Sandbox for more details.
Also what exactly "its not working"? Do you get any errors in the console / logfile?
I've never tried to read out pixels manually from a downloaded image. Does it work when you build for standalone?
Btw. you might want to use Texture2D.GetPixels instead so you get an array of all pixels, you can do your changes and finally write them to the new texture. It's faster than using GetPixel
Your answer
Follow this Question
Related Questions
crossdomain.xml on Server Requiring Basic Authorization 0 Answers
asset bundles download problem 0 Answers
Crossdomain woes 2 Answers
WebGL WWW and Localhost CORS 0 Answers
WWW doesn't work on localhost eventhough crossdomain.xml exists 1 Answer