11package com .ss .editor .control .transform ;
22
3+ import static com .ss .editor .util .GeomUtils .*;
34import com .jme3 .math .Quaternion ;
45import com .jme3 .math .Transform ;
56import com .jme3 .math .Vector3f ;
67import com .jme3 .renderer .Camera ;
78import com .jme3 .scene .Node ;
89import com .jme3 .scene .Spatial ;
9- import com .ss .editor .util .GeomUtils ;
1010import com .ss .editor .util .LocalObjects ;
1111import org .jetbrains .annotations .NotNull ;
1212import org .jetbrains .annotations .Nullable ;
@@ -98,6 +98,20 @@ public void prepareToRotate(@NotNull final Node parent, @NotNull final Node chil
9898 child .setLocalRotation (transform .getRotation ());
9999 }
100100
101+ @ NotNull
102+ @ Override
103+ protected Vector3f getScaleAxis (@ NotNull final Transform transform , @ NotNull final PickedAxis pickedAxis ,
104+ @ NotNull final Camera camera ) {
105+
106+ final LocalObjects local = LocalObjects .get ();
107+
108+ if (pickedAxis == PickedAxis .Y ) {
109+ return getUp (transform .getRotation (), local .nextVector ());
110+ } else if (pickedAxis == PickedAxis .Z ) {
111+ return getDirection (transform .getRotation (), local .nextVector ());
112+ } else return getLeft (transform .getRotation (), local .nextVector ());
113+ }
114+
101115 @ Override
102116 public void prepareToMove (@ NotNull final Node parent , @ NotNull final Node child ,
103117 @ NotNull final Transform transform , @ NotNull final Camera camera ) {
@@ -125,13 +139,18 @@ public void prepareToRotate(@NotNull final Node parent, @NotNull final Node chil
125139 child .setLocalRotation (transform .getRotation ());
126140 }
127141
142+ @ NotNull
128143 @ Override
129- public void prepareToMove (@ NotNull final Node parent , @ NotNull final Node child ,
130- @ NotNull final Transform transform , @ NotNull final Camera camera ) {
131- parent .setLocalRotation (camera .getRotation ());
132- parent .setLocalTranslation (transform .getTranslation ());
133- child .setLocalTranslation (Vector3f .ZERO );
134- child .setLocalRotation (Quaternion .IDENTITY );
144+ protected Vector3f getScaleAxis (@ NotNull final Transform transform , @ NotNull final PickedAxis pickedAxis ,
145+ @ NotNull final Camera camera ) {
146+
147+ final LocalObjects local = LocalObjects .get ();
148+
149+ if (pickedAxis == PickedAxis .Y ) {
150+ return getUp (camera .getRotation (), local .nextVector ());
151+ } else if (pickedAxis == PickedAxis .Z ) {
152+ return getDirection (camera .getRotation (), local .nextVector ());
153+ } else return getLeft (camera .getRotation (), local .nextVector ());
135154 }
136155
137156 @ NotNull
@@ -142,12 +161,19 @@ protected Vector3f getPickedVector(@NotNull final Transform transform, @NotNull
142161 final LocalObjects local = LocalObjects .get ();
143162
144163 if (pickedAxis == PickedAxis .Y ) {
145- return GeomUtils . getUp (camera .getRotation (), local .nextVector ());
164+ return getUp (camera .getRotation (), local .nextVector ());
146165 } else if (pickedAxis == PickedAxis .Z ) {
147- return GeomUtils .getDirection (camera .getRotation (), local .nextVector ());
148- } else {
149- return GeomUtils .getLeft (camera .getRotation (), local .nextVector ());
150- }
166+ return getDirection (camera .getRotation (), local .nextVector ());
167+ } else return getLeft (camera .getRotation (), local .nextVector ());
168+ }
169+
170+ @ Override
171+ public void prepareToMove (@ NotNull final Node parent , @ NotNull final Node child ,
172+ @ NotNull final Transform transform , @ NotNull final Camera camera ) {
173+ parent .setLocalRotation (camera .getRotation ());
174+ parent .setLocalTranslation (transform .getTranslation ());
175+ child .setLocalTranslation (Vector3f .ZERO );
176+ child .setLocalRotation (Quaternion .IDENTITY );
151177 }
152178
153179 @ NotNull
@@ -178,7 +204,7 @@ public Quaternion getToolRotation(@NotNull final Transform transform, @NotNull f
178204 }
179205
180206 /**
181- * Apply rotations to nodes to calculate transformations .
207+ * Prepare nodes to rotate .
182208 *
183209 * @param parent the parent node.
184210 * @param child the child node.
@@ -192,7 +218,21 @@ public void prepareToRotate(@NotNull final Node parent, @NotNull final Node chil
192218 }
193219
194220 /**
195- * Apply positions to nodes to calculate transformations.
221+ * Prepare nodes to scale.
222+ *
223+ * @param parent the parent node.
224+ * @param child the child node.
225+ * @param transform the base transform.
226+ * @param camera the camera.
227+ */
228+ public void prepareToScale (@ NotNull final Node parent , @ NotNull final Node child ,
229+ @ NotNull final Transform transform , @ NotNull final Camera camera ) {
230+ parent .setLocalScale (transform .getScale ());
231+ child .setLocalScale (Vector3f .UNIT_XYZ );
232+ }
233+
234+ /**
235+ * Prepare nodes to move.
196236 *
197237 * @param parent the parent node.
198238 * @param child the child node.
@@ -227,15 +267,22 @@ protected Vector3f getPickedVector(@NotNull final Transform transform, @NotNull
227267 }
228268
229269 /**
230- * Gets the rotation to calculate scale transformations .
270+ * Get a vector to calculate scaling by the axis .
231271 *
232- * @param spatial the spatial.
233- * @param camera the camera.
234- * @return the target rotation.
272+ * @param transform the base transform.
273+ * @param pickedAxis the picked Axis.
274+ * @param camera the camera.
275+ * @return the axis vector.
235276 */
236277 @ NotNull
237- public Quaternion getScaleRotation (@ NotNull final Spatial spatial , @ NotNull final Camera camera ) {
238- return spatial .getWorldRotation ();
278+ protected Vector3f getScaleAxis (@ NotNull final Transform transform , @ NotNull final PickedAxis pickedAxis ,
279+ @ NotNull final Camera camera ) {
280+
281+ if (pickedAxis == PickedAxis .Y ) {
282+ return Vector3f .UNIT_Y ;
283+ } else if (pickedAxis == PickedAxis .Z ) {
284+ return Vector3f .UNIT_Z ;
285+ } else return Vector3f .UNIT_X ;
239286 }
240287 }
241288
@@ -278,19 +325,46 @@ public Quaternion getScaleRotation(@NotNull final Spatial spatial, @NotNull fina
278325 Node getCollisionPlane ();
279326
280327 /**
281- * Sets delta vector .
328+ * Set delta of transformation .
282329 *
283- * @param deltaVector the delta vector .
330+ * @param transformDeltaX the x delta .
284331 */
285- void setDeltaVector ( @ Nullable final Vector3f deltaVector );
332+ void setTransformDeltaX ( float transformDeltaX );
286333
287334 /**
288- * Gets delta vector .
335+ * Set delta of transformation .
289336 *
290- * @return the delta vector .
337+ * @param transformDeltaY the y delta .
291338 */
292- @ Nullable
293- Vector3f getDeltaVector ();
339+ void setTransformDeltaY (float transformDeltaY );
340+
341+ /**
342+ * Set delta of transformation.
343+ *
344+ * @param transformDeltaZ the z delta.
345+ */
346+ void setTransformDeltaZ (float transformDeltaZ );
347+
348+ /**
349+ * Get delta of transformation.
350+ *
351+ * @return the delta x.
352+ */
353+ float getTransformDeltaX ();
354+
355+ /**
356+ * Get delta of transformation.
357+ *
358+ * @return the delta y.
359+ */
360+ float getTransformDeltaY ();
361+
362+ /**
363+ * Get delta of transformation.
364+ *
365+ * @return the delta z.
366+ */
367+ float getTransformDeltaZ ();
294368
295369 /**
296370 * Gets to transform.
0 commit comments