Skip to content

Commit e5475ba

Browse files
committed
fixed selecting nodes from scene when opened other editor tools.
1 parent b06837c commit e5475ba

File tree

5 files changed

+101
-18
lines changed

5 files changed

+101
-18
lines changed

src/main/java/com/ss/editor/model/EditorCamera.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,13 @@ protected void verticalRotateCamera(final float value) {
452452
* @param tpf the tpf
453453
*/
454454
public void updateCamera(float tpf) {
455-
if (!enabled) return;
456455

457-
targetLocation.set(target.getWorldTranslation()).addLocal(lookAtOffset);
456+
if (!enabled) {
457+
return;
458+
}
459+
460+
targetLocation.set(target.getWorldTranslation())
461+
.addLocal(lookAtOffset);
458462

459463
if (smoothMotion) {
460464

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

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,16 +2010,46 @@ public void moveCameraTo(@NotNull final Vector3f location) {
20102010
}
20112011

20122012
/**
2013-
* Look at the position from the camera.
2013+
* Look at the spatial.
20142014
*
2015-
* @param location the location.
2015+
* @param spatial the spatial.
20162016
*/
20172017
@FromAnyThread
2018-
public void cameraLookAt(@NotNull final Vector3f location) {
2018+
public void cameraLookAt(@NotNull final Spatial spatial) {
20192019
EXECUTOR_MANAGER.addJmeTask(() -> {
2020+
20202021
final EditorCamera editorCamera = notNull(getEditorCamera());
2021-
editorCamera.setTargetDistance(location.distance(getCamera().getLocation()));
2022-
getNodeForCamera().setLocalTranslation(location);
2022+
2023+
final LocalObjects local = LocalObjects.get();
2024+
float distance;
2025+
2026+
final BoundingVolume worldBound = spatial.getWorldBound();
2027+
2028+
if (worldBound != null) {
2029+
distance = worldBound.getVolume();
2030+
2031+
if (worldBound instanceof BoundingBox) {
2032+
final BoundingBox boundingBox = (BoundingBox) worldBound;
2033+
distance = boundingBox.getXExtent();
2034+
distance = Math.max(distance, boundingBox.getYExtent());
2035+
distance = Math.max(distance, boundingBox.getZExtent());
2036+
distance *= 2F;
2037+
} else if (worldBound instanceof BoundingSphere) {
2038+
distance = ((BoundingSphere) worldBound).getRadius() * 2F;
2039+
}
2040+
2041+
} else {
2042+
2043+
distance = getCamera().getLocation()
2044+
.distance(spatial.getWorldTranslation());
2045+
}
2046+
2047+
editorCamera.setTargetDistance(distance);
2048+
2049+
final Vector3f position = local.nextVector()
2050+
.set(spatial.getWorldTranslation());
2051+
2052+
getNodeForCamera().setLocalTranslation(position);
20232053
});
20242054
}
20252055

src/main/java/com/ss/editor/plugin/api/editor/Advanced3DFileEditorWithRightTool.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ protected void createContent(@NotNull final StackPane root) {
6464
editorToolComponent.addChangeListener((observable, oldValue, newValue) -> processChangeTool(oldValue, newValue));
6565
editorToolComponent.getSelectionModel().selectedIndexProperty().addListener((observable, oldValue, newValue) -> {
6666
final S editorState = getEditorState();
67-
if (editorState != null) editorState.setOpenedTool(newValue.intValue());
67+
if (editorState != null) {
68+
editorState.setOpenedTool(newValue.intValue());
69+
}
6870
});
6971

7072
mainSplitContainer.initFor(editorToolComponent, getEditorAreaPane());
@@ -112,8 +114,10 @@ protected void loadState() {
112114
return;
113115
}
114116

115-
editorToolComponent.getSelectionModel().select(editorState.getOpenedTool());
116-
mainSplitContainer.updateFor(editorState);
117+
getEditorToolComponent().getSelectionModel()
118+
.select(editorState.getOpenedTool());
119+
120+
getMainSplitContainer().updateFor(editorState);
117121
}
118122

119123
@Override
@@ -123,13 +127,35 @@ protected void loadState() {
123127
}
124128

125129
/**
130+
* Get the pane of editor area.
131+
*
126132
* @return the pane of editor area.
127133
*/
128134
@FxThread
129135
protected @NotNull StackPane getEditorAreaPane() {
130136
return notNull(editorAreaPane);
131137
}
132138

139+
/**
140+
* Get the editor tool component.
141+
*
142+
* @return the editor tool component.
143+
*/
144+
@FxThread
145+
protected @NotNull ScrollableEditorToolComponent getEditorToolComponent() {
146+
return notNull(editorToolComponent);
147+
}
148+
149+
/**
150+
* Get the main split container.
151+
*
152+
* @return the main split container.
153+
*/
154+
@FxThread
155+
protected @NotNull EditorToolSplitPane getMainSplitContainer() {
156+
return notNull(mainSplitContainer);
157+
}
158+
133159
/**
134160
* Create and add tool components to the container.
135161
*

src/main/java/com/ss/editor/ui/component/editor/impl/scene/AbstractSceneFileEditor.java

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@
106106
public abstract class AbstractSceneFileEditor<M extends Spatial, MA extends AbstractSceneEditor3DPart, ES extends BaseEditorSceneEditorState> extends
107107
Advanced3DFileEditorWithSplitRightTool<MA, ES> implements ModelChangeConsumer, ModelEditingProvider {
108108

109-
private static final int OBJECTS_TOOL = 0;
110-
private static final int PAINTING_TOOL = 1;
109+
protected static final int OBJECTS_TOOL = 0;
110+
protected static final int PAINTING_TOOL = 1;
111+
protected static final int SCRIPTING_TOOL = 2;
111112

112113
@NotNull
113114
private static final Array<String> ACCEPTED_FILES = ArrayFactory.asArray(
@@ -727,13 +728,31 @@ public void notifySelected(@Nullable Object object) {
727728

728729
setIgnoreCameraMove(true);
729730
try {
731+
730732
final ModelNodeTree modelNodeTree = getModelNodeTree();
731733
modelNodeTree.selectSingle(object);
734+
735+
final SingleSelectionModel<Tab> selectionModel = getEditorToolComponent().getSelectionModel();
736+
if (isNeedToOpenObjectsTool(selectionModel.getSelectedIndex())) {
737+
selectionModel.select(OBJECTS_TOOL);
738+
}
739+
732740
} finally {
733741
setIgnoreCameraMove(false);
734742
}
735743
}
736744

745+
/**
746+
* Return true if need to open objects tool.
747+
*
748+
* @param current the current opened tool.
749+
* @return true if need to open objects tool.
750+
*/
751+
@FxThread
752+
protected boolean isNeedToOpenObjectsTool(final int current) {
753+
return !(current == OBJECTS_TOOL || current == SCRIPTING_TOOL);
754+
}
755+
737756
/**
738757
* Return true of the spatial can be selected.
739758
*
@@ -880,14 +899,12 @@ protected void singleSelectNodesFromTree(@NotNull final Array<?> objects, @NotNu
880899
spatial = null;
881900
}
882901

883-
if (spatial != null) {
902+
if (spatial != null && canSelect(spatial)) {
884903

885-
if (canSelect(spatial)) {
886-
editor3DPart.select(spatial);
887-
}
904+
editor3DPart.select(spatial);
888905

889906
if (!isIgnoreCameraMove() && !isVisibleOnEditor(spatial)) {
890-
editor3DPart.cameraLookAt(spatial.getWorldTranslation());
907+
editor3DPart.cameraLookAt(spatial);
891908
}
892909
}
893910

@@ -1322,7 +1339,7 @@ private void addNewModel(@NotNull final DragEvent dragEvent, @NotNull final Path
13221339
camera.getHeight() - (float) areaPoint.getY());
13231340
final Vector3f result = local.nextVector(scenePoint)
13241341
.subtractLocal(parent.getWorldTranslation());
1325-
1342+
13261343
final boolean isPhysics = NodeUtils.children(loadedModel)
13271344
.flatMap(ControlUtils::controls)
13281345
.anyMatch(PhysicsControl.class::isInstance);

src/main/java/com/ss/editor/ui/component/editor/impl/scene/SceneFileEditor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@ private void updateVisibility(@NotNull final Spatial spatial) {
253253
return notNull(propertyEditorFiltersContainer);
254254
}
255255

256+
@Override
257+
@FxThread
258+
protected boolean isNeedToOpenObjectsTool(final int current) {
259+
return !(current == OBJECTS_TOOL || current == LAYERS_TOOL || current == SCRIPTING_TOOL);
260+
}
261+
256262
/**
257263
* Get the container of property editor in app states tool.
258264
*

0 commit comments

Comments
 (0)