Skip to content

Commit

Permalink
+ Mesh Editor.
Browse files Browse the repository at this point in the history
#2 ExportAs ok
Improving TreeNode.
Game works again.
TextDialog in feature processing

Signed-off-by: Manuel Daniel Dahmen <[email protected]>
  • Loading branch information
manuelddahmen committed Jan 22, 2024
1 parent 78de3d7 commit d87228f
Show file tree
Hide file tree
Showing 27 changed files with 563 additions and 1,026 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ publishing {
pom {
name = 'empty3-library-3d'
description = '3D rendering engine. Plus modeling. Expected glsl textures 3d and 2d rendering' +
'3D primitives, and a lots of essays to tests.'
'3D primitives, and a lot of scenes\' samples to test.'
packaging 'jar'
url = "https://github.com/manuelddahmen/empty3_miror"

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/one/empty3/apps/vecmesh/VecMeshEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@

package one.empty3.apps.vecmesh;
//heights = ((1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,1,1,1,1,1,1,1),(1,1,1,,1,1,1,1,1,1,3,3,3,3,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,4,1,1,1,1,1,1,1,1,1,1,4,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1))

import one.empty3.library.*;
import one.empty3.library.core.nurbs.CourbeParametriquePolynomiale;
import one.empty3.library.core.nurbs.FctXY;
import one.empty3.library.core.nurbs.ParametricSurface;
import one.empty3.library.core.tribase.Plan3D;
import one.empty3.library.core.tribase.Tubulaire3;
import one.empty3.library1.shader.Vec;
import one.empty3.library1.tree.AlgebricTree;
import one.empty3.library1.tree.AlgebraicTree;
import one.empty3.library1.tree.ListInstructions;

import javax.swing.*;
Expand Down Expand Up @@ -75,7 +76,7 @@ public double result(double input) {
}
});
} else if (representableClass.equals(Plan3D.class)) {
shape = new Plan3D(new Point3D(-3.0, -halfSize, 0.0), new Point3D(halfSize, -halfSize, 0.0), new Point3D(-halfSize, halfSize, 0.0));
shape = new Plan3D(new Point3D(-halfSize, -halfSize, 0.0), new Point3D(halfSize, -halfSize, 0.0), new Point3D(-halfSize, halfSize, 0.0));
}
shape = shape == null ? new Plan3D(new Point3D(-halfSize, -halfSize, 0.0), new Point3D(halfSize, -halfSize, 0.0), new Point3D(-halfSize, halfSize, 0.0)) : shape;

