Skip to content

Commit

Permalink
[scene] added setRenderProps, refactored from ShaderEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
EspeuteClement committed Jan 6, 2025
1 parent 9085527 commit ca64a52
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
30 changes: 30 additions & 0 deletions hide/comp/Scene.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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.;

Expand Down Expand Up @@ -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) {
}

Expand Down
28 changes: 1 addition & 27 deletions hide/view/shadereditor/ShaderEditor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ca64a52

Please sign in to comment.