Browse Source

[scene] added setRenderProps, refactored from ShaderEditor

Clément Espeute 8 months ago
parent
commit
ca64a525d7
2 changed files with 31 additions and 27 deletions
  1. 30 0
      hide/comp/Scene.hx
  2. 1 27
      hide/view/shadereditor/ShaderEditor.hx

+ 30 - 0
hide/comp/Scene.hx

@@ -25,6 +25,8 @@ 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;
+
 	public var errorMessageBox : Element;
 	var unFocusedTime = 0.;
 
@@ -553,6 +555,34 @@ class Scene extends hide.comp.Component implements h3d.IDrawable {
 		s2d.render(e);
 	}
 
+	public function setRenderProps(path: String) {
+		var pbrRenderer = Std.downcast(s3d.renderer, h3d.scene.pbr.Renderer);
+		if ( pbrRenderer != null ) {
+			pbrRenderer.env = h3d.scene.pbr.Environment.getDefault();
+		}
+
+		if (currentRenderProps != null) {
+			currentRenderProps.shared.root3d.remove();
+			currentRenderProps.dispose();
+		}
+		currentRenderProps = null;
+
+		if (path == null)
+			return;
+		try {
+			currentRenderProps = Ide.inst.loadPrefab(path);
+		} catch(e) {
+			return;
+		}
+		var ctx = new hide.prefab.ContextShared(null, new h3d.scene.Object(s3d));
+		ctx.scene = this;
+		currentRenderProps.setSharedRec(ctx);
+		currentRenderProps.make();
+		var renderProps = currentRenderProps.getOpt(hrt.prefab.RenderProps, true);
+		if (renderProps != null)
+			renderProps.applyProps(s3d.renderer);
+	}
+
 	public dynamic function onUpdate(dt:Float) {
 	}
 

+ 1 - 27
hide/view/shadereditor/ShaderEditor.hx

@@ -1174,33 +1174,7 @@ class ShaderEditor extends hide.view.FileView implements GraphInterface.IGraphEd
 	}
 
 	public function refreshRenderProps() {
-		var pbrRenderer = Std.downcast(meshPreviewScene.s3d.renderer, h3d.scene.pbr.Renderer);
-		if ( pbrRenderer != null ) {
-			pbrRenderer.env = h3d.scene.pbr.Environment.getDefault();
-		}
-
-		if (meshPreviewRenderProps != null) {
-			meshPreviewRenderProps.dispose();
-		}
-
-		if (meshPreviewRenderPropsRoot != null) {
-			meshPreviewRenderPropsRoot.remove();
-		}
-		meshPreviewRenderPropsRoot = new h3d.scene.Object(meshPreviewScene.s3d);
-		if (previewSettings.renderPropsPath == null)
-			return;
-		try {
-			meshPreviewRenderProps = Ide.inst.loadPrefab(previewSettings.renderPropsPath);
-		} catch(e) {
-			return;
-		}
-		var ctx = new hide.prefab.ContextShared(null, meshPreviewRenderPropsRoot);
-		ctx.scene = meshPreviewScene;
-		meshPreviewRenderProps.setSharedRec(ctx);
-		meshPreviewRenderProps.make();
-		var renderProps = meshPreviewRenderProps.getOpt(hrt.prefab.RenderProps, true);
-		if (renderProps != null)
-			renderProps.applyProps(meshPreviewScene.s3d.renderer);
+		meshPreviewScene.setRenderProps(previewSettings.renderPropsPath);
 	}
 
 	public function dispose() {