Normand Briere
2019-08-17 ecc1309a04b527c62ffe97e814daf050dbd025cd
Grafreed.java
....@@ -23,6 +23,8 @@
2323 static float epsvertex2 = 0.001f;
2424 static boolean linkUV = false; // not uniform at load time
2525
26
+ static boolean smoothmode = false;
27
+
2628 static Wav wav = new Wav("/Users/nbriere/0ut/wavs/monoformat"); // output");
2729 static boolean hassound = false;
2830 static boolean savesound = false;
....@@ -41,7 +43,84 @@
4143 static void Assert(boolean b)
4244 {
4345 if (!b)
46
+ {
47
+ b = !!b;
4448 new Exception().printStackTrace(); // assert(b);
49
+
50
+ }
51
+ }
52
+
53
+ public static String RemovePrefix(String s, String prefix)
54
+ {
55
+ if (s != null && prefix != null && s.startsWith(prefix))
56
+ {
57
+ return s.substring(prefix.length());
58
+ }
59
+
60
+ return s;
61
+ }
62
+
63
+ static void ParseFileSystem(java.io.File dir, iResourceCallBack callback, String prefix)
64
+ {
65
+ callback.ResourceCallBack(RemovePrefix(dir.toString(),prefix).split("/"));
66
+ File[] listFiles = dir.listFiles();
67
+ if (listFiles != null)
68
+ {
69
+ for (java.io.File file : listFiles)
70
+ {
71
+ ParseFileSystem(file, callback, prefix);
72
+ }
73
+ }
74
+ }
75
+
76
+ static interface iResourceCallBack
77
+ {
78
+ void ResourceCallBack(String[] path);
79
+ }
80
+
81
+ static void ParseResources(String path, iResourceCallBack callback)
82
+ {
83
+ java.io.File jarFile = new java.io.File(Grafreed.class.getProtectionDomain().getCodeSource().getLocation().getPath());
84
+
85
+ if (jarFile.isFile())
86
+ {
87
+ // Run with JAR file
88
+ try
89
+ {
90
+ java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile);
91
+ java.util.Enumeration<java.util.jar.JarEntry> entries = jar.entries(); //gives ALL entries in jar
92
+ while (entries.hasMoreElements())
93
+ {
94
+ String name = entries.nextElement().getName();
95
+
96
+ if (name.startsWith(path + "/"))
97
+ callback.ResourceCallBack(RemovePrefix(name, path + "/").split("/"));
98
+ }
99
+ jar.close();
100
+ } catch (Exception ex)
101
+ {
102
+ ex.printStackTrace();
103
+ }
104
+ } else
105
+ {
106
+ // Run with IDE
107
+ final java.net.URL url = Object3D.class.getResource("/" + path);
108
+ if (url != null)
109
+ {
110
+ try
111
+ {
112
+ java.io.File apps = new java.io.File(url.toURI());
113
+ ParseFileSystem(apps, callback, RemovePrefix(url.toString() + "/", "file:"));
114
+// for (java.io.File app : apps.listFiles())
115
+// {
116
+// //System.out.println(RemovePrefix(app.toString(), RemovePrefix(url.toString(), "file:") + "/"));
117
+// }
118
+ } catch (Exception ex)
119
+ {
120
+ ex.printStackTrace();
121
+ }
122
+ }
123
+ }
45124 }
46125
47126 public void init()
....@@ -52,7 +131,7 @@
52131 universe.material = new cMaterial();
53132 //god.addChild(universe);
54133 universe.name = "Applet";
55
- grafreeD = this;
134
+ grafreed = this;
56135 }
57136
58137 /**/
....@@ -597,7 +676,8 @@
597676
598677 public static void main(String argv[])
599678 {
600
- String osArch = System.getProperty("os.arch");
679
+ String osArch = System.getProperty("os.arch");
680
+ if (Globals.DEBUG)
601681 System.out.println("os.arch = " + osArch);
602682
603683 if (argv.length == 0)
....@@ -843,19 +923,67 @@
843923
844924 //Monitor mon=MonitorFactory.start("myFirstMonitor");
845925 standAlone = true;
846
- grafreeD = new Grafreed();
847
- grafreeD.universe = new Composite();
848
- grafreeD.universe.name = "Grafreed";
849
- grafreeD.universe.material = new cMaterial();
926
+ grafreed = new Grafreed();
927
+ grafreed.materials = ReadGFD(grafreed.getClass().getClassLoader().getResourceAsStream("gfd/materials.gfd"));
928
+
929
+ grafreed.universe = new cGroup();
930
+ grafreed.universe.name = "Grafreed";
931
+ grafreed.universe.material = new cMaterial();
932
+ grafreed.universe.skyboxname = "cubemaps/penguins-skyboxes/yonder";
933
+ grafreed.universe.skyboxext = "jpg";
934
+
850935 // theApplet3D.universe.textures = CameraPane.DEFAULT_TEXTURE;
851936
852
- grafreeD.universe.root = true;
853
- grafreeD.universe.openEditWindow(null, true); //, true);
937
+ grafreed.universe.root = true;
938
+ grafreed.universe.openEditWindow(null, true); //, true);
854939 //mon.stop();
855940 //System.out.println(mon);
856941 //timeflow.app.TimeflowAppLauncher.GetTimeFlow();
942
+
943
+ javax.swing.ToolTipManager.sharedInstance().setEnabled(Globals.TOOLTIPS);
857944 }
858945
946
+ static Object3D materials;
947
+
948
+ static Object3D ReadGFD(java.io.InputStream istream)
949
+ {
950
+ Object3D readobj = null;
951
+
952
+ try
953
+ {
954
+ // Try compressed version first.
955
+ java.util.zip.GZIPInputStream zstream = new java.util.zip.GZIPInputStream(istream);
956
+ java.io.ObjectInputStream p = new java.io.ObjectInputStream(zstream);
957
+
958
+ readobj = (Object3D) p.readObject();
959
+ p.close();
960
+ zstream.close();
961
+ istream.close();
962
+
963
+ readobj.ResetDisplayList();
964
+ } catch (Exception e)
965
+ {
966
+ if (!e.toString().contains("GZIP"))
967
+ e.printStackTrace();
968
+
969
+ try
970
+ {
971
+ java.io.ObjectInputStream p = new java.io.ObjectInputStream(istream);
972
+
973
+ readobj = (Object3D) p.readObject();
974
+ p.close();
975
+ istream.close();
976
+
977
+ readobj.ResetDisplayList();
978
+ } catch (Exception e2)
979
+ {
980
+ e2.printStackTrace();
981
+ }
982
+ }
983
+
984
+ return readobj;
985
+ }
986
+
859987 // Timer callback
860988 public void actionPerformed(ActionEvent e)
861989 {
....@@ -870,7 +998,7 @@
870998 static int depth = 0;
871999 static java.util.Stack stack = new java.util.Stack();
8721000 static boolean traceoff = false; // true;
873
- static float[] colorV = new float[5];
1001
+ static float[] colorV = new float[4]; // 5];
8741002
8751003 static void traceon()
8761004 {
....@@ -1079,7 +1207,7 @@
10791207 } while (avail > 0 && numRead >= 0);
10801208 return new String(data, 0, pos, "US-ASCII");
10811209 }
1082
- public static Grafreed grafreeD;
1210
+ public static Grafreed grafreed;
10831211 public static boolean standAlone = true;
10841212 public Composite universe;
10851213 public static Object3D clipboard = new Object3D();