ソースを参照

Drop support for internal references prefabs (#127)

A reference can now only reference a file and not another prefab in the
same scene.
Leonardo Jeanteur 4 年 前
コミット
43fc9ddd95
2 ファイル変更35 行追加95 行削除
  1. 8 26
      hide/comp/SceneEditor.hx
  2. 27 69
      hrt/prefab/Reference.hx

+ 8 - 26
hide/comp/SceneEditor.hx

@@ -516,11 +516,10 @@ class SceneEditor {
 				{ label : "Rename", enabled : current != null, click : function() tree.editNode(current) },
 				{ label : "Delete", enabled : current != null, click : function() deleteElements(curEdit.rootElements) },
 				{ label : "Duplicate", enabled : current != null, click : duplicate.bind(false) },
-				{ label : "Reference", enabled : current != null, click : function() createRef(current, current.parent) },
 			];
 
 			var isObj = current != null && (current.to(Object3D) != null || current.to(Object2D) != null);
-			var isRef = current != null && current.to(hrt.prefab.Reference) != null;
+			var isRef = isReference(current);
 
 			if( isObj ) {
 				var visible = !isHidden(current);
@@ -1828,7 +1827,7 @@ class SceneEditor {
 
 	public function setEnabled(elements : Array<PrefabElement>, enable: Bool) {
 		// Don't disable/enable Object3Ds, too confusing with visibility
-		elements = [for(e in elements) if(e.to(Object3D) == null || e.to(hrt.prefab.Reference) != null) e];
+		elements = [for(e in elements) if(e.to(Object3D) == null || isReference(e)) e];
 		var old = [for(e in elements) e.enabled];
 		function apply(on) {
 			for(i in 0...elements.length) {
@@ -1944,25 +1943,6 @@ class SceneEditor {
 		setVisible(toHide, false);
 	}
 
-	function createRef(elt: PrefabElement, toParent: PrefabElement) {
-		var ref = new hrt.prefab.Reference(toParent);
-		ref.name = elt.name;
-		ref.source = "/"+elt.getAbsPath();
-		var obj3d = Std.downcast(elt, Object3D);
-		if(obj3d != null) {
-			ref.x = obj3d.x;
-			ref.y = obj3d.y;
-			ref.z = obj3d.z;
-			ref.scaleX = obj3d.scaleX;
-			ref.scaleY = obj3d.scaleY;
-			ref.scaleZ = obj3d.scaleZ;
-			ref.rotationX = obj3d.rotationX;
-			ref.rotationY = obj3d.rotationY;
-			ref.rotationZ = obj3d.rotationZ;
-		}
-		addElements([ref]);
-	}
-
 	function duplicate(thenMove: Bool) {
 		if(curEdit == null) return;
 		var elements = curEdit.rootElements;
@@ -2078,10 +2058,8 @@ class SceneEditor {
 		if( to == null )
 			to = sceneData;
 
-		{
-			var ref = Std.downcast(to, Reference);
-			@:privateAccess if( ref != null && ref.editMode ) to = ref.ref;
-		}
+		var ref = Std.downcast(to, Reference);
+		@:privateAccess if( ref != null && ref.editMode ) to = ref.ref;
 
 		var effectFunc = reparentImpl(e, to, index);
 		undo.change(Custom(function(undo) {
@@ -2589,6 +2567,10 @@ class SceneEditor {
 		return bestVertex;
 	}
 
+	static function isReference( what : PrefabElement ) : Bool {
+		return what != null && what.to(hrt.prefab.Reference) != null;
+	}
+
 	static function getPivot(objects: Array<Object>) {
 		if (customPivot != null) {
 			return customPivot.mesh.localToGlobal(customPivot.locPos.toPoint());

+ 27 - 69
hrt/prefab/Reference.hx

@@ -19,17 +19,10 @@ class Reference extends Object3D {
 		}
 	}
 
-	public function isFile() {
-		return source != null && source.charCodeAt(0) != "/".code;
-	}
-
 	override function save() {
-		// Recalc abs path if ref has been resolved to supprot renaming
-		if( ref != null && !isFile() )
-			source = "/"+ref.getAbsPath();
 		var obj : Dynamic = super.save();
 		#if editor
-		if( editMode && isFile() && ref != null )
+		if( editMode && ref != null )
 			hide.Ide.inst.savePrefab(source, ref);
 		#end
 		return obj;
@@ -40,32 +33,16 @@ class Reference extends Object3D {
 			return ref;
 		if(source == null)
 			return null;
-		if(isFile()) {
-			if(shared == null) { // Allow resolving ref in Hide prefore makeInstance
-				#if editor
-				ref = hide.Ide.inst.loadPrefab(source, null, true);
-				#else
-				return null;
-				#end
-			}
-			else
-				ref = shared.loadPrefab(source);
-			return ref;
-		}
-		else {
-			var lib = getParent(hrt.prefab.Library);
-			if(lib == null)
-				return null;
-			var all = lib.getAll(Prefab);
-			var path = source.substr(1);
-			for(p in all) {
-				if(!Std.is(p, Reference) && p.getAbsPath() == path) {
-					ref = p;
-					return ref;
-				}
-			}
+		if(shared == null) { // Allow resolving ref in Hide prefore makeInstance
+			#if editor
+			ref = hide.Ide.inst.loadPrefab(source, null, true);
+			#else
+			return null;
+			#end
 		}
-		return null;
+		else
+			ref = shared.loadPrefab(source);
+		return ref;
 	}
 
 	override function updateInstance( ctx: Context, ?propName : String ) {
@@ -108,33 +85,23 @@ class Reference extends Object3D {
 		if(p == null)
 			return ctx;
 
-		if(isFile()) {
-			ctx = super.makeInstance(ctx);
-			var prevShared = ctx.shared;
-			ctx.shared = ctx.shared.cloneRef(this, source);
-			makeChildren(ctx, p);
-			ctx.shared = prevShared;
+		ctx = super.makeInstance(ctx);
+		var prevShared = ctx.shared;
+		ctx.shared = ctx.shared.cloneRef(this, source);
+		makeChildren(ctx, p);
+		ctx.shared = prevShared;
 
-			#if editor
-			if (ctx.local2d == null) {
-				var path = hide.Ide.inst.appPath + "/res/icons/fileRef.png";
-				var data = sys.io.File.getBytes(path);
-				var tile = hxd.res.Any.fromBytes(path, data).toTile().center();
-				var objFollow = new h2d.ObjectFollower(ctx.local3d, ctx.shared.root2d);
-				objFollow.followVisibility = true;
-				var bmp = new h2d.Bitmap(tile, objFollow);
-				ctx.local2d = objFollow;
-			}
-			#end
-
-		}
-		else {
-			ctx = ctx.clone(this);
-			ctx.isSceneReference = true;
-			var refCtx = p.make(ctx); // no customMake here
-			ctx.local3d = refCtx.local3d;
-			updateInstance(ctx);
+		#if editor
+		if (ctx.local2d == null) {
+			var path = hide.Ide.inst.appPath + "/res/icons/fileRef.png";
+			var data = sys.io.File.getBytes(path);
+			var tile = hxd.res.Any.fromBytes(path, data).toTile().center();
+			var objFollow = new h2d.ObjectFollower(ctx.local3d, ctx.shared.root2d);
+			objFollow.followVisibility = true;
+			var bmp = new h2d.Bitmap(tile, objFollow);
+			ctx.local2d = objFollow;
 		}
+		#end
 
 		return ctx;
 	}
@@ -169,7 +136,7 @@ class Reference extends Object3D {
 		var element = new hide.Element('
 			<div class="group" name="Reference">
 			<dl>
-				<dt>Reference</dt><dd><input type="text" field="source"/></dd>
+				<dt>Reference</dt><dd><input type="fileselect" extensions="prefab l3d" field="source"/></dd>
 				<dt>Edit</dt><dd><input type="checkbox" field="editMode"/></dd>
 			</dl>
 			</div>');
@@ -181,18 +148,9 @@ class Reference extends Object3D {
 		}
 		updateProps();
 
-		element.find("input").contextmenu((e) -> {
-			e.preventDefault();
-			if( isFile() ) {
-				new hide.comp.ContextMenu([
-					{ label : "Open", click : () -> ctx.ide.openFile(ctx.ide.getPath(source)) },
-				]);
-			}
-		});
-
 		var props = ctx.properties.add(element, this, function(pname) {
 			ctx.onChange(this, pname);
-			if(pname == "source" || pname=="editMode") {
+			if(pname == "source" || pname == "editMode") {
 				ref = null;
 				updateProps();
 				if(!ctx.properties.isTempChange)