Skip to content
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 @@ -33,8 +33,8 @@ private static BindTarget vanillaTarget(String name, int priority, boolean shoul
BindConfig bindConfig = new BindConfig(shouldBind, true, shouldBind, shouldBind);
OffsetConfig offsets = new OffsetConfig();
offsets.x = -0.1f;
DisableConfig playerHead = new DisableConfig("player_head", textureId, false, List.of(new UVRectangle(0, 0, 1.0f, 0.25f)));
DisableConfig dragonHead = new DisableConfig("dragon_head", "minecraft:textures/entity/enderdragon/dragon.png", true, List.of());
DisableConfig playerHead = new DisableConfig("player_head", textureId, true, false, List.of(new UVRectangle(0, 0, 1.0f, 0.25f)));
DisableConfig dragonHead = new DisableConfig("dragon_head", "minecraft:textures/entity/enderdragon/dragon.png", true, true, List.of());
List<DisableConfig> disableConfigs = List.of(playerHead, dragonHead);
return new BindTarget(name, textureId, priority, 0.2f, targetConfig, bindConfig, offsets, disableConfigs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@ public final class DisableConfig {
private final LongOpenHashSet disabledUVs = new LongOpenHashSet(), enabledUVs = new LongOpenHashSet();
private final String name;
private final String textureId;
private final boolean active;
private final boolean disableAll;
private final List<UVRectangle> rectangles;

public DisableConfig(String name, String textureId, boolean disableAll, List<UVRectangle> rectangles) {
public DisableConfig(String name, String textureId, boolean active, boolean disableAll, List<UVRectangle> rectangles) {
this.name = name;
this.textureId = textureId;
this.active = active;
this.disableAll = disableAll;
this.rectangles = rectangles;
}

@Deprecated
public DisableConfig(String name, String textureId, boolean disableAll, List<UVRectangle> rectangles) {
this(name, textureId, true, disableAll, rectangles);
}

public String name() {
return name;
}
Expand All @@ -38,7 +45,12 @@ public List<UVRectangle> rectangles() {
return rectangles;
}

public boolean active() {
return this.active;
}

public boolean disable(VertexData vertex) {
Comment thread
H31M5 marked this conversation as resolved.
if (!this.active) return false;
final float u = vertex.u(), v = vertex.v();
final long packed = (long) Float.floatToIntBits(u) << 32 | Float.floatToIntBits(v);
if (enabledUVs.contains(packed)) return false;
Expand All @@ -51,4 +63,4 @@ public boolean disable(VertexData vertex) {
enabledUVs.add(packed);
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
import java.util.zip.InflaterInputStream;

public final class ConfigCodec {
static final short CURRENT_VERSION = 703;
static final short VERSION_703 = 703;
static final short CURRENT_VERSION = 709;
static final Short2ReferenceMap<StreamCodec<ByteBuf, BindTarget>> CODECS = Short2ReferenceMap.ofEntries(
Short2ReferenceMap.entry(CURRENT_VERSION, ConfigCodec703.CODEC)
Short2ReferenceMap.entry(VERSION_703, ConfigCodec703.CODEC),
Short2ReferenceMap.entry(CURRENT_VERSION, ConfigCodec709.CODEC)
);

public static BindTarget readWithVersion(ByteBuf byteBuf) throws DecoderException, IllegalArgumentException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.List;

@SuppressWarnings("deprecation")
final class ConfigCodec703 {
static final StreamCodec<ByteBuf, TargetConfig> TARGET_CONFIG_CODEC = StreamCodec.composite(
ByteBufCodecs.FLOAT, TargetConfig::forwardU,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.xtracr.realcamera.config.codec;

import com.xtracr.realcamera.config.BindTarget;
import com.xtracr.realcamera.config.BindTarget.BindConfig;
import com.xtracr.realcamera.config.BindTarget.TargetConfig;
import com.xtracr.realcamera.config.DisableConfig;
import com.xtracr.realcamera.config.OffsetConfig;
import com.xtracr.realcamera.config.UVRectangle;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec;

import java.util.List;

final class ConfigCodec709 {
static final StreamCodec<ByteBuf, TargetConfig> TARGET_CONFIG_CODEC = StreamCodec.composite(
ByteBufCodecs.FLOAT, TargetConfig::forwardU,
ByteBufCodecs.FLOAT, TargetConfig::forwardV,
ByteBufCodecs.FLOAT, TargetConfig::upwardU,
ByteBufCodecs.FLOAT, TargetConfig::upwardV,
ByteBufCodecs.FLOAT, TargetConfig::posU,
ByteBufCodecs.FLOAT, TargetConfig::posV,
TargetConfig::new
);
static final StreamCodec<ByteBuf, BindConfig> BIND_CONFIG_CODEC = StreamCodec.composite(
ByteBufCodecs.BYTE,
bindConfig -> {
byte bindFlags = 0;
if (bindConfig.bindX()) bindFlags |= 0x01;
if (bindConfig.bindY()) bindFlags |= 0x02;
if (bindConfig.bindZ()) bindFlags |= 0x04;
if (bindConfig.bindRotation()) bindFlags |= 0x08;
return bindFlags;
},
bindFlags -> {
boolean bindX = (bindFlags & 0x01) != 0;
boolean bindY = (bindFlags & 0x02) != 0;
boolean bindZ = (bindFlags & 0x04) != 0;
boolean bindRotation = (bindFlags & 0x08) != 0;
return new BindConfig(bindX, bindY, bindZ, bindRotation);
}
);
static final StreamCodec<ByteBuf, OffsetConfig> OFFSET_CONFIG_CODEC = StreamCodec.composite(
ByteBufCodecs.FLOAT, offsets -> offsets.scale,
ByteBufCodecs.FLOAT, offsets -> offsets.x,
ByteBufCodecs.FLOAT, offsets -> offsets.y,
ByteBufCodecs.FLOAT, offsets -> offsets.z,
ByteBufCodecs.FLOAT, offsets -> offsets.pitch,
ByteBufCodecs.FLOAT, offsets -> offsets.yaw,
ByteBufCodecs.FLOAT, offsets -> offsets.roll,
OffsetConfig::new
);
static final StreamCodec<ByteBuf, List<UVRectangle>> UV_RECTANGLES_CODEC = StreamCodec.composite(
ByteBufCodecs.FLOAT, UVRectangle::uMin,
ByteBufCodecs.FLOAT, UVRectangle::vMin,
ByteBufCodecs.FLOAT, UVRectangle::uMax,
ByteBufCodecs.FLOAT, UVRectangle::vMax,
UVRectangle::new
).apply(ByteBufCodecs.list());
static final StreamCodec<ByteBuf, List<DisableConfig>> DISABLE_CONFIGS_CODEC = StreamCodec.composite(
ByteBufCodecs.STRING_UTF8, DisableConfig::name,
ByteBufCodecs.STRING_UTF8, DisableConfig::textureId,
ByteBufCodecs.BOOL, DisableConfig::active,
ByteBufCodecs.BOOL, DisableConfig::disableAll,
UV_RECTANGLES_CODEC, DisableConfig::rectangles,
DisableConfig::new
).apply(ByteBufCodecs.list());
static final StreamCodec<ByteBuf, BindTarget> CODEC = StreamCodec.composite(
ByteBufCodecs.STRING_UTF8, BindTarget::name,
ByteBufCodecs.STRING_UTF8, BindTarget::textureId,
ByteBufCodecs.VAR_INT, BindTarget::priority,
ByteBufCodecs.FLOAT, BindTarget::disablingDepth,
TARGET_CONFIG_CODEC, BindTarget::targetConfig,
BIND_CONFIG_CODEC, BindTarget::bindConfig,
OFFSET_CONFIG_CODEC, BindTarget::offsets,
DISABLE_CONFIGS_CODEC, BindTarget::disableConfigs,
BindTarget::new
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void write(JsonWriter out, DisableConfig value) throws IOException {
out.beginObject();
out.name("name").value(value.name());
out.name("textureId").value(value.textureId());
out.name("active").value(value.active());
out.name("disableAll").value(value.disableAll());
out.name("rectangles");
out.beginArray();
Expand All @@ -35,6 +36,7 @@ public void write(JsonWriter out, DisableConfig value) throws IOException {
public DisableConfig read(JsonReader in) throws IOException {
String name = "";
String textureId = "";
boolean active = false;
boolean disableAll = false;
List<UVRectangle> rectangles = new ArrayList<>();

Expand All @@ -43,6 +45,7 @@ public DisableConfig read(JsonReader in) throws IOException {
switch (in.nextName()) {
case "name" -> name = in.nextString();
case "textureId" -> textureId = in.nextString();
case "active" -> active = in.nextBoolean();
case "disableAll" -> disableAll = in.nextBoolean();
case "rectangles" -> {
in.beginArray();
Expand All @@ -53,7 +56,7 @@ public DisableConfig read(JsonReader in) throws IOException {
}
}
in.endObject();
return new DisableConfig(name, textureId, disableAll, rectangles);
return new DisableConfig(name, textureId, active, disableAll, rectangles);
}

private UVRectangle readRectangle(JsonReader in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public final class ModelAnalyser {
@Nullable
private BuiltModelRecord focusedRecord;

public static void applyDisableConfigs(List<BuiltModelRecord> modelRecords, BindTarget target, String textureId, Set<String> hiddenNames) {
public static void applyDisableConfigs(List<BuiltModelRecord> modelRecords, BindTarget target, String textureId, Set<String> disableActiveNameMap) {
for (int i = 0; i < modelRecords.size(); i++) {
BuiltModelRecord record = modelRecords.get(i);
List<VertexData[]> primitives = new ArrayList<>();
DisableConfig[] disableConfigs = target.filteredDisableConfigs(config -> record.containsTextureId(config.textureId()) && hiddenNames.contains(config.name()));
DisableConfig[] disableConfigs = target.filteredDisableConfigs(config -> record.containsTextureId(config.textureId()) && disableActiveNameMap.contains(config.name()));
boolean disableAll = !record.containsTextureId(textureId);
for (DisableConfig config : disableConfigs) {
if (config.disableAll()) {
Expand Down Expand Up @@ -273,4 +273,4 @@ private void computeRecord(BuiltIterableBuffer builtBuffer, List<BuiltModelRecor

private record ZEntry(BuiltModelRecord record, VertexData[] primitive, float z) {
}
}
}
38 changes: 23 additions & 15 deletions common/src/main/java/com/xtracr/realcamera/gui/ModelViewScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public final class ModelViewScreen extends Screen {
private final NumberWidgetPair offsetRollPair = new NumberWidgetPair(font, "roll", compactWidgetWidth, widgetHeight, -180.0f, 180.0f);
private final List<DisableConfig> disableConfigs = new ArrayList<>();
private final List<UVRectangleWidget> rectWidgets = new ArrayList<>();
private final Map<String, Set<String>> hiddenNameMap = new HashMap<>();
private final Set<String> disableActiveNameMap = new HashSet<>();
private final List<NumberWidgetPair> widgetPairs = List.of(offsetXPair, offsetYPair, offsetZPair, offsetPitchPair, offsetYawPair, offsetRollPair);
private final CycleButton<Integer> selectingButton = createCyclingButtonBuilder(ImmutableSortedMap.of(
0, LocUtil.MODEL_VIEW_WIDGET("forwardVector").withStyle(ChatFormatting.GREEN),
Expand Down Expand Up @@ -268,7 +268,6 @@ else if (index > 0 && index <= rectWidgets.size()) {
BindTarget bindTarget = genBindTarget();
ConfigFile.config().putBindTarget(bindTarget);
ConfigFile.save();
if (toggleCategoryButton.getValue() != Category.DISABLE) loadBindTarget(bindTarget);
initWidgets(page);
}));
rows.addChild(priorityField, smallSettings).setTooltip(createTooltip("priority"));
Expand Down Expand Up @@ -303,12 +302,11 @@ private void initRightWidgets() {
}), smallSettings).setTooltip(createTooltip("saveAs"));
for (int i = page * widgetsPerPage; i < Math.min((page + 1) * widgetsPerPage, size); i++) {
DisableConfig config = disableConfigs.get(i);
String targetName = nameField.getValue();
Set<String> hiddenNames = hiddenNameMap.computeIfAbsent(targetName, _ -> new HashSet<>());
addRenderableWidget(new CycleIconButton(32, 16, hiddenNames.contains(config.name()) ? 1 : 0, 2))
addRenderableWidget(new CycleIconButton(32, 16, disableActiveNameMap.contains(config.name()) ? 1 : 0,
2))
.setOnValueChange(value -> {
if (value == 0) hiddenNames.remove(config.name());
else hiddenNames.add(config.name());
if (value == 0) disableActiveNameMap.remove(config.name());
else disableActiveNameMap.add(config.name());
})
.setPosition(x + (xSize + middleWidth) / 2 - 20, y + 5 + (widgetHeight + 2) * (2 + i % widgetsPerPage));
rows.addChild(createButton(LocUtil.literal(config.name()), compactWidgetWidth, _ -> {
Expand All @@ -317,7 +315,7 @@ private void initRightWidgets() {
}), 3).setTooltip(Tooltip.create(LocUtil.literal(config.name())));
rows.addChild(new SimpleIconButton(48, 0, _ -> {
disableConfigs.removeIf(disableConfig -> disableConfig.name().equals(config.name()));
hiddenNameMap.values().forEach(names -> names.remove(config.name()));
disableActiveNameMap.remove(config.name());
if (disabledNameField.getValue().equals(config.name())) clearDisableDraft();
initWidgets(page * widgetsPerPage > size - 2 && size > 1 ? page - 1 : page);
}), smallSettings);
Expand Down Expand Up @@ -395,10 +393,10 @@ public void extractBackground(@NonNull GuiGraphicsExtractor graphics, int mouseX
BindTarget target = genBindTarget();
target.offsets().scale *= modelScale;
String textureId = toggleCategoryButton.getValue() == Category.DISABLE ? disabledIdField.getValue() : "";
Set<String> hiddenNames = hiddenNameMap.getOrDefault(nameField.getValue(), Set.of());
List<BuiltModelRecord> modelRecords = captureRotatedEntity(analyser, target, minecraft.player);
List<BuiltModelRecord> textureRecords = modelRecords.stream().filter(record -> record.containsTextureId(textureId)).toList();
ModelAnalyser.applyDisableConfigs(modelRecords, target, textureId, hiddenNames);
if (toggleCategoryButton.getValue() == Category.DISABLE)
ModelAnalyser.applyDisableConfigs(modelRecords, target, textureId, disableActiveNameMap);
computeFocusedPrimitives(analyser, modelRecords, textureRecords, mouseX, mouseY);
renderCulledModels(graphics, analyser, target, modelRecords);
renderFlattenedModels(graphics, analyser, textureRecords);
Expand Down Expand Up @@ -574,7 +572,8 @@ private boolean syncDisableDraft(Button button, boolean autoName) {
button.setTooltip(Tooltip.create(LocUtil.MODEL_VIEW_TOOLTIP("emptyTextureId").withStyle(ChatFormatting.RED)));
return false;
}
DisableConfig disableConfig = new DisableConfig(name, textureId, disableModeButton.getValue() == 0, rectWidgets.stream().map(UVRectangleWidget::toUVRectangle).toList());
DisableConfig disableConfig = new DisableConfig(name, textureId, disableActiveNameMap.contains(name),
disableModeButton.getValue() == 0, rectWidgets.stream().map(UVRectangleWidget::toUVRectangle).toList());
upsertDisableConfig(disableConfig);
return true;
}
Expand Down Expand Up @@ -669,15 +668,24 @@ private void loadBindTarget(BindTarget target) {
offsetRollPair.setNumber(offsets.roll);
disableConfigs.clear();
disableConfigs.addAll(target.disableConfigs());
disableConfigs.forEach(config -> {
if (config.active()) disableActiveNameMap.add(config.name());
});
clearDisableDraft();
}

private BindTarget genBindTarget() {
DisableConfig currentDisableConfig = new DisableConfig(disabledNameField.getValue(), disabledIdField.getValue(), disableModeButton.getValue() == 0, rectWidgets.stream().map(UVRectangleWidget::toUVRectangle).toList());
List<DisableConfig> newDisableConfigs = new ArrayList<>(disableConfigs);
for (int i = 0; i < newDisableConfigs.size(); i++) {
if (newDisableConfigs.get(i).name().equals(currentDisableConfig.name()))
newDisableConfigs.set(i, currentDisableConfig);
DisableConfig newDisableConfig = newDisableConfigs.get(i);
boolean active = disableActiveNameMap.contains(newDisableConfig.name());
if (newDisableConfig.name().equals(disabledNameField.getValue()))
newDisableConfigs.set(i, new DisableConfig(disabledNameField.getValue(), disabledIdField.getValue(), active,
disableModeButton.getValue() == 0, rectWidgets.stream().map(UVRectangleWidget::toUVRectangle).toList()));
else if (newDisableConfig.active() != active) {
newDisableConfigs.set(i, new DisableConfig(newDisableConfig.name(), newDisableConfig.textureId(), active,
newDisableConfig.disableAll(), newDisableConfig.rectangles()));
}
}
TargetConfig targetConfig = new TargetConfig(forwardUField.getNumber(), forwardVField.getNumber(), upwardUField.getNumber(), upwardVField.getNumber(), posUField.getNumber(), posVField.getNumber());
BindConfig bindConfig = new BindConfig(bindXButton.getValue() == 0, bindYButton.getValue() == 0, bindZButton.getValue() == 0, bindRotButton.getValue() == 0);
Expand Down Expand Up @@ -984,4 +992,4 @@ public void setFocused(boolean focused) {
protected void updateWidgetNarration(@NonNull NarrationElementOutput narrationElementOutput) {
}
}
}
}