瀏覽代碼

Can customize lod config, and refresh it from ModelCache.

clementlandrin 3 月之前
父節點
當前提交
f43cf537b6
共有 2 個文件被更改,包括 18 次插入8 次删除
  1. 9 1
      h3d/prim/ModelCache.hx
  2. 9 7
      h3d/prim/ModelDatabase.hx

+ 9 - 1
h3d/prim/ModelCache.hx

@@ -175,6 +175,15 @@ class ModelCache {
 		}
 	}
 
+	public function refreshLodConfig() {
+		for ( model in models )
+			for ( p in @:privateAccess model.lib.cachedPrimitives ) {
+				if ( p == null )
+					continue;
+				@:privateAccess p.lodConfig = null;
+			}
+	}
+
 	#if hide
 
 	public function loadPrefab( res : hxd.res.Prefab, ?p : hrt.prefab.Prefab, ?parent : h3d.scene.Object ) {
@@ -205,5 +214,4 @@ class ModelCache {
 	}
 
 	#end
-
 }

+ 9 - 7
h3d/prim/ModelDatabase.hx

@@ -20,6 +20,9 @@ class ModelDatabase {
 
 	static var defaultLodConfigs : Map<String, Array<Float>> = new Map();
 	static var baseLodConfig = [ 0.5, 0.2, 0.01];
+	public static dynamic function customizeLodConfig(c : Array<Float>) {
+		return c;
+	}
 
 	function new() {
 	}
@@ -74,20 +77,19 @@ class ModelDatabase {
 
 	function getDefaultLodConfig( dir : String ) : Array<Float> {
 		var fs = Std.downcast(hxd.res.Loader.currentInstance.fs, hxd.fs.LocalFileSystem);
-		if (fs == null)
-			return baseLodConfig;
-
+		var c = baseLodConfig;
 		#if (sys || nodejs)
-			var c = @:privateAccess fs.convert.getConfig(defaultLodConfigs, baseLodConfig, dir, function(fullObj) {
+		if (fs != null) {
+			c = @:privateAccess fs.convert.getConfig(defaultLodConfigs, baseLodConfig, dir, function(fullObj) {
 				if (Reflect.hasField(fullObj, "lods.screenRatio"))
 					return Reflect.field(fullObj, "lods.screenRatio");
 
 				return baseLodConfig;
 			});
-			return c;
-		#else
-			return baseLodConfig;
+		}
 		#end
+		c = customizeLodConfig(c);
+		return c;
 	}
 
 	// Used to clean previous version of modelDatabase, should be removed after some time