Expand All @@ -93,7 +94,7 @@ public void run() {
try {
long t1 = System.currentTimeMillis();
StructureMatrix<Double> eval = null;
AlgebricTree algebricTree = new AlgebricTree(vecMeshEditorGui.getDefaultCode());
AlgebraicTree algebraicTree = new AlgebraicTree(vecMeshEditorGui.getDefaultCode());
ListInstructions listInstructions = new ListInstructions();
listInstructions.addInstructions(vecMeshEditorGui.getDefaultCode());
listInstructions.runInstructions();
Expand All @@ -112,6 +113,7 @@ public void run() {
}
VecHeightMap vecHeightMap = new VecHeightMap(getParametricSurface(4.0),
new Vec(doubles), vecMeshEditorGui.getTextFieldRows());
vecHeightMap.getIncrNormale().setElem(0.01);
if (rotate == null)
rotate = new Rotate(vecHeightMap, vecMeshEditorGui.getPanelGraphics());
else {
Expand Down Expand Up @@ -146,7 +148,7 @@ public void run() {
//Output.println("Drawn");
zBuffer.idzpp();
long t2 = System.currentTimeMillis();
Output.println("Matrix was : " + vecHeightMap.getVec() + " FPS : " + (t2 - t1));
Output.println("Matrix was : " + vecHeightMap.getVec() + " FPS : " + 1.0 / ((t2 - t1) / 1000.));

}
} catch (RuntimeException ex) {
Expand Down
72 changes: 39 additions & 33 deletions src/main/java/one/empty3/apps/vecmesh/VecMeshEditorGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ public VecMeshEditorGui() {

config = new Config();

currentFile= new File(config.getDefaultCodeVecMesh());
currentFile = new File(config.getDefaultCodeVecMesh());

setDefaultFile();

Output.setGetText(buttonOutput);

instanceCount++;
System.out.println("Instance==1 : "+(instanceCount==1));
System.out.println("Instance==1 : " + (instanceCount == 1));
}

private void menuItemSave(ActionEvent e) {
String text = getTextAreaCode().getText();
int columns = getTextFieldRows();
if(currentFile!=null&&currentFile.exists()) {
if (currentFile != null && currentFile.exists()) {
try {
PrintWriter fileOutputStream = new PrintWriter(currentFile);
fileOutputStream.println(columns);
Expand All @@ -101,24 +101,26 @@ private void menuItemSave(ActionEvent e) {
public void setDefaultFile() {
getDefaultOrNewFileTextCode();
}

private void getDefaultOrNewFileTextCode() {
if(!currentFile.exists()) {
if (!currentFile.exists()) {
try {
currentFile.createNewFile();
PrintWriter printWriter = new PrintWriter(currentFile);
printWriter.println("2");
printWriter.println(representableClass.getCanonicalName());
printWriter.println("heights = ((1,1),(1,1))");
printWriter.println("heights = ((1,1),(1,1))\n" +
"heights.cols = 2");
printWriter.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
try {
try (BufferedReader reader = Files.newBufferedReader(currentFile.toPath(), Charset.defaultCharset())){
try (BufferedReader reader = Files.newBufferedReader(currentFile.toPath(), Charset.defaultCharset())) {
String line = null;
String columnsString = reader.readLine();
if(columnsString!=null)
if (columnsString != null)
textAreaColumsCount.setText(String.valueOf(Double.parseDouble(columnsString)));
String classNameReader = reader.readLine();
try {
Expand All @@ -133,7 +135,7 @@ private void getDefaultOrNewFileTextCode() {
}
getTextAreaCode().setText(sb.toString());
}
} catch (IOException|RuntimeException e) {
} catch (IOException | RuntimeException e) {
e.printStackTrace();
}
}
Expand Down Expand Up @@ -180,25 +182,25 @@ private void menuItemOpen(ActionEvent e) {

int columns = getTextFieldRows();

try (BufferedReader reader = Files.newBufferedReader(currentFile.toPath(), Charset.defaultCharset())){
try (BufferedReader reader = Files.newBufferedReader(currentFile.toPath(), Charset.defaultCharset())) {
String line = "";
String columnsString = reader.readLine();
if(columnsString!=null)
if (columnsString != null)
textAreaColumsCount.setText(String.valueOf(Double.parseDouble(columnsString)));
String classNameReader = reader.readLine();
try {
Class<?> aClass =getClass().getClassLoader().loadClass(classNameReader);
Class<?> aClass = getClass().getClassLoader().loadClass(classNameReader);
Object o = aClass.getConstructor().newInstance();
if(o instanceof Representable r) {
if (o instanceof Representable r) {
representableClass = r.getClass();
}
} catch (ClassNotFoundException | InvocationTargetException | InstantiationException |
IllegalAccessException | NoSuchMethodException | NullPointerException ex1) {
representableClass = defaultClassRepresentable;
}
if(representableClass==null && defaultClassRepresentable!=null)
if (representableClass == null && defaultClassRepresentable != null)
representableClass = defaultClassRepresentable;
else if(representableClass==null&&defaultClassRepresentable==null) {
else if (representableClass == null && defaultClassRepresentable == null) {
defaultClassRepresentable = Tubulaire3.class;
representableClass = defaultClassRepresentable;
}
Expand All @@ -221,12 +223,15 @@ else if(representableClass==null&&defaultClassRepresentable==null) {
private void menuItemSphere(ActionEvent e) {
this.representableClass = Sphere.class;
}

private void menuItemTube(ActionEvent e) {
this.representableClass = Tubulaire3.class;
}

private void menuItemRectangle(ActionEvent e) {
this.representableClass = Plan3D.class;
}

private void menuItemCube(ActionEvent e) {
this.representableClass = Cube.class;
}
Expand Down Expand Up @@ -258,7 +263,7 @@ private void menuItemExportAs(ActionEvent e) {
JFileChooser jFileChooser = new JFileChooser(currentFile.getParentFile());
jFileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
jFileChooser.setDialogTitle("Choisir où exporter les fichiers");
if(jFileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
if (jFileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
currentFile = jFileChooser.getSelectedFile();
File currentFile1 = currentFile;
File dir = currentFile1;
Expand All @@ -272,10 +277,10 @@ private void menuItemExportAs(ActionEvent e) {
if (currentFile1.exists() && !currentFile1.isDirectory()) {
dir = new File(currentFile1.getParentFile().getAbsolutePath());
}
File xml = new File(dir.getAbsolutePath() + File.separator+"scene.xml");
File moo = new File(dir.getAbsolutePath() + File.separator+"scene.moo");
File stl = new File(dir.getAbsolutePath() + File.separator+"scene.stl");
File obj = new File(dir.getAbsolutePath() + File.separator+"scene.obj");
File xml = new File(dir.getAbsolutePath() + File.separator + "scene.xml");
File moo = new File(dir.getAbsolutePath() + File.separator + "scene.moo");
File stl = new File(dir.getAbsolutePath() + File.separator + "scene.stl");
File obj = new File(dir.getAbsolutePath() + File.separator + "scene.obj");
STLExport.save(stl, model.getScene(), false);
ObjExport.save(obj, model.getScene(), false);
PrintWriter printWriter = new PrintWriter(moo);
Expand Down Expand Up @@ -305,15 +310,15 @@ private void menuItemSettings(ActionEvent e) {
}

private void menuAddImages(ActionEvent e) {
File direFile = currentFile==null?new Config().getFileDirectoryDefault():currentFile;
File direFile = currentFile == null ? new Config().getFileDirectoryDefault() : currentFile;
JFileChooser jFileChooser = new JFileChooser(direFile);
jFileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
jFileChooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
return (f.getName().toLowerCase().endsWith(".jpg")||f.getName().toLowerCase().endsWith(".png")
||f.getName().toLowerCase().endsWith(".jpeg")||f.getName().toLowerCase().endsWith(".bmp"));
return (f.getName().toLowerCase().endsWith(".jpg") || f.getName().toLowerCase().endsWith(".png")
|| f.getName().toLowerCase().endsWith(".jpeg") || f.getName().toLowerCase().endsWith(".bmp"));
}

@Override
Expand All @@ -322,17 +327,17 @@ public String getDescription() {

}
});
if(jFileChooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) {
if (jFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
File f1 = jFileChooser.getSelectedFile();
File[] selectedFiles = null;
if(f1!=null) {
selectedFiles =new File[] {f1};
if (f1 != null) {
selectedFiles = new File[]{f1};
} else {
selectedFiles = jFileChooser.getSelectedFiles();
}
for(File f : selectedFiles) {
if(!getImages().contains(f) && f!=null) {
if(getImages().add(f)) {
for (File f : selectedFiles) {
if (!getImages().contains(f) && f != null) {
if (getImages().add(f)) {
JMenuItem jMenuItem = new JMenuItem(f.getAbsolutePath());
jMenuItem.addActionListener(new AbstractAction() {
@Override
Expand All @@ -343,7 +348,7 @@ public void actionPerformed(ActionEvent e) {
fileTexture = file;
System.out.println("texture: " + file.getAbsolutePath());
} else
System.err.println("File"+file+" doesn't exist");
System.err.println("File" + file + " doesn't exist");
}
});
menuImages.add(jMenuItem);
Expand All @@ -366,6 +371,7 @@ private void menuAddImage(ActionEvent e) {
private void menuItemHeightMap(ActionEvent e) {
this.containerClassType = TYPE_CONTAINER_CLASS_VEC_HEIGHT_MAP;
}

private void menuItemVoronoi(ActionEvent e) {
this.containerClassType = TYPE_CONTAINER_CLASS_VORONOI_HEIGHTS;
}
Expand Down Expand Up @@ -780,7 +786,7 @@ public JTextArea getTextAreaCode() {
}

public int getTextFieldRows() {
return (int)(Double.parseDouble(textAreaColumsCount.getText()));
return (int) (Double.parseDouble(textAreaColumsCount.getText()));
}

public JPanel getPanelGraphics() {
Expand All @@ -801,10 +807,9 @@ public ZBufferImpl getZBuffer() {
ZBufferImpl zBuffer1 = zBuffer;
zBuffer = new ZBufferImpl(getPanelGraphics().getWidth(),
getPanelGraphics().getHeight());
if(zBuffer1!=null) {
if (zBuffer1 != null) {
zBuffer.setDisplayType(zBuffer1.getDisplayType());
}
else {
} else {
zBuffer.setDisplayType(ZBufferImpl.SURFACE_DISPLAY_COL_QUADS);
}
}
Expand All @@ -818,6 +823,7 @@ public void setModel(VecMeshEditor vecMeshEditor) {
public void setResY(int i) {
this.resY = i;
}

public void setResX(int j) {
this.resX = j;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ public class ImageIO {
public static java.awt.image.BufferedImage read(File file) {
try {
FileInputStream fileInputStream = new FileInputStream(file);
java.awt.image.BufferedImage BufferedImage2 = javax.imageio.ImageIO.read(fileInputStream);
java.awt.image.BufferedImage bufferedImage2 = javax.imageio.ImageIO.read(fileInputStream);
fileInputStream.close();
return BufferedImage2;
} catch (Exception ex) {}

return null;
return bufferedImage2;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}

public static boolean write(BufferedImage imageOut, String jpg, File out) throws IOException {
if(out.getAbsolutePath().endsWith("png"))
if (out.getAbsolutePath().endsWith("png"))
jpg = "png";
if(out.getAbsolutePath().endsWith("jpg"))
if (out.getAbsolutePath().endsWith("jpg"))
jpg = "jpg";
FileOutputStream fileOutputStream = new FileOutputStream(out);
// ???
Expand Down
Loading

0 comments on commit d87228f

Please sign in to comment.