10000 this fixes #418 by adding a button to enable the pbr light probe in t… · neph1/sdk@f9f5846 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9f5846

Browse files
committed
this fixes jMonkeyEngine#418 by adding a button to enable the pbr light probe in the material preview.
1 parent a920c9c commit f9f5846

File tree

3 files changed

+125
-53
lines changed

3 files changed

+125
-53
lines changed

jme3-core/src/com/jme3/gde/core/scene/SceneApplication.java

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -595,70 +595,87 @@ public Object call() throws Exception {
595595
}
596596
});
597597
}
598+
599+
private void createPbrLightProbe(final Node activeNode) {
600+
new Thread() {
601+
@Override
602+
public void run() {
603+
Spatial s = assetManager.loadModel("com/jme3/gde/core/sceneviewer/pbrenv.j3o");
604+
pbrLightProbe = (LightProbe)s.getLocalLightList().get(0);
605+
s.getLocalLightList().clear();
598606

599-
public void enablePBRProbe(final boolean selected) {
600-
if (pbrLightProbe == null) {
601-
new Thread() {
602-
@Override
603-
public void run() {
604-
Spatial s = assetManager.loadModel("com/jme3/gde/core/sceneviewer/pbrenv.j3o");
605-
pbrLightProbe = (LightProbe)s.getLocalLightList().get(0);
606-
s.getLocalLightList().clear();
607-
608-
enqueue(new Callable<Void>() {
609-
@Override
610-
public Void call() throws Exception {
611-
rootNode.addLight(pbrLightProbe);
612-
return null;
613-
}
614-
});
615-
}
607+
enqueue(() -> {
608+
activeNode.addLight(pbrLightProbe);
609+
return null;
610+
});
611+
}
616612

617-
}.start();
613+
}.start();
614+
}
615+
616+
private void togglePbrProbe(final boolean selected, final Node activeNode) {
617+
if (pbrLightProbe == null) {
618+
createPbrLightProbe(activeNode);
618619
} else {
619-
enqueue(new Callable<Void>() {
620-
@Override
621-
public Void call() throws Exception {
622-
if (selected) {
623-
rootNode.addLight(pbrLightProbe);
624-
} else {
625-
rootNode.removeLight(pbrLightProbe);
626-
}
627-
return null;
620+
enqueue(() -> {
621+
if (selected) {
622+
activeNode.addLight(pbrLightProbe);
623+
} else {
624+
activeNode.removeLight(pbrLightProbe);
628625
}
626+
return null;
629627
});
630628
}
631629
}
630+
632631

633-
public void enablePBRSkybox(final boolean selected) {
634-
if (pbrSky == null) {
635-
new Thread() {
632+
public void enablePBRProbe(final boolean selected) {
633+
if (pbrLightProbe == null) {
634+
createPbrLightProbe(rootNode);
635+
} else {
636+
togglePbrProbe(selected, rootNode);
637+
}
638+
}
639+
640+
private void createPbrSkyBox(final Node activeNode) {
641+
new Thread() {
636642
@Override
637643
public void run() {
638644
pbrSky = SkyFactory.createSky(assetManager, "Textures/Sky/Path.hdr", SkyFactory.EnvMapType.EquirectMap);
639645

640-
enqueue(new Callable<Void>() {
641-
@Override
642-
public Void call() throws Exception {
643-
rootNode.attachChild(pbrSky);
644-
return null;
645-
}
646+
enqueue(() -> {
647+
activeNode.attachChild(pbrSky);
648+
return null;
646649
});
647650
}
648651

649652
}.start();
653+
}
654+
655+
private void togglePbrSkybox(final boolean selected, final Node activeNode) {
656+
enqueue(() -> {
657+
if (selected) {
658+
activeNode.attachChild(pbrSky);
659+
} else {
660+
pbrSky.removeFromParent();
661+
}
662+
return null;
663+
});
664+
}
665+
666+
public void enablePBRSkybox(final boolean selected) {
667+
if (pbrSky == null) {
668+
createPbrSkyBox(rootNode);
650669
} else {
651-
enqueue(new Callable<Void>() {
652-
@Override
653-
public Void call() throws Exception {
654-
if (selected) {
655-
rootNode.attachChild(pbrSky);
656-
} else {
657-
pbrSky.removeFromParent();
658-
}
659-
return null;
660-
}
661-
});
670+
togglePbrSkybox(selected, rootNode);
671+
}
672+
}
673+
674+
public void enablePreviewLighting(final boolean selected) {
675+
if (pbrLightProbe == null) {
676+
createPbrLightProbe(previewProcessor.previewNode);
< F438 /td>
677+
} else {
678+
togglePbrProbe(selected, previewProcessor.previewNode);
662679
}
663680
}
664681

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
<Layout>
2121
<DimensionLayout dim="0">
2222
<Group type="103" groupAlignment="0" attributes="0">
23-
<Component id="previewLabel" alignment="0" pref="120" max="32767" attributes="0"/>
24-
<Component id="jToolBar1" alignment="0" pref="120" max="32767" attributes="0"/>
23+
<Component id="previewLabel" alignment="0" pref="180" max="32767" attributes="0"/>
24+
<Component id="jToolBar1" alignment="0" pref="180" max="32767" attributes="0"/>
2525
</Group>
2626
</DimensionLayout>
2727
<DimensionLayout dim="1">
@@ -51,7 +51,6 @@
5151
</Component>
5252
<Container class="javax.swing.JToolBar" name="jToolBar1">
5353
<Properties>
54-
<Property name="floatable" type="boolean" value="false"/>
5554
<Property name="rollover" type="boolean" value="true"/>
5655
</Properties>
5756

@@ -126,6 +125,34 @@
126125
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="planeButtonActionPerformed"/>
127126
</Events>
128127
</Component>
128+
<Component class="javax.swing.JToolBar$Separator" name="jSeparator1">
129+
</Component>
130+
<Component class="javax.swing.JToggleButton" name="togglePbrEnvButton">
131+
<Properties>
132+
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
133+
<Connection code="IconList.lightYellow" type="code"/>
134+
</Property>
135+
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
136+
<ResourceString bundle="com/jme3/gde/materials/multiview/widgets/Bundle.properties" key="MaterialPreviewWidget.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
137+
</Property>
138+
<Property name="focusable" type="boolean" value="false"/>
139+
<Property name="horizontalTextPosition" type="int" value="0"/>
140+
<Property name="label" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
141+
<ResourceString bundle="com/jme3/gde/materials/multiview/widgets/Bundle.properties" key="MaterialPreviewWidget.label" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
142+
</Property>
143+
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
144+
<Dimension value="[26, 24]"/>
145+
</Property>
146+
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
147+
<Dimension value="[26, 24]"/>
148+
</Property>
149+
<Property name="name" type="java.lang.String" value="" noResource="true"/>
150+
<Property name="verticalTextPosition" type="int" value="3"/>
151+
</Properties>
152+
<Events>
153+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="togglePbrEnvButtonActionPerformed"/>
154+
</Events>
155+
</Component>
129156
</SubComponents>
130157
</Container>
131158
</SubComponents>

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
package com.jme3.gde.materials.multiview.widgets;
1212

1313
import com.jme3.gde.core.assets.ProjectAssetManager;
14+
import com.jme3.gde.core.icons.IconList;
15+
import com.jme3.gde.core.scene.SceneApplication;
1416
import com.jme3.gde.core.scene.SceneRequest;
1517
import com.jme3.gde.materials.MaterialPreviewRenderer;
1618

@@ -70,13 +72,14 @@ private void initComponents() {
7072
sphereButton = new javax.swing.JToggleButton();
7173
cubeButton = new javax.swing.JToggleButton();
7274
planeButton = new javax.swing.JToggleButton();
75+
jSeparator1 = new javax.swing.JToolBar.Separator();
76+
togglePbrEnvButton = new javax.swing.JToggleButton();
7377

7478
previewLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
7579
previewLabel.setText(org.openide.util.NbBundle.getMessage(MaterialPreviewWidget.class, "MaterialPreviewWidget.previewLabel.text")); // NOI18N
7680
previewLabel.setMaximumSize(new java.awt.Dimension(120, 120));
7781
previewLabel.setMinimumSize(new java.awt.Dimension(120, 120));
7882

79-
jToolBar1.setFloatable(false);
8083
jToolBar1.setRollover(true);
8184

8285
toggleButtonGroup.add(sphereButton);
@@ -123,13 +126,30 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
123126
}
124127
});
125128
jToolBar1.add(planeButton);
129+
jToolBar1.add(jSeparator1);
130+
131+
togglePbrEnvButton.setIcon(IconList.lightYellow);
132+
togglePbrEnvButton.setToolTipText(org.openide.util.NbBundle.getMessage(MaterialPreviewWidget.class, "MaterialPreviewWidget.toolTipText")); // NOI18N
133+
togglePbrEnvButton.setFocusable(false);
134+
togglePbrEnvButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
135+
togglePbrEnvButton.setLabel(org.openide.util.NbBundle.getMessage(MaterialPreviewWidget.class, "MaterialPreviewWidget.label")); // NOI18N
136+
togglePbrEnvButton.setMaximumSize(new java.awt.Dimension(26, 24));
137+
togglePbrEnvButton.setMinimumSize(new java.awt.Dimension(26, 24));
138+
togglePbrEnvButton.setName(""); // NOI18N
139+
togglePbrEnvButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
140+
togglePbrEnvButton.addActionListener(new java.awt.event.ActionListener() {
141+
public void actionPerformed(java.awt.event.ActionEvent evt) {
142+
togglePbrEnvButtonActionPerformed(evt);
143+
}
144+
});
145+
jToolBar1.add(togglePbrEnvButton);
126146

127147
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
128148
this.setLayout(layout);
129149
layout.setHorizontalGroup(
130150
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
131-
.addComponent(previewLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
132-
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
151+
.addComponent(previewLabel, javax 433 .swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
152+
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
133153
);
134154
layout.setVerticalGroup(
135155
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -151,12 +171,20 @@ private void cubeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
151171
private void planeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_planeButtonActionPerformed
152172
matRenderer.switchDisplay(MaterialPreviewRenderer.DisplayType.Quad);
153173
}//GEN-LAST:event_planeButtonActionPerformed
174+
175+
private void togglePbrEnvButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_togglePbrEnvButtonActionPerformed
176+
SceneApplication.getApplication().enablePreviewLighting(togglePbrEnvButton.isSelected());
177+
matRenderer.refreshOnly();
178+
}//GEN-LAST:event_togglePbrEnvButtonActionPerformed
179+
154180
// Variables declaration - do not modify//GEN-BEGIN:variables
155181
private javax.swing.JToggleButton cubeButton;
182+
private javax.swing.JToolBar.Separator jSeparator1;
156183
private javax.swing.JToolBar jToolBar1;
157184
private javax.swing.JToggleButton planeButton;
158185
private javax.swing.JLabel previewLabel;
159186
private javax.swing.JToggleButton sphereButton;
160187
private javax.swing.ButtonGroup toggleButtonGroup;
188+
private javax.swing.JToggleButton togglePbrEnvButton;
161189
// End of variables declaration//GEN-END:variables
162190
}

0 commit comments

Comments
 (0)
0