joonsrenderer 1.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +53 -0
  3. data/.mvn/extensions.xml +8 -0
  4. data/CHANGELOG.md +2 -0
  5. data/Gemfile +6 -0
  6. data/LICENSE +674 -0
  7. data/README.md +2 -0
  8. data/Rakefile +43 -0
  9. data/docs/.gitignore +6 -0
  10. data/docs/_config.yml +20 -0
  11. data/docs/_includes/footer.html +38 -0
  12. data/docs/_includes/head.html +15 -0
  13. data/docs/_includes/header.html +27 -0
  14. data/docs/_includes/icon-github.html +1 -0
  15. data/docs/_includes/icon-github.svg +1 -0
  16. data/docs/_includes/icon-twitter.html +1 -0
  17. data/docs/_includes/icon-twitter.svg +1 -0
  18. data/docs/_layouts/default.html +20 -0
  19. data/docs/_layouts/page.html +14 -0
  20. data/docs/_layouts/post.html +15 -0
  21. data/docs/_posts/2017-01-08-animated_ray_tracing.md +72 -0
  22. data/docs/_posts/2017-01-08-welcome.md +78 -0
  23. data/docs/_sass/_base.scss +206 -0
  24. data/docs/_sass/_layout.scss +242 -0
  25. data/docs/_sass/_syntax-highlighting.scss +71 -0
  26. data/docs/about.md +12 -0
  27. data/docs/assets/Animation.ogv +0 -0
  28. data/docs/assets/Animation.png +0 -0
  29. data/docs/assets/basic.png +0 -0
  30. data/docs/assets/basic_traced.png +0 -0
  31. data/docs/css/main.scss +38 -0
  32. data/docs/favicon.ico +0 -0
  33. data/docs/feed.xml +30 -0
  34. data/docs/index.html +38 -0
  35. data/joonsrenderer.gemspec +23 -0
  36. data/lib/joonsrenderer.rb +12 -0
  37. data/lib/joonsrenderer/version.rb +3 -0
  38. data/pom.rb +75 -0
  39. data/pom.xml +163 -0
  40. data/src/main/java/SunflowGUI.java +1354 -0
  41. data/src/main/java/joons/JRFiller.java +79 -0
  42. data/src/main/java/joons/JRImagePanel.java +141 -0
  43. data/src/main/java/joons/JRRecorder.java +183 -0
  44. data/src/main/java/joons/JRStatics.java +199 -0
  45. data/src/main/java/joons/JoonsRenderer.java +837 -0
  46. data/src/main/java/org/sunflow/AsciiFileSunflowAPI.java +98 -0
  47. data/src/main/java/org/sunflow/Benchmark.java +313 -0
  48. data/src/main/java/org/sunflow/BinaryFileSunflowAPI.java +228 -0
  49. data/src/main/java/org/sunflow/FileSunflowAPI.java +354 -0
  50. data/src/main/java/org/sunflow/PluginRegistry.java +322 -0
  51. data/src/main/java/org/sunflow/RealtimeBenchmark.java +125 -0
  52. data/src/main/java/org/sunflow/RenderObjectMap.java +344 -0
  53. data/src/main/java/org/sunflow/SunflowAPI.java +762 -0
  54. data/src/main/java/org/sunflow/SunflowAPIInterface.java +277 -0
  55. data/src/main/java/org/sunflow/core/AccelerationStructure.java +20 -0
  56. data/src/main/java/org/sunflow/core/AccelerationStructureFactory.java +36 -0
  57. data/src/main/java/org/sunflow/core/BucketOrder.java +21 -0
  58. data/src/main/java/org/sunflow/core/Camera.java +125 -0
  59. data/src/main/java/org/sunflow/core/CameraLens.java +29 -0
  60. data/src/main/java/org/sunflow/core/CausticPhotonMapInterface.java +15 -0
  61. data/src/main/java/org/sunflow/core/Display.java +78 -0
  62. data/src/main/java/org/sunflow/core/Filter.java +27 -0
  63. data/src/main/java/org/sunflow/core/GIEngine.java +42 -0
  64. data/src/main/java/org/sunflow/core/Geometry.java +157 -0
  65. data/src/main/java/org/sunflow/core/GlobalPhotonMapInterface.java +21 -0
  66. data/src/main/java/org/sunflow/core/ImageSampler.java +26 -0
  67. data/src/main/java/org/sunflow/core/Instance.java +224 -0
  68. data/src/main/java/org/sunflow/core/InstanceList.java +83 -0
  69. data/src/main/java/org/sunflow/core/IntersectionState.java +120 -0
  70. data/src/main/java/org/sunflow/core/LightSample.java +104 -0
  71. data/src/main/java/org/sunflow/core/LightServer.java +382 -0
  72. data/src/main/java/org/sunflow/core/LightSource.java +67 -0
  73. data/src/main/java/org/sunflow/core/Modifier.java +16 -0
  74. data/src/main/java/org/sunflow/core/Options.java +20 -0
  75. data/src/main/java/org/sunflow/core/ParameterList.java +758 -0
  76. data/src/main/java/org/sunflow/core/PhotonStore.java +62 -0
  77. data/src/main/java/org/sunflow/core/PrimitiveList.java +70 -0
  78. data/src/main/java/org/sunflow/core/Ray.java +219 -0
  79. data/src/main/java/org/sunflow/core/RenderObject.java +25 -0
  80. data/src/main/java/org/sunflow/core/Scene.java +377 -0
  81. data/src/main/java/org/sunflow/core/SceneParser.java +58 -0
  82. data/src/main/java/org/sunflow/core/Shader.java +30 -0
  83. data/src/main/java/org/sunflow/core/ShadingCache.java +84 -0
  84. data/src/main/java/org/sunflow/core/ShadingState.java +939 -0
  85. data/src/main/java/org/sunflow/core/Statistics.java +85 -0
  86. data/src/main/java/org/sunflow/core/Tesselatable.java +36 -0
  87. data/src/main/java/org/sunflow/core/Texture.java +128 -0
  88. data/src/main/java/org/sunflow/core/TextureCache.java +48 -0
  89. data/src/main/java/org/sunflow/core/accel/BoundingIntervalHierarchy.java +652 -0
  90. data/src/main/java/org/sunflow/core/accel/KDTree.java +833 -0
  91. data/src/main/java/org/sunflow/core/accel/NullAccelerator.java +30 -0
  92. data/src/main/java/org/sunflow/core/accel/UniformGrid.java +329 -0
  93. data/src/main/java/org/sunflow/core/bucket/BucketOrderFactory.java +26 -0
  94. data/src/main/java/org/sunflow/core/bucket/ColumnBucketOrder.java +21 -0
  95. data/src/main/java/org/sunflow/core/bucket/DiagonalBucketOrder.java +28 -0
  96. data/src/main/java/org/sunflow/core/bucket/HilbertBucketOrder.java +65 -0
  97. data/src/main/java/org/sunflow/core/bucket/InvertedBucketOrder.java +28 -0
  98. data/src/main/java/org/sunflow/core/bucket/RandomBucketOrder.java +49 -0
  99. data/src/main/java/org/sunflow/core/bucket/RowBucketOrder.java +21 -0
  100. data/src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java +43 -0
  101. data/src/main/java/org/sunflow/core/camera/FisheyeLens.java +25 -0
  102. data/src/main/java/org/sunflow/core/camera/PinholeLens.java +43 -0
  103. data/src/main/java/org/sunflow/core/camera/SphericalLens.java +22 -0
  104. data/src/main/java/org/sunflow/core/camera/ThinLens.java +107 -0
  105. data/src/main/java/org/sunflow/core/display/FastDisplay.java +119 -0
  106. data/src/main/java/org/sunflow/core/display/FileDisplay.java +83 -0
  107. data/src/main/java/org/sunflow/core/display/FrameDisplay.java +97 -0
  108. data/src/main/java/org/sunflow/core/display/ImgPipeDisplay.java +109 -0
  109. data/src/main/java/org/sunflow/core/filter/BlackmanHarrisFilter.java +28 -0
  110. data/src/main/java/org/sunflow/core/filter/BoxFilter.java +16 -0
  111. data/src/main/java/org/sunflow/core/filter/CatmullRomFilter.java +29 -0
  112. data/src/main/java/org/sunflow/core/filter/CubicBSpline.java +32 -0
  113. data/src/main/java/org/sunflow/core/filter/GaussianFilter.java +24 -0
  114. data/src/main/java/org/sunflow/core/filter/LanczosFilter.java +30 -0
  115. data/src/main/java/org/sunflow/core/filter/MitchellFilter.java +28 -0
  116. data/src/main/java/org/sunflow/core/filter/SincFilter.java +25 -0
  117. data/src/main/java/org/sunflow/core/filter/TriangleFilter.java +16 -0
  118. data/src/main/java/org/sunflow/core/gi/AmbientOcclusionGIEngine.java +57 -0
  119. data/src/main/java/org/sunflow/core/gi/FakeGIEngine.java +48 -0
  120. data/src/main/java/org/sunflow/core/gi/InstantGI.java +194 -0
  121. data/src/main/java/org/sunflow/core/gi/IrradianceCacheGIEngine.java +268 -0
  122. data/src/main/java/org/sunflow/core/gi/PathTracingGIEngine.java +65 -0
  123. data/src/main/java/org/sunflow/core/light/DirectionalSpotlight.java +103 -0
  124. data/src/main/java/org/sunflow/core/light/ImageBasedLight.java +303 -0
  125. data/src/main/java/org/sunflow/core/light/PointLight.java +72 -0
  126. data/src/main/java/org/sunflow/core/light/SphereLight.java +166 -0
  127. data/src/main/java/org/sunflow/core/light/SunSkyLight.java +362 -0
  128. data/src/main/java/org/sunflow/core/light/TriangleMeshLight.java +296 -0
  129. data/src/main/java/org/sunflow/core/modifiers/BumpMappingModifier.java +37 -0
  130. data/src/main/java/org/sunflow/core/modifiers/NormalMapModifier.java +34 -0
  131. data/src/main/java/org/sunflow/core/modifiers/PerlinModifier.java +80 -0
  132. data/src/main/java/org/sunflow/core/parser/Keyword.java +39 -0
  133. data/src/main/java/org/sunflow/core/parser/RA2Parser.java +107 -0
  134. data/src/main/java/org/sunflow/core/parser/RA3Parser.java +68 -0
  135. data/src/main/java/org/sunflow/core/parser/SCAbstractParser.java +299 -0
  136. data/src/main/java/org/sunflow/core/parser/SCAsciiParser.java +251 -0
  137. data/src/main/java/org/sunflow/core/parser/SCBinaryParser.java +156 -0
  138. data/src/main/java/org/sunflow/core/parser/SCParser.java +1403 -0
  139. data/src/main/java/org/sunflow/core/parser/ShaveRibParser.java +174 -0
  140. data/src/main/java/org/sunflow/core/parser/TriParser.java +79 -0
  141. data/src/main/java/org/sunflow/core/photonmap/CausticPhotonMap.java +429 -0
  142. data/src/main/java/org/sunflow/core/photonmap/GlobalPhotonMap.java +530 -0
  143. data/src/main/java/org/sunflow/core/photonmap/GridPhotonMap.java +308 -0
  144. data/src/main/java/org/sunflow/core/primitive/Background.java +55 -0
  145. data/src/main/java/org/sunflow/core/primitive/BanchoffSurface.java +100 -0
  146. data/src/main/java/org/sunflow/core/primitive/Box.java +210 -0
  147. data/src/main/java/org/sunflow/core/primitive/CornellBox.java +476 -0
  148. data/src/main/java/org/sunflow/core/primitive/CubeGrid.java +318 -0
  149. data/src/main/java/org/sunflow/core/primitive/Cylinder.java +104 -0
  150. data/src/main/java/org/sunflow/core/primitive/Hair.java +275 -0
  151. data/src/main/java/org/sunflow/core/primitive/JuliaFractal.java +266 -0
  152. data/src/main/java/org/sunflow/core/primitive/ParticleSurface.java +114 -0
  153. data/src/main/java/org/sunflow/core/primitive/Plane.java +163 -0
  154. data/src/main/java/org/sunflow/core/primitive/QuadMesh.java +413 -0
  155. data/src/main/java/org/sunflow/core/primitive/Sphere.java +101 -0
  156. data/src/main/java/org/sunflow/core/primitive/SphereFlake.java +234 -0
  157. data/src/main/java/org/sunflow/core/primitive/Torus.java +145 -0
  158. data/src/main/java/org/sunflow/core/primitive/TriangleMesh.java +849 -0
  159. data/src/main/java/org/sunflow/core/renderer/BucketRenderer.java +491 -0
  160. data/src/main/java/org/sunflow/core/renderer/MultipassRenderer.java +237 -0
  161. data/src/main/java/org/sunflow/core/renderer/ProgressiveRenderer.java +171 -0
  162. data/src/main/java/org/sunflow/core/renderer/SimpleRenderer.java +106 -0
  163. data/src/main/java/org/sunflow/core/shader/AmbientOcclusionShader.java +53 -0
  164. data/src/main/java/org/sunflow/core/shader/AnisotropicWardShader.java +216 -0
  165. data/src/main/java/org/sunflow/core/shader/ConstantShader.java +31 -0
  166. data/src/main/java/org/sunflow/core/shader/DiffuseShader.java +65 -0
  167. data/src/main/java/org/sunflow/core/shader/GlassShader.java +147 -0
  168. data/src/main/java/org/sunflow/core/shader/IDShader.java +27 -0
  169. data/src/main/java/org/sunflow/core/shader/MirrorShader.java +68 -0
  170. data/src/main/java/org/sunflow/core/shader/NormalShader.java +32 -0
  171. data/src/main/java/org/sunflow/core/shader/PhongShader.java +89 -0
  172. data/src/main/java/org/sunflow/core/shader/PrimIDShader.java +30 -0
  173. data/src/main/java/org/sunflow/core/shader/QuickGrayShader.java +63 -0
  174. data/src/main/java/org/sunflow/core/shader/ShinyDiffuseShader.java +98 -0
  175. data/src/main/java/org/sunflow/core/shader/SimpleShader.java +24 -0
  176. data/src/main/java/org/sunflow/core/shader/TexturedAmbientOcclusionShader.java +31 -0
  177. data/src/main/java/org/sunflow/core/shader/TexturedDiffuseShader.java +31 -0
  178. data/src/main/java/org/sunflow/core/shader/TexturedPhongShader.java +31 -0
  179. data/src/main/java/org/sunflow/core/shader/TexturedShinyDiffuseShader.java +31 -0
  180. data/src/main/java/org/sunflow/core/shader/TexturedWardShader.java +31 -0
  181. data/src/main/java/org/sunflow/core/shader/UVShader.java +27 -0
  182. data/src/main/java/org/sunflow/core/shader/UberShader.java +149 -0
  183. data/src/main/java/org/sunflow/core/shader/ViewCausticsShader.java +33 -0
  184. data/src/main/java/org/sunflow/core/shader/ViewGlobalPhotonsShader.java +25 -0
  185. data/src/main/java/org/sunflow/core/shader/ViewIrradianceShader.java +25 -0
  186. data/src/main/java/org/sunflow/core/shader/WireframeShader.java +83 -0
  187. data/src/main/java/org/sunflow/core/tesselatable/BezierMesh.java +254 -0
  188. data/src/main/java/org/sunflow/core/tesselatable/FileMesh.java +251 -0
  189. data/src/main/java/org/sunflow/core/tesselatable/Gumbo.java +1147 -0
  190. data/src/main/java/org/sunflow/core/tesselatable/Teapot.java +237 -0
  191. data/src/main/java/org/sunflow/image/Bitmap.java +15 -0
  192. data/src/main/java/org/sunflow/image/BitmapReader.java +39 -0
  193. data/src/main/java/org/sunflow/image/BitmapWriter.java +79 -0
  194. data/src/main/java/org/sunflow/image/BlackbodySpectrum.java +16 -0
  195. data/src/main/java/org/sunflow/image/ChromaticitySpectrum.java +55 -0
  196. data/src/main/java/org/sunflow/image/Color.java +374 -0
  197. data/src/main/java/org/sunflow/image/ColorEncoder.java +94 -0
  198. data/src/main/java/org/sunflow/image/ColorFactory.java +122 -0
  199. data/src/main/java/org/sunflow/image/ConstantSpectralCurve.java +21 -0
  200. data/src/main/java/org/sunflow/image/IrregularSpectralCurve.java +57 -0
  201. data/src/main/java/org/sunflow/image/RGBSpace.java +207 -0
  202. data/src/main/java/org/sunflow/image/RegularSpectralCurve.java +30 -0
  203. data/src/main/java/org/sunflow/image/SpectralCurve.java +118 -0
  204. data/src/main/java/org/sunflow/image/XYZColor.java +50 -0
  205. data/src/main/java/org/sunflow/image/formats/BitmapBlack.java +27 -0
  206. data/src/main/java/org/sunflow/image/formats/BitmapG8.java +36 -0
  207. data/src/main/java/org/sunflow/image/formats/BitmapGA8.java +30 -0
  208. data/src/main/java/org/sunflow/image/formats/BitmapRGB8.java +40 -0
  209. data/src/main/java/org/sunflow/image/formats/BitmapRGBA8.java +40 -0
  210. data/src/main/java/org/sunflow/image/formats/BitmapRGBE.java +60 -0
  211. data/src/main/java/org/sunflow/image/formats/BitmapXYZ.java +38 -0
  212. data/src/main/java/org/sunflow/image/formats/GenericBitmap.java +73 -0
  213. data/src/main/java/org/sunflow/image/readers/BMPBitmapReader.java +39 -0
  214. data/src/main/java/org/sunflow/image/readers/HDRBitmapReader.java +155 -0
  215. data/src/main/java/org/sunflow/image/readers/IGIBitmapReader.java +104 -0
  216. data/src/main/java/org/sunflow/image/readers/JPGBitmapReader.java +39 -0
  217. data/src/main/java/org/sunflow/image/readers/PNGBitmapReader.java +40 -0
  218. data/src/main/java/org/sunflow/image/readers/TGABitmapReader.java +141 -0
  219. data/src/main/java/org/sunflow/image/writers/EXRBitmapWriter.java +395 -0
  220. data/src/main/java/org/sunflow/image/writers/HDRBitmapWriter.java +54 -0
  221. data/src/main/java/org/sunflow/image/writers/IGIBitmapWriter.java +75 -0
  222. data/src/main/java/org/sunflow/image/writers/PNGBitmapWriter.java +39 -0
  223. data/src/main/java/org/sunflow/image/writers/TGABitmapWriter.java +63 -0
  224. data/src/main/java/org/sunflow/math/BoundingBox.java +340 -0
  225. data/src/main/java/org/sunflow/math/MathUtils.java +159 -0
  226. data/src/main/java/org/sunflow/math/Matrix4.java +573 -0
  227. data/src/main/java/org/sunflow/math/MovingMatrix4.java +119 -0
  228. data/src/main/java/org/sunflow/math/OrthoNormalBasis.java +110 -0
  229. data/src/main/java/org/sunflow/math/PerlinScalar.java +331 -0
  230. data/src/main/java/org/sunflow/math/PerlinVector.java +132 -0
  231. data/src/main/java/org/sunflow/math/Point2.java +36 -0
  232. data/src/main/java/org/sunflow/math/Point3.java +133 -0
  233. data/src/main/java/org/sunflow/math/QMC.java +209 -0
  234. data/src/main/java/org/sunflow/math/Solvers.java +142 -0
  235. data/src/main/java/org/sunflow/math/Vector3.java +197 -0
  236. data/src/main/java/org/sunflow/system/BenchmarkFramework.java +73 -0
  237. data/src/main/java/org/sunflow/system/BenchmarkTest.java +17 -0
  238. data/src/main/java/org/sunflow/system/ByteUtil.java +119 -0
  239. data/src/main/java/org/sunflow/system/FileUtils.java +27 -0
  240. data/src/main/java/org/sunflow/system/ImagePanel.java +282 -0
  241. data/src/main/java/org/sunflow/system/Memory.java +18 -0
  242. data/src/main/java/org/sunflow/system/Parser.java +162 -0
  243. data/src/main/java/org/sunflow/system/Plugins.java +142 -0
  244. data/src/main/java/org/sunflow/system/RenderGlobalsPanel.java +209 -0
  245. data/src/main/java/org/sunflow/system/SearchPath.java +67 -0
  246. data/src/main/java/org/sunflow/system/Timer.java +53 -0
  247. data/src/main/java/org/sunflow/system/UI.java +112 -0
  248. data/src/main/java/org/sunflow/system/UserInterface.java +46 -0
  249. data/src/main/java/org/sunflow/system/ui/ConsoleInterface.java +48 -0
  250. data/src/main/java/org/sunflow/system/ui/SilentInterface.java +28 -0
  251. data/src/main/java/org/sunflow/util/FastHashMap.java +220 -0
  252. data/src/main/java/org/sunflow/util/FloatArray.java +77 -0
  253. data/src/main/java/org/sunflow/util/IntArray.java +77 -0
  254. data/src/test/java/a_maintest.java +129 -0
  255. metadata +300 -0
