Skip to content

Commit

Permalink
Merge pull request #502 from neph1/make_texture_panel_resizable
Browse files Browse the repository at this point in the history
makes most widgets resizable. center pane is still a bit greedy. the …
  • Loading branch information
neph1 committed Apr 27, 2023
2 parents 88ef54e + 86ea7ba commit e7cbb2a
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import com.jme3.math.Vector3f;
import com.jme3.renderer.RendererException;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Quad;
import com.jme3.scene.shape.Sphere;
Expand All @@ -59,8 +58,9 @@
import javax.swing.JLabel;

/**
* Handles rendering of materials in preview widgets of Material and Shader Node editor.
*
* Handles rendering of materials in preview widgets of Material and Shader Node
* editor.
*
* @author Nehon
*/
public class MaterialPreviewRenderer implements SceneListener {
Expand Down Expand Up @@ -108,14 +108,14 @@ private void init() {
quad = new Geometry("previewQuad", quadMesh);
quad.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0));
MikktspaceTangentGenerator.generate(quad);

teapot = (Geometry) SceneApplication.getApplication().getAssetManager()
.loadModel("Models/Teapot/Teapot.obj");
teapot.scale(3.5f);
teapot.rotate(FastMath.PI, -FastMath.QUARTER_PI * 0.5f, -0.0f);
teapot.setLocalTranslation(new Vector3f(-0.5f, 1.75f, 0));
MikktspaceTangentGenerator.generate(teapot);

currentGeom = sphere;
init = true;
}
Expand All @@ -125,19 +125,14 @@ public void showMaterial(final ProjectAssetManager assetManager, final String ma
if (!init) {
init();
}
exec.execute(new Runnable() {

@Override
public void run() {
MaterialKey key = new MaterialKey(assetManager.getRelativeAssetPath(materialFileName));
assetManager.deleteFromCache(key);
Material mat = assetManager.loadAsset(key);
if (mat != null) {
showMaterial(mat);
}
exec.execute(() -> {
MaterialKey key = new MaterialKey(assetManager.getRelativeAssetPath(materialFileName));
assetManager.deleteFromCache(key);
Material mat = assetManager.loadAsset(key);
if (mat != null) {
showMaterial(mat);
}
});


}

Expand All @@ -149,46 +144,36 @@ public void showMaterial(final Material m, final String techniqueName) {
if (!init) {
init();
}
SceneApplication.getApplication().enqueue(new Callable<Material>() {

@Override
public Material call() throws Exception {
if (techniqueName != null) {
SceneApplication.getApplication().enqueue(() -> {
if (techniqueName != null) {
try {
m.selectTechnique(techniqueName, SceneApplication.getApplication().getRenderManager());
} catch (Exception e) {
//
}
}
final Material mat = reloadMaterial(m);
if (mat != null) {
java.awt.EventQueue.invokeLater(() -> {
currentMaterial = mat;
currentGeom.setMaterial(mat);
try {
m.selectTechnique(techniqueName, SceneApplication.getApplication().getRenderManager());
if (currentGeom.getMaterial() != null) {
PreviewRequest request = new PreviewRequest(MaterialPreviewRenderer.this, currentGeom, label.getWidth(), label.getHeight());
request.getCameraRequest().setLocation(new Vector3f(0, 0, 7));
request.getCameraRequest().setLookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y);
SceneApplication.getApplication().createPreview(request);
}
} catch (Exception e) {
//
java.awt.EventQueue.invokeLater(() -> {
label.setIcon(Icons.error);
});
smartLog("Error rendering material{0}", e.getMessage());
}
}
final Material mat = reloadMaterial(m);
if (mat != null) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
currentMaterial = mat;
currentGeom.setMaterial(mat);
try {
if (currentGeom.getMaterial() != null) {
PreviewRequest request = new PreviewRequest(MaterialPreviewRenderer.this, currentGeom, label.getWidth(), label.getHeight());
request.getCameraRequest().setLocation(new Vector3f(0, 0, 7));
request.getCameraRequest().setLookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y);
SceneApplication.getApplication().createPreview(request);
}
} catch (Exception e) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
label.setIcon(Icons.error);
}
});
smartLog("Error rendering material{0}", e.getMessage());
}
}
});
});

}
return mat;
}
return mat;
});
}

