Skip to content

Commit

Permalink
Export Offset/Translation feature for Groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fexcraft committed Mar 8, 2020
1 parent 37bbb1e commit 6e87db3
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 2 deletions.
1 change: 1 addition & 0 deletions resources/lang/default.lang
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ editor.model_group.group.texture=Group Texture
editor.model_group.group.texture.select=Select a group texture file.
editor.model_group.group.add_animator=Add Animator
editor.model_group.group.animator_settings=Animator Settings
editor.model_group.group.export_offset=Export Offset/Translation
editor.model_group.animations=Animations in first selected Group
editor.preview.container=General Settings
editor.preview.container.position_full=Position (full units)
Expand Down
2 changes: 1 addition & 1 deletion src/net/fexcraft/app/fmt/FMTB.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class FMTB {

public static final String deftitle = "[FPS:%s] Fexcraft Modelling Toolbox - %s";
public static final String deftitle0 = "Fexcraft Modelling Toolbox - %s";
public static final String version = "2.0.4";
public static final String version = "2.0.5";
public static final String CLID = "587016218196574209";
//
public static GGR ggr;
Expand Down
5 changes: 5 additions & 0 deletions src/net/fexcraft/app/fmt/porters/DFMExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ private void insertList(GroupCompound compound, List<PolygonWrapper> list, int i
if(wrapper.rot.xCoord != 0f){
buffer.append(tab2 + name + "[" + index + "].rotateAngleZ = " + (float)Math.toRadians(wrapper.rot.zCoord) + "f;\n");
} buffer.append("\n");
//
if(list instanceof TurboList && ((TurboList)list).exportoffset != null){
TurboList turbo = (TurboList)list;
buffer.append(tab2 + "translate(" + name + format(",%s, %s, %s);\n", null, turbo.exportoffset.xCoord, turbo.exportoffset.yCoord, turbo.exportoffset.zCoord));
}
index++;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/net/fexcraft/app/fmt/porters/FVTMFormatBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ else if(cyl.radius2 != 0f){
buffer.append(tab2 + name + ".addProgram(" + string + ");\n");
}
}
if(turbo.exportoffset != null){
buffer.append(tab2 + name + format(".translate(%s, %s, %s);\n", null, turbo.exportoffset.xCoord, turbo.exportoffset.yCoord, turbo.exportoffset.zCoord));
}
}
buffer.append(tab2 + "this.groups.add(" + name + ");\n");
}
Expand Down
58 changes: 57 additions & 1 deletion src/net/fexcraft/app/fmt/ui/editor/ModelGroupEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.liquidengine.legui.component.Label;
import org.liquidengine.legui.component.SelectBox;
import org.liquidengine.legui.component.TextInput;
import org.liquidengine.legui.component.Tooltip;
import org.liquidengine.legui.component.event.selectbox.SelectBoxChangeSelectionEvent;
import org.liquidengine.legui.component.optional.align.HorizontalAlign;
import org.liquidengine.legui.event.FocusEvent;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class ModelGroupEditor extends EditorBase {

private static final int[] texsizes = new int[]{ 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };//, 8192 };
public static NumberField pos_x, pos_y, pos_z, poss_x, poss_y, poss_z;
public static NumberField rot_x, rot_y, rot_z;
public static NumberField rot_x, rot_y, rot_z, exoff_x, exoff_y, exoff_z;
public static TextInput model_texture, model_name;
public static SelectBox<Float> m_tex_x, m_tex_y, m_tex_s;
public static ColorField group_color;
Expand Down Expand Up @@ -162,6 +163,42 @@ else if(listener.getButton() == MouseButton.MOUSE_BUTTON_RIGHT){
g_tex_s.setVisibleCount(10); g_tex_s.setElementHeight(20);
g_tex_s.getSelectionButton().getStyle().setFontSize(20f);
g_tex_s.addSelectBoxChangeSelectionEventListener(event -> updateGroupTexSize(event, null));
//
Label exoff_label = new Label(translate("editor.model_group.group.export_offset"), 3, pass += 24, 240, 20);
Button exoff_autobutton = new Button("AUTO", 240, pass + 2, 50, 18);
exoff_autobutton.getListenerMap().addListener(MouseClickEvent.class, listener -> {
if(listener.getAction() != CLICK) return;
boolean opp = listener.getButton() != MouseButton.MOUSE_BUTTON_LEFT;
TurboList list = FMTB.MODEL.getFirstSelectedGroup();
if(list == null || list.size() < 1) return;
if(list.exportoffset == null) list.exportoffset = new Vec3f();
list.exportoffset.xCoord = opp ? -list.get(0).pos.xCoord : list.get(0).pos.xCoord;
list.exportoffset.yCoord = opp ? -list.get(0).pos.yCoord : list.get(0).pos.yCoord;
list.exportoffset.zCoord = opp ? -list.get(0).pos.zCoord : list.get(0).pos.zCoord;
exoff_x.apply(list.exportoffset.xCoord);
exoff_y.apply(list.exportoffset.yCoord);
exoff_z.apply(list.exportoffset.zCoord);
});
exoff_autobutton.getStyle().setFontSize(16f);
Tooltip exoff_buttontooltip = new Tooltip("Copies first polygon's position.\nleft = normal / rightclick = opposite");
exoff_buttontooltip.setSize(250, 40);
exoff_buttontooltip.setPosition(-200, -40);
exoff_buttontooltip.getStyle().getBackground().setColor(FMTB.rgba(69, 137, 196, 0.9f));
exoff_buttontooltip.getStyle().setHorizontalAlign(HorizontalAlign.CENTER);
exoff_autobutton.setTooltip(exoff_buttontooltip);
group.getContainer().add(exoff_autobutton);
group.getContainer().add(exoff_label);
Tooltip exoff_tooltip = new Tooltip("This is valid for FVTM and Flansmod* Export. (e.g. 'translate(group, x, y, z);')");
exoff_tooltip.setSize(290, 40);
exoff_tooltip.setPosition(0, -40);
exoff_tooltip.getStyle().getBackground().setColor(FMTB.rgba(69, 137, 196, 0.9f));
exoff_tooltip.getStyle().setHorizontalAlign(HorizontalAlign.CENTER);
exoff_label.setTooltip(exoff_tooltip);
group.getContainer().add(exoff_x = new NumberField(4, pass += 24, 90, 20).setup(Integer.MIN_VALUE, Integer.MAX_VALUE, true, () -> setgroupoffset()));
group.getContainer().add(exoff_y = new NumberField(102, pass, 90, 20).setup(Integer.MIN_VALUE, Integer.MAX_VALUE, true, () -> setgroupoffset()));
group.getContainer().add(exoff_z = new NumberField(200, pass, 90, 20).setup(Integer.MIN_VALUE, Integer.MAX_VALUE, true, () -> setgroupoffset()));
//exoff_x.setTooltip(exoff_tooltip); exoff_y.setTooltip(exoff_tooltip); exoff_z.setTooltip(exoff_tooltip);
//
group.getContainer().add(new Label(translate("editor.model_group.group.texture"), 3, pass += 24, 290, 20));
group.getContainer().add(group_texture = new TextField(FMTB.MODEL.texture, 3, pass += 24, 290, 20));
group_texture.getListenerMap().addListener(MouseClickEvent.class, listener -> {
Expand Down Expand Up @@ -212,6 +249,25 @@ else if(listener.getButton() == MouseButton.MOUSE_BUTTON_RIGHT){
reOrderWidgets();
}

private void setgroupoffset(){
ArrayList<TurboList> arrlist = FMTB.MODEL.getDirectlySelectedGroups();
if(arrlist.isEmpty()) return;
float xval = exoff_x.getValue();
float yval = exoff_y.getValue();
float zval = exoff_z.getValue();
if(xval == 0f && yval == 0f && zval == 0f){
arrlist.forEach(list -> list.exportoffset = null);
}
else{
arrlist.forEach(list -> {
if(list.exportoffset == null) list.exportoffset = new Vec3f();
list.exportoffset.xCoord = xval;
list.exportoffset.yCoord = yval;
list.exportoffset.zCoord = zval;
});
}
}

public static class AnimationsEditorWidget extends EditorWidget {

private TurboList group = null;
Expand Down
11 changes: 11 additions & 0 deletions src/net/fexcraft/app/fmt/utils/SaveLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ public static JsonObject modelToJTMT(GroupCompound root, boolean export){
group.addProperty("texture_size_y", list.textureY);
group.addProperty("texture_scale", list.textureS);
}
if(list.exportoffset != null){
group.addProperty("export_offset_x", list.exportoffset.xCoord);
group.addProperty("export_offset_y", list.exportoffset.yCoord);
group.addProperty("export_offset_z", list.exportoffset.zCoord);
}
if(!list.animations.isEmpty()){
JsonArray animations = new JsonArray();
for(Animation ani : list.animations){
Expand Down Expand Up @@ -316,6 +321,12 @@ public static GroupCompound getModel(File from, JsonObject obj, boolean ggr){
list.setTexture(group.get("texture").getAsString(), texx, texy);
list.textureS = JsonUtil.getIfExists(obj, "texture_scale", 1).intValue();
}
if(group.has("export_offset_x") || group.has("export_offset_y") || group.has("export_offset_z")){
list.exportoffset = new Vec3f();
list.exportoffset.xCoord = JsonUtil.getIfExists(obj, "export_offset_x", 0).floatValue();
list.exportoffset.yCoord = JsonUtil.getIfExists(obj, "export_offset_y", 0).floatValue();
list.exportoffset.zCoord = JsonUtil.getIfExists(obj, "export_offset_z", 0).floatValue();
}
JsonArray polygons = group.get("polygons").getAsJsonArray();
for(JsonElement elm : polygons){
try{
Expand Down
6 changes: 6 additions & 0 deletions src/net/fexcraft/app/fmt/wrappers/GroupCompound.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,19 @@ public void updateFields(){
ModelGroupEditor.g_tex_x.setSelected(8f, true);
ModelGroupEditor.g_tex_y.setSelected(8f, true);
ModelGroupEditor.g_tex_s.setSelected(8f, true);
ModelGroupEditor.exoff_x.apply(0);
ModelGroupEditor.exoff_y.apply(0);
ModelGroupEditor.exoff_z.apply(0);
}
else{
ModelGroupEditor.group_color.apply((list.color == null ? RGB.WHITE : list.color).packed);
ModelGroupEditor.group_name.getTextState().setText(list.id);
ModelGroupEditor.g_tex_x.setSelected((float)list.textureX, true);
ModelGroupEditor.g_tex_y.setSelected((float)list.textureY, true);
ModelGroupEditor.g_tex_s.setSelected((float)list.textureS, true);
ModelGroupEditor.exoff_x.apply(list.exportoffset == null ? 0 : list.exportoffset.xCoord);
ModelGroupEditor.exoff_y.apply(list.exportoffset == null ? 0 : list.exportoffset.yCoord);
ModelGroupEditor.exoff_z.apply(list.exportoffset == null ? 0 : list.exportoffset.zCoord);
//
String texname = list.getGroupTexture() + "";
if(texname.length() > 32){ texname = texname.substring(texname.length() - 32, texname.length()); }
Expand Down
2 changes: 2 additions & 0 deletions src/net/fexcraft/app/fmt/wrappers/TurboList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import net.fexcraft.app.fmt.utils.Animator.Animation;
import net.fexcraft.app.fmt.utils.Settings;
import net.fexcraft.lib.common.math.RGB;
import net.fexcraft.lib.common.math.Vec3f;

public class TurboList extends ArrayList<PolygonWrapper> {

private static final long serialVersionUID = -6386049255131269547L;

public String id; public RGB color;
private boolean rotXb, rotYb, rotZb;
public Vec3f exportoffset;
//private float rotX, rotY, rotZ, posX, posY, posZ;//FMR stuff
public boolean visible = true, minimized, aminimized, selected;
public int tempheight, textureX = 256, textureY = 256, textureS = 1;
Expand Down

0 comments on commit 6e87db3

Please sign in to comment.