浏览代码

loadTexture : add a load try with texture name first letter case swapped

bstouls 9 年之前
父节点
当前提交
45fdf27f33
共有 1 个文件被更改,包括 18 次插入2 次删除
  1. 18 2
      h3d/prim/ModelCache.hx

+ 18 - 2
h3d/prim/ModelCache.hx

@@ -45,13 +45,29 @@ class ModelCache {
 		var tres;
 		try {
 			tres = hxd.res.Loader.currentInstance.load(texturePath);
-		} catch( e : hxd.res.NotFound ) try {
+		} catch( error : hxd.res.NotFound ) {
 			// try again to load into the current model directory
 			var path = model.entry.directory;
 			if( path != "" ) path += "/";
 			path += texturePath.split("/").pop();
-			tres = hxd.res.Loader.currentInstance.load(path);
+			try {
+				tres = hxd.res.Loader.currentInstance.load(path);
+			} catch( e : hxd.res.NotFound ) try {
+				// if this still fails, maybe our first letter is wrongly cased
+				var name = path.split("/").pop();
+				var c = name.charAt(0);
+				if(c == c.toLowerCase())
+					name = c.toUpperCase() + name.substr(1);
+				else
+					name = c.toLowerCase() + name.substr(1);
+				path = path.substr(0, -name.length) + name;
+				tres = hxd.res.Loader.currentInstance.load(path);
+			} catch( e : hxd.res.NotFound ) {
+				// force good path error
+				throw error;
+			}
 		}
+
 		t = tres.toTexture();
 		textures.set(fullPath, t);
 		return t;