Browse Source

this fixes #418 by adding a button to enable the pbr light probe in the material preview.

rickard 2 years ago
parent
commit
f9f5846e1f

+ 64 - 47
jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java

@@ -595,70 +595,87 @@ public class SceneApplication extends LegacyApplication implements LookupProvide
             }
             }
         });
         });
     }
     }
+    
+    private void createPbrLightProbe(final Node activeNode) {
+        new Thread() {
+            @Override
+            public void run() {
+                Spatial s = assetManager.loadModel("com/jme3/gde/core/sceneviewer/pbrenv.j3o");
+                pbrLightProbe = (LightProbe)s.getLocalLightList().get(0);
+                s.getLocalLightList().clear();
 
 
-    public void enablePBRProbe(final boolean selected) {
-        if (pbrLightProbe == null) {
-            new Thread() {
-                @Override
-                public void run() {
-                    Spatial s = assetManager.loadModel("com/jme3/gde/core/sceneviewer/pbrenv.j3o");
-                    pbrLightProbe = (LightProbe)s.getLocalLightList().get(0);
-                    s.getLocalLightList().clear();
-
-                    enqueue(new Callable<Void>() {
-                        @Override
-                        public Void call() throws Exception {
-                            rootNode.addLight(pbrLightProbe);
-                            return null;
-                        }
-                    });
-                }
+                enqueue(() -> {
+                    activeNode.addLight(pbrLightProbe);
+                    return null;
+                });
+            }
 
 
-            }.start();
+        }.start();
+    }
+    
+    private void togglePbrProbe(final boolean selected, final Node activeNode) {
+        if (pbrLightProbe == null) {
+            createPbrLightProbe(activeNode);
         } else {
         } else {
-            enqueue(new Callable<Void>() {
-                @Override
-                public Void call() throws Exception {
-                    if (selected) {
-                        rootNode.addLight(pbrLightProbe);
-                    } else {
-                        rootNode.removeLight(pbrLightProbe);
-                    }
-                    return null;
+            enqueue(() -> {
+                if (selected) {
+                    activeNode.addLight(pbrLightProbe);
+                } else {
+                    activeNode.removeLight(pbrLightProbe);
                 }
                 }
+                return null;
             });
             });
         }
         }
     }
     }
+    
 
 
-    public void enablePBRSkybox(final boolean selected) {
-        if (pbrSky == null) {
-            new Thread() {
+    public void enablePBRProbe(final boolean selected) {
+        if (pbrLightProbe == null) {
+            createPbrLightProbe(rootNode);
+        } else {
+            togglePbrProbe(selected, rootNode);
+        }
+    }
+    
+    private void createPbrSkyBox(final Node activeNode) {
+        new Thread() {
                 @Override
                 @Override
                 public void run() {
                 public void run() {
                     pbrSky = SkyFactory.createSky(assetManager, "Textures/Sky/Path.hdr", SkyFactory.EnvMapType.EquirectMap);
                     pbrSky = SkyFactory.createSky(assetManager, "Textures/Sky/Path.hdr", SkyFactory.EnvMapType.EquirectMap);
 
 
-                    enqueue(new Callable<Void>() {
-                        @Override
-                        public Void call() throws Exception {
-                            rootNode.attachChild(pbrSky);
-                            return null;
-                        }
+                    enqueue(() -> {
+                        activeNode.attachChild(pbrSky);
+                        return null;
                     });
                     });
                 }
                 }
 
 
             }.start();
             }.start();
+    }
+    
+    private void togglePbrSkybox(final boolean selected, final Node activeNode) {
+        enqueue(() -> {
+            if (selected) {
+                activeNode.attachChild(pbrSky);
+            } else {
+                pbrSky.removeFromParent();
+            }
+            return null;
+        });
+    }
+
+    public void enablePBRSkybox(final boolean selected) {
+        if (pbrSky == null) {
+            createPbrSkyBox(rootNode);
         } else {
         } else {
-            enqueue(new Callable<Void>() {
-                @Override
-                public Void call() throws Exception {
-                    if (selected) {
-                        rootNode.attachChild(pbrSky);
-                    } else {
-                        pbrSky.removeFromParent();
-                    }
-                    return null;
-                }
-            });
+            togglePbrSkybox(selected, rootNode);
+        }
+    }
+    
+    public void enablePreviewLighting(final boolean selected) {
+        if (pbrLightProbe == null) {
+            createPbrLightProbe(previewProcessor.previewNode);
+        } else {
+            togglePbrProbe(selected, previewProcessor.previewNode);
         }
         }
     }
     }
 
 

