瀏覽代碼

Merge get config of ModelDatabase & FileConverter

lviguier 1 年之前
父節點
當前提交
46a77eed64
共有 3 個文件被更改,包括 19 次插入24 次删除
  1. 1 1
      h3d/prim/HMDModel.hx
  2. 8 19
      h3d/prim/ModelDatabase.hx
  3. 10 4
      hxd/fs/FileConverter.hx

+ 1 - 1
h3d/prim/HMDModel.hx

@@ -303,7 +303,7 @@ class HMDModel extends MeshPrimitive {
 		if ( lodCount == 1 )
 			return 0;
 
-		lodConfig = getLodConfig();
+		var lodConfig = getLodConfig();
 		if ( lodConfig != null && lodConfig.length >= lodCount - 1) {
 			var lodLevel : Int = 0;
 			var maxIter = ( ( lodConfig.length > lodCount - 1 ) ? lodCount - 1: lodConfig.length );

+ 8 - 19
h3d/prim/ModelDatabase.hx

@@ -5,7 +5,7 @@ class ModelDatabase {
 	public static var db : Map<String,{ v : Dynamic }> = new Map();
 
 	static var defaultLodConfigs : Map<String, Array<Float>> = new Map();
-	static var baseLodConfig = [ 0.3, 0.2, 0.1];
+	static var baseLodConfig = [ 0.5, 0.2, 0.01];
 
 	static var filename = "model.props";
 
@@ -77,25 +77,14 @@ class ModelDatabase {
 	}
 
 	public function getDefaultLodConfig( dir : String ) : Array<Float> {
-		var c = defaultLodConfigs.get(dir);
-		if( c != null ) return c;
-
-		var dirPos = dir.lastIndexOf("/");
-		var parent = dir == "" ? baseLodConfig : getDefaultLodConfig(dirPos < 0 ? "" : dir.substr(0,dirPos));
-		var propsFile = (dir == "" ? baseDir : baseDir + dir + "/")+"props.json";
-		if( !hxd.res.Loader.currentInstance.exists(propsFile) ) {
-			c = parent;
-		} else {
-			var content = hxd.res.Loader.currentInstance.load(propsFile).toText();
-			var obj = try haxe.Json.parse(content) catch( e : Dynamic ) throw "Failed to parse "+propsFile+"("+e+")";
-
-			if (Reflect.hasField(obj, "lods.screenRatio"))
-				c = Reflect.field(obj, "lods.screenRatio");
-			else
-				c = parent;
-		}
+		var fs = Std.downcast(hxd.res.Loader.currentInstance.fs, hxd.fs.LocalFileSystem);
+		var c = @:privateAccess fs.convert.getConfig(defaultLodConfigs, baseLodConfig, dir, function(fullObj) {
+			if (Reflect.hasField(fullObj, "lods.screenRatio"))
+				return Reflect.field(fullObj, "lods.screenRatio");
+
+			return baseLodConfig;
+		});
 
-		defaultLodConfigs.set(dir, c);
 		return c;
 	}
 

+ 10 - 4
hxd/fs/FileConverter.hx

@@ -182,11 +182,17 @@ class FileConverter {
 	}
 
 	function loadConfig( dir : String ) : ConvertConfig {
-		var c = configs.get(dir);
+		return getConfig(configs, defaultConfig, dir, function(fullObj) {
+			return makeConfig(fullObj);
+		});
+	}
+
+	function getConfig(cachedConfigs : Map<String, Dynamic>, defaultConfig : Dynamic, dir : String, makeConfig : Dynamic -> Dynamic) : Dynamic {
+		var c = cachedConfigs.get(dir);
 		if( c != null ) return c;
 		var dirPos = dir.lastIndexOf("/");
-		var parent = dir == "" ? defaultConfig : loadConfig(dirPos < 0 ? "" : dir.substr(0,dirPos));
-		var propsFile = (dir == "" ? baseDir : baseDir + dir + "/")+"props.json";
+		var parent = dir == "" ? defaultConfig : getConfig(cachedConfigs, defaultConfig, dirPos < 0 ? "" : dir.substr(0,dirPos), (fullObj) -> makeConfig(fullObj));
+		var propsFile = (dir == "" ? baseDir : baseDir + dir + "/") +"props.json";
 		if( !sys.FileSystem.exists(propsFile) ) {
 			c = parent;
 		} else {
@@ -195,7 +201,7 @@ class FileConverter {
 			var fullObj = mergeRec(parent.obj, obj);
 			c = makeConfig(fullObj);
 		}
-		configs.set(dir, c);
+		cachedConfigs.set(dir, c);
 		return c;
 	}