@@ -0,0 +1,12 @@
1
+ require 'java'
2
+
3
+ working_directory = File.join(File.dirname(__FILE__))
4
+ $LOAD_PATH << working_directory unless $LOAD_PATH.include?(working_directory)
5
+ Dir[File.join(working_directory, '*.jar')].each do |jar|
6
+ require jar
7
+ end
8
+
9
+ java_import "joons.JoonsRenderer"
10
+
11
+
12
+
@@ -0,0 +1,3 @@
1
+ module JoonsRenderer
2
+ VERSION = '1.1'
3
+ end
data/pom.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'fileutils'
2
+ project 'joonsrenderer' do
3
+
4
+ model_version '4.0.0'
5
+ id 'joons:joonsrenderer:1.1-SNAPSHOT'
6
+ packaging 'jar'
7
+ description 'joonsrenderer for propane and JRubyArt'
8
+ organization 'ruby-processing', 'https://ruby-processing.github.io'
9
+ { 'fpsunflower' => 'Christopher Kulla', 'geneome' => 'Not Known', 'joonhyublee' => 'Joon Hyub Lee', 'monkstone' => 'Martin Prout' }.each do |key, value|
10
+ developer key do
11
+ name value
12
+ roles 'developer'
13
+ end
14
+ end
15
+ license 'GPL 3', 'http://www.gnu.org/licenses/gpl-3.0-standalone.html'
16
+ issue_management 'https://github.com/monkstone/joonsrenderer/issues', 'Github'
17
+
18
+ properties( 'source.directory' => 'src',
19
+ 'joonsrenderer.basedir' => '${project.basedir}',
20
+ 'polyglot.dump.pom' => 'pom.xml',
21
+ 'maven.compiler.source' => '1.8',
22
+ 'project.build.sourceEncoding' => 'utf-8',
23
+ 'maven.compiler.target' => '1.8',
24
+ 'janino.version' => '3.0.6',
25
+ 'jogl.version' => '2.3.2',
26
+ 'processing.version' => '3.2.3'
27
+ )
28
+
29
+ jar 'org.processing:core:${processing.version}'
30
+ jar 'org.jogamp.jogl:jogl-all:${jogl.version}'
31
+ jar 'org.jogamp.gluegen:gluegen-rt:${jogl.version}'
32
+ jar('org.codehaus.janino:commons-compiler:${janino.version}')
33
+ jar('org.codehaus.janino:janino:${janino.version}')
34
+
35
+ overrides do
36
+ plugin :resources, '2.6'
37
+ plugin :dependency, '2.10' do
38
+ execute_goals( id: 'default-cli',
39
+ artifactItems:[
40
+ { groupId: 'org.codehaus.janino',
41
+ artifactId: 'janino',
42
+ version: '${janino.version}',
43
+ type: 'jar',
44
+ outputDirectory: '${joonsrenderer.basedir}/lib'
45
+ },
46
+ { groupId: 'org.codehaus.janino',
47
+ artifactId: 'commons-compiler',
48
+ version: '${janino.version}',
49
+ type: 'jar',
50
+ outputDirectory: '${joonsrenderer.basedir}/lib'
51
+ }
52
+ ]
53
+ )
54
+ end
55
+
56
+ plugin( :compiler, '3.6.0',
57
+ source: '${maven.compiler.source}',
58
+ target: '${maven.compiler.target}'
59
+ )
60
+ plugin( :javadoc, '2.10.4',
61
+ detect_offline_links: 'false',
62
+ )
63
+ plugin( :jar, '3.0.2',
64
+ 'archive' => {
65
+ 'manifestFile' => 'MANIFEST.MF'
66
+ }
67
+ )
68
+ end
69
+
70
+ build do
71
+ default_goal 'package'
72
+ source_directory 'src'
73
+ final_name 'joonsrenderer'
74
+ end
75
+ end
data/pom.xml ADDED
@@ -0,0 +1,163 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+
4
+
5
+ DO NOT MODIFIY - GENERATED CODE
6
+
7
+
8
+ -->
9
+ <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
10
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
11
+ <modelVersion>4.0.0</modelVersion>
12
+ <groupId>joons</groupId>
13
+ <artifactId>joonsrenderer</artifactId>
14
+ <version>1.1-SNAPSHOT</version>
15
+ <name>joonsrenderer</name>
16
+ <description>joonsrenderer for propane and JRubyArt</description>
17
+ <organization>
18
+ <name>ruby-processing</name>
19
+ <url>https://ruby-processing.github.io</url>
20
+ </organization>
21
+ <licenses>
22
+ <license>
23
+ <name>GPL 3</name>
24
+ <url>http://www.gnu.org/licenses/gpl-3.0-standalone.html</url>
25
+ </license>
26
+ </licenses>
27
+ <developers>
28
+ <developer>
29
+ <id>fpsunflower</id>
30
+ <name>Christopher Kulla</name>
31
+ <roles>
32
+ <role>developer</role>
33
+ </roles>
34
+ </developer>
35
+ <developer>
36
+ <id>geneome</id>
37
+ <name>Not Known</name>
38
+ <roles>
39
+ <role>developer</role>
40
+ </roles>
41
+ </developer>
42
+ <developer>
43
+ <id>joonhyublee</id>
44
+ <name>Joon Hyub Lee</name>
45
+ <roles>
46
+ <role>developer</role>
47
+ </roles>
48
+ </developer>
49
+ <developer>
50
+ <id>monkstone</id>
51
+ <name>Martin Prout</name>
52
+ <roles>
53
+ <role>developer</role>
54
+ </roles>
55
+ </developer>
56
+ </developers>
57
+ <issueManagement>
58
+ <system>Github</system>
59
+ <url>https://github.com/monkstone/joonsrenderer/issues</url>
60
+ </issueManagement>
61
+ <properties>
62
+ <jogl.version>2.3.2</jogl.version>
63
+ <source.directory>src</source.directory>
64
+ <joonsrenderer.basedir>${project.basedir}</joonsrenderer.basedir>
65
+ <maven.compiler.target>1.8</maven.compiler.target>
66
+ <processing.version>3.2.3</processing.version>
67
+ <project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
68
+ <janino.version>3.0.6</janino.version>
69
+ <polyglot.dump.pom>pom.xml</polyglot.dump.pom>
70
+ <maven.compiler.source>1.8</maven.compiler.source>
71
+ </properties>
72
+ <dependencies>
73
+ <dependency>
74
+ <groupId>org.processing</groupId>
75
+ <artifactId>core</artifactId>
76
+ <version>${processing.version}</version>
77
+ </dependency>
78
+ <dependency>
79
+ <groupId>org.jogamp.jogl</groupId>
80
+ <artifactId>jogl-all</artifactId>
81
+ <version>${jogl.version}</version>
82
+ </dependency>
83
+ <dependency>
84
+ <groupId>org.jogamp.gluegen</groupId>
85
+ <artifactId>gluegen-rt</artifactId>
86
+ <version>${jogl.version}</version>
87
+ </dependency>
88
+ <dependency>
89
+ <groupId>org.codehaus.janino</groupId>
90
+ <artifactId>commons-compiler</artifactId>
91
+ <version>${janino.version}</version>
92
+ </dependency>
93
+ <dependency>
94
+ <groupId>org.codehaus.janino</groupId>
95
+ <artifactId>janino</artifactId>
96
+ <version>${janino.version}</version>
97
+ </dependency>
98
+ </dependencies>
99
+ <build>
100
+ <sourceDirectory>src</sourceDirectory>
101
+ <defaultGoal>package</defaultGoal>
102
+ <finalName>joonsrenderer</finalName>
103
+ <pluginManagement>
104
+ <plugins>
105
+ <plugin>
106
+ <artifactId>maven-resources-plugin</artifactId>
107
+ <version>2.6</version>
108
+ </plugin>
109
+ <plugin>
110
+ <artifactId>maven-dependency-plugin</artifactId>
111
+ <version>2.10</version>
112
+ <executions>
113
+ <execution>
114
+ <id>default-cli</id>
115
+ <configuration>
116
+ <artifactItems>
117
+ <artifactItem>
118
+ <groupId>org.codehaus.janino</groupId>
119
+ <artifactId>janino</artifactId>
120
+ <version>${janino.version}</version>
121
+ <type>jar</type>
122
+ <outputDirectory>${joonsrenderer.basedir}/lib</outputDirectory>
123
+ </artifactItem>
124
+ <artifactItem>
125
+ <groupId>org.codehaus.janino</groupId>
126
+ <artifactId>commons-compiler</artifactId>
127
+ <version>${janino.version}</version>
128
+ <type>jar</type>
129
+ <outputDirectory>${joonsrenderer.basedir}/lib</outputDirectory>
130
+ </artifactItem>
131
+ </artifactItems>
132
+ </configuration>
133
+ </execution>
134
+ </executions>
135
+ </plugin>
136
+ <plugin>
137
+ <artifactId>maven-compiler-plugin</artifactId>
138
+ <version>3.6.0</version>
139
+ <configuration>
140
+ <source>${maven.compiler.source}</source>
141
+ <target>${maven.compiler.target}</target>
142
+ </configuration>
143
+ </plugin>
144
+ <plugin>
145
+ <artifactId>maven-javadoc-plugin</artifactId>
146
+ <version>2.10.4</version>
147
+ <configuration>
148
+ <detectOfflineLinks>false</detectOfflineLinks>
149
+ </configuration>
150
+ </plugin>
151
+ <plugin>
152
+ <artifactId>maven-jar-plugin</artifactId>
153
+ <version>3.0.2</version>
154
+ <configuration>
155
+ <archive>
156
+ <manifestFile>MANIFEST.MF</manifestFile>
157
+ </archive>
158
+ </configuration>
159
+ </plugin>
160
+ </plugins>
161
+ </pluginManagement>
162
+ </build>
163
+ </project>
@@ -0,0 +1,1354 @@
1
+
2
+ import java.awt.BorderLayout;
3
+ import java.awt.Dimension;
4
+ import java.awt.FlowLayout;
5
+ import java.awt.Toolkit;
6
+ import java.awt.datatransfer.DataFlavor;
7
+ import java.awt.datatransfer.Transferable;
8
+ import java.awt.event.ActionEvent;
9
+ import java.awt.event.ActionListener;
10
+ import java.beans.PropertyVetoException;
11
+ import java.io.BufferedReader;
12
+ import java.io.File;
13
+ import java.io.FileNotFoundException;
14
+ import java.io.FileReader;
15
+ import java.io.FileWriter;
16
+ import java.io.IOException;
17
+ import java.util.List;
18
+ import java.util.logging.Level;
19
+ import java.util.logging.Logger;
20
+
21
+ import javax.swing.BorderFactory;
22
+ import javax.swing.JButton;
23
+ import javax.swing.JCheckBoxMenuItem;
24
+ import javax.swing.JComponent;
25
+ import javax.swing.JDesktopPane;
26
+ import javax.swing.JFileChooser;
27
+ import javax.swing.JInternalFrame;
28
+ import javax.swing.JMenu;
29
+ import javax.swing.JMenuBar;
30
+ import javax.swing.JMenuItem;
31
+ import javax.swing.JOptionPane;
32
+ import javax.swing.JPanel;
33
+ import javax.swing.JProgressBar;
34
+ import javax.swing.JScrollPane;
35
+ import javax.swing.JSeparator;
36
+ import javax.swing.JTextArea;
37
+ import javax.swing.KeyStroke;
38
+ import javax.swing.ScrollPaneConstants;
39
+ import javax.swing.SwingUtilities;
40
+ import javax.swing.TransferHandler;
41
+ import javax.swing.UIManager;
42
+ import javax.swing.UIManager.LookAndFeelInfo;
43
+ import javax.swing.filechooser.FileFilter;
44
+ import javax.swing.plaf.metal.DefaultMetalTheme;
45
+ import javax.swing.plaf.metal.MetalLookAndFeel;
46
+
47
+ import org.sunflow.Benchmark;
48
+ import org.sunflow.RealtimeBenchmark;
49
+ import org.sunflow.SunflowAPI;
50
+ import org.sunflow.core.Display;
51
+ import org.sunflow.core.TextureCache;
52
+ import org.sunflow.core.accel.KDTree;
53
+ import org.sunflow.core.display.FileDisplay;
54
+ import org.sunflow.core.display.FrameDisplay;
55
+ import org.sunflow.core.display.ImgPipeDisplay;
56
+ import org.sunflow.core.primitive.TriangleMesh;
57
+ import org.sunflow.system.ImagePanel;
58
+ import org.sunflow.system.Timer;
59
+ import org.sunflow.system.UI;
60
+ import org.sunflow.system.UserInterface;
61
+ import org.sunflow.system.UI.Module;
62
+ import org.sunflow.system.UI.PrintLevel;
63
+
64
+ @SuppressWarnings("serial")
65
+ public class SunflowGUI extends javax.swing.JFrame implements UserInterface {
66
+
67
+ final String JAVA_EXT = ".java";
68
+ private static final int DEFAULT_WIDTH = 1024;
69
+ private static final int DEFAULT_HEIGHT = 768;
70
+ private JPanel jPanel3;
71
+ private JScrollPane jScrollPane1;
72
+ private JMenuItem exitMenuItem;
73
+ private JSeparator jSeparator2;
74
+ private JPanel jPanel1;
75
+ private JButton renderButton;
76
+ private JMenuItem jMenuItem4;
77
+ private JSeparator jSeparator1;
78
+ private JMenuItem fitWindowMenuItem;
79
+ private JMenuItem tileWindowMenuItem;
80
+ private JSeparator jSeparator5;
81
+ private JMenuItem consoleWindowMenuItem;
82
+ private JMenuItem editorWindowMenuItem;
83
+ private JMenuItem imageWindowMenuItem;
84
+ private JMenu windowMenu;
85
+ private JInternalFrame consoleFrame;
86
+ private JInternalFrame editorFrame;
87
+ private JInternalFrame imagePanelFrame;
88
+ private JDesktopPane desktop;
89
+ private JCheckBoxMenuItem smallTrianglesMenuItem;
90
+ private JMenuItem textureCacheClearMenuItem;
91
+ private JSeparator jSeparator4;
92
+ private JMenuItem resetZoomMenuItem;
93
+ private JMenu imageMenu;
94
+ private ImagePanel imagePanel;
95
+ private JPanel jPanel6;
96
+ private JCheckBoxMenuItem clearLogMenuItem;
97
+ private JPanel jPanel5;
98
+ private JButton taskCancelButton;
99
+ private JProgressBar taskProgressBar;
100
+ private JSeparator jSeparator3;
101
+ private JCheckBoxMenuItem autoBuildMenuItem;
102
+ private JMenuItem iprMenuItem;
103
+ private JMenuItem renderMenuItem;
104
+ private JMenuItem buildMenuItem;
105
+ private JMenu sceneMenu;
106
+ private JTextArea editorTextArea;
107
+ private JTextArea consoleTextArea;
108
+ private JButton clearConsoleButton;
109
+ private JPanel jPanel4;
110
+ private JScrollPane jScrollPane2;
111
+ private JButton iprButton;
112
+ private JButton buildButton;
113
+ private JMenuItem saveAsMenuItem;
114
+ private JMenuItem saveMenuItem;
115
+ private JMenuItem openFileMenuItem;
116
+ private JMenuItem newFileMenuItem;
117
+ private JMenu fileMenu;
118
+ private JMenuBar jMenuBar1;
119
+ // non-swing items
120
+ private String currentFile;
121
+ private String currentTask;
122
+ private int currentTaskLastP;
123
+ private SunflowAPI api;
124
+ private File lastSaveDirectory;
125
+
126
+ public static void usage(boolean verbose) {
127
+ System.out.println("Usage: SunflowGUI [options] scenefile");
128
+ if (verbose) {
129
+ System.out.println("Sunflow v" + SunflowAPI.VERSION + " textmode");
130
+ System.out.println("Renders the specified scene file");
131
+ System.out.println("Options:");
132
+ System.out.println(" -o filename Saves the output as the specified filename (png, hdr, tga)");
133
+ System.out.println(" #'s get expanded to the current frame number");
134
+ System.out.println(" -nogui Don't open the frame showing rendering progress");
135
+ System.out.println(" -ipr Render using progressive algorithm");
136
+ System.out.println(" -sampler type Render using the specified algorithm");
137
+ System.out.println(" -threads n Render using n threads");
138
+ System.out.println(" -lopri Set thread priority to low (default)");
139
+ System.out.println(" -hipri Set thread priority to high");
140
+ System.out.println(" -smallmesh Load triangle meshes using triangles optimized for memory use");
141
+ System.out.println(" -dumpkd Dump KDTree to an obj file for visualization");
142
+ System.out.println(" -buildonly Do not call render method after loading the scene");
143
+ System.out.println(" -showaa Display sampling levels per pixel for bucket renderer");
144
+ System.out.println(" -nogi Disable any global illumination engines in the scene");
145
+ System.out.println(" -nocaustics Disable any caustic engine in the scene");
146
+ System.out.println(" -pathgi n Use path tracing with n samples to render global illumination");
147
+ System.out.println(" -quick_ambocc d Applies ambient occlusion to the scene with specified maximum distance");
148
+ System.out.println(" -quick_uvs Applies a surface uv visualization shader to the scene");
149
+ System.out.println(" -quick_normals Applies a surface normal visualization shader to the scene");
150
+ System.out.println(" -quick_id Renders using a unique color for each instance");
151
+ System.out.println(" -quick_prims Renders using a unique color for each primitive");
152
+ System.out.println(" -quick_gray Renders using a plain gray diffuse shader");
153
+ System.out.println(" -quick_wire Renders using a wireframe shader");
154
+ System.out.println(" -resolution w h Changes the render resolution to the specified width and height (in pixels)");
155
+ System.out.println(" -aa min max Overrides the image anti-aliasing depths");
156
+ System.out.println(" -samples n Overrides the image sample count (affects bucket and multipass samplers)");
157
+ System.out.println(" -bucket n order Changes the default bucket size to n pixels and the default order");
158
+ System.out.println(" -bake name Bakes a lightmap for the specified instance");
159
+ System.out.println(" -bakedir dir Selects the type of lightmap baking: dir=view or ortho");
160
+ System.out.println(" -filter type Selects the image filter to use");
161
+ System.out.println(" -bench Run several built-in scenes for benchmark purposes");
162
+ System.out.println(" -rtbench Run realtime ray-tracing benchmark");
163
+ System.out.println(" -frame n Set frame number to the specified value");
164
+ System.out.println(" -anim n1 n2 Render all frames between the two specified values (inclusive)");
165
+ System.out.println(" -translate file Translate input scene to the specified filename");
166
+ System.out.println(" -v verbosity Set the verbosity level: 0=none,1=errors,2=warnings,3=info,4=detailed");
167
+ System.out.println(" -h Prints this message");
168
+ }
169
+ System.exit(1);
170
+ }
171
+
172
+ public static void main(String[] args) {
173
+ if (args.length > 0) {
174
+ boolean showFrame = true;
175
+ String sampler = null;
176
+ boolean noRender = false;
177
+ String filename = null;
178
+ String input = null;
179
+ int i = 0;
180
+ int threads = 0;
181
+ boolean lowPriority = true;
182
+ boolean showAA = false;
183
+ boolean noGI = false;
184
+ boolean noCaustics = false;
185
+ int pathGI = 0;
186
+ float maxDist = 0;
187
+ String shaderOverride = null;
188
+ int resolutionW = 0, resolutionH = 0;
189
+ int aaMin = -5, aaMax = -5;
190
+ int samples = -1;
191
+ int bucketSize = 0;
192
+ String bucketOrder = null;
193
+ String bakingName = null;
194
+ boolean bakeViewdep = false;
195
+ String filterType = null;
196
+ boolean runBenchmark = false;
197
+ boolean runRTBenchmark = false;
198
+ String translateFilename = null;
199
+ int frameStart = 1, frameStop = 1;
200
+ while (i < args.length) {
201
+ if (args[i].equals("-o")) {
202
+ if (i > args.length - 2) {
203
+ usage(false);
204
+ }
205
+ filename = args[i + 1];
206
+ i += 2;
207
+ } else if (args[i].equals("-nogui")) {
208
+ showFrame = false;
209
+ i++;
210
+ } else if (args[i].equals("-ipr")) {
211
+ sampler = "ipr";
212
+ i++;
213
+ } else if (args[i].equals("-threads")) {
214
+ if (i > args.length - 2) {
215
+ usage(false);
216
+ }
217
+ threads = Integer.parseInt(args[i + 1]);
218
+ i += 2;
219
+ } else if (args[i].equals("-lopri")) {
220
+ lowPriority = true;
221
+ i++;
222
+ } else if (args[i].equals("-hipri")) {
223
+ lowPriority = false;
224
+ i++;
225
+ } else if (args[i].equals("-sampler")) {
226
+ if (i > args.length - 2) {
227
+ usage(false);
228
+ }
229
+ sampler = args[i + 1];
230
+ i += 2;
231
+ } else if (args[i].equals("-smallmesh")) {
232
+ TriangleMesh.setSmallTriangles(true);
233
+ i++;
234
+ } else if (args[i].equals("-dumpkd")) {
235
+ KDTree.setDumpMode(true, "kdtree");
236
+ i++;
237
+ } else if (args[i].equals("-buildonly")) {
238
+ noRender = true;
239
+ i++;
240
+ } else if (args[i].equals("-showaa")) {
241
+ showAA = true;
242
+ i++;
243
+ } else if (args[i].equals("-nogi")) {
244
+ noGI = true;
245
+ i++;
246
+ } else if (args[i].equals("-nocaustics")) {
247
+ noCaustics = true;
248
+ i++;
249
+ } else if (args[i].equals("-pathgi")) {
250
+ if (i > args.length - 2) {
251
+ usage(false);
252
+ }
253
+ pathGI = Integer.parseInt(args[i + 1]);
254
+ i += 2;
255
+ } else if (args[i].equals("-quick_ambocc")) {
256
+ if (i > args.length - 2) {
257
+ usage(false);
258
+ }
259
+ maxDist = Float.parseFloat(args[i + 1]);
260
+ shaderOverride = "ambient_occlusion"; // new
261
+ // AmbientOcclusionShader(Color.WHITE,
262
+ // d);
263
+ i += 2;
264
+ } else if (args[i].equals("-quick_uvs")) {
265
+ if (i > args.length - 1) {
266
+ usage(false);
267
+ }
268
+ shaderOverride = "show_uvs";
269
+ i++;
270
+ } else if (args[i].equals("-quick_normals")) {
271
+ if (i > args.length - 1) {
272
+ usage(false);
273
+ }
274
+ shaderOverride = "show_normals";
275
+ i++;
276
+ } else if (args[i].equals("-quick_id")) {
277
+ if (i > args.length - 1) {
278
+ usage(false);
279
+ }
280
+ shaderOverride = "show_instance_id";
281
+ i++;
282
+ } else if (args[i].equals("-quick_prims")) {
283
+ if (i > args.length - 1) {
284
+ usage(false);
285
+ }
286
+ shaderOverride = "show_primitive_id";
287
+ i++;
288
+ } else if (args[i].equals("-quick_gray")) {
289
+ if (i > args.length - 1) {
290
+ usage(false);
291
+ }
292
+ shaderOverride = "quick_gray";
293
+ i++;
294
+ } else if (args[i].equals("-quick_wire")) {
295
+ if (i > args.length - 1) {
296
+ usage(false);
297
+ }
298
+ shaderOverride = "wireframe";
299
+ i++;
300
+ } else if (args[i].equals("-resolution")) {
301
+ if (i > args.length - 3) {
302
+ usage(false);
303
+ }
304
+ resolutionW = Integer.parseInt(args[i + 1]);
305
+ resolutionH = Integer.parseInt(args[i + 2]);
306
+ i += 3;
307
+ } else if (args[i].equals("-aa")) {
308
+ if (i > args.length - 3) {
309
+ usage(false);
310
+ }
311
+ aaMin = Integer.parseInt(args[i + 1]);
312
+ aaMax = Integer.parseInt(args[i + 2]);
313
+ i += 3;
314
+ } else if (args[i].equals("-samples")) {
315
+ if (i > args.length - 2) {
316
+ usage(false);
317
+ }
318
+ samples = Integer.parseInt(args[i + 1]);
319
+ i += 2;
320
+ } else if (args[i].equals("-bucket")) {
321
+ if (i > args.length - 3) {
322
+ usage(false);
323
+ }
324
+ bucketSize = Integer.parseInt(args[i + 1]);
325
+ bucketOrder = args[i + 2];
326
+ i += 3;
327
+ } else if (args[i].equals("-bake")) {
328
+ if (i > args.length - 2) {
329
+ usage(false);
330
+ }
331
+ bakingName = args[i + 1];
332
+ i += 2;
333
+ } else if (args[i].equals("-bakedir")) {
334
+ if (i > args.length - 2) {
335
+ usage(false);
336
+ }
337
+ String baketype = args[i + 1];
338
+ if (baketype.equals("view")) {
339
+ bakeViewdep = true;
340
+ } else if (baketype.equals("ortho")) {
341
+ bakeViewdep = false;
342
+ } else {
343
+ usage(false);
344
+ }
345
+ i += 2;
346
+ } else if (args[i].equals("-filter")) {
347
+ if (i > args.length - 2) {
348
+ usage(false);
349
+ }
350
+ filterType = args[i + 1];
351
+ i += 2;
352
+ } else if (args[i].equals("-bench")) {
353
+ runBenchmark = true;
354
+ i++;
355
+ } else if (args[i].equals("-rtbench")) {
356
+ runRTBenchmark = true;
357
+ i++;
358
+ } else if (args[i].equals("-frame")) {
359
+ if (i > args.length - 2) {
360
+ usage(false);
361
+ }
362
+ frameStart = frameStop = Integer.parseInt(args[i + 1]);
363
+ i += 2;
364
+ } else if (args[i].equals("-anim")) {
365
+ if (i > args.length - 3) {
366
+ usage(false);
367
+ }
368
+ frameStart = Integer.parseInt(args[i + 1]);
369
+ frameStop = Integer.parseInt(args[i + 2]);
370
+ i += 3;
371
+ } else if (args[i].equals("-v")) {
372
+ if (i > args.length - 2) {
373
+ usage(false);
374
+ }
375
+ UI.verbosity(Integer.parseInt(args[i + 1]));
376
+ i += 2;
377
+ } else if (args[i].equals("-translate")) {
378
+ if (i > args.length - 2) {
379
+ usage(false);
380
+ }
381
+ translateFilename = args[i + 1];
382
+ i += 2;
383
+ } else if (args[i].equals("-h") || args[i].equals("-help")) {
384
+ usage(true);
385
+ } else {
386
+ if (input != null) {
387
+ usage(false);
388
+ }
389
+ input = args[i];
390
+ i++;
391
+ }
392
+ }
393
+ if (runBenchmark) {
394
+ SunflowAPI.runSystemCheck();
395
+ new Benchmark().execute();
396
+ return;
397
+ }
398
+ if (runRTBenchmark) {
399
+ SunflowAPI.runSystemCheck();
400
+ new RealtimeBenchmark(showFrame, threads);
401
+ return;
402
+ }
403
+ if (input == null) {
404
+ usage(false);
405
+ }
406
+ SunflowAPI.runSystemCheck();
407
+ if (translateFilename != null) {
408
+ SunflowAPI.translate(input, translateFilename);
409
+ return;
410
+ }
411
+ if (frameStart < frameStop && showFrame) {
412
+ UI.printWarning(Module.GUI, "Animations should not be rendered without -nogui - forcing GUI off anyway");
413
+ showFrame = false;
414
+ }
415
+ if (frameStart < frameStop && filename == null) {
416
+ filename = "output.#.png";
417
+ UI.printWarning(Module.GUI, "Animation output was not specified - defaulting to: \"%s\"", filename);
418
+ }
419
+ for (int frameNumber = frameStart; frameNumber <= frameStop; frameNumber++) {
420
+ SunflowAPI api = SunflowAPI.create(input, frameNumber);
421
+ if (api == null) {
422
+ continue;
423
+ }
424
+ if (noRender) {
425
+ continue;
426
+ }
427
+ if (resolutionW > 0 && resolutionH > 0) {
428
+ api.parameter("resolutionX", resolutionW);
429
+ api.parameter("resolutionY", resolutionH);
430
+ }
431
+ if (aaMin != -5 || aaMax != -5) {
432
+ api.parameter("aa.min", aaMin);
433
+ api.parameter("aa.max", aaMax);
434
+ }
435
+ if (samples >= 0) {
436
+ api.parameter("aa.samples", samples);
437
+ }
438
+ if (bucketSize > 0) {
439
+ api.parameter("bucket.size", bucketSize);
440
+ }
441
+ if (bucketOrder != null) {
442
+ api.parameter("bucket.order", bucketOrder);
443
+ }
444
+ api.parameter("aa.display", showAA);
445
+ api.parameter("threads", threads);
446
+ api.parameter("threads.lowPriority", lowPriority);
447
+ if (bakingName != null) {
448
+ api.parameter("baking.instance", bakingName);
449
+ api.parameter("baking.viewdep", bakeViewdep);
450
+ }
451
+ if (filterType != null) {
452
+ api.parameter("filter", filterType);
453
+ }
454
+ if (noGI) {
455
+ api.parameter("gi.engine", "none");
456
+ } else if (pathGI > 0) {
457
+ api.parameter("gi.engine", "path");
458
+ api.parameter("gi.path.samples", pathGI);
459
+ }
460
+ if (noCaustics) {
461
+ api.parameter("caustics", "none");
462
+ }
463
+ if (sampler != null) {
464
+ api.parameter("sampler", sampler);
465
+ }
466
+ api.options(SunflowAPI.DEFAULT_OPTIONS);
467
+ if (shaderOverride != null) {
468
+ if (shaderOverride.equals("ambient_occlusion")) {
469
+ api.parameter("maxdist", maxDist);
470
+ }
471
+ api.shader("cmdline_override", shaderOverride);
472
+ api.parameter("override.shader", "cmdline_override");
473
+ api.parameter("override.photons", true);
474
+ api.options(SunflowAPI.DEFAULT_OPTIONS);
475
+ }
476
+ // create display
477
+ Display display;
478
+ String currentFilename = (filename != null) ? filename.replace("#", String.format("%04d", frameNumber)) : null;
479
+ if (showFrame) {
480
+ display = new FrameDisplay(currentFilename);
481
+ } else {
482
+ if (currentFilename != null && currentFilename.equals("imgpipe")) {
483
+ display = new ImgPipeDisplay();
484
+ } else {
485
+ display = new FileDisplay(currentFilename);
486
+ }
487
+ }
488
+ api.render(SunflowAPI.DEFAULT_OPTIONS, display);
489
+ }
490
+ } else {
491
+ try {
492
+ for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
493
+ if ("Nimbus".equals(info.getName())) {
494
+ UIManager.setLookAndFeel(info.getClassName());
495
+ break;
496
+ }
497
+ }
498
+ } catch (Exception e) {
499
+ // If Nimbus is not available, you can set the GUI to another look and feel.
500
+ MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
501
+ }
502
+
503
+ SunflowGUI gui = new SunflowGUI();
504
+ gui.setVisible(true);
505
+ Dimension screenRes = Toolkit.getDefaultToolkit().getScreenSize();
506
+ if (screenRes.getWidth() <= DEFAULT_WIDTH || screenRes.getHeight() <= DEFAULT_HEIGHT) {
507
+ gui.setExtendedState(MAXIMIZED_BOTH);
508
+ }
509
+ gui.tileWindowMenuItem.doClick();
510
+ SunflowAPI.runSystemCheck();
511
+ }
512
+ }
513
+
514
+ public SunflowGUI() {
515
+ super();
516
+ currentFile = null;
517
+ lastSaveDirectory = null;
518
+ api = null;
519
+ initGUI();
520
+ pack();
521
+ setLocationRelativeTo(null);
522
+ newFileMenuItemActionPerformed(null);
523
+ UI.set(this);
524
+ }
525
+
526
+ private void initGUI() {
527
+ setTitle("Sunflow v" + SunflowAPI.VERSION);
528
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
529
+ {
530
+ desktop = new JDesktopPane();
531
+ getContentPane().add(desktop, BorderLayout.CENTER);
532
+ Dimension screenRes = Toolkit.getDefaultToolkit().getScreenSize();
533
+ if (screenRes.getWidth() <= DEFAULT_WIDTH || screenRes.getHeight() <= DEFAULT_HEIGHT) {
534
+ desktop.setPreferredSize(new java.awt.Dimension(640, 480));
535
+ } else {
536
+ desktop.setPreferredSize(new java.awt.Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
537
+ }
538
+ {
539
+ imagePanelFrame = new JInternalFrame();
540
+ desktop.add(imagePanelFrame);
541
+ {
542
+ jPanel1 = new JPanel();
543
+ FlowLayout jPanel1Layout = new FlowLayout();
544
+ jPanel1Layout.setAlignment(FlowLayout.LEFT);
545
+ jPanel1.setLayout(jPanel1Layout);
546
+ imagePanelFrame.getContentPane().add(jPanel1, BorderLayout.NORTH);
547
+ {
548
+ renderButton = new JButton();
549
+ jPanel1.add(renderButton);
550
+ renderButton.setText("Render");
551
+ renderButton.addActionListener(new ActionListener() {
552
+ @Override
553
+ public void actionPerformed(ActionEvent evt) {
554
+ renderMenuItemActionPerformed(evt);
555
+ }
556
+ });
557
+ }
558
+ {
559
+ iprButton = new JButton();
560
+ jPanel1.add(iprButton);
561
+ iprButton.setText("IPR");
562
+ iprButton.addActionListener(new ActionListener() {
563
+ @Override
564
+ public void actionPerformed(ActionEvent evt) {
565
+ iprMenuItemActionPerformed(evt);
566
+ }
567
+ });
568
+ }
569
+ }
570
+ {
571
+ imagePanel = new ImagePanel();
572
+ imagePanelFrame.getContentPane().add(imagePanel, BorderLayout.CENTER);
573
+ }
574
+ imagePanelFrame.pack();
575
+ imagePanelFrame.setResizable(true);
576
+ imagePanelFrame.setMaximizable(true);
577
+ imagePanelFrame.setVisible(true);
578
+ imagePanelFrame.setTitle("Image");
579
+ imagePanelFrame.setIconifiable(true);
580
+ }
581
+ {
582
+ editorFrame = new JInternalFrame();
583
+ desktop.add(editorFrame);
584
+ editorFrame.setTitle("Script Editor");
585
+ editorFrame.setMaximizable(true);
586
+ editorFrame.setResizable(true);
587
+ editorFrame.setIconifiable(true);
588
+ {
589
+ jScrollPane1 = new JScrollPane();
590
+ editorFrame.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
591
+ jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
592
+ jScrollPane1.setPreferredSize(new java.awt.Dimension(360, 280));
593
+ {
594
+ editorTextArea = new JTextArea();
595
+ jScrollPane1.setViewportView(editorTextArea);
596
+ editorTextArea.setFont(new java.awt.Font("Monospaced", 0, 12));
597
+ // drag and drop
598
+ editorTextArea.setTransferHandler(new SceneTransferHandler());
599
+ }
600
+ }
601
+ {
602
+ jPanel3 = new JPanel();
603
+ editorFrame.getContentPane().add(jPanel3, BorderLayout.SOUTH);
604
+ FlowLayout jPanel3Layout = new FlowLayout();
605
+ jPanel3Layout.setAlignment(FlowLayout.RIGHT);
606
+ jPanel3.setLayout(jPanel3Layout);
607
+ {
608
+ buildButton = new JButton();
609
+ jPanel3.add(buildButton);
610
+ buildButton.setText("Build Scene");
611
+ buildButton.addActionListener(new ActionListener() {
612
+ @Override
613
+ public void actionPerformed(ActionEvent evt) {
614
+ buildMenuItemActionPerformed(evt);
615
+ }
616
+ });
617
+ }
618
+ }
619
+ editorFrame.pack();
620
+ editorFrame.setVisible(true);
621
+ }
622
+ {
623
+ consoleFrame = new JInternalFrame();
624
+ desktop.add(consoleFrame);
625
+ consoleFrame.setIconifiable(true);
626
+ consoleFrame.setMaximizable(true);
627
+ consoleFrame.setResizable(true);
628
+ consoleFrame.setTitle("Console");
629
+ {
630
+ jScrollPane2 = new JScrollPane();
631
+ consoleFrame.getContentPane().add(jScrollPane2, BorderLayout.CENTER);
632
+ jScrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
633
+ jScrollPane2.setPreferredSize(new java.awt.Dimension(360, 100));
634
+ {
635
+ consoleTextArea = new JTextArea();
636
+ jScrollPane2.setViewportView(consoleTextArea);
637
+ consoleTextArea.setFont(new java.awt.Font("Monospaced", 0, 12));
638
+ consoleTextArea.setEditable(false);
639
+ }
640
+ }
641
+ {
642
+ jPanel4 = new JPanel();
643
+ consoleFrame.getContentPane().add(jPanel4, BorderLayout.SOUTH);
644
+ BorderLayout jPanel4Layout = new BorderLayout();
645
+ jPanel4.setLayout(jPanel4Layout);
646
+ {
647
+ jPanel6 = new JPanel();
648
+ BorderLayout jPanel6Layout = new BorderLayout();
649
+ jPanel6.setLayout(jPanel6Layout);
650
+ jPanel4.add(jPanel6, BorderLayout.CENTER);
651
+ jPanel6.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));
652
+ {
653
+ taskProgressBar = new JProgressBar();
654
+ jPanel6.add(taskProgressBar);
655
+ taskProgressBar.setEnabled(false);
656
+ taskProgressBar.setString("");
657
+ taskProgressBar.setStringPainted(true);
658
+ taskProgressBar.setOpaque(false);
659
+ }
660
+ }
661
+ {
662
+ jPanel5 = new JPanel();
663
+ FlowLayout jPanel5Layout = new FlowLayout();
664
+ jPanel5Layout.setAlignment(FlowLayout.RIGHT);
665
+ jPanel5.setLayout(jPanel5Layout);
666
+ jPanel4.add(jPanel5, BorderLayout.EAST);
667
+ {
668
+ taskCancelButton = new JButton();
669
+ jPanel5.add(taskCancelButton);
670
+ taskCancelButton.setText("Cancel");
671
+ taskCancelButton.setEnabled(false);
672
+ taskCancelButton.addActionListener(new ActionListener() {
673
+ @Override
674
+ public void actionPerformed(ActionEvent evt) {
675
+ UI.taskCancel();
676
+ }
677
+ });
678
+ }
679
+ {
680
+ clearConsoleButton = new JButton();
681
+ jPanel5.add(clearConsoleButton);
682
+ clearConsoleButton.setText("Clear");
683
+ clearConsoleButton.addActionListener(new ActionListener() {
684
+ @Override
685
+ public void actionPerformed(ActionEvent evt) {
686
+ clearConsole();
687
+ }
688
+ });
689
+ }
690
+ }
691
+ }
692
+ consoleFrame.pack();
693
+ consoleFrame.setVisible(true);
694
+ }
695
+ }
696
+ {
697
+ jMenuBar1 = new JMenuBar();
698
+ setJMenuBar(jMenuBar1);
699
+ {
700
+ fileMenu = new JMenu();
701
+ jMenuBar1.add(fileMenu);
702
+ fileMenu.setText("File");
703
+ {
704
+ newFileMenuItem = new JMenuItem();
705
+ fileMenu.add(newFileMenuItem);
706
+ newFileMenuItem.setText("New");
707
+ newFileMenuItem.setAccelerator(KeyStroke.getKeyStroke("ctrl N"));
708
+ newFileMenuItem.addActionListener(new ActionListener() {
709
+ @Override
710
+ public void actionPerformed(ActionEvent evt) {
711
+ newFileMenuItemActionPerformed(evt);
712
+ }
713
+ });
714
+ }
715
+ {
716
+ openFileMenuItem = new JMenuItem();
717
+ fileMenu.add(openFileMenuItem);
718
+ openFileMenuItem.setText("Open ...");
719
+ openFileMenuItem.setAccelerator(KeyStroke.getKeyStroke("ctrl O"));
720
+ openFileMenuItem.addActionListener(new ActionListener() {
721
+ @Override
722
+ public void actionPerformed(ActionEvent evt) {
723
+ openFileMenuItemActionPerformed(evt);
724
+ }
725
+ });
726
+ }
727
+ {
728
+ saveMenuItem = new JMenuItem();
729
+ fileMenu.add(saveMenuItem);
730
+ saveMenuItem.setText("Save");
731
+ saveMenuItem.setAccelerator(KeyStroke.getKeyStroke("ctrl S"));
732
+ saveMenuItem.addActionListener(new ActionListener() {
733
+ @Override
734
+ public void actionPerformed(ActionEvent evt) {
735
+ saveCurrentFile(currentFile);
736
+ }
737
+ });
738
+ }
739
+ {
740
+ saveAsMenuItem = new JMenuItem();
741
+ fileMenu.add(saveAsMenuItem);
742
+ saveAsMenuItem.setText("Save As ...");
743
+ saveAsMenuItem.addActionListener(new ActionListener() {
744
+ @Override
745
+ public void actionPerformed(ActionEvent evt) {
746
+ saveAsMenuItemActionPerformed(evt);
747
+ }
748
+ });
749
+ }
750
+ {
751
+ jSeparator2 = new JSeparator();
752
+ fileMenu.add(jSeparator2);
753
+ }
754
+ {
755
+ exitMenuItem = new JMenuItem();
756
+ fileMenu.add(exitMenuItem);
757
+ exitMenuItem.setText("Exit");
758
+ exitMenuItem.addActionListener(new ActionListener() {
759
+ @Override
760
+ public void actionPerformed(ActionEvent evt) {
761
+ System.exit(0);
762
+ }
763
+ });
764
+ }
765
+ }
766
+ {
767
+ sceneMenu = new JMenu();
768
+ jMenuBar1.add(sceneMenu);
769
+ sceneMenu.setText("Scene");
770
+ {
771
+ buildMenuItem = new JMenuItem();
772
+ sceneMenu.add(buildMenuItem);
773
+ buildMenuItem.setText("Build");
774
+ buildMenuItem.setAccelerator(KeyStroke.getKeyStroke("ctrl B"));
775
+ buildMenuItem.addActionListener(new ActionListener() {
776
+ @Override
777
+ public void actionPerformed(ActionEvent evt) {
778
+ if (sceneMenu.isEnabled()) {
779
+ buildMenuItemActionPerformed(evt);
780
+ }
781
+ }
782
+ });
783
+ }
784
+ {
785
+ autoBuildMenuItem = new JCheckBoxMenuItem();
786
+ sceneMenu.add(autoBuildMenuItem);
787
+ autoBuildMenuItem.setText("Build on open");
788
+ autoBuildMenuItem.setSelected(true);
789
+ }
790
+ {
791
+ jSeparator3 = new JSeparator();
792
+ sceneMenu.add(jSeparator3);
793
+ }
794
+ {
795
+ renderMenuItem = new JMenuItem();
796
+ sceneMenu.add(renderMenuItem);
797
+ renderMenuItem.setText("Render");
798
+ renderMenuItem.addActionListener(new ActionListener() {
799
+ @Override
800
+ public void actionPerformed(ActionEvent evt) {
801
+ renderMenuItemActionPerformed(evt);
802
+ }
803
+ });
804
+ }
805
+ {
806
+ iprMenuItem = new JMenuItem();
807
+ sceneMenu.add(iprMenuItem);
808
+ iprMenuItem.setText("IPR");
809
+ iprMenuItem.addActionListener(new ActionListener() {
810
+ @Override
811
+ public void actionPerformed(ActionEvent evt) {
812
+ iprMenuItemActionPerformed(evt);
813
+ }
814
+ });
815
+ }
816
+ {
817
+ clearLogMenuItem = new JCheckBoxMenuItem();
818
+ sceneMenu.add(clearLogMenuItem);
819
+ clearLogMenuItem.setText("Auto Clear Log");
820
+ clearLogMenuItem.setToolTipText("Clears the console before building or rendering");
821
+ clearLogMenuItem.setSelected(true);
822
+ }
823
+ {
824
+ jSeparator4 = new JSeparator();
825
+ sceneMenu.add(jSeparator4);
826
+ }
827
+ {
828
+ textureCacheClearMenuItem = new JMenuItem();
829
+ sceneMenu.add(textureCacheClearMenuItem);
830
+ textureCacheClearMenuItem.setText("Clear Texture Cache");
831
+ textureCacheClearMenuItem.addActionListener(new ActionListener() {
832
+ @Override
833
+ public void actionPerformed(ActionEvent evt) {
834
+ textureCacheClearMenuItemActionPerformed(evt);
835
+ }
836
+ });
837
+ }
838
+ {
839
+ smallTrianglesMenuItem = new JCheckBoxMenuItem();
840
+ sceneMenu.add(smallTrianglesMenuItem);
841
+ smallTrianglesMenuItem.setText("Low Mem Triangles");
842
+ smallTrianglesMenuItem.setToolTipText("Load future meshes using a low memory footprint triangle representation");
843
+ smallTrianglesMenuItem.addActionListener(new ActionListener() {
844
+ @Override
845
+ public void actionPerformed(ActionEvent evt) {
846
+ smallTrianglesMenuItemActionPerformed(evt);
847
+ }
848
+ });
849
+ }
850
+ }
851
+ {
852
+ imageMenu = new JMenu();
853
+ jMenuBar1.add(imageMenu);
854
+ imageMenu.setText("Image");
855
+ {
856
+ resetZoomMenuItem = new JMenuItem();
857
+ imageMenu.add(resetZoomMenuItem);
858
+ resetZoomMenuItem.setText("Reset Zoom");
859
+ resetZoomMenuItem.addActionListener(new ActionListener() {
860
+ @Override
861
+ public void actionPerformed(ActionEvent evt) {
862
+ imagePanel.reset();
863
+ }
864
+ });
865
+ }
866
+ {
867
+ fitWindowMenuItem = new JMenuItem();
868
+ imageMenu.add(fitWindowMenuItem);
869
+ fitWindowMenuItem.setText("Fit to Window");
870
+ fitWindowMenuItem.addActionListener(new ActionListener() {
871
+ @Override
872
+ public void actionPerformed(ActionEvent evt) {
873
+ imagePanel.fit();
874
+ }
875
+ });
876
+ }
877
+ {
878
+ jSeparator1 = new JSeparator();
879
+ imageMenu.add(jSeparator1);
880
+ }
881
+ {
882
+ jMenuItem4 = new JMenuItem();
883
+ imageMenu.add(jMenuItem4);
884
+ jMenuItem4.setText("Save Image ...");
885
+ jMenuItem4.addActionListener(new ActionListener() {
886
+ @Override
887
+ public void actionPerformed(ActionEvent evt) {
888
+ // imagePanel.image;
889
+ JFileChooser fc = new JFileChooser(".");
890
+ fc.setFileFilter(new FileFilter() {
891
+ @Override
892
+ public String getDescription() {
893
+ return "Image File";
894
+ }
895
+
896
+ @Override
897
+ public boolean accept(File f) {
898
+ return (f.isDirectory() || f.getName().endsWith(".png") || f.getName().endsWith(".tga"));
899
+ }
900
+ });
901
+ if (fc.showSaveDialog(SunflowGUI.this) == JFileChooser.APPROVE_OPTION) {
902
+ String filename = fc.getSelectedFile().getAbsolutePath();
903
+ imagePanel.save(filename);
904
+ }
905
+ }
906
+ });
907
+ }
908
+ }
909
+ {
910
+ windowMenu = new JMenu();
911
+ jMenuBar1.add(windowMenu);
912
+ windowMenu.setText("Window");
913
+ }
914
+ {
915
+ imageWindowMenuItem = new JMenuItem();
916
+ windowMenu.add(imageWindowMenuItem);
917
+ imageWindowMenuItem.setText("Image");
918
+ imageWindowMenuItem.setAccelerator(KeyStroke.getKeyStroke("ctrl 1"));
919
+ imageWindowMenuItem.addActionListener(new ActionListener() {
920
+ @Override
921
+ public void actionPerformed(ActionEvent evt) {
922
+ selectFrame(imagePanelFrame);
923
+ }
924
+ });
925
+ }
926
+ {
927
+ editorWindowMenuItem = new JMenuItem();
928
+ windowMenu.add(editorWindowMenuItem);
929
+ editorWindowMenuItem.setText("Script Editor");
930
+ editorWindowMenuItem.setAccelerator(KeyStroke.getKeyStroke("ctrl 2"));
931
+ editorWindowMenuItem.addActionListener(new ActionListener() {
932
+ @Override
933
+ public void actionPerformed(ActionEvent evt) {
934
+ selectFrame(editorFrame);
935
+ }
936
+ });
937
+ }
938
+ {
939
+ consoleWindowMenuItem = new JMenuItem();
940
+ windowMenu.add(consoleWindowMenuItem);
941
+ consoleWindowMenuItem.setText("Console");
942
+ consoleWindowMenuItem.setAccelerator(KeyStroke.getKeyStroke("ctrl 3"));
943
+ consoleWindowMenuItem.addActionListener(new ActionListener() {
944
+ @Override
945
+ public void actionPerformed(ActionEvent evt) {
946
+ selectFrame(consoleFrame);
947
+ }
948
+ });
949
+ }
950
+ {
951
+ jSeparator5 = new JSeparator();
952
+ windowMenu.add(jSeparator5);
953
+ }
954
+ {
955
+ tileWindowMenuItem = new JMenuItem();
956
+ windowMenu.add(tileWindowMenuItem);
957
+ tileWindowMenuItem.setText("Tile");
958
+ tileWindowMenuItem.setAccelerator(KeyStroke.getKeyStroke("ctrl T"));
959
+ tileWindowMenuItem.addActionListener(new ActionListener() {
960
+ @Override
961
+ public void actionPerformed(ActionEvent evt) {
962
+ tileWindowMenuItemActionPerformed(evt);
963
+ }
964
+ });
965
+ }
966
+ }
967
+ }
968
+
969
+ private void newFileMenuItemActionPerformed(ActionEvent evt) {
970
+ if (evt != null) {
971
+ // check save?
972
+ }
973
+ // put some template code into the editor
974
+ String template = "import org.sunflow.core.*;\nimport org.sunflow.core.accel.*;\nimport org.sunflow.core.camera.*;\nimport org.sunflow.core.primitive.*;\nimport org.sunflow.core.shader.*;\nimport org.sunflow.image.Color;\nimport org.sunflow.math.*;\n\npublic void build() {\n // your code goes here\n\n}\n";
975
+ editorTextArea.setText(template);
976
+ }
977
+
978
+ private void openFileMenuItemActionPerformed(ActionEvent evt) {
979
+ JFileChooser fc = new JFileChooser(".");
980
+ if (lastSaveDirectory != null) {
981
+ fc.setCurrentDirectory(lastSaveDirectory);
982
+ }
983
+ fc.setFileFilter(new FileFilter() {
984
+ @Override
985
+ public String getDescription() {
986
+ return "Scene File";
987
+ }
988
+
989
+ @Override
990
+ public boolean accept(File f) {
991
+ return (f.isDirectory() || f.getName().endsWith(".sc") || f.getName().endsWith(JAVA_EXT));
992
+ }
993
+ });
994
+
995
+ if (fc.showOpenDialog(SunflowGUI.this) == JFileChooser.APPROVE_OPTION) {
996
+ final String f = fc.getSelectedFile().getAbsolutePath();
997
+ openFile(f);
998
+ lastSaveDirectory = fc.getSelectedFile().getParentFile();
999
+ }
1000
+ }
1001
+
1002
+ private void buildMenuItemActionPerformed(ActionEvent evt) {
1003
+ new Thread() {
1004
+ @Override
1005
+ public void run() {
1006
+ setEnableInterface(false);
1007
+ if (clearLogMenuItem.isSelected()) {
1008
+ clearConsole();
1009
+ }
1010
+ Timer t = new Timer();
1011
+ t.start();
1012
+ try {
1013
+ api = SunflowAPI.compile(editorTextArea.getText());
1014
+ } catch (NoClassDefFoundError e) {
1015
+ UI.printError(Module.GUI, "Janino library not found. Please check command line.");
1016
+ api = null;
1017
+ }
1018
+ if (api != null) {
1019
+ try {
1020
+ if (currentFile != null) {
1021
+ String dir = new File(currentFile).getAbsoluteFile().getParent();
1022
+ api.searchpath("texture", dir);
1023
+ api.searchpath("include", dir);
1024
+ }
1025
+ api.build();
1026
+
1027
+
1028
+ } catch (Exception e) {
1029
+ UI.printError(Module.GUI, "Build terminated abnormally: %s", e.getMessage());
1030
+ for (StackTraceElement elt : e.getStackTrace()) {
1031
+ UI.printInfo(Module.GUI, " at %s", elt.toString());
1032
+ }
1033
+ Logger.getLogger(SunflowGUI.class.getName()).log(Level.SEVERE, null, e);
1034
+ }
1035
+ t.end();
1036
+ UI.printInfo(Module.GUI, "Build time: %s", t.toString());
1037
+ }
1038
+ setEnableInterface(true);
1039
+ }
1040
+ }.start();
1041
+ }
1042
+
1043
+ private void clearConsole() {
1044
+ consoleTextArea.setText(null);
1045
+ }
1046
+
1047
+ private void println(final String s) {
1048
+ SwingUtilities.invokeLater(new Runnable() {
1049
+ @Override
1050
+ public void run() {
1051
+ consoleTextArea.append(s + "\n");
1052
+ }
1053
+ });
1054
+ }
1055
+
1056
+ private void setEnableInterface(boolean enabled) {
1057
+ // lock or unlock options which are unsafe during builds or renders
1058
+ newFileMenuItem.setEnabled(enabled);
1059
+ openFileMenuItem.setEnabled(enabled);
1060
+ saveMenuItem.setEnabled(enabled);
1061
+ saveAsMenuItem.setEnabled(enabled);
1062
+ sceneMenu.setEnabled(enabled);
1063
+ buildButton.setEnabled(enabled);
1064
+ renderButton.setEnabled(enabled);
1065
+ iprButton.setEnabled(enabled);
1066
+ }
1067
+
1068
+ @Override
1069
+ public void print(Module m, PrintLevel level, String s) {
1070
+ if (level == PrintLevel.ERROR) {
1071
+ JOptionPane.showMessageDialog(SunflowGUI.this, s, String.format("Error - %s", m.name()), JOptionPane.ERROR_MESSAGE);
1072
+ }
1073
+ println(UI.formatOutput(m, level, s));
1074
+ }
1075
+
1076
+ @Override
1077
+ public void taskStart(String s, int min, int max) {
1078
+ currentTask = s;
1079
+ currentTaskLastP = -1;
1080
+ final int taskMin = min;
1081
+ final int taskMax = max;
1082
+ SwingUtilities.invokeLater(new Runnable() {
1083
+ @Override
1084
+ public void run() {
1085
+ taskProgressBar.setEnabled(true);
1086
+ taskCancelButton.setEnabled(true);
1087
+ taskProgressBar.setMinimum(taskMin);
1088
+ taskProgressBar.setMaximum(taskMax);
1089
+ taskProgressBar.setValue(taskMin);
1090
+ taskProgressBar.setString(currentTask);
1091
+ }
1092
+ });
1093
+ }
1094
+
1095
+ @Override
1096
+ public void taskUpdate(int current) {
1097
+ final int taskCurrent = current;
1098
+ final String taskString = currentTask;
1099
+ SwingUtilities.invokeLater(new Runnable() {
1100
+ @Override
1101
+ public void run() {
1102
+ taskProgressBar.setValue(taskCurrent);
1103
+ int p = (int) (100.0 * taskProgressBar.getPercentComplete());
1104
+ if (p > currentTaskLastP) {
1105
+ taskProgressBar.setString(taskString + " [" + p + "%]");
1106
+ currentTaskLastP = p;
1107
+ }
1108
+ }
1109
+ });
1110
+ }
1111
+
1112
+ @Override
1113
+ public void taskStop() {
1114
+ SwingUtilities.invokeLater(new Runnable() {
1115
+ @Override
1116
+ public void run() {
1117
+ taskProgressBar.setValue(taskProgressBar.getMinimum());
1118
+ taskProgressBar.setString("");
1119
+ taskProgressBar.setEnabled(false);
1120
+ taskCancelButton.setEnabled(false);
1121
+ }
1122
+ });
1123
+ }
1124
+
1125
+ private void renderMenuItemActionPerformed(ActionEvent evt) {
1126
+ new Thread() {
1127
+ @Override
1128
+ public void run() {
1129
+ setEnableInterface(false);
1130
+ if (clearLogMenuItem.isSelected()) {
1131
+ clearConsole();
1132
+ }
1133
+ if (api != null) {
1134
+ api.parameter("sampler", "bucket");
1135
+ api.options(SunflowAPI.DEFAULT_OPTIONS);
1136
+ api.render(SunflowAPI.DEFAULT_OPTIONS, imagePanel);
1137
+ } else {
1138
+ UI.printError(Module.GUI, "Nothing to render!");
1139
+ }
1140
+ setEnableInterface(true);
1141
+ }
1142
+ }.start();
1143
+ }
1144
+
1145
+ private void iprMenuItemActionPerformed(ActionEvent evt) {
1146
+ new Thread() {
1147
+ @Override
1148
+ public void run() {
1149
+ setEnableInterface(false);
1150
+ if (clearLogMenuItem.isSelected()) {
1151
+ clearConsole();
1152
+ }
1153
+ if (api != null) {
1154
+ api.parameter("sampler", "ipr");
1155
+ api.options(SunflowAPI.DEFAULT_OPTIONS);
1156
+ api.render(SunflowAPI.DEFAULT_OPTIONS, imagePanel);
1157
+ } else {
1158
+ UI.printError(Module.GUI, "Nothing to IPR!");
1159
+ }
1160
+ setEnableInterface(true);
1161
+ }
1162
+ }.start();
1163
+ }
1164
+
1165
+ private void textureCacheClearMenuItemActionPerformed(ActionEvent evt) {
1166
+ TextureCache.flush();
1167
+ }
1168
+
1169
+ private void smallTrianglesMenuItemActionPerformed(ActionEvent evt) {
1170
+ TriangleMesh.setSmallTriangles(smallTrianglesMenuItem.isSelected());
1171
+ }
1172
+
1173
+ private void saveAsMenuItemActionPerformed(ActionEvent evt) {
1174
+ JFileChooser fc = new JFileChooser(".");
1175
+ if (lastSaveDirectory != null) {
1176
+ fc.setCurrentDirectory(lastSaveDirectory);
1177
+ }
1178
+ fc.setFileFilter(new FileFilter() {
1179
+ @Override
1180
+ public String getDescription() {
1181
+ return "Scene File";
1182
+ }
1183
+
1184
+ @Override
1185
+ public boolean accept(File f) {
1186
+ return (f.isDirectory() || f.getName().endsWith(JAVA_EXT));
1187
+ }
1188
+ });
1189
+
1190
+ if (fc.showSaveDialog(SunflowGUI.this) == JFileChooser.APPROVE_OPTION) {
1191
+ String f = fc.getSelectedFile().getAbsolutePath();
1192
+ if (!f.endsWith(JAVA_EXT)) {
1193
+ f += JAVA_EXT;
1194
+ }
1195
+ File file = new File(f);
1196
+ if (!file.exists() || JOptionPane.showConfirmDialog(SunflowGUI.this, "This file already exists.\nOverwrite?", "Warning", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
1197
+ // save file
1198
+ saveCurrentFile(f);
1199
+ lastSaveDirectory = file.getParentFile();
1200
+ }
1201
+ }
1202
+ }
1203
+
1204
+ private void saveCurrentFile(String filename) {
1205
+ if (filename == null) {
1206
+ // no filename was picked, go to save as dialog
1207
+ saveAsMenuItemActionPerformed(null);
1208
+ return;
1209
+ }
1210
+ FileWriter file;
1211
+ try {
1212
+ file = new FileWriter(filename);
1213
+ // get text from editor pane
1214
+ file.write(editorTextArea.getText());
1215
+ file.close();
1216
+ // update current filename
1217
+ currentFile = filename;
1218
+ UI.printInfo(Module.GUI, "Saved current script to \"%s\"", filename);
1219
+ } catch (IOException e) {
1220
+ UI.printError(Module.GUI, "Unable to save: \"%s\"", filename);
1221
+ Logger.getLogger(SunflowGUI.class.getName()).log(Level.SEVERE, null, e);
1222
+ }
1223
+ }
1224
+
1225
+ private void selectFrame(JInternalFrame frame) {
1226
+ try {
1227
+ frame.setSelected(true);
1228
+ frame.setIcon(false);
1229
+ } catch (PropertyVetoException e) {
1230
+ // this should never happen
1231
+ Logger.getLogger(SunflowGUI.class.getName()).log(Level.SEVERE, null, e);
1232
+ }
1233
+ }
1234
+
1235
+ private void tileWindowMenuItemActionPerformed(ActionEvent evt) {
1236
+ try {
1237
+ if (imagePanelFrame.isIcon()) {
1238
+ imagePanelFrame.setIcon(false);
1239
+ }
1240
+ if (editorFrame.isIcon()) {
1241
+ editorFrame.setIcon(false);
1242
+ }
1243
+ if (consoleFrame.isIcon()) {
1244
+ consoleFrame.setIcon(false);
1245
+ }
1246
+
1247
+ int width = desktop.getWidth();
1248
+ int height = desktop.getHeight();
1249
+ int widthLeft = width * 7 / 12;
1250
+ int widthRight = width - widthLeft;
1251
+ int pad = 2;
1252
+ int pad2 = pad + pad;
1253
+
1254
+ imagePanelFrame.reshape(pad, pad, widthLeft - pad2, height - pad2);
1255
+ editorFrame.reshape(pad + widthLeft, pad, widthRight - pad2, height / 2 - pad2);
1256
+ consoleFrame.reshape(pad + widthLeft, pad + height / 2, widthRight - pad2, height / 2 - pad2);
1257
+ } catch (PropertyVetoException e) {
1258
+ Logger.getLogger(SunflowGUI.class.getName()).log(Level.SEVERE, null, e);
1259
+ }
1260
+ }
1261
+
1262
+ private void openFile(String filename) {
1263
+ if (filename.endsWith(JAVA_EXT)) {
1264
+ // read the file line by line
1265
+ String code = "";
1266
+ FileReader file;
1267
+ try {
1268
+ file = new FileReader(filename);
1269
+ BufferedReader bf = new BufferedReader(file);
1270
+ while (true) {
1271
+ String line;
1272
+ line = bf.readLine();
1273
+ if (line == null) {
1274
+ break;
1275
+ }
1276
+ code += line;
1277
+ code += "\n";
1278
+ }
1279
+ file.close();
1280
+ editorTextArea.setText(code);
1281
+ } catch (FileNotFoundException e) {
1282
+ UI.printError(Module.GUI, "Unable to load: \"%s\"", filename);
1283
+ return;
1284
+ } catch (IOException e) {
1285
+ UI.printError(Module.GUI, "Unable to load: \"%s\"", filename);
1286
+ return;
1287
+ }
1288
+ // loade went ok, use filename as current
1289
+ currentFile = filename;
1290
+ UI.printInfo(Module.GUI, "Loaded script: \"%s\"", filename);
1291
+ } else if (filename.endsWith(".sc")) {
1292
+ String template = "import org.sunflow.core.*;\nimport org.sunflow.core.accel.*;\nimport org.sunflow.core.camera.*;\nimport org.sunflow.core.primitive.*;\nimport org.sunflow.core.shader.*;\nimport org.sunflow.image.Color;\nimport org.sunflow.math.*;\n\npublic void build() {\n include(\"" + filename.replace("\\", "\\\\") + "\");\n}\n";
1293
+ editorTextArea.setText(template);
1294
+ // no java file associated
1295
+ currentFile = null;
1296
+ UI.printInfo(Module.GUI, "Created template for \"%s\"", filename);
1297
+ } else {
1298
+ UI.printError(Module.GUI, "Unknown file format selected");
1299
+ return;
1300
+ }
1301
+ editorTextArea.setCaretPosition(0);
1302
+ if (autoBuildMenuItem.isSelected()) {
1303
+ // try to compile the code we just loaded
1304
+ buildMenuItemActionPerformed(null);
1305
+ }
1306
+
1307
+ }
1308
+
1309
+ private class SceneTransferHandler extends TransferHandler {
1310
+
1311
+ @Override
1312
+ public boolean importData(JComponent c, Transferable t) {
1313
+ if (!sceneMenu.isEnabled()) {
1314
+ return false;
1315
+ }
1316
+ // can I import it?
1317
+ if (!canImport(c, t.getTransferDataFlavors())) {
1318
+ return false;
1319
+ }
1320
+ try {
1321
+ // get a List of Files
1322
+ @SuppressWarnings("unchecked") // because they are nonsense here
1323
+ List<File> files = (java.util.List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
1324
+ for (File file : files) {
1325
+ String filename = file.getAbsolutePath();
1326
+ // check extension
1327
+ if (filename.endsWith(".sc") || filename.endsWith(JAVA_EXT)) {
1328
+ openFile(filename);
1329
+ // load only one file at a time, stop here
1330
+ break;
1331
+ }
1332
+ }
1333
+ } catch (Exception exp) {
1334
+ Logger.getLogger(SunflowGUI.class.getName()).log(Level.SEVERE, null, exp);
1335
+ }
1336
+
1337
+ return false;
1338
+ }
1339
+
1340
+ @Override
1341
+ public boolean canImport(JComponent c, DataFlavor[] flavors) {
1342
+ // Just a quick check to see if a file can be accepted at this time
1343
+ // Are there any files around?
1344
+ for (int i = 0; i < flavors.length; i++) {
1345
+ if (flavors[i].isFlavorJavaFileListType()) {
1346
+ return true;
1347
+ }
1348
+ }
1349
+
1350
+ // guess not
1351
+ return false;
1352
+ }
1353
+ }
1354
+ }