Skip to content

Commit 0527eea

Browse files
Add capture screen with transparent background
1 parent 4e37565 commit 0527eea

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

bin/app.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
<menu label="Gpu mem dump" class="gpudump"></menu>
136136
</menu>
137137
<menu label="Screen Capture" class="screen-capture"></menu>
138+
<menu label="Capture Transparent BG" class="capture-transparentBG"></menu>
138139
</menu>
139140

140141
<menu label="Settings" class="settings">

hide_js/hide/Ide.hx

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,64 @@ class Ide extends hide.tools.IdeData {
16821682
config.global.save();
16831683
});
16841684

1685+
menu.find(".capture-transparentBG").click(function(_) {
1686+
var currentView : hide.ui.View<Dynamic> = null;
1687+
for (v in views) {
1688+
if (v.isActive())
1689+
currentView = v;
1690+
}
1691+
1692+
var scene : hide.comp.Scene = null;
1693+
var modelView = Std.downcast(currentView, hide.view.Model);
1694+
if (modelView != null)
1695+
scene = @:privateAccess modelView.scene;
1696+
var prefabView = Std.downcast(currentView, hide.view.Prefab);
1697+
if (prefabView != null)
1698+
scene = @:privateAccess prefabView.scene;
1699+
var fxView = Std.downcast(currentView, hide.view.FXEditor);
1700+
if (fxView != null)
1701+
scene = @:privateAccess fxView.scene;
1702+
1703+
if (scene == null) {
1704+
quickError("Active view isn't capturable");
1705+
return;
1706+
}
1707+
1708+
chooseFileSave("capture.png", (path) -> {
1709+
var renderer = Std.downcast(scene.s3d.renderer, h3d.scene.pbr.Renderer);
1710+
if(renderer == null) {
1711+
quickError("Renderer not available for screen capture");
1712+
return;
1713+
}
1714+
1715+
var textureRes = ideConfig.screenCaptureResolution;
1716+
var renderTexture = new h3d.mat.Texture(Std.int(textureRes * scene.s3d.camera.screenRatio), textureRes, [Target], RGBA);
1717+
renderTexture.depthBuffer = new h3d.mat.Texture(renderTexture.width, renderTexture.height, Depth24Stencil8);
1718+
renderTexture.clear(0, 0);
1719+
var prevBackgroundColor = scene.engine.backgroundColor;
1720+
var prevSkyMode = renderer.skyMode;
1721+
var props : h3d.scene.pbr.Renderer.RenderProps = renderer.props;
1722+
var prevForceDirectDiscard = props.forceDirectDiscard;
1723+
1724+
scene.engine.backgroundColor &= 0x00FFFFFF;
1725+
scene.s3d.setOutputTarget(scene.engine, renderTexture);
1726+
renderer.skyMode = Hide;
1727+
props.forceDirectDiscard = true;
1728+
1729+
scene.s3d.render(scene.engine);
1730+
scene.s3d.setOutputTarget();
1731+
1732+
scene.engine.backgroundColor = prevBackgroundColor;
1733+
renderer.skyMode = prevSkyMode;
1734+
props.forceDirectDiscard = prevForceDirectDiscard;
1735+
1736+
var pixels = renderTexture.capturePixels();
1737+
var absPath = getPath(path);
1738+
sys.io.File.saveBytes(absPath, pixels.toPNG());
1739+
quickMessage('Screen capture saved at ${path}');
1740+
});
1741+
});
1742+
16851743
menu.find(".screen-capture").click(function(_) {
16861744
var currentView : hide.ui.View<Dynamic> = null;
16871745
for (v in views) {
@@ -1717,7 +1775,7 @@ class Ide extends hide.tools.IdeData {
17171775

17181776
var pixels = renderTexture.capturePixels();
17191777
var absPath = getPath(path);
1720-
sys.io.File.saveBytes(absPath, pixels.toPNG(0));
1778+
sys.io.File.saveBytes(absPath, pixels.toPNG());
17211779
quickMessage('Screen capture saved at ${path}');
17221780
});
17231781
});

0 commit comments

Comments
 (0)