Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added further selectors for model and texture viewer and export button for shader program blob #68

Merged
merged 3 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
@Selector(type = @Type(name = "PrefabResource")),
@Selector(type = @Type(name = "PrefabInstance")),
@Selector(type = @Type(name = "ModelPartResource")),
@Selector(type = @Type(name = "HumanoidBodyVariant"), game = GameType.HZD),
@Selector(type = @Type(name = "HairModelComponentResource")),
@Selector(type = @Type(name = "HairSkinnedMeshLod")),
@Selector(type = @Type(name = "HairSkinnedMesh")),
@Selector(type = @Type(name = "SkinnedModelResource"), game = GameType.HZD),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ private static Node serialize(
serializeStaticMeshInstance(task.split(1), node, object, file, project, context);
case "SkinnedModelResource" ->
serializeSkinnedModelResource(task.split(1), node, object, file, project, context);
case "HumanoidBodyVariant" ->
serializeHumanoidBodyVariant(task.split(1), node, object, file, project, context);
case "ObjectCollection" ->
serializeObjectCollection(task.split(1), node, object, file, project, context);
case "PrefabResource" ->
serializePrefabResource(task.split(1), node, object, file, project, context);
case "PrefabInstance" ->
serializePrefabInstance(task.split(1), node, object, file, project, context);
case "HairModelComponentResource" ->
serializeHairModelComponentResource(task.split(1), node, object, file, project, context);
case "HairResource" ->
serializeHairResource(task.split(1), node, object, file, project, context);
case "HairSkinnedMeshLod" ->
Expand All @@ -144,6 +148,21 @@ private static Node serialize(
return node;
}

private static void serializeHairModelComponentResource(
@NotNull ProgressMonitor monitor,
@NotNull Node parent,
@NotNull RTTIObject object,
@NotNull RTTICoreFile file,
@NotNull Project project,
@NotNull Context context
) throws IOException {
final Node child = serialize(monitor, object.ref("HairResource"), file, project, context);

if (child != null) {
parent.add(child);
}
}

private static void serializeHairResource(
@NotNull ProgressMonitor monitor,
@NotNull Node parent,
Expand Down Expand Up @@ -294,6 +313,21 @@ private static void serializeSkinnedModelResource(
}
}

private static void serializeHumanoidBodyVariant(
@NotNull ProgressMonitor monitor,
@NotNull Node parent,
@NotNull RTTIObject object,
@NotNull RTTICoreFile file,
@NotNull Project project,
@NotNull Context context
) throws IOException {
final Node child = serialize(monitor, object.ref("ModelPartResource"), file, project, context);

if (child != null) {
parent.add(child);
}
}

private static void serializeStaticMeshInstance(
@NotNull ProgressMonitor monitor,
@NotNull Node parent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
import com.shade.decima.ui.data.ValueController;
import com.shade.decima.ui.data.viewer.shader.com.*;
import com.shade.decima.ui.data.viewer.shader.settings.ShaderViewerSettings;
import com.shade.platform.ui.controls.FileChooser;
import com.shade.platform.ui.util.UIUtils;
import com.shade.util.NotNull;
import com.sun.jna.ptr.PointerByReference;
import net.miginfocom.swing.MigLayout;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.file.Files;
import java.util.Objects;

public class ShaderViewerPanel extends JComponent {
Expand Down Expand Up @@ -66,9 +72,42 @@ public ProgramPanel(@NotNull HwShader.Entry entry) {
area.setText(text);
});

final JToolBar mainToolbar = new JToolBar();
mainToolbar.add(new ExportAction(entry));
mainToolbar.add(button);

setLayout(new MigLayout("ins panel,wrap", "[grow,fill]", "[grow,fill][]"));
add(new JScrollPane(area));
add(button);
add(mainToolbar);
}

private class ExportAction extends AbstractAction {
final private byte[] programBlob;

public ExportAction(@NotNull HwShader.Entry entry) {
programBlob = entry.program().blob();
putValue(SMALL_ICON, UIManager.getIcon("Action.exportIcon"));
putValue(SHORT_DESCRIPTION, "Export binary data");
setEnabled(true);
}

@Override
public void actionPerformed(ActionEvent event) {
final JFileChooser chooser = new FileChooser();
chooser.setDialogTitle("Export binary data as");
chooser.setSelectedFile(new File("exported.bin"));
chooser.setAcceptAllFileFilterUsed(true);

if (chooser.showSaveDialog(JOptionPane.getRootFrame()) != JFileChooser.APPROVE_OPTION) {
return;
}

try {
Files.write(chooser.getSelectedFile().toPath(), programBlob);
} catch (IOException e) {
UIUtils.showErrorDialog(e, "Error exporting data");
}
}
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.shade.decima.ui.data.viewer.shader.settings;

import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.SystemInfo;
import com.shade.decima.ui.controls.FileExtensionFilter;
import com.shade.decima.ui.controls.LabeledBorder;
import com.shade.decima.ui.controls.validators.ExistingFileValidator;
Expand All @@ -24,7 +25,8 @@ public class ShaderViewerSettingsPage implements SettingsPage {
@Override
public JComponent createComponent(@NotNull PropertyChangeListener listener) {
{
final FileExtensionFilter filter = new FileExtensionFilter("Direct3D compiler library", "dll");
final String extension = SystemInfo.isMacOS ? "dylib" : SystemInfo.isLinux ? "so" : "dll";
final FileExtensionFilter filter = new FileExtensionFilter("Direct3D compiler library", extension);

d3dCompilerPath = new JTextField();
d3dCompilerPath.putClientProperty(FlatClientProperties.PLACEHOLDER_TEXT, "d3dcompiler.dll");
Expand All @@ -33,7 +35,8 @@ public JComponent createComponent(@NotNull PropertyChangeListener listener) {
}

{
final FileExtensionFilter filter = new FileExtensionFilter("DirectX compiler library", "dll");
final String extension = SystemInfo.isMacOS ? "dylib" : SystemInfo.isLinux ? "so" : "dll";
final FileExtensionFilter filter = new FileExtensionFilter("DirectX compiler library", extension);

dxCompilerPath = new JTextField();
dxCompilerPath.putClientProperty(FlatClientProperties.PLACEHOLDER_TEXT, "dxcompiler.dll");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
@Selector(type = @Type(name = "TextureSetEntry")),
@Selector(type = @Type(name = "TextureList")),
@Selector(type = @Type(name = "TextureBindingWithHandle")),
@Selector(type = @Type(name = "ShaderTextureBinding")),
@Selector(type = @Type(name = "UITexture")),
@Selector(type = @Type(name = "ImageMapEntry")),
@Selector(type = @Type(name = "ButtonIcon")),
Expand Down Expand Up @@ -126,7 +127,7 @@ public static TextureInfo getTextureInfo(@NotNull RTTIObject object, @NotNull Pr
final RTTIObject bigTexture = object.obj("BigTexture");
texture = bigTexture != null ? bigTexture : object.obj("SmallTexture");
}
case "TextureBindingWithHandle" -> {
case "TextureBindingWithHandle", "ShaderTextureBinding" -> {
return getTextureInfo(object.ref("TextureResource"), project, file, object.i32("PackedData"));
}
case "TextureSetEntry", "ImageMapEntry", "ButtonIcon", "MenuStreamingTexture" -> {
Expand Down