Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Live updates for materials #342

Merged
merged 8 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion jme3-core/src/com/jme3/gde/core/editor/nodes/Diagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
/**
* The Diagram is the main canvas where all nodes {@link NodePanel} and
* their connections {@link ConnectionEndpoint} {@link Connection} are added onto.
*
* @author Nehon
*/
public abstract class Diagram extends JPanel implements MouseListener,
Expand Down Expand Up @@ -272,7 +273,7 @@ public void removeNode(NodePanel node) {
repaint();
parent.notifyRemoveNode(node);
}

public List<Selectable> getSelectedItems() {
return selectedItems;
}
Expand Down Expand Up @@ -558,6 +559,12 @@ public void fixSize() {
*/
public abstract void autoLayout();

/**
* This toggles continuous updates for material previews
* @param on
*/
public abstract void toggleUpdateThread(boolean on);

@Override
public void componentResized(ComponentEvent e) {
minWidth = e.getComponent().getWidth() - 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.jme3.gde.materialdefinition.fileStructure.leaves.MatParamBlock;
import com.jme3.gde.materialdefinition.fileStructure.leaves.OutputMappingBlock;
import com.jme3.gde.materialdefinition.navigator.node.MatDefNode;
import com.jme3.material.MatParam;
import com.jme3.material.Material;
import com.jme3.material.MaterialDef;
import com.jme3.material.TechniqueDef;
Expand Down Expand Up @@ -78,7 +77,9 @@
import org.openide.util.WeakListeners;

/**
*
* This is the MatDef representation in the editor. It will update the file with
* any changes.
*
* @author Nehon
*/
public class EditableMatDefFile {
Expand Down Expand Up @@ -254,14 +255,6 @@ private void updateLookupWithMaterialData(MatDefDataObject obj) {
try {
//material.selectTechnique("Default", SceneApplication.getApplication().getRenderManager());
if (matToRemove != null) {
for (MatParam matParam : matToRemove.getParams()) {
try {
material.setParam(matParam.getName(), matParam.getVarType(), matParam.getValue());
} catch (IllegalArgumentException ie) {
matToRemove.clearParam(matParam.getName());
}

}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what caused the mat previews not to update when changing parameters. They got overwritten when the material was reloaded.

obj.getLookupContents().remove(matToRemove);
matToRemove = null;
}
Expand Down Expand Up @@ -405,4 +398,5 @@ public void cleanup(){
setCurrentTechnique(null);
setLoaded(false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -528,5 +528,14 @@ public void mouseMoved(MouseEvent e) {
((MouseMotionListener) c).mouseMoved(SwingUtilities.convertMouseEvent(this, e, c));
}
}

public MaterialPreviewRenderer getRenderer(){
return renderer;
}

public void refreshOnly() {
if (mat != null) {
renderer.refreshOnly();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ ShaderNodeToolBar.codeButton.toolTipText=Display code
NodeToolBar.deleteButton.toolTipText=Delete node
NodeToolBar.deleteButton.text=
NodeToolBar.codeButton.toolTipText=Display code
MatDefEditorToolBar.toggleLiveUpdates.actionCommand=toggleLiveUpdates
MatDefEditorToolBar.toggleLiveUpdates.toolTipText=Toggle Live Backpanel Updates
MatDefEditorToolBar.toggleLiveUpdates.text=
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
<Component id="jButton1" min="-2" pref="53" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="103" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="jToggleButton2" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="99" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand All @@ -42,6 +44,7 @@
<Component id="techniqueComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jToggleButton2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jSeparator1" alignment="0" max="32767" attributes="0"/>
</Group>
Expand Down Expand Up @@ -106,5 +109,40 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JToggleButton" name="jToggleButton2">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/com/jme3/gde/core/editor/icons/repeat.png"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/materialdefinition/editor/Bundle.properties" key="MatDefEditorToolBar.toggleLiveUpdates.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="toolTipText" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/materialdefinition/editor/Bundle.properties" key="MatDefEditorToolBar.toggleLiveUpdates.toolTipText" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="actionCommand" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="com/jme3/gde/materialdefinition/editor/Bundle.properties" key="MatDefEditorToolBar.toggleLiveUpdates.actionCommand" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
<Property name="horizontalAlignment" type="int" value="11"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="iconTextGap" type="int" value="0"/>
<Property name="margin" type="java.awt.Insets" editor="org.netbeans.beaninfo.editors.InsetsEditor">
<Insets value="[2, 14, 2, 18]"/>
</Property>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[25, 24]"/>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[25, 24]"/>
</Property>
<Property name="name" type="java.lang.String" value="toggleLiveUpdates" noResource="true"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[25, 24]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jToggleButton2ActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.ListCellRenderer;

/**
Expand Down Expand Up @@ -101,6 +102,7 @@ private void initComponents() {
jButton1 = new javax.swing.JButton();
jSeparator1 = new javax.swing.JSeparator();
jButton2 = new javax.swing.JButton();
jToggleButton2 = new javax.swing.JToggleButton();

setPreferredSize(new java.awt.Dimension(474, 20));

Expand Down Expand Up @@ -133,6 +135,24 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

jToggleButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/jme3/gde/core/editor/icons/repeat.png"))); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(jToggleButton2, org.openide.util.NbBundle.getMessage(MatDefEditorToolBar.class, "MatDefEditorToolBar.toggleLiveUpdates.text")); // NOI18N
jToggleButton2.setToolTipText(org.openide.util.NbBundle.getMessage(MatDefEditorToolBar.class, "MatDefEditorToolBar.toggleLiveUpdates.toolTipText")); // NOI18N
jToggleButton2.setActionCommand(org.openide.util.NbBundle.getMessage(MatDefEditorToolBar.class, "MatDefEditorToolBar.toggleLiveUpdates.actionCommand")); // NOI18N
jToggleButton2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jToggleButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jToggleButton2.setIconTextGap(0);
jToggleButton2.setMargin(new java.awt.Insets(2, 14, 2, 18));
jToggleButton2.setMaximumSize(new java.awt.Dimension(25, 24));
jToggleButton2.setMinimumSize(new java.awt.Dimension(25, 24));
jToggleButton2.setName("toggleLiveUpdates"); // NOI18N
jToggleButton2.setPreferredSize(new java.awt.Dimension(25, 24));
jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton2ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
Expand All @@ -147,15 +167,18 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addGap(0, 103, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jToggleButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(99, 99, 99))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(techniqueComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2))
.addComponent(jButton2)
.addComponent(jToggleButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jSeparator1)
);
}// </editor-fold>//GEN-END:initComponents
Expand Down Expand Up @@ -187,16 +210,28 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
}
}//GEN-LAST:event_jButton1ActionPerformed

/**
* Autolayout button
* @param evt
*/
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
parent.getDiagram().autoLayout();
}//GEN-LAST:event_jButton2ActionPerformed

/**
* Toggle continuous updates thread
* @param evt
*/
private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton2ActionPerformed
parent.getDiagram().toggleUpdateThread(((JToggleButton)evt.getSource()).isSelected());
}//GEN-LAST:event_jToggleButton2ActionPerformed

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JToggleButton jToggleButton2;
private javax.swing.JComboBox<TechniqueBlock> techniqueComboBox;
// End of variables declaration//GEN-END:variables
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.jme3.gde.core.editor.nodes.Selectable;
import com.jme3.asset.ShaderNodeDefinitionKey;
import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.gde.core.errorreport.ExceptionPanel;
import com.jme3.gde.materialdefinition.EditableMatDefFile;
import com.jme3.gde.materialdefinition.MatDefDataObject;
import com.jme3.gde.materialdefinition.MatDefMetaData;
Expand Down Expand Up @@ -81,6 +82,8 @@
import org.netbeans.core.spi.multiview.MultiViewElement;
import org.netbeans.core.spi.multiview.MultiViewElementCallback;
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.awt.UndoRedo;
import org.openide.cookies.EditorCookie;
import org.openide.filesystems.FileObject;
Expand Down Expand Up @@ -133,7 +136,6 @@ public MatDefEditorlElement(final Lookup lkp) {
if (!file.isLoaded()) {
throw new IllegalArgumentException("Cannot build MatDefEditorlElement: Failed at loading the EditableMatDefFile");
}

reload(file, lkp);
toolbar.setParent(this);
toolbar.addTechnique(lkp.lookup(MatDefBlock.class).getTechniques());
Expand Down Expand Up @@ -769,15 +771,10 @@ private void reload(final EditableMatDefFile file, final Lookup lkp) throws Numb
}
} else {
diagram1.clear();
JLabel error = new JLabel("<html><center>Cannot load material definition.<br>Please see the error log and fix it in the text editor</center></html>");
error.setForeground(Color.ORANGE);
error.setFont(new Font("Arial", Font.BOLD, 24));
error.setBounds(0, 0, 400, 100);
jScrollPane1.getHorizontalScrollBar().setValue(0);
error.setLocation(jScrollPane1.getViewport().getWidth() / 2 - 200, jScrollPane1.getViewport().getHeight() / 2 - 50);
diagram1.add(error);
diagram1.repaint();

ExceptionPanel ep = new ExceptionPanel("Please see the error log and fix it in the text editor", false);
DialogDescriptor d = new DialogDescriptor(ep, "Cannot load material definition", true, new Object[] { DialogDescriptor.OK_OPTION }, DialogDescriptor.DEFAULT_OPTION, DialogDescriptor.DEFAULT_ALIGN, null, null);
DialogDisplayer.getDefault().notifyLater(d);

}
}
}
Loading