Expand All @@ -209,7 +194,7 @@ public Material reloadMaterial(Material mat) {

//creating a dummy mat with the mat def of the mat to reload
dummy = new Material(mat.getMaterialDef());

for (MatParam matParam : mat.getParams()) {
dummy.setParam(matParam.getName(), matParam.getVarType(), matParam.getValue());
}
Expand All @@ -231,12 +216,7 @@ public Material reloadMaterial(Material mat) {
//Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, e.getMessage());
smartLog("{0}", e.getMessage());

java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
label.setIcon(Icons.error);
}
});
java.awt.EventQueue.invokeLater(() -> label.setIcon(Icons.error));
return null;
} catch (NullPointerException npe) {
//utterly bad, but for some reason I get random NPE here and can't figure out why so to avoid bigger issues, I just catch it.
Expand Down Expand Up @@ -282,11 +262,8 @@ public void sceneClosed(SceneRequest request) {
public void previewCreated(PreviewRequest request) {
if (request.getRequester() == this) {
final ImageIcon icon = new ImageIcon(request.getImage());
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
label.setIcon(icon);
}
java.awt.EventQueue.invokeLater(() -> {
label.setIcon(icon);
});
previewRequested = false;
}
Expand All @@ -296,15 +273,16 @@ public void cleanUp() {
SceneApplication.getApplication().removeSceneListener(this);
exec.shutdownNow();
}
public boolean isPreviewRequested(){

public boolean isPreviewRequested() {
return previewRequested;
}

/**
* A more lightweight refresh than showMaterials that doesn't rebuild the material
* A more lightweight refresh than showMaterials that doesn't rebuild the
* material
*/
public void refreshOnly(){
public void refreshOnly() {
previewRequested = true;
SceneApplication.getApplication().enqueue((Callable<Object>) () -> {
if (currentGeom.getMaterial() != null) {
Expand All @@ -316,5 +294,5 @@ public void refreshOnly(){
return null;
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="materialPreviewWidget1" min="-2" pref="255" max="-2" attributes="0"/>
<Component id="jTabbedPane3" pref="477" max="32767" attributes="0"/>
<Component id="jTabbedPane3" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="texturesAndColorsPane" min="-2" pref="496" max="-2" attributes="0"/>
<Component id="texturesAndColorsPane" pref="496" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="additionalRenderStatePane" pref="352" max="32767" attributes="0"/>
<Component id="additionalRenderStatePane" pref="329" max="32767" attributes="0"/>
<EmptySpace pref="12" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
Expand Down Expand Up @@ -182,6 +182,7 @@
</Container>
<Container class="javax.swing.JTabbedPane" name="jTabbedPane3">
<Properties>
<Property name="tabLayoutPolicy" type="int" value="1"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[380, 355]"/>
</Property>
Expand Down Expand Up @@ -374,8 +375,9 @@
</Component>
<Container class="javax.swing.JTabbedPane" name="additionalRenderStatePane">
<Properties>
<Property name="tabLayoutPolicy" type="int" value="1"/>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[150, 100]"/>
<Dimension value="[100, 100]"/>
</Property>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[380, 355]"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ private void initComponents() {

texturesAndColorsPane.addTab(org.openide.util.NbBundle.getMessage(MaterialEditorTopComponent.class, "MaterialEditorTopComponent.jScrollPane3.TabConstraints.tabTitle"), jScrollPane3); // NOI18N

jTabbedPane3.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
jTabbedPane3.setMinimumSize(new java.awt.Dimension(380, 355));
jTabbedPane3.setPreferredSize(new java.awt.Dimension(500, 355));

Expand All @@ -180,7 +181,6 @@ private void initComponents() {

jTabbedPane3.addTab(org.openide.util.NbBundle.getMessage(MaterialEditorTopComponent.class, "MaterialEditorTopComponent.jScrollPane2.TabConstraints.tabTitle_1"), jScrollPane2); // NOI18N

jToolBar2.setFloatable(false);
jToolBar2.setRollover(true);

jPanel3.setPreferredSize(new java.awt.Dimension(0, 21));
Expand Down Expand Up @@ -215,7 +215,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});
jToolBar2.add(jComboBox1);
jToolBar3.setFloatable(false);

jToolBar3.setRollover(true);

jPanel1.setPreferredSize(new java.awt.Dimension(140, 21));
Expand Down Expand Up @@ -256,7 +256,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});

additionalRenderStatePane.setMinimumSize(new java.awt.Dimension(150, 100));
additionalRenderStatePane.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
additionalRenderStatePane.setMinimumSize(new java.awt.Dimension(100, 100));
additionalRenderStatePane.setPreferredSize(new java.awt.Dimension(380, 355));

jScrollPane10.setBorder(null);
Expand All @@ -273,13 +274,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGroup(editorPanelLayout.createSequentialGroup()
.addGroup(editorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(materialPreviewWidget1, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTabbedPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 477, Short.MAX_VALUE))
.addComponent(jTabbedPane3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(editorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(editorPanelLayout.createSequentialGroup()
.addComponent(texturesAndColorsPane, javax.swing.GroupLayout.PREFERRED_SIZE, 496, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(texturesAndColorsPane, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(additionalRenderStatePane, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)
.addComponent(additionalRenderStatePane, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
.addContainerGap(12, Short.MAX_VALUE))
.addGroup(editorPanelLayout.createSequentialGroup()
.addGroup(editorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
Expand Down
Loading

0 comments on commit e7cbb2a

Please sign in to comment.