Skip to content

Commit

Permalink
Utility to select all unused nodes even on HD models
Browse files Browse the repository at this point in the history
  • Loading branch information
Retera committed Jul 17, 2022
1 parent 84d445f commit ecbb857
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public UndoAction invertSelection() {
private void toggleSelection(final Set<IdObject> selection, final IdObject position) {
if (selection.contains(position)) {
selection.remove(position);
} else {
}
else {
selection.add(position);
}
}
Expand All @@ -213,6 +214,14 @@ public UndoAction selectAll() {
return new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select all");
}

@Override
public UndoAction selectHDUnusedNodes() {
final ArrayList<IdObject> oldSelection = new ArrayList<>(selectionManager.getSelection());
final Set<IdObject> allSelection = new HashSet<>();
selectionManager.setSelection(allSelection);
return new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select HD unused");
}

@Override
protected List<IdObject> genericSelect(final Rectangle2D region, final CoordinateSystem coordinateSystem) {
final List<IdObject> selectedItems = new ArrayList<>();
Expand Down Expand Up @@ -688,10 +697,11 @@ public UndoAction setPosition(final Vertex center, final double x, final double

@Override
public UndoAction rotate(final Vertex center, final double rotateX, final double rotateY, final double rotateZ) {
return new CompoundAction("rotate", CollectionUtils.asList(Arrays.asList(
beginRotation(center.x, center.y, center.z, (byte) 2, (byte) 1).updateRotation(rotateX),
beginRotation(center.x, center.y, center.z, (byte) 0, (byte) 2).updateRotation(rotateY),
beginRotation(center.x, center.y, center.z, (byte) 1, (byte) 0).updateRotation(rotateZ))));
return new CompoundAction("rotate",
CollectionUtils.asList(Arrays.asList(
beginRotation(center.x, center.y, center.z, (byte) 2, (byte) 1).updateRotation(rotateX),
beginRotation(center.x, center.y, center.z, (byte) 0, (byte) 2).updateRotation(rotateY),
beginRotation(center.x, center.y, center.z, (byte) 1, (byte) 0).updateRotation(rotateZ))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ public UndoAction invertSelection() {
for (final Triangle triangle : geoset.getTriangles()) {
if (invertedSelection.contains(triangle)) {
invertedSelection.remove(triangle);
} else {
}
else {
invertedSelection.add(triangle);
}
}
Expand All @@ -154,6 +155,14 @@ public UndoAction selectAll() {
return new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select all");
}

@Override
public UndoAction selectHDUnusedNodes() {
final Set<Triangle> oldSelection = new HashSet<>(selectionManager.getSelection());
final Set<Triangle> allSelection = new HashSet<>();
selectionManager.setSelection(allSelection);
return new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select HD unused");
}

@Override
protected List<Triangle> genericSelect(final Rectangle2D region, final CoordinateSystem coordinateSystem) {
final List<Triangle> newSelection = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ public UndoAction invertSelection() {
private void toggleSelection(final Set<GeosetVertex> selection, final GeosetVertex position) {
if (selection.contains(position)) {
selection.remove(position);
} else {
}
else {
selection.add(position);
}
}
Expand All @@ -156,6 +157,14 @@ public UndoAction selectAll() {
return (new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select all"));
}

@Override
public UndoAction selectHDUnusedNodes() {
final ArrayList<GeosetVertex> oldSelection = new ArrayList<>(selectionManager.getSelection());
final Set<GeosetVertex> allSelection = new HashSet<>();
selectionManager.setSelection(allSelection);
return (new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select HD unused"));
}

@Override
protected List<GeosetVertex> genericSelect(final Rectangle2D region, final CoordinateSystem coordinateSystem) {
final List<GeosetVertex> selectedItems = new ArrayList<>();
Expand Down Expand Up @@ -281,7 +290,8 @@ public CopiedModelData copySelection() {
newGeosetVertex.getTriangles().clear();
copiedVertices.add(newGeosetVertex);
triangleVertices.add(newGeosetVertex);
} else {
}
else {
triangleIsFullySelected = false;
}
}
Expand Down Expand Up @@ -333,7 +343,8 @@ public UndoAction addVertex(final double x, final double y, final double z,
final NewGeosetAction newGeosetAction = new NewGeosetAction(solidWhiteGeoset, model.getModel(),
structureChangeListener);
action = new CompoundAction("add vertex", ListView.Util.of(newGeosetAction, drawVertexAction));
} else {
}
else {
action = drawVertexAction;
}
action.redo();
Expand All @@ -354,7 +365,8 @@ public UndoAction createFaceFromSelection(final Vertex preferredFacingVector) {
verticesArray[index++] = vertex;
if (geoset == null) {
geoset = vertex.getGeoset();
} else if (geoset != vertex.getGeoset()) {
}
else if (geoset != vertex.getGeoset()) {
throw new FaceCreationException(
"All three vertices to create a face must be a part of the same Geoset");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ GenericMoveAction addBox(double x, double y, double x2, double y2, byte dim1, by

UndoAction selectAll();

UndoAction selectHDUnusedNodes();

@Override
UndoAction hideComponent(ListView<? extends SelectableComponent> selectableComponents,
EditabilityToggleHandler editabilityToggleHandler, Runnable refreshGUIRunnable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ public UndoAction selectAll() {
return mergeActions(actions);
}

@Override
public UndoAction selectHDUnusedNodes() {
final List<UndoAction> actions = new ArrayList<>();
for (final ModelEditor handler : set) {
actions.add(handler.selectHDUnusedNodes());
}
return mergeActions(actions);
}

@Override
public UndoAction hideComponent(final ListView<? extends SelectableComponent> selectableComponents,
final EditabilityToggleHandler editabilityToggleHandler, final Runnable refreshGUIRunnable) {
Expand All @@ -134,7 +143,8 @@ public UndoAction autoCenterSelectedBones() {
for (final ModelEditor handler : set) {
try {
actions.add(handler.autoCenterSelectedBones());
} catch (final UnsupportedOperationException e) {
}
catch (final UnsupportedOperationException e) {
// don't add actions for unsupported operations
}
}
Expand All @@ -147,7 +157,8 @@ public UndoAction setSelectedBoneName(final String name) {
for (final ModelEditor handler : set) {
try {
actions.add(handler.setSelectedBoneName(name));
} catch (final UnsupportedOperationException e) {
}
catch (final UnsupportedOperationException e) {
// don't add actions for unsupported operations
}
}
Expand All @@ -160,7 +171,8 @@ public UndoAction addSelectedBoneSuffix(final String name) {
for (final ModelEditor handler : set) {
try {
actions.add(handler.addSelectedBoneSuffix(name));
} catch (final UnsupportedOperationException e) {
}
catch (final UnsupportedOperationException e) {
// don't add actions for unsupported operations
}
}
Expand All @@ -173,7 +185,8 @@ public UndoAction setParent(final IdObject parent) {
for (final ModelEditor handler : set) {
try {
actions.add(handler.setParent(parent));
} catch (final UnsupportedOperationException e) {
}
catch (final UnsupportedOperationException e) {
// don't add actions for unsupported operations
}
}
Expand Down Expand Up @@ -534,7 +547,8 @@ public UndoAction addBone(final double x, final double y, final double z) {
for (final ModelEditor handler : set) {
try {
actions.add(handler.addBone(x, y, z));
} catch (final WrongModeException e) {
}
catch (final WrongModeException e) {
// don't add actions for unsupported operations
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ public void attachment(final Attachment attachment) {
private void toggleSelection(final Set<Vertex> selection, final Vertex position) {
if (selection.contains(position)) {
selection.remove(position);
} else {
}
else {
selection.add(position);
}
}
Expand Down Expand Up @@ -475,6 +476,38 @@ public void attachment(final Attachment attachment) {
return new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select all");
}

@Override
public UndoAction selectHDUnusedNodes() {
final ArrayList<Vertex> oldSelection = new ArrayList<>(selectionManager.getSelection());
final Set<Bone> usedBones = new HashSet<>();
for (final Geoset geoset : model.getEditableGeosets()) {
for (final GeosetVertex vertex : geoset.getVertices()) {
final Bone[] skinBones = vertex.getSkinBones();
if (skinBones != null) {
for (int i = 0; i < skinBones.length; i++) {
final Bone bone = skinBones[i];
if (bone != null) {
usedBones.add(bone);
}
}
}
else {
for (final Bone bone : vertex.getBoneAttachments()) {
usedBones.add(bone);
}
}
}
}
final Set<Vertex> allSelection = new HashSet<>();
for (final IdObject node : model.getEditableIdObjects()) {
if ((node instanceof Bone) && !usedBones.contains(node)) {
allSelection.add(node.getPivotPoint());
}
}
selectionManager.setSelection(allSelection);
return new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select HD unused");
}

@Override
protected List<Vertex> genericSelect(final Rectangle2D region, final CoordinateSystem coordinateSystem) {
final List<Vertex> selectedItems = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ public UndoAction invertSelection() {
private void toggleSelection(final Set<Vertex> selection, final Vertex position) {
if (selection.contains(position)) {
selection.remove(position);
} else {
}
else {
selection.add(position);
}
}
Expand Down Expand Up @@ -367,6 +368,11 @@ public UndoAction selectAll() {
// selectionManager, "select all"));
}

@Override
public UndoAction selectHDUnusedNodes() {
throw new WrongModeException("Not supported in T-Pose mode");
}

@Override
protected List<IdObject> genericSelect(final Rectangle2D region, final CoordinateSystem coordinateSystem) {
final List<IdObject> selectedItems = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public boolean equals(final Object obj) {
if (other.geoset != null) {
return false;
}
} else if (!geoset.equals(other.geoset)) {
}
else if (!geoset.equals(other.geoset)) {
return false;
}
if (vertexGroupId != other.vertexGroupId) {
Expand Down Expand Up @@ -151,7 +152,8 @@ public UndoAction invertSelection() {
final VertexGroupBundle bundle = new VertexGroupBundle(geoset, vertexGroupId);
if (invertedSelection.contains(bundle)) {
invertedSelection.remove(bundle);
} else {
}
else {
invertedSelection.add(bundle);
}
}
Expand All @@ -175,6 +177,14 @@ public UndoAction selectAll() {
return (new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select all"));
}

@Override
public UndoAction selectHDUnusedNodes() {
final Set<VertexGroupBundle> oldSelection = new HashSet<>(selectionManager.getSelection());
final Set<VertexGroupBundle> allSelection = new HashSet<>();
selectionManager.setSelection(allSelection);
return (new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select HD unused"));
}

@Override
public boolean canSelectAt(final Point point, final CoordinateSystem axes) {
boolean canSelect = false;
Expand Down Expand Up @@ -312,7 +322,8 @@ public CopiedModelData copySelection() {
newGeosetVertex.getTriangles().clear();
copiedVertices.add(newGeosetVertex);
triangleVertices.add(newGeosetVertex);
} else {
}
else {
triangleIsFullySelected = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public boolean equals(final Object obj) {
if (other.geoset != null) {
return false;
}
} else if (!geoset.equals(other.geoset)) {
}
else if (!geoset.equals(other.geoset)) {
return false;
}
if (vertexGroupId != other.vertexGroupId) {
Expand Down Expand Up @@ -144,7 +145,8 @@ public UndoAction invertSelection() {
final VertexGroupBundle bundle = new VertexGroupBundle(geoset, vertexGroupId);
if (invertedSelection.contains(bundle)) {
invertedSelection.remove(bundle);
} else {
}
else {
invertedSelection.add(bundle);
}
}
Expand All @@ -167,6 +169,14 @@ public UndoAction selectAll() {
return (new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select all"));
}

@Override
public UndoAction selectHDUnusedNodes() {
final Set<VertexGroupBundle> oldSelection = new HashSet<>(selectionManager.getSelection());
final Set<VertexGroupBundle> allSelection = new HashSet<>();
selectionManager.setSelection(allSelection);
return (new SetSelectionAction<>(allSelection, oldSelection, selectionManager, "select HD unused"));
}

@Override
public boolean canSelectAt(final Point point, final CoordinateSystem axes) {
boolean canSelect = false;
Expand Down Expand Up @@ -303,7 +313,8 @@ public CopiedModelData copySelection() {
newGeosetVertex.getTriangles().clear();
copiedVertices.add(newGeosetVertex);
triangleVertices.add(newGeosetVertex);
} else {
}
else {
triangleIsFullySelected = false;
}
}
Expand Down
14 changes: 14 additions & 0 deletions matrixeater/src/com/matrixeater/src/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3521,6 +3521,20 @@ public void actionPerformed(final ActionEvent e) {
forDarkfang.add(removeAll3D);
scriptsMenu.add(forDarkfang);

final JMenuItem selectHDUnused = new JMenuItem("Select HD Unused Bones");
selectHDUnused.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final ModelPanel mpanel = currentModelPanel();
if (mpanel != null) {
mpanel.getUndoManager()
.pushAction(mpanel.getModelEditorManager().getModelEditor().selectHDUnusedNodes());
}
repaint();
}
});
scriptsMenu.add(selectHDUnused);

final JMenuItem jokebutton = new JMenuItem("Load Retera Land");
jokebutton.setMnemonic(KeyEvent.VK_A);
jokebutton.addActionListener(new ActionListener() {
Expand Down

0 comments on commit ecbb857

Please sign in to comment.