Skip to content

Commit

Permalink
Merge pull request #599 from tonihele/bugfix/material-editor-fixes
Browse files Browse the repository at this point in the history
Material editor fixes
  • Loading branch information
tonihele authored Apr 29, 2024
2 parents 20875e2 + 45a0083 commit 828da64
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ public class EditableMaterialFile {
private final List<String> matDefEntries = new ArrayList<>();
private final ProjectAssetManager manager;
private FileSystem fs;
public static final String[] variableTypes = new String[]{"Int", "Boolean", "Float", "Vector2", "Vector3", "Vector4", "Color", "Texture2D", "Texture3D", "TextureArray", "TextureBuffer", "TextureCubeMap"};

// Note that these are tested with startsWith, so the ordering matters (i.e. FloatArray & Float)
public static final String[] variableTypes = new String[]{
"IntArray", "Int", "Boolean", "FloatArray", "Float", "Vector2Array",
"Vector3Array", "Vector4Array", "Vector2", "Vector3", "Vector4",
"Color", "Texture2D", "Texture3D", "TextureArray", "TextureBuffer",
"TextureCubeMap"};

public EditableMaterialFile(FileObject material, ProjectAssetManager manager) {
this.material = material;
Expand Down Expand Up @@ -188,24 +194,26 @@ private void initMatDef() {
matDef = manager.getAssetFolder().getFileObject(getMatDefName());

//try to read from classpath if not in assets folder and store in a virtual filesystem folder
if (matDef == null || !matDef.isValid()) {
try {
fs = FileUtil.createMemoryFileSystem();
matDef = fs.getRoot().createData(name, "j3md");
try ( OutputStream out = matDef.getOutputStream()) {
InputStream in = manager.getResourceAsStream(getMatDefName());
if (in != null) {
int input = in.read();
while (input != -1) {
out.write(input);
input = in.read();
}
in.close();
if (matDef != null && matDef.isValid()) {
return;
}

try {
fs = FileUtil.createMemoryFileSystem();
matDef = fs.getRoot().createData(name, "j3md");
try ( OutputStream out = matDef.getOutputStream()) {
InputStream in = manager.getResourceAsStream(getMatDefName());
if (in != null) {
int input = in.read();
while (input != -1) {
out.write(input);
input = in.read();
}
in.close();
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}

Expand Down Expand Up @@ -255,6 +263,8 @@ private void checkWithMatDef() {
materialParameters.put(prop.getName(), prop);
}
prop.setType(string);

break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,6 @@
<ResourceString bundle="com/jme3/gde/materials/multiview/Bundle.properties" key="MaterialEditorTopComponent.jTextField1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jTextField1ActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,32 @@ public void componentHidden(ComponentEvent e) {
materialPreviewWidget1.showMaterial(manager, materialFileName);

relativeMaterialFileName = manager.getRelativeAssetPath(materialFileName);

jTextField1.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
updateName();
}

@Override
public void removeUpdate(DocumentEvent e) {
updateName();
}

@Override
public void changedUpdate(DocumentEvent e) {
updateName();
}

private void updateName() {
if (materialFile != null) {
materialFile.setName(jTextField1.getText());
String string = materialFile.getUpdatedContent();
jTextArea1.setText(string);
}
}

});
}

/** This method is called from within the constructor to
Expand Down Expand Up @@ -266,11 +292,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jToolBar3.add(jPanel1);

jTextField1.setText(org.openide.util.NbBundle.getMessage(MaterialEditorTopComponent.class, "MaterialEditorTopComponent.jTextField1.text")); // NOI18N
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jToolBar3.add(jTextField1);

jCheckBox1.setSelected(true);
Expand Down Expand Up @@ -360,14 +381,6 @@ private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
saveImmediate = jCheckBox1.isSelected();
}//GEN-LAST:event_jCheckBox1ActionPerformed

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
if (materialFile != null) {
materialFile.setName(jTextField1.getText());
String string = materialFile.getUpdatedContent();
jTextArea1.setText(string);
}
}//GEN-LAST:event_jTextField1ActionPerformed

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
if (materialFile != null) {
updateProperties = true;
Expand Down Expand Up @@ -587,19 +600,10 @@ public void setMatDefList(final String[] matDefs, String selected) {
jComboBox1.addItem("");
List<String> matDefList = Arrays.asList(matDefs);
Collections.sort(matDefList);
String[] sortedMatDefs = matDefList.toArray(String[]::new);
for (String string : sortedMatDefs) {
jComboBox1.addItem(string);
for (String matDef : matDefList) {
jComboBox1.addItem(matDef);
}

// jComboBox1.addItem("Common/MatDefs/Light/Lighting.j3md");
// jComboBox1.addItem("Common/MatDefs/Misc/Unshaded.j3md");
// jComboBox1.addItem("Common/MatDefs/Misc/Particle.j3md");
// jComboBox1.addItem("Common/MatDefs/Misc/Sky.j3md");
// jComboBox1.addItem("Common/MatDefs/Gui/Gui.j3md");
// jComboBox1.addItem("Common/MatDefs/Terrain/TerrainLighting.j3md");
// jComboBox1.addItem("Common/MatDefs/Terrain/Terrain.j3md");
// jComboBox1.addItem("Common/MatDefs/Misc/ShowNormals.j3md");
jComboBox1.setSelectedItem(selected);
materialFile = prop;
}
Expand Down

0 comments on commit 828da64

Please sign in to comment.