瀏覽代碼

remove model props handling

ncannasse 6 年之前
父節點
當前提交
1f7e1236b2
共有 4 個文件被更改,包括 33 次插入49 次删除
  1. 1 0
      bin/defaultProps.json
  2. 4 32
      hide/comp/Scene.hx
  3. 28 15
      hide/view/Model.hx
  4. 0 2
      hide/view/l3d/Level3D.hx

+ 1 - 0
bin/defaultProps.json

@@ -1,6 +1,7 @@
 {
 	// define location of animations in HMD files
 	"hmd.animPaths" : [],
+	"hmd.savePropsByAnimation" : false,
 
 	// path to js scripts containing hide plugins
 	"plugins" : [],

+ 4 - 32
hide/comp/Scene.hx

@@ -72,7 +72,6 @@ class Scene extends Component implements h3d.IDrawable {
 	public var visible(default, null) : Bool = true;
 	public var editor : hide.comp.SceneEditor;
 	public var refreshIfUnfocused = false;
-	public var loadHMDData = true;
 
 	public function new(config, parent, el) {
 		super(parent,el);
@@ -256,9 +255,11 @@ class Scene extends Component implements h3d.IDrawable {
 		for( dir in dirs ) {
 			var dir = dir;
 			if( StringTools.endsWith(dir, "/") ) dir = dir.substr(0,-1);
-			for( f in try sys.FileSystem.readDirectory(dir) catch( e : Dynamic ) [] )
-				if( StringTools.startsWith(f,"Anim_") )
+			for( f in try sys.FileSystem.readDirectory(dir) catch( e : Dynamic ) [] ) {
+				var file = f.toLowerCase();
+				if( StringTools.startsWith(f,"Anim_") && (StringTools.endsWith(file,".hmd") || StringTools.endsWith(file,".fbx")) )
 					anims.push(dir+"/"+f);
+			}
 		}
 		return anims;
 	}
@@ -296,40 +297,11 @@ class Scene extends Component implements h3d.IDrawable {
 			return hsd.root;
 		}
 		var lib = loadHMD(path,false);
-
-		if(loadHMDData) {
-			function loadHideData( path : String ) : hxd.fmt.hmd.Library.HideData {
-				var relPath = StringTools.startsWith(path, ide.resourceDir) ? path.substr(ide.resourceDir.length+1) : path;
-				var parts = relPath.split("/");
-				parts.pop();
-				var propsPath = parts.join("/") + "/model.props";
-				if(!hxd.res.Loader.currentInstance.exists(propsPath)) return null;
-				var props = hxd.res.Loader.currentInstance.load(propsPath).toText();
-				var hideData : hxd.fmt.hmd.Library.HideData;
-				hideData = haxe.Json.parse(props);
-				return hideData;
-			}
-			lib.hideData = loadHideData(path);
-		}
-
 		return lib.makeObject(loadTexture.bind(path));
 	}
 
 	public function loadAnimation( path : String ) {
 		var lib = loadHMD(path,true);
-
-		// HideData
-		if(loadHMDData) {
-			var relPath = StringTools.startsWith(path, ide.resourceDir) ? path.substr(ide.resourceDir.length+1) : path;
-			var parts = relPath.split("/");
-			parts.pop();
-			var propsPath = parts.join("/") + "/model.props";
-			if( propsPath != null && hxd.res.Loader.currentInstance.exists(propsPath)){
-				var props = hxd.res.Loader.currentInstance.load(propsPath).toText();
-				lib.hideData = haxe.Json.parse(props);
-			}
-		}
-
 		return lib.loadAnimation();
 	}
 

+ 28 - 15
hide/view/Model.hx

@@ -29,19 +29,8 @@ class Model extends FileView {
 	override function save() {
 		if(!modified) return;
 		// Save current Anim data
-		if(obj.currentAnimation != null){
-			var path = getPath();
-			var relPath = StringTools.startsWith(path, ide.resourceDir) ? path.substr(ide.resourceDir.length+1) : path;
-			var parts = relPath.split("/");
-			parts.pop();
-			var propsPath = parts.join("/") + "/model.props";
-			var hideData : hxd.fmt.hmd.Library.HideData;
-			if( hxd.res.Loader.currentInstance.exists(propsPath)){
-				var props = hxd.res.Loader.currentInstance.load(propsPath).toText();
-				hideData = haxe.Json.parse(props);
-			}
-			else
-				hideData = { animations : {} };
+		if( currentAnimation != null ) {
+			var hideData = loadProps();
 
 			var events : Array<{ frame : Int, data : String }> = [];
 			for(i in 0 ... obj.currentAnimation.events.length){
@@ -49,15 +38,33 @@ class Model extends FileView {
 				for( e in obj.currentAnimation.events[i])
 					events.push({frame:i, data:e});
 			}
-			hideData.animations.set(currentAnimation.name, {events : events} );
+			hideData.animations.set(currentAnimation.file.split("/").pop(), {events : events} );
 
 			var bytes = new haxe.io.BytesOutput();
 			bytes.writeString(haxe.Json.stringify(hideData, "\t"));
-			hxd.File.saveBytes(ide.getPath(propsPath), bytes.getBytes());
+			hxd.File.saveBytes(getPropsPath(), bytes.getBytes());
 		}
 		super.save();
 	}
 
+	function loadProps() {
+		var propsPath = getPropsPath();
+		var hideData : h3d.prim.ModelCache.HideProps;
+		if( sys.FileSystem.exists(propsPath) )
+			hideData = haxe.Json.parse(sys.io.File.getContent(propsPath));
+		else
+			hideData = { animations : {} };
+		return hideData;
+	}
+
+	function getPropsPath() {
+		var path = config.get("hmd.savePropsByAnimation") ? currentAnimation.file : getPath();
+		var parts = path.split(".");
+		parts.pop();
+		parts.push("props");
+		return ide.getPath(parts.join("."));
+	}
+
 	override function onDisplay() {
 		element.html('
 			<div class="flex vertical">
@@ -455,6 +462,12 @@ class Model extends FileView {
 		}
 		var anim = scene.loadAnimation(file);
 		currentAnimation = { file : file, name : scene.animationName(file) };
+
+		var hideData = loadProps();
+		var animData = hideData.animations.get(currentAnimation.file.split("/").pop());
+		if( animData != null && animData.events != null )
+			anim.setEvents(animData.events);
+
 		obj.playAnimation(anim);
 		buildTimeline();
 		buildEventPanel();

+ 0 - 2
hide/view/l3d/Level3D.hx

@@ -361,8 +361,6 @@ class Level3D extends FileView {
 			data.edit(edit);
 		}
 
-		scene.loadHMDData = false;
-
 		refreshSceneFilters();
 	}