+ 30 - 3
jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/MaterialPreviewWidget.form

@@ -20,8 +20,8 @@
   <Layout>
   <Layout>
     <DimensionLayout dim="0">
     <DimensionLayout dim="0">
       <Group type="103" groupAlignment="0" attributes="0">
       <Group type="103" groupAlignment="0" attributes="0">
-          <Component id="previewLabel" alignment="0" pref="120" max="32767" attributes="0"/>
-          <Component id="jToolBar1" alignment="0" pref="120" max="32767" attributes="0"/>
+          <Component id="previewLabel" alignment="0" pref="180" max="32767" attributes="0"/>
+          <Component id="jToolBar1" alignment="0" pref="180" max="32767" attributes="0"/>
       </Group>
       </Group>
     </DimensionLayout>
     </DimensionLayout>
     <DimensionLayout dim="1">
     <DimensionLayout dim="1">
@@ -51,7 +51,6 @@
     </Component>
     </Component>
     <Container class="javax.swing.JToolBar" name="jToolBar1">
     <Container class="javax.swing.JToolBar" name="jToolBar1">
       <Properties>
       <Properties>
-        <Property name="floatable" type="boolean" value="false"/>
         <Property name="rollover" type="boolean" value="true"/>
         <Property name="rollover" type="boolean" value="true"/>
       </Properties>
       </Properties>
 
 
@@ -126,6 +125,34 @@
             <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="planeButtonActionPerformed"/>
             <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="planeButtonActionPerformed"/>
           </Events>
           </Events>
         </Component>
         </Component>
+        <Component class="javax.swing.JToolBar$Separator" name="jSeparator1">
+        </Component>
+        <Component class="javax.swing.JToggleButton" name="togglePbrEnvButton">
+          <Properties>
+            <Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
+              <Connection code="IconList.lightYellow" type="code"/>
+            </Property>
+            <Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+              <ResourceString bundle="com/jme3/gde/materials/multiview/widgets/Bundle.properties" key="MaterialPreviewWidget.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+            </Property>
+            <Property name="focusable" type="boolean" value="false"/>
+            <Property name="horizontalTextPosition" type="int" value="0"/>
+            <Property name="label" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
+              <ResourceString bundle="com/jme3/gde/materials/multiview/widgets/Bundle.properties" key="MaterialPreviewWidget.label" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
+            </Property>
+            <Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
+              <Dimension value="[26, 24]"/>
+            </Property>
+            <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
+              <Dimension value="[26, 24]"/>
+            </Property>
+            <Property name="name" type="java.lang.String" value="" noResource="true"/>
+            <Property name="verticalTextPosition" type="int" value="3"/>
+          </Properties>
+          <Events>
+            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="togglePbrEnvButtonActionPerformed"/>
+          </Events>
+        </Component>
       </SubComponents>
       </SubComponents>
     </Container>
     </Container>
   </SubComponents>
   </SubComponents>

+ 31 - 3
jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/MaterialPreviewWidget.java

@@ -11,6 +11,8 @@
 package com.jme3.gde.materials.multiview.widgets;
 package com.jme3.gde.materials.multiview.widgets;
 
 
 import com.jme3.gde.core.assets.ProjectAssetManager;
 import com.jme3.gde.core.assets.ProjectAssetManager;
+import com.jme3.gde.core.icons.IconList;
+import com.jme3.gde.core.scene.SceneApplication;
 import com.jme3.gde.core.scene.SceneRequest;
 import com.jme3.gde.core.scene.SceneRequest;
 import com.jme3.gde.materials.MaterialPreviewRenderer;
 import com.jme3.gde.materials.MaterialPreviewRenderer;
 
 
