22
33import static com .ss .editor .util .NodeUtils .findParent ;
44import static com .ss .rlib .util .ObjectUtils .notNull ;
5- import static java .util .stream .Collectors .toMap ;
6-
75import com .jme3 .app .state .AppState ;
86import com .jme3 .asset .AssetManager ;
97import com .jme3 .asset .AssetNotFoundException ;
@@ -82,6 +80,7 @@ public abstract class AbstractSceneEditor3DPart<T extends AbstractSceneFileEdito
8280 public static final String KEY_IGNORE_RAY_CAST = "jMB.sceneEditor.ignoreRayCast" ;
8381 public static final String KEY_MODEL_NODE = "jMB.sceneEditor.modelNode" ;
8482 public static final String KEY_SHAPE_CENTER = "jMB.sceneEditor.shapeCenter" ;
83+ public static final String KEY_SHAPE_INIT_SCALE = "jMB.sceneEditor.initScale" ;
8584
8685 private static final String KEY_S = "SSEditor.sceneEditorState.S" ;
8786 private static final String KEY_G = "SSEditor.sceneEditorState.G" ;
@@ -211,7 +210,7 @@ public static void registerPostTransformHandler(@NotNull final Consumer<Spatial>
211210 * The selection models of selected models.
212211 */
213212 @ NotNull
214- private final ObjectDictionary <Spatial , Spatial > selectionShape ;
213+ private final ObjectDictionary <Spatial , Geometry > selectionShape ;
215214
216215 /**
217216 * The array of selected models.
@@ -873,8 +872,8 @@ protected void postCameraUpdate(final float tpf) {
873872
874873 state .updateTransformNode (spatial .getWorldTransform ());
875874
876- final ObjectDictionary <Spatial , Spatial > selectionShape = state .getSelectionShape ();
877- final Spatial shape = selectionShape .get (spatial );
875+ final ObjectDictionary <Spatial , Geometry > selectionShape = state .getSelectionShape ();
876+ final Geometry shape = selectionShape .get (spatial );
878877 if (shape == null ) {
879878 return ;
880879 }
@@ -883,13 +882,31 @@ protected void postCameraUpdate(final float tpf) {
883882 position .set (spatial .getWorldTranslation ());
884883
885884 final Vector3f center = shape .getUserData (KEY_SHAPE_CENTER );
885+ final Vector3f initScale = shape .getUserData (KEY_SHAPE_INIT_SCALE );
886886
887887 if (center != null ) {
888+
889+ if (!initScale .equals (spatial .getLocalScale ())) {
890+
891+ initScale .set (spatial .getLocalScale ());
892+
893+ NodeUtils .updateWorldBound (spatial );
894+
895+ final BoundingBox bound = (BoundingBox ) spatial .getWorldBound ();
896+ bound .getCenter ().subtract (spatial .getWorldTranslation (), center );
897+
898+ final WireBox mesh = (WireBox ) shape .getMesh ();
899+ mesh .updatePositions (bound .getXExtent (), bound .getYExtent (), bound .getZExtent ());
900+ }
901+
888902 position .addLocal (center );
903+
904+ } else {
905+ shape .setLocalRotation (spatial .getWorldRotation ());
906+ shape .setLocalScale (spatial .getWorldScale ());
889907 }
890908
891909 shape .setLocalTranslation (position );
892- shape .setLocalRotation (spatial .getWorldRotation ());
893910 });
894911
895912 transformToolNode .detachAllChildren ();
@@ -1028,7 +1045,7 @@ private void updateTransformNode(@Nullable final Transform transform) {
10281045 * @return the selection models of selected models.
10291046 */
10301047 @ FromAnyThread
1031- private @ NotNull ObjectDictionary <Spatial , Spatial > getSelectionShape () {
1048+ private @ NotNull ObjectDictionary <Spatial , Geometry > getSelectionShape () {
10321049 return selectionShape ;
10331050 }
10341051
@@ -1213,7 +1230,7 @@ private void addToSelection(@NotNull final Spatial spatial) {
12131230 return ;
12141231 }
12151232
1216- Spatial shape ;
1233+ Geometry shape ;
12171234
12181235 if (spatial instanceof ParticleEmitter ) {
12191236 shape = buildBoxSelection (spatial );
@@ -1232,7 +1249,7 @@ private void addToSelection(@NotNull final Spatial spatial) {
12321249 toolNode .attachChild (shape );
12331250 }
12341251
1235- final ObjectDictionary <Spatial , Spatial > selectionShape = getSelectionShape ();
1252+ final ObjectDictionary <Spatial , Geometry > selectionShape = getSelectionShape ();
12361253 selectionShape .put (spatial , shape );
12371254 }
12381255
@@ -1244,7 +1261,7 @@ private void removeFromSelection(@NotNull final Spatial spatial) {
12441261 setTransformCenter (null );
12451262 setToTransform (null );
12461263
1247- final ObjectDictionary <Spatial , Spatial > selectionShape = getSelectionShape ();
1264+ final ObjectDictionary <Spatial , Geometry > selectionShape = getSelectionShape ();
12481265
12491266 final Spatial shape = selectionShape .remove (spatial );
12501267 if (shape != null ) {
@@ -1260,7 +1277,7 @@ private void removeFromSelection(@NotNull final Spatial spatial) {
12601277 * Build the selection box for the spatial.
12611278 */
12621279 @ JmeThread
1263- private Spatial buildBoxSelection (@ NotNull final Spatial spatial ) {
1280+ private Geometry buildBoxSelection (@ NotNull final Spatial spatial ) {
12641281 NodeUtils .updateWorldBound (spatial );
12651282
12661283 final BoundingVolume bound = spatial .getWorldBound ();
@@ -1269,11 +1286,13 @@ private Spatial buildBoxSelection(@NotNull final Spatial spatial) {
12691286
12701287 final BoundingBox boundingBox = (BoundingBox ) bound ;
12711288 final Vector3f center = boundingBox .getCenter ().subtract (spatial .getWorldTranslation ());
1289+ final Vector3f initScale = spatial .getLocalScale ().clone ();
12721290
12731291 final Geometry geometry = WireBox .makeGeometry (boundingBox );
12741292 geometry .setName ("SelectionShape" );
12751293 geometry .setMaterial (getSelectionMaterial ());
12761294 geometry .setUserData (KEY_SHAPE_CENTER , center );
1295+ geometry .setUserData (KEY_SHAPE_INIT_SCALE , initScale );
12771296
12781297 final Vector3f position = geometry .getLocalTranslation ();
12791298 position .addLocal (center );
@@ -1308,10 +1327,12 @@ private Spatial buildBoxSelection(@NotNull final Spatial spatial) {
13081327 * Build selection grid for the geometry.
13091328 */
13101329 @ JmeThread
1311- private Spatial buildGeometrySelection (@ NotNull final Geometry geom ) {
1330+ private Geometry buildGeometrySelection (@ NotNull final Geometry geom ) {
13121331
13131332 final Mesh mesh = geom .getMesh ();
1314- if (mesh == null ) return null ;
1333+ if (mesh == null ) {
1334+ return null ;
1335+ }
13151336
13161337 final Geometry geometry = new Geometry ("SelectionShape" , mesh );
13171338 geometry .setMaterial (getSelectionMaterial ());
@@ -1380,7 +1401,7 @@ private void updateShowSelectionImpl(final boolean showSelection) {
13801401 return ;
13811402 }
13821403
1383- final ObjectDictionary <Spatial , Spatial > selectionShape = getSelectionShape ();
1404+ final ObjectDictionary <Spatial , Geometry > selectionShape = getSelectionShape ();
13841405 final Node toolNode = getToolNode ();
13851406
13861407 if (showSelection && !selectionShape .isEmpty ()) {
0 commit comments