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

Material editor fixes #599

Merged
merged 5 commits into from
Apr 29, 2024
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
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;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

👍


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
Loading