Преглед на файлове

Add animation support to material editor

Co-authored-by: neph1 <[email protected]>
copilot-swe-agent[bot] преди 4 дни
родител
ревизия
4d7439d749

+ 31 - 0
jme3-materialeditor/src/com/jme3/gde/materialdefinition/editor/MatPanel.java

@@ -52,6 +52,7 @@ import javax.swing.Timer;
 public class MatPanel extends JPanel implements MouseListener, ComponentListener {
     private final MaterialPreviewRenderer renderer;
     private Material mat;
+    private boolean animationEnabled = false;
     /**
      * Creates new form PreviewPanel
      */
@@ -64,6 +65,7 @@ public class MatPanel extends JPanel implements MouseListener, ComponentListener
     }
     
     public void cleanup() {
+        animationTimer.stop();
         renderer.cleanUp();        
     }
     
@@ -366,6 +368,15 @@ public class MatPanel extends JPanel implements MouseListener, ComponentListener
         }
     });
     
+    private final Timer animationTimer = new Timer(20, new ActionListener() {
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            if (animationEnabled && mat != null) {
+                renderer.refreshOnly();
+            }
+        }
+    });
+    
     @Override
     public void mouseExited(MouseEvent e) {
         t.restart();
@@ -399,4 +410,24 @@ public class MatPanel extends JPanel implements MouseListener, ComponentListener
             renderer.showMaterial(mat);
         }
     }
+    
+    /**
+     * Enable or disable animation rendering
+     * @param enabled true to enable continuous rendering, false to disable
+     */
+    public void setAnimationEnabled(boolean enabled) {
+        this.animationEnabled = enabled;
+        if (enabled) {
+            animationTimer.start();
+        } else {
+            animationTimer.stop();
+        }
+    }
+    
+    /**
+     * @return true if animation rendering is enabled
+     */
+    public boolean isAnimationEnabled() {
+        return animationEnabled;
+    }
 }

+ 62 - 0
jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/MaterialPreviewWidget.java

@@ -41,6 +41,9 @@ import com.jme3.gde.core.scene.SceneApplication;
 import com.jme3.gde.core.scene.SceneRequest;
 import com.jme3.gde.materials.MaterialPreviewRenderer;
 import com.jme3.gde.materials.multiview.widgets.icons.Icons;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.Timer;
 
 /**
  *
@@ -50,11 +53,21 @@ public class MaterialPreviewWidget extends javax.swing.JPanel {
 
     private boolean init=false;
     private MaterialPreviewRenderer matRenderer;
+    private boolean animationEnabled = false;
     
     /** Creates new form MaterialPreviewWidget */
     public MaterialPreviewWidget() {
         initComponents();        
     }
+    
+    private final Timer animationTimer = new Timer(20, new ActionListener() {
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            if (animationEnabled && matRenderer != null) {
+                matRenderer.refreshOnly();
+            }
+        }
+    });
 
     private  void initWidget() {
         sphereButton.setSelected(true);
@@ -81,9 +94,33 @@ public class MaterialPreviewWidget extends javax.swing.JPanel {
     }
 
     public void cleanUp(){
+         animationTimer.stop();
          matRenderer.cleanUp();
     }
     
+    /**
+     * Enable or disable animation rendering
+     * @param enabled true to enable continuous rendering, false to disable
+     */
+    public void setAnimationEnabled(boolean enabled) {
+        this.animationEnabled = enabled;
+        if (animationToggleButton != null) {
+            animationToggleButton.setSelected(enabled);
+        }
+        if (enabled) {
+            animationTimer.start();
+        } else {
+            animationTimer.stop();
+        }
+    }
+    
+    /**
+     * @return true if animation rendering is enabled
+     */
+    public boolean isAnimationEnabled() {
+        return animationEnabled;
+    }
+    
     /** This method is called from within the constructor to
      * initialize the form.
      * WARNING: Do NOT modify this code. The content of this method is
@@ -102,6 +139,8 @@ public class MaterialPreviewWidget extends javax.swing.JPanel {
         teapotButton = new javax.swing.JToggleButton();
         jSeparator1 = new javax.swing.JToolBar.Separator();
         togglePbrEnvButton = new javax.swing.JToggleButton();
+        jSeparator2 = new javax.swing.JToolBar.Separator();
+        animationToggleButton = new javax.swing.JToggleButton();
 
         setMaximumSize(new java.awt.Dimension(244, 200));
         setMinimumSize(new java.awt.Dimension(244, 200));
@@ -213,6 +252,23 @@ public class MaterialPreviewWidget extends javax.swing.JPanel {
             }
         });
         jToolBar1.add(togglePbrEnvButton);
+        jToolBar1.add(jSeparator2);
+
+        animationToggleButton.setIcon(Icons.animationOff);
+        animationToggleButton.setToolTipText("Enable animation rendering");
+        animationToggleButton.setFocusable(false);
+        animationToggleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
+        animationToggleButton.setMaximumSize(new java.awt.Dimension(40, 40));
+        animationToggleButton.setMinimumSize(new java.awt.Dimension(40, 40));
+        animationToggleButton.setPreferredSize(new java.awt.Dimension(40, 40));
+        animationToggleButton.setSelectedIcon(Icons.animationOn);
+        animationToggleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
+        animationToggleButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                animationToggleButtonActionPerformed(evt);
+            }
+        });
+        jToolBar1.add(animationToggleButton);
 
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         this.setLayout(layout);
@@ -257,9 +313,15 @@ private void planeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-F
         matRenderer.switchDisplay(MaterialPreviewRenderer.DisplayType.Teapot);
     }//GEN-LAST:event_teapotButtonActionPerformed
 
+    private void animationToggleButtonActionPerformed(java.awt.event.ActionEvent evt) {
+        setAnimationEnabled(animationToggleButton.isSelected());
+    }
+
     // Variables declaration - do not modify//GEN-BEGIN:variables
+    private javax.swing.JToggleButton animationToggleButton;
     private javax.swing.JToggleButton cubeButton;
     private javax.swing.JToolBar.Separator jSeparator1;
+    private javax.swing.JToolBar.Separator jSeparator2;
     private javax.swing.JToolBar jToolBar1;
     private javax.swing.JToggleButton planeButton;
     private javax.swing.JLabel previewLabel;

+ 8 - 0
jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/icons/Icons.java

@@ -53,6 +53,10 @@ public class Icons {
     public static final String LIGHT_ON = ICONS_PATH + "light-bulb-on.svg";
     public static final String LIGHT_OFF = ICONS_PATH + "light-bulb-off.svg";
     
+    // Using reload icon from core editor icons
+    public static final String ANIMATION_OFF = "com/jme3/gde/core/editor/icons/reload.png";
+    public static final String ANIMATION_ON = "com/jme3/gde/core/editor/icons/reload.png";
+    
     public static final ImageIcon textureRemove =
             ImageUtilities.loadImageIcon(TEXTURE_REMOVE, false);
     public static final ImageIcon cube =
@@ -75,4 +79,8 @@ public class Icons {
             ImageUtilities.loadImageIcon(LIGHT_ON, false);
     public static final ImageIcon lightOff =
             ImageUtilities.loadImageIcon(LIGHT_OFF, false);
+    public static final ImageIcon animationOff =
+            ImageUtilities.loadImageIcon(ANIMATION_OFF, false);
+    public static final ImageIcon animationOn =
+            ImageUtilities.loadImageIcon(ANIMATION_ON, false);
 }