Skip to content

Commit 9fd598b

Browse files
committed
updated control property builder, fixed shapes of selected nodes.
1 parent f86f3cb commit 9fd598b

File tree

5 files changed

+215
-510
lines changed

5 files changed

+215
-510
lines changed

src/main/java/com/ss/editor/part3d/editor/impl/scene/AbstractSceneEditor3DPart.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public abstract class AbstractSceneEditor3DPart<T extends AbstractSceneFileEdito
8181
public static final String KEY_LOADED_MODEL = "jMB.sceneEditor.loadedModel";
8282
public static final String KEY_IGNORE_RAY_CAST = "jMB.sceneEditor.ignoreRayCast";
8383
public static final String KEY_MODEL_NODE = "jMB.sceneEditor.modelNode";
84+
public static final String KEY_SHAPE_CENTER = "jMB.sceneEditor.shapeCenter";
8485

8586
private static final String KEY_S = "SSEditor.sceneEditorState.S";
8687
private static final String KEY_G = "SSEditor.sceneEditorState.G";
@@ -878,9 +879,17 @@ protected void postCameraUpdate(final float tpf) {
878879
return;
879880
}
880881

881-
shape.setLocalTranslation(spatial.getWorldTranslation());
882+
final Vector3f position = shape.getLocalTranslation();
883+
position.set(spatial.getWorldTranslation());
884+
885+
final Vector3f center = shape.getUserData(KEY_SHAPE_CENTER);
886+
887+
if (center != null) {
888+
position.addLocal(center);
889+
}
890+
891+
shape.setLocalTranslation(position);
882892
shape.setLocalRotation(spatial.getWorldRotation());
883-
shape.setLocalScale(spatial.getWorldScale());
884893
});
885894

886895
transformToolNode.detachAllChildren();
@@ -1252,18 +1261,24 @@ private void removeFromSelection(@NotNull final Spatial spatial) {
12521261
*/
12531262
@JmeThread
12541263
private Spatial buildBoxSelection(@NotNull final Spatial spatial) {
1255-
spatial.updateModelBound();
1264+
NodeUtils.updateWorldBound(spatial);
12561265

12571266
final BoundingVolume bound = spatial.getWorldBound();
12581267

12591268
if (bound instanceof BoundingBox) {
12601269

12611270
final BoundingBox boundingBox = (BoundingBox) bound;
1271+
final Vector3f center = boundingBox.getCenter().subtract(spatial.getWorldTranslation());
12621272

12631273
final Geometry geometry = WireBox.makeGeometry(boundingBox);
12641274
geometry.setName("SelectionShape");
12651275
geometry.setMaterial(getSelectionMaterial());
1266-
geometry.setLocalTranslation(spatial.getWorldTranslation());
1276+
geometry.setUserData(KEY_SHAPE_CENTER, center);
1277+
1278+
final Vector3f position = geometry.getLocalTranslation();
1279+
position.addLocal(center);
1280+
1281+
geometry.setLocalTranslation(position);
12671282

12681283
return geometry;
12691284

src/main/java/com/ss/editor/plugin/api/editor/material/BaseMaterialFileEditor.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.ss.editor.ui.css.CssClasses;
2424
import com.ss.editor.ui.util.DynamicIconSupport;
2525
import com.ss.rlib.ui.util.FXUtils;
26+
import com.ss.rlib.util.array.Array;
2627
import javafx.collections.ObservableList;
2728
import javafx.scene.control.*;
2829
import javafx.scene.image.ImageView;
@@ -32,6 +33,7 @@
3233
import org.jetbrains.annotations.NotNull;
3334
import org.jetbrains.annotations.Nullable;
3435

36+
import java.util.function.Consumer;
3537
import java.util.function.Supplier;
3638

3739
/**
@@ -42,6 +44,19 @@
4244
public abstract class BaseMaterialFileEditor<T extends BaseMaterialEditor3DPart, S extends EditorMaterialEditorState, C extends ChangeConsumer> extends
4345
Advanced3DFileEditorWithSplitRightTool<T, S> {
4446

47+
private static class MaterialSettingsNodeTree<C extends ChangeConsumer> extends NodeTree<C> {
48+
49+
public MaterialSettingsNodeTree(@NotNull final Consumer<Array<Object>> selectionHandler, @Nullable final C consumer) {
50+
super(selectionHandler, consumer);
51+
}
52+
53+
@Override
54+
@FxThread
55+
protected @NotNull SelectionMode getSelectionMode() {
56+
return SelectionMode.SINGLE;
57+
}
58+
}
59+
4560
/**
4661
* The default state of editor light.
4762
*/
@@ -141,7 +156,7 @@ protected boolean handleKeyActionImpl(@NotNull final KeyCode keyCode, final bool
141156
protected void createToolComponents(@NotNull final EditorToolComponent container, @NotNull final StackPane root) {
142157
super.createToolComponents(container, root);
143158

144-
settingsTree = new NodeTree<>(this::selectedFromTree, getChangeConsumer());
159+
settingsTree = new MaterialSettingsNodeTree<>(this::selectedFromTree, getChangeConsumer());
145160
propertyEditor = new PropertyEditor<>(getChangeConsumer());
146161
propertyEditor.prefHeightProperty().bind(root.heightProperty());
147162

@@ -177,12 +192,14 @@ protected void createToolComponents(@NotNull final EditorToolComponent container
177192
}
178193

179194
/**
180-
* Handle selected object from tree.
195+
* Handle selected objects from tree.
181196
*
182-
* @param object the selected object.
197+
* @param objects the selected objects.
183198
*/
184199
@FxThread
185-
private void selectedFromTree(@Nullable final Object object) {
200+
private void selectedFromTree(@NotNull final Array<Object> objects) {
201+
202+
final Object object = objects.first();
186203

187204
Object parent = null;
188205
Object element;

0 commit comments

Comments
 (0)