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

Map tile export #61

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -10,4 +10,8 @@ public DMFAttachmentNode(@NotNull String name, @NotNull String boneName, @NotNul
this.boneName = boneName;
this.transform = transform;
}

public boolean isEmpty() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public DMFCompositeModel(@NotNull String name, int skeletonId) {
super(name, DMFNodeType.SKINNED_MODEL);
this.skeletonId = skeletonId;
}

public boolean isEmpty() {
return children.isEmpty();
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ public DMFInstance(@NotNull String name, int instanceId) {
super(name, DMFNodeType.INSTANCE);
this.instanceId = instanceId;
}

public boolean isEmpty() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public void addLod(@NotNull DMFNode model, float distance) {
}

public record Lod(@NotNull DMFNode model, int id, float distance) {}

public boolean isEmpty() {
return children.isEmpty() && lods.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.shade.decima.ui.data.viewer.model.dmf;

import com.shade.util.NotNull;

import java.util.HashMap;
import java.util.Map;

public class DMFMapTile extends DMFNode {
int[] gridCoordinate;
float[] bboxMin;
float[] bboxMax;
Map<String, DMFMapTile.TileTextureInfo> textures = new HashMap<>();
REDxEYE marked this conversation as resolved.
Show resolved Hide resolved

public DMFMapTile(@NotNull String name) {
super(name, DMFNodeType.MAP_TILE);
}

public static final class TileTextureInfo {
public final Map<String, TileTextureChannelInfo> channels = new HashMap<>();
public Integer textureId = null;

public static class TileTextureChannelInfo {
public String usage;
public float minRange;
public float maxRange;

public TileTextureChannelInfo(String usage, float minRange, float maxRange) {
this.usage = usage;
this.minRange = minRange;
this.maxRange = maxRange;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public void setSkeleton(@NotNull DMFSkeleton skeleton, @NotNull DMFSceneFile sce
scene.skeletons.add(skeleton);
skeletonId = scene.skeletons.indexOf(skeleton);
}

public boolean isEmpty() {
return children.isEmpty() && (mesh==null || mesh.primitives.isEmpty());
}
REDxEYE marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ protected DMFNode(@NotNull String name, @NotNull DMFNodeType type) {
public void addToCollection(@NotNull DMFCollection collection, @NotNull DMFSceneFile scene) {
collectionIds.add(scene.collections.indexOf(collection));
}

public boolean isEmpty() {
return children.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public enum DMFNodeType {
MODEL,
SKINNED_MODEL,
ATTACHMENT,
MAP_TILE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,6 @@
public class TextureViewer implements ValueViewer {
private static final Logger log = LoggerFactory.getLogger(TextureViewer.class);

@NotNull
@Override
public JComponent createComponent() {
return new TextureViewerPanel();
}

@Override
public void refresh(@NotNull JComponent component, @NotNull ValueController<?> controller) {
final TextureInfo info = Objects.requireNonNull(getTextureInfo(controller));
final HwTextureHeader header = info.texture.obj("Header").cast();
final TextureViewerPanel panel = (TextureViewerPanel) component;

panel.setStatusText("%sx%s (%s, %s)".formatted(
header.getWidth(), header.getHeight(),
header.getType(), header.getPixelFormat()
));

SwingUtilities.invokeLater(() -> {
final ImageProvider provider = getImageProvider(info.texture, controller.getProject().getPackfileManager());
panel.getImagePanel().setProvider(provider, info.channels);
panel.getImagePanel().fit();
});
}

@Override
public boolean canView(@NotNull ValueController<?> controller) {
return getTextureInfo(controller) != null;
}

@Nullable
public static ImageProvider getImageProvider(RTTIObject value, @NotNull PackfileManager manager) {
final HwTextureHeader header = value.<RTTIObject>get("Header").cast();
Expand Down Expand Up @@ -178,9 +149,51 @@ public static EnumSet<Channel> getChannels(int packedData, int packingInfo) {
return channels;
}

@NotNull
@Override
public JComponent createComponent() {
return new TextureViewerPanel();
}

@Override
public void refresh(@NotNull JComponent component, @NotNull ValueController<?> controller) {
final TextureInfo info = Objects.requireNonNull(getTextureInfo(controller));
final HwTextureHeader header = info.texture.obj("Header").cast();
final TextureViewerPanel panel = (TextureViewerPanel) component;

panel.setStatusText("%sx%s (%s, %s)".formatted(
header.getWidth(), header.getHeight(),
header.getType(), header.getPixelFormat()
));

SwingUtilities.invokeLater(() -> {
final ImageProvider provider = getImageProvider(info.texture, controller.getProject().getPackfileManager());
panel.getImagePanel().setProvider(provider, info.channels);
panel.getImagePanel().fit();
});
}

@Override
public boolean canView(@NotNull ValueController<?> controller) {
return getTextureInfo(controller) != null;
}

REDxEYE marked this conversation as resolved.
Show resolved Hide resolved
public record TextureInfo(@NotNull RTTIObject texture, @Nullable EnumSet<Channel> channels) {}

private record MyImageProvider(@NotNull HwTextureHeader header, @NotNull HwTextureData data, @NotNull PackfileManager manager, @NotNull ImageReaderProvider readerProvider) implements ImageProvider {
@NotNull
private static Dimension getTextureDimension(@NotNull ImageReader reader, @NotNull Dimension dimension, int mip) {
return new Dimension(
Math.max(dimension.width >> mip, reader.getBlockSize()),
Math.max(dimension.height >> mip, reader.getBlockSize())
);
}

private static int getTextureSize(@NotNull ImageReader reader, @NotNull Dimension dimension, int mip) {
final Dimension scaled = getTextureDimension(reader, dimension, mip);
return scaled.width * scaled.height * reader.getPixelBits() / 8;
}

REDxEYE marked this conversation as resolved.
Show resolved Hide resolved
@NotNull
@Override
public BufferedImage getImage(int mip, int slice) {
Expand Down Expand Up @@ -311,17 +324,17 @@ public String getPixelFormat() {
return header.getPixelFormat();
}

@NotNull
private static Dimension getTextureDimension(@NotNull ImageReader reader, @NotNull Dimension dimension, int mip) {
return new Dimension(
Math.max(dimension.width >> mip, reader.getBlockSize()),
Math.max(dimension.height >> mip, reader.getBlockSize())
);
}

private static int getTextureSize(@NotNull ImageReader reader, @NotNull Dimension dimension, int mip) {
final Dimension scaled = getTextureDimension(reader, dimension, mip);
return scaled.width * scaled.height * reader.getPixelBits() / 8;
@Override
public int getBitsPerChannel() {
return switch (getPixelFormat()) {
case "RGBA_8888", "BC4U", "BC7", "BC5S", "BC5U", "BC4S", "BC3", "BC2", "BC1", "R_INT_8", "RG_INT_8", "RGBA_INT_8", "R_UINT_8", "RG_UINT_8", "RGBA_UINT_8", "R_NORM_8", "RG_NORM_8", "RGBA_NORM_8", "R_UNORM_8", "RG_UNORM_8", "RGBA_UNORM_8" ->
1;
case "RGBA_FLOAT_16", "RGB_FLOAT_16", "RG_FLOAT_16", "R_FLOAT_16", "BC6S", "BC6U", "RGBA_UNORM_10_10_10_2", "RGB_FLOAT_11_11_10", "R_INT_16", "RG_INT_16", "RGBA_INT_16", "R_UINT_16", "RG_UINT_16", "RGBA_UINT_16", "RG_NORM_16", "RGBA_NORM_16", "R_UNORM_16", "RG_UNORM_16", "RGBA_UNORM_16", "R_NORM_16" ->
2;
case "RGBA_FLOAT_32", "RGB_FLOAT_32", "RG_FLOAT_32", "R_FLOAT_32", "R_INT_32", "RG_INT_32", "RGBA_INT_32", "R_UINT_32", "RG_UINT_32", "RGBA_UINT_32", "RGBA_UNORM_32" ->
4;
default -> 0;
};
REDxEYE marked this conversation as resolved.
Show resolved Hide resolved
}

private record ImageData(@NotNull ImageReader reader, @NotNull ByteBuffer buffer, int width, int height) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ enum Type {

@NotNull
String getPixelFormat();

int getBitsPerChannel();
}