1717import com .ss .editor .annotation .FXThread ;
1818import com .ss .editor .manager .ResourceManager ;
1919import com .ss .editor .state .editor .impl .model .ModelEditor3DState ;
20+ import com .ss .editor .state .editor .impl .model .ModelEditorBulletState ;
2021import com .ss .editor .ui .Icons ;
2122import com .ss .editor .ui .component .editor .EditorDescription ;
2223import com .ss .editor .ui .component .editor .impl .AbstractFileEditor ;
@@ -77,6 +78,9 @@ public class ModelFileEditor extends AbstractSceneFileEditor<Spatial, ModelEdito
7778 FAST_SKY_LIST .add ("graphics/textures/sky/inside.hdr" );
7879 }
7980
81+ @ NotNull
82+ private final ModelEditorBulletState bulletState ;
83+
8084 /**
8185 * The list of fast skies.
8286 */
@@ -89,8 +93,25 @@ public class ModelFileEditor extends AbstractSceneFileEditor<Spatial, ModelEdito
8993 @ Nullable
9094 private ToggleButton lightButton ;
9195
96+ /**
97+ * The physics toggle.
98+ */
99+ @ Nullable
100+ private ToggleButton physicsButton ;
101+
102+ /**
103+ * The debug physics toggle.
104+ */
105+ @ Nullable
106+ private ToggleButton debugPhysicsButton ;
107+
92108 private ModelFileEditor () {
93109 super ();
110+ this .bulletState = new ModelEditorBulletState (getEditor3DState ());
111+ this .bulletState .setEnabled (false );
112+ this .bulletState .setDebugEnabled (false );
113+ this .bulletState .setSpeed (1F );
114+ addEditorState (bulletState );
94115 }
95116
96117 @ Override
@@ -113,6 +134,20 @@ private ModelFileEditor() {
113134 return notNull (lightButton );
114135 }
115136
137+ /**
138+ * @return the physics toggle.
139+ */
140+ private @ NotNull ToggleButton getPhysicsButton () {
141+ return notNull (physicsButton );
142+ }
143+
144+ /**
145+ * @return the debug physics button.
146+ */
147+ private @ NotNull ToggleButton getDebugPhysicsButton () {
148+ return notNull (debugPhysicsButton );
149+ }
150+
116151 @ Override
117152 @ FXThread
118153 protected void doOpenFile (@ NotNull final Path file ) {
@@ -156,6 +191,12 @@ protected void loadState() {
156191
157192 final ToggleButton lightButton = getLightButton ();
158193 lightButton .setSelected (editorState .isEnableLight ());
194+
195+ final ToggleButton physicsButton = getPhysicsButton ();
196+ physicsButton .setSelected (editorState .isEnablePhysics ());
197+
198+ final ToggleButton debugPhysicsButton = getDebugPhysicsButton ();
199+ debugPhysicsButton .setSelected (editorState .isEnableDebugPhysics ());
159200 }
160201
161202 @ Override
@@ -181,6 +222,25 @@ protected void handleAddedObject(@NotNull final Spatial model) {
181222 }
182223 }
183224
225+ @ FXThread
226+ @ Override
227+ protected void handleRemovedObject (@ NotNull final Spatial model ) {
228+ super .handleRemovedObject (model );
229+
230+ final ModelEditor3DState editor3DState = getEditor3DState ();
231+ final Array <Geometry > geometries = ArrayFactory .newArray (Geometry .class );
232+
233+ NodeUtils .addGeometry (model , geometries );
234+
235+ if (!geometries .isEmpty ()) {
236+ geometries .forEach (geometry -> {
237+ if (geometry .getQueueBucket () == RenderQueue .Bucket .Sky ) {
238+ editor3DState .removeCustomSky (geometry );
239+ }
240+ });
241+ }
242+ }
243+
184244 @ Override
185245 public @ NotNull EditorDescription getDescription () {
186246 return DESCRIPTION ;
@@ -219,10 +279,24 @@ protected void createActions(@NotNull final HBox container) {
219279 lightButton .selectedProperty ()
220280 .addListener ((observable , oldValue , newValue ) -> changeLight (newValue ));
221281
222- DynamicIconSupport .addSupport (lightButton );
282+ physicsButton = new ToggleButton ();
283+ physicsButton .setTooltip (new Tooltip (Messages .SCENE_FILE_EDITOR_ACTION_CAMERA_LIGHT ));
284+ physicsButton .setGraphic (new ImageView (Icons .PHYSICS_16 ));
285+ physicsButton .setSelected (false );
286+ physicsButton .selectedProperty ()
287+ .addListener ((observable , oldValue , newValue ) -> changePhysics (newValue ));
288+
289+ debugPhysicsButton = new ToggleButton ();
290+ debugPhysicsButton .setTooltip (new Tooltip (Messages .SCENE_FILE_EDITOR_ACTION_CAMERA_LIGHT ));
291+ debugPhysicsButton .setGraphic (new ImageView (Icons .DEBUG_16 ));
292+ debugPhysicsButton .setSelected (false );
293+ debugPhysicsButton .selectedProperty ()
294+ .addListener ((observable , oldValue , newValue ) -> changeDebugPhysics (newValue ));
223295
224- FXUtils .addClassTo (lightButton , CSSClasses .FILE_EDITOR_TOOLBAR_BUTTON );
225- FXUtils .addToPane (lightButton , container );
296+ DynamicIconSupport .addSupport (lightButton , physicsButton , debugPhysicsButton );
297+
298+ FXUtils .addClassTo (lightButton , physicsButton , debugPhysicsButton , CSSClasses .FILE_EDITOR_TOOLBAR_BUTTON );
299+ FXUtils .addToPane (lightButton , physicsButton , debugPhysicsButton , container );
226300 }
227301
228302 /**
@@ -258,6 +332,35 @@ private void changeFastSky(@NotNull final String newSky) {
258332 if (editorState != null ) editorState .setSkyType (selectedIndex );
259333 }
260334
335+ /**
336+ * @return the bullet state.
337+ */
338+ private @ NotNull ModelEditorBulletState getBulletState () {
339+ return bulletState ;
340+ }
341+
342+ /**
343+ * Handle to change enabling of physics.
344+ */
345+ private void changePhysics (@ NotNull final Boolean newValue ) {
346+ if (isIgnoreListeners ()) return ;
347+
348+ EXECUTOR_MANAGER .addJMETask (() -> getBulletState ().setEnabled (newValue ));
349+
350+ if (editorState != null ) editorState .setEnablePhysics (newValue );
351+ }
352+
353+ /**
354+ * Handle to change enabling of physics.
355+ */
356+ private void changeDebugPhysics (@ NotNull final Boolean newValue ) {
357+ if (isIgnoreListeners ()) return ;
358+
359+ EXECUTOR_MANAGER .addJMETask (() -> getBulletState ().setDebugEnabled (newValue ));
360+
361+ if (editorState != null ) editorState .setEnableDebugPhysics (newValue );
362+ }
363+
261364 /**
262365 * Handle changing camera light visibility.
263366 */
@@ -287,6 +390,8 @@ public void notifyFXAddedChild(@NotNull final Object parent, @NotNull final Obje
287390 editor3DState .updateLightProbe ();
288391 }
289392 }
393+
394+ EXECUTOR_MANAGER .addFXTask (() -> getBulletState ().notifyAdded (added ));
290395 }
291396
292397 @ Override
@@ -305,6 +410,8 @@ public void notifyFXRemovedChild(@NotNull final Object parent, @NotNull final Ob
305410 editor3DState .updateLightProbe ();
306411 }
307412 }
413+
414+ EXECUTOR_MANAGER .addFXTask (() -> getBulletState ().notifyRemoved (removed ));
308415 }
309416
310417 @ Override
0 commit comments