Selaa lähdekoodia

[scene] Auto load a render props in ScenePreview

Clément Espeute 8 kuukautta sitten
vanhempi
commit
c040c1a379
2 muutettua tiedostoa jossa 49 lisäystä ja 12 poistoa
  1. 16 12
      hide/comp/Scene.hx
  2. 33 0
      hide/comp/ScenePreview.hx

+ 16 - 12
hide/comp/Scene.hx

@@ -25,7 +25,7 @@ class Scene extends hide.comp.Component implements h3d.IDrawable {
 	public var editor : hide.comp.SceneEditor;
 	public var autoDisposeOutOfDocument : Bool = true;
 
-	var currentRenderProps: hrt.prefab.Prefab;
+	var currentRenderProps: hrt.prefab.Reference;
 
 	public var errorMessageBox : Element;
 	var unFocusedTime = 0.;
@@ -579,20 +579,24 @@ class Scene extends hide.comp.Component implements h3d.IDrawable {
 		}
 		currentRenderProps = null;
 
-		if (path == null)
-			return;
-		try {
-			currentRenderProps = Ide.inst.loadPrefab(path);
-		} catch(e) {
+		if (path == null) {
 			return;
 		}
-		var ctx = new hide.prefab.ContextShared(null, new h3d.scene.Object(s3d));
-		ctx.scene = this;
-		currentRenderProps.setSharedRec(ctx);
+		currentRenderProps = new hrt.prefab.Reference(null, new hide.prefab.ContextShared(null, new h3d.scene.Object(s3d)));
+		currentRenderProps.shared.scene = this;
+		currentRenderProps.source = path;
+
 		currentRenderProps.make();
-		var renderProps = currentRenderProps.getOpt(hrt.prefab.RenderProps, true);
-		if (renderProps != null)
-			renderProps.applyProps(s3d.renderer);
+
+		if (currentRenderProps.refInstance != null) {
+			var renderProps = currentRenderProps.refInstance.getOpt(hrt.prefab.RenderProps, true);
+			if (renderProps != null)
+				renderProps.applyProps(s3d.renderer);
+
+			for (light in currentRenderProps.refInstance.findAll(hrt.prefab.Light, true)) {
+				@:privateAccess light.icon.visible = false;
+			}
+		}
 	}
 
 	public dynamic function onUpdate(dt:Float) {

+ 33 - 0
hide/comp/ScenePreview.hx

@@ -2,6 +2,7 @@ package hide.comp;
 
 class ScenePreviewSettings {
     public var modelPath: String = null;
+	public var renderPropsPath: String = null;
 
     public function new() {};
 }
@@ -32,6 +33,7 @@ class ScenePreview extends Scene {
 		super.preOnReady();
 
 		loadSettings();
+		loadSavedRenderProps();
 
 		cameraController = new hide.comp.Scene.PreviewCamController(s3d);
 
@@ -53,6 +55,37 @@ class ScenePreview extends Scene {
 		}
 	}
 
+	function listRenderProps() : Array<{name: String, value: String}> {
+		var renderProps = config.getLocal("scene.renderProps");
+		var ret : Array<{name: String, value: String}> = [];
+
+		if (renderProps is String) {
+			ret.push({name: "default", value: renderProps});
+		} else if (renderProps is Array) {
+			var renderProps : Array<Dynamic> = cast renderProps;
+			for (renderProp in renderProps) {
+				ret.push({name: renderProp.name, value: renderProp.value});
+			}
+		}
+		return ret;
+	}
+
+	function loadSavedRenderProps() {
+		var path = null;
+		var renderProps = listRenderProps();
+		var rp = renderProps[0];
+		for (prop in renderProps) {
+			if (prop.value == previewSettings.renderPropsPath) {
+				rp = prop;
+			}
+		}
+
+		trace("renderprops", rp);
+		setRenderProps(rp.value);
+		previewSettings.renderPropsPath = rp.value;
+		saveSettings();
+	}
+
 	public function resetPreviewCamera() {
 		if (prefab == null)
 			return;