@@ -70,13 +72,14 @@ public class MaterialPreviewWidget extends javax.swing.JPanel {
         sphereButton = new javax.swing.JToggleButton();
         sphereButton = new javax.swing.JToggleButton();
         cubeButton = new javax.swing.JToggleButton();
         cubeButton = new javax.swing.JToggleButton();
         planeButton = new javax.swing.JToggleButton();
         planeButton = new javax.swing.JToggleButton();
+        jSeparator1 = new javax.swing.JToolBar.Separator();
+        togglePbrEnvButton = new javax.swing.JToggleButton();
 
 
         previewLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
         previewLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
         previewLabel.setText(org.openide.util.NbBundle.getMessage(MaterialPreviewWidget.class, "MaterialPreviewWidget.previewLabel.text")); // NOI18N
         previewLabel.setText(org.openide.util.NbBundle.getMessage(MaterialPreviewWidget.class, "MaterialPreviewWidget.previewLabel.text")); // NOI18N
         previewLabel.setMaximumSize(new java.awt.Dimension(120, 120));
         previewLabel.setMaximumSize(new java.awt.Dimension(120, 120));
         previewLabel.setMinimumSize(new java.awt.Dimension(120, 120));
         previewLabel.setMinimumSize(new java.awt.Dimension(120, 120));
 
 
-        jToolBar1.setFloatable(false);
         jToolBar1.setRollover(true);
         jToolBar1.setRollover(true);
 
 
         toggleButtonGroup.add(sphereButton);
         toggleButtonGroup.add(sphereButton);
@@ -123,13 +126,30 @@ public class MaterialPreviewWidget extends javax.swing.JPanel {
             }
             }
         });
         });
         jToolBar1.add(planeButton);
         jToolBar1.add(planeButton);
+        jToolBar1.add(jSeparator1);
+
+        togglePbrEnvButton.setIcon(IconList.lightYellow);
+        togglePbrEnvButton.setToolTipText(org.openide.util.NbBundle.getMessage(MaterialPreviewWidget.class, "MaterialPreviewWidget.toolTipText")); // NOI18N
+        togglePbrEnvButton.setFocusable(false);
+        togglePbrEnvButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
+        togglePbrEnvButton.setLabel(org.openide.util.NbBundle.getMessage(MaterialPreviewWidget.class, "MaterialPreviewWidget.label")); // NOI18N
+        togglePbrEnvButton.setMaximumSize(new java.awt.Dimension(26, 24));
+        togglePbrEnvButton.setMinimumSize(new java.awt.Dimension(26, 24));
+        togglePbrEnvButton.setName(""); // NOI18N
+        togglePbrEnvButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
+        togglePbrEnvButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                togglePbrEnvButtonActionPerformed(evt);
+            }
+        });
+        jToolBar1.add(togglePbrEnvButton);
 
 
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         this.setLayout(layout);
         this.setLayout(layout);
         layout.setHorizontalGroup(
         layout.setHorizontalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-            .addComponent(previewLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
-            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
+            .addComponent(previewLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
+            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
         );
         );
         layout.setVerticalGroup(
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -151,12 +171,20 @@ private void cubeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
 private void planeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_planeButtonActionPerformed
 private void planeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_planeButtonActionPerformed
     matRenderer.switchDisplay(MaterialPreviewRenderer.DisplayType.Quad);
     matRenderer.switchDisplay(MaterialPreviewRenderer.DisplayType.Quad);
 }//GEN-LAST:event_planeButtonActionPerformed
 }//GEN-LAST:event_planeButtonActionPerformed
+
+    private void togglePbrEnvButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_togglePbrEnvButtonActionPerformed
+        SceneApplication.getApplication().enablePreviewLighting(togglePbrEnvButton.isSelected());
+        matRenderer.refreshOnly();
+    }//GEN-LAST:event_togglePbrEnvButtonActionPerformed
+
     // Variables declaration - do not modify//GEN-BEGIN:variables
     // Variables declaration - do not modify//GEN-BEGIN:variables
     private javax.swing.JToggleButton cubeButton;
     private javax.swing.JToggleButton cubeButton;
+    private javax.swing.JToolBar.Separator jSeparator1;
     private javax.swing.JToolBar jToolBar1;
     private javax.swing.JToolBar jToolBar1;
     private javax.swing.JToggleButton planeButton;
     private javax.swing.JToggleButton planeButton;
     private javax.swing.JLabel previewLabel;
     private javax.swing.JLabel previewLabel;
     private javax.swing.JToggleButton sphereButton;
     private javax.swing.JToggleButton sphereButton;
     private javax.swing.ButtonGroup toggleButtonGroup;
     private javax.swing.ButtonGroup toggleButtonGroup;
+    private javax.swing.JToggleButton togglePbrEnvButton;
     // End of variables declaration//GEN-END:variables
     // End of variables declaration//GEN-END:variables
 }
 }