Tom SPIRA пре 6 година
родитељ
комит
e82d34dd43
4 измењених фајлова са 51 додато и 9 уклоњено
  1. 16 5
      hide/comp/Scene.hx
  2. 18 0
      hide/comp/SceneEditor.hx
  3. 3 2
      hide/view/FileView.hx
  4. 14 2
      hide/view/Model.hx

+ 16 - 5
hide/comp/Scene.hx

@@ -289,14 +289,14 @@ class Scene extends Component implements h3d.IDrawable {
 		return { root : root, camera : hsd.camera };
 	}
 
-	public function loadModel( path : String, mainScene = false ) {
+	public function loadModel( path : String, mainScene = false, reload = false ) {
 		checkCurrent();
 		if( StringTools.endsWith(path.toLowerCase(), ".hsd") ) {
 			var hsd = loadHSD(path);
 			if( mainScene ) defaultCamera = hsd.camera;
 			return hsd.root;
 		}
-		var lib = loadHMD(path,false);
+		var lib = loadHMD(path, false, reload);
 		return lib.makeObject(loadTexture.bind(path));
 	}
 
@@ -380,18 +380,18 @@ class Scene extends Component implements h3d.IDrawable {
 		return t;
 	}
 
-	function loadHMD( path : String, isAnimation : Bool ) {
+	function loadHMD( path : String, isAnimation : Bool, reload = false ) {
 		checkCurrent();
 		var fullPath = ide.getPath(path);
 		var key = fullPath;
 		var hmd = hmdCache.get(key);
 
-		if( hmd != null )
+		if( !reload && hmd != null )
 			return hmd;
 
 		var relPath = StringTools.startsWith(path, ide.resourceDir) ? path.substr(ide.resourceDir.length+1) : path;
 		var e = try hxd.res.Loader.currentInstance.load(relPath) catch( e : hxd.res.NotFound ) null;
-		if( e == null ) {
+		if( e == null || reload ) {
 			var data = sys.io.File.getBytes(fullPath);
 			if( data.get(0) != 'H'.code ) {
 				var hmdOut = new hxd.fmt.fbx.HMDOut(fullPath);
@@ -407,6 +407,17 @@ class Scene extends Component implements h3d.IDrawable {
 			hmd = e.toModel().toHmd();
 		}
 
+		if (!reload) {
+			e.watch(function() {
+				var lib = e.toModel().toHmd();
+				hmdCache.set(key, lib);
+				editor.onResourceChanged(lib);
+			});
+			cleanup.push(function() {
+				e.watch(null);
+			});
+		}
+
 		hmdCache.set(key, hmd);
 		return hmd;
 	}

+ 18 - 0
hide/comp/SceneEditor.hx

@@ -202,6 +202,24 @@ class SceneEditor {
 		}
 	}
 
+	public function onResourceChanged(lib : hxd.fmt.hmd.Library) {
+
+		var models = sceneData.findAll(p -> Std.instance(p, PrefabElement));
+		var toRebuild : Array<PrefabElement> = [];
+		for(m in models) {
+			@:privateAccess if(m.source == lib.resource.entry.path) {
+				if (toRebuild.indexOf(m) < 0) {
+					toRebuild.push(m);
+				}
+			}
+		}
+
+		for(m in toRebuild) {
+			removeInstance(m);
+			makeInstance(m);
+		}
+	}
+
 	public dynamic function onResize() {
 	}
 

+ 3 - 2
hide/view/FileView.hx

@@ -21,7 +21,7 @@ class FileView extends hide.ui.View<{ path : String }> {
 			}, { checkDelete : true, keepOnRebuild : true });
 	}
 
-	function onFileChanged( wasDeleted : Bool ) {
+	function onFileChanged( wasDeleted : Bool, rebuildView = true ) {
 		if( !wasDeleted ) {
 			// double check if content has changed
 			var content = sys.io.File.getContent(getPath());
@@ -37,7 +37,8 @@ class FileView extends hide.ui.View<{ path : String }> {
 		if( modified && !ide.confirm('${state.path} has been modified, reload and ignore local changes?') )
 			return;
 		modified = false;
-		rebuild();
+		if (rebuildView)
+			rebuild();
 	}
 
 	function get_extension() {

+ 14 - 2
hide/view/Model.hx

@@ -47,6 +47,17 @@ class Model extends FileView {
 		super.save();
 	}
 
+	override function onFileChanged( wasDeleted : Bool, rebuildView = true ) {
+		if (wasDeleted ) {
+			super.onFileChanged(wasDeleted);
+		} else if (element.find(".heaps-scene").length == 0) {
+			super.onFileChanged(wasDeleted);
+		} else {
+			super.onFileChanged(wasDeleted, false);
+			onRefresh();
+		}
+	}
+
 	function loadProps() {
 		var propsPath = getPropsPath();
 		var hideData : h3d.prim.ModelCache.HideProps;
@@ -300,7 +311,6 @@ class Model extends FileView {
 	}
 
 	function onRefresh() {
-
 		var r = root.get(hrt.prefab.RenderProps);
 		if( r != null ) r.applyProps(scene.s3d.renderer);
 
@@ -312,7 +322,9 @@ class Model extends FileView {
 
 		undo.onChange = function() {};
 
-		obj = scene.loadModel(state.path, true);
+		if (obj != null)
+			obj.remove();
+		obj = scene.loadModel(state.path, true, true);
 		new h3d.scene.Object(scene.s3d).addChild(obj);
 
 		var autoHide : Array<String> = config.get("scene.autoHide");