Skip to content
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 @@ -32,6 +32,8 @@
import com.shade.platform.model.util.IOUtils;
import com.shade.util.NotNull;
import com.shade.util.Nullable;
import org.joml.Vector2i;
import org.joml.Vector2ic;
import org.joml.Vector3f;
import org.joml.Vector3fc;
import org.slf4j.Logger;
Expand Down Expand Up @@ -72,6 +74,8 @@ public class DMFExporter extends BaseModelExporter implements ModelExporter {
.registerTypeHierarchyAdapter(List.class, new JsonListSerializer())
.registerTypeHierarchyAdapter(DMFBuffer.class, new JsonBufferSerializer())
.registerTypeAdapter(DMFTransform.class, new JsonTransformSerializer())
.registerTypeAdapter(Vector3fc.class, new JsonVector3fcSerializer())
.registerTypeAdapter(Vector2ic.class, new JsonVector2icSerializer())
.create();
private final Project project;
private final Set<ModelExporterProvider.Option> options;
Expand Down Expand Up @@ -109,9 +113,9 @@ public void export(
private void generateMapTileNode(TileData tileData) {
DMFMapTile mapTile = new DMFMapTile("Tile_%d_%d".formatted(tileData.gridCoordinate.x, tileData.gridCoordinate.y));
mapTile.textures.putAll(tileData.textures);
mapTile.bboxMin = new float[]{tileData.bboxMin.x(), tileData.bboxMin.y(), tileData.bboxMin.z()};
mapTile.bboxMax = new float[]{tileData.bboxMax.x(), tileData.bboxMax.y(), tileData.bboxMax.z()};
mapTile.gridCoordinate = new int[]{tileData.gridCoordinate.x, tileData.gridCoordinate.y};
mapTile.bboxMin = new Vector3f(tileData.bboxMin.x(), tileData.bboxMin.y(), tileData.bboxMin.z());
mapTile.bboxMax = new Vector3f(tileData.bboxMax.x(), tileData.bboxMax.y(), tileData.bboxMax.z());
mapTile.gridCoordinate = new Vector2i(tileData.gridCoordinate.x, tileData.gridCoordinate.y);
Comment thread
ShadelessFox marked this conversation as resolved.
scene.models.add(mapTile);
}

Expand Down Expand Up @@ -497,9 +501,8 @@ private DMFNode worldDataTextureMapToModel(

final RTTIReference.FollowResult resultTextureRef = object.ref("ResultTexture").follow(project, core);
if (resultTextureRef != null) {
DMFTexture texture = exportTexture(monitor,resultTextureRef.object(), resourceName);
DMFMapTile.TileTextureInfo textureInfo = new DMFMapTile.TileTextureInfo();
textureInfo.textureId = scene.textures.indexOf(texture);
DMFTexture texture = exportTexture(monitor, resultTextureRef.object(), resourceName);
DMFMapTile.TileTextureInfo textureInfo = new DMFMapTile.TileTextureInfo(scene.textures.indexOf(texture), new HashMap<>());
for (RTTIReference entryRef : object.refs("Entries")) {
final RTTIReference.FollowResult entryRefRes = entryRef.follow(project, core);
if (entryRefRes == null) {
Expand All @@ -512,7 +515,7 @@ private DMFNode worldDataTextureMapToModel(
final RTTIObject typeInfo = typeRef.object();
final String channel = entryRefRes.object().str("Channel");
final String usage = typeRef.object().str("Name");
textureInfo.channels.put(channel, new DMFMapTile.TileTextureInfo.TileTextureChannelInfo(usage,
textureInfo.channels().put(channel, new DMFMapTile.TileTextureChannelInfo(usage,
typeInfo.obj("Range").f32("Min"), typeInfo.obj("Range").f32("Max")));
}
tileData.textures.put(resourceName, textureInfo);
Expand Down Expand Up @@ -1358,7 +1361,7 @@ private void exportTextureBinding(ProgressMonitor monitor, @NotNull CoreBinary b
continue;
}
final String textureName = nameFromReference(textureRef, "Texture_%s".formatted(uuidToString(textureSetTextureRef))) + "_%d".formatted(i);
DMFTexture texture = exportTexture(textureExportTask.split(1),textureSetTexture, textureName);
DMFTexture texture = exportTexture(textureExportTask.split(1), textureSetTexture, textureName);
textureId = scene.textures.indexOf(texture);
if (PackingInfoHandler.getInfo(usageInfo & 0xFF).contains(textureUsageName)) {
channels += "R";
Expand Down Expand Up @@ -1560,6 +1563,26 @@ public JsonElement serialize(DMFTransform src, Type type, JsonSerializationConte
}
}

private static class JsonVector3fcSerializer implements JsonSerializer<Vector3fc> {
@Override
public JsonElement serialize(Vector3fc src, Type type, JsonSerializationContext context) {
JsonArray jsonObject = new JsonArray();
jsonObject.add(src.x());
jsonObject.add(src.y());
jsonObject.add(src.z());
return jsonObject;
}
}
private static class JsonVector2icSerializer implements JsonSerializer<Vector2ic> {
@Override
public JsonElement serialize(Vector2ic src, Type type, JsonSerializationContext context) {
JsonArray jsonObject = new JsonArray();
jsonObject.add(src.x());
jsonObject.add(src.y());
return jsonObject;
}
}

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

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

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

public record DMFInstanceSource(String uuid, DMFNode rootNode) {
public record DMFInstanceSource(@NotNull String uuid, @NotNull DMFNode rootNode) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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 +21,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,34 +1,48 @@
package com.shade.decima.ui.data.viewer.model.dmf.nodes;

import com.shade.util.NotNull;
import org.joml.Vector2ic;
import org.joml.Vector3fc;

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

public class DMFMapTile extends DMFNode {
public int[] gridCoordinate;
public float[] bboxMin;
public float[] bboxMax;
public Vector2ic gridCoordinate;
public Vector3fc bboxMin;
public Vector3fc bboxMax;
public Map<String, DMFMapTile.TileTextureInfo> textures = new HashMap<>();

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 record TileTextureInfo(int textureId, @NotNull Map<String, TileTextureChannelInfo> channels) {
@Override
public int textureId() {
return textureId;
}

@Override
public Map<String, TileTextureChannelInfo> channels() {
return channels;
}
}

public static class TileTextureChannelInfo {
public String usage;
public float minRange;
public float maxRange;
public record TileTextureChannelInfo(@NotNull String usage, float minRange, float maxRange) {
@Override
public String usage() {
return usage;
}

@Override
public float minRange() {
return minRange;
}

public TileTextureChannelInfo(String usage, float minRange, float maxRange) {
this.usage = usage;
this.minRange = minRange;
this.maxRange = maxRange;
}
@Override
public float maxRange() {
return maxRange;
}
}
}