Hi, I'm loading an md2 file & texture from a url, e.g.: http://foo/bar/1.md2
and http://foo/bar/1.png

I expected I could call Md2.load and have it automatically load the
mesh and and the texture, like so:
  var path:String = "http://foo/bar/";;
  loader = Md2.load(path + "1.md2", {pcxConvert:"png"});

But the above does not load the texture. Instead I have to explicitly
load the texture:
  var material:BitmapFileMaterial = new BitmapFileMaterial(path +
"1.png");
  loader = Md2.load(path + "1.md2", {material:material});

Looking at Md2.as, the issue is the loader uses the texture name from
the .md2 file as an absolute path, so although the pcxConvert param
successfully maps the texture name to 1.png, it tries to load "1.png"
instead of "http://foo/bar/1.png";.

Here's the code from MD2.as:
  //overridden by the material property in constructor
  if (material) {
    mesh.material = material;
  } else if(url.substring(url.length -4, url.length -3) == "."){
    if(url.toLowerCase().indexOf("pcx") != -1){
      url = url.substring(-1, url.length -3) + pcxConvert;
    }
    trace("Material source: "+url+". Pass pcxConvert:'gif' or 'png' to
load other file types. ...");
    mesh.material = new BitmapFileMaterial(url);
  }

Just for fun I tried setting texturePath explicitly but it has no
effect (and I don't see it in the code above):
  loader = Md2.load(path + "1.md2", {pcxConvert:"png",
texturePath:path});

Questions:
- Am I just doing something dumb here? Is there something I should be
setting up so the loader looks in the right path?
- If not... should the md2 loader treat the texture as a relative
path? What's the convention for the other loaders? (imho it should, as
the md2 texture name is only 64 chars so not intended to be carrying
full urls etc)
- Or maybe it should just support the texturePath parameter? That
might be an easy solution. Do the other loaders use texturePath?

Thanks!

btw all the md2 examples I found avoid the issue by loading and
assigning the texture like my workaround.

Reply via email to