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 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 @@ -15,6 +15,7 @@
@Selector(type = @Type(name = "MeshResourceBase")),
@Selector(type = @Type(name = "ArtPartsDataResource"), game = {GameType.DS, GameType.DSDC}),
@Selector(type = @Type(name = "ArtPartsSubModelResource"), game = {GameType.DS, GameType.DSDC}),
@Selector(type = @Type(name = "LevelDataGame"), game = {GameType.DS, GameType.DSDC}),
@Selector(type = @Type(name = "ArtPartsSubModelWithChildrenResource"), game = {GameType.DS, GameType.DSDC}),
@Selector(type = @Type(name = "ObjectCollection")),
@Selector(type = @Type(name = "StaticMeshResource")),
Expand Down

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

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.decima.model.app.Project;
import com.shade.decima.ui.data.viewer.model.ModelExporter;
import com.shade.decima.ui.data.viewer.model.ModelExporterProvider;
import com.shade.util.NotNull;

import java.nio.file.Path;
import java.util.Set;

public class DMFExporterProvider implements ModelExporterProvider {
@NotNull
@Override
public ModelExporter create(@NotNull Project project, @NotNull Set<Option> options, @NotNull Path outputPath) {
return new DMFExporter(project, options, outputPath);
}

@Override
public boolean supportsOption(@NotNull Option option) {
return true;
}

@NotNull
@Override
public String getExtension() {
return "dmf";
}

@NotNull
@Override
public String getName() {
return "DMF Scene";
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.util.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.shade.decima.model.app.Project;
import com.shade.decima.model.rtti.types.java.HwDataSource;
import com.shade.decima.ui.data.viewer.model.dmf.DMFExporter;
import com.shade.util.NotNull;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

public abstract class DMFBuffer {
public final String name;
protected final DataProvider provider;

public DMFBuffer(@NotNull String name, @NotNull DataProvider provider) {
this.name = name;
this.provider = provider;
}

@NotNull
public JsonObject serialize(@NotNull DMFExporter exporter, @NotNull JsonSerializationContext context) throws IOException {
final JsonObject object = new JsonObject();
object.addProperty("name", name);
object.addProperty("size", provider.length());
return object;
}

public interface DataProvider {
@NotNull
InputStream openInputStream() throws IOException;

int length();
}

public record ByteArrayDataProvider(@NotNull byte[] data) implements DMFBuffer.DataProvider {

@NotNull
@Override
public InputStream openInputStream() {
return new ByteArrayInputStream(data);
}

@Override
public int length() {
return data.length;
}
}
public static class DataSourceDataProvider implements DMFBuffer.DataProvider {
private final Project project;
private final HwDataSource dataSource;
private final int offset;
private final int length;

public DataSourceDataProvider(@NotNull Project project, @NotNull HwDataSource dataSource, int offset, int length) {
this.dataSource = dataSource;
this.offset = offset;
this.length = length;
this.project = project;
}

@NotNull
@Override
public InputStream openInputStream() throws IOException {
return new ByteArrayInputStream(dataSource.getData(project.getPackfileManager(), offset, length));
}

@Override
public int length() {
return length;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

public record DMFBufferView(int bufferId, int offset, int size) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.util.NotNull;
import com.shade.util.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.util.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.shade.decima.ui.data.viewer.model.dmf.DMFExporter;
import com.shade.util.NotNull;

import java.io.BufferedOutputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.decima.ui.data.viewer.model.dmf.nodes.DMFNode;
import com.shade.util.NotNull;

public record DMFInstanceSource(@NotNull String uuid, @NotNull DMFNode rootNode) {
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.shade.decima.ui.data.viewer.model.dmf.DMFExporter;
import com.shade.util.NotNull;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Base64;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;

public class DMFInternalBuffer extends DMFBuffer {
Expand All @@ -20,7 +22,8 @@ public DMFInternalBuffer(@NotNull String name, @NotNull DataProvider provider) {
@Override
public JsonObject serialize(@NotNull DMFExporter exporter, @NotNull JsonSerializationContext context) throws IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (OutputStream os = new DeflaterOutputStream(baos)) {
Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
try (OutputStream os = new DeflaterOutputStream(baos,deflater)) {
try (InputStream is = provider.openInputStream()) {
is.transferTo(os);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.util.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.util.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.decima.ui.data.viewer.model.dmf.nodes.DMFNode;
import com.shade.util.NotNull;
import com.shade.util.Nullable;

Expand All @@ -17,7 +18,7 @@ public class DMFSceneFile {
public final List<DMFBuffer> buffers;
public final List<DMFMaterial> materials;
public final List<DMFTexture> textures;
public final List<DMFNode> instances;
public final List<DMFInstanceSource> instances;

public DMFSceneFile(int version) {
metadata = new DMFSceneMetaData("%s (%s, %s)".formatted(APP_TITLE, APP_VERSION, BUILD_COMMIT), version);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.util.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.util.NotNull;
import com.shade.util.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.util.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

public class DMFTextureDescriptor {
public int textureId = -1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.decima.ui.data.viewer.model.dmf.nodes.DMFMapTile;
import org.joml.Vector3f;
import org.joml.Vector3fc;

import java.awt.*;
import java.util.HashMap;
import java.util.Map;

public final class DMFTileData {
public final Map<String, DMFMapTile.TileTextureInfo> textures;
public final Point gridCoordinate;
public Vector3fc bboxMin;
public Vector3fc bboxMax;

private DMFTileData(Map<String, DMFMapTile.TileTextureInfo> textures, Point gridCoordinate, Vector3f bboxMin, Vector3f bboxMax) {
this.textures = textures;
this.gridCoordinate = gridCoordinate;
this.bboxMin = bboxMin;
this.bboxMax = bboxMax;
}

public DMFTileData(Point gridCoordinate) {
this(new HashMap<>(), gridCoordinate, null, null);
}

public String toString() {
return "TileData[" +
"textures=" + textures + ", " +
"gridCoordinate=" + gridCoordinate + ", " +
"bboxMin=" + bboxMin + ", " +
"bboxMax=" + bboxMax + ']';
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.util.NotNull;
import org.joml.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

import com.shade.util.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.data;

public enum DMFVertexBufferType {
MULTI_BUFFER,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.shade.decima.ui.data.viewer.model.dmf.nodes;

import com.shade.decima.ui.data.viewer.model.dmf.data.DMFTransform;
import com.shade.util.NotNull;

public class DMFAttachment extends DMFNode {
public final String boneName;

public DMFAttachment(@NotNull String name, @NotNull String boneName, @NotNull DMFTransform transform) {
super(name, DMFNodeType.ATTACHMENT);
this.boneName = boneName;
this.transform = transform;
}

@Override
public boolean isEmpty() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.nodes;

import com.shade.util.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.shade.decima.ui.data.viewer.model.dmf;
package com.shade.decima.ui.data.viewer.model.dmf.nodes;


import com.shade.util.NotNull;
Expand All @@ -10,4 +10,9 @@ public DMFInstance(@NotNull String name, int instanceId) {
super(name, DMFNodeType.INSTANCE);
this.instanceId = instanceId;
}

@Override
public boolean isEmpty() {
return false;
}
}
Loading