joonsrenderer 1.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +53 -0
- data/.mvn/extensions.xml +8 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +6 -0
- data/LICENSE +674 -0
- data/README.md +2 -0
- data/Rakefile +43 -0
- data/docs/.gitignore +6 -0
- data/docs/_config.yml +20 -0
- data/docs/_includes/footer.html +38 -0
- data/docs/_includes/head.html +15 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/icon-github.html +1 -0
- data/docs/_includes/icon-github.svg +1 -0
- data/docs/_includes/icon-twitter.html +1 -0
- data/docs/_includes/icon-twitter.svg +1 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_posts/2017-01-08-animated_ray_tracing.md +72 -0
- data/docs/_posts/2017-01-08-welcome.md +78 -0
- data/docs/_sass/_base.scss +206 -0
- data/docs/_sass/_layout.scss +242 -0
- data/docs/_sass/_syntax-highlighting.scss +71 -0
- data/docs/about.md +12 -0
- data/docs/assets/Animation.ogv +0 -0
- data/docs/assets/Animation.png +0 -0
- data/docs/assets/basic.png +0 -0
- data/docs/assets/basic_traced.png +0 -0
- data/docs/css/main.scss +38 -0
- data/docs/favicon.ico +0 -0
- data/docs/feed.xml +30 -0
- data/docs/index.html +38 -0
- data/joonsrenderer.gemspec +23 -0
- data/lib/joonsrenderer.rb +12 -0
- data/lib/joonsrenderer/version.rb +3 -0
- data/pom.rb +75 -0
- data/pom.xml +163 -0
- data/src/main/java/SunflowGUI.java +1354 -0
- data/src/main/java/joons/JRFiller.java +79 -0
- data/src/main/java/joons/JRImagePanel.java +141 -0
- data/src/main/java/joons/JRRecorder.java +183 -0
- data/src/main/java/joons/JRStatics.java +199 -0
- data/src/main/java/joons/JoonsRenderer.java +837 -0
- data/src/main/java/org/sunflow/AsciiFileSunflowAPI.java +98 -0
- data/src/main/java/org/sunflow/Benchmark.java +313 -0
- data/src/main/java/org/sunflow/BinaryFileSunflowAPI.java +228 -0
- data/src/main/java/org/sunflow/FileSunflowAPI.java +354 -0
- data/src/main/java/org/sunflow/PluginRegistry.java +322 -0
- data/src/main/java/org/sunflow/RealtimeBenchmark.java +125 -0
- data/src/main/java/org/sunflow/RenderObjectMap.java +344 -0
- data/src/main/java/org/sunflow/SunflowAPI.java +762 -0
- data/src/main/java/org/sunflow/SunflowAPIInterface.java +277 -0
- data/src/main/java/org/sunflow/core/AccelerationStructure.java +20 -0
- data/src/main/java/org/sunflow/core/AccelerationStructureFactory.java +36 -0
- data/src/main/java/org/sunflow/core/BucketOrder.java +21 -0
- data/src/main/java/org/sunflow/core/Camera.java +125 -0
- data/src/main/java/org/sunflow/core/CameraLens.java +29 -0
- data/src/main/java/org/sunflow/core/CausticPhotonMapInterface.java +15 -0
- data/src/main/java/org/sunflow/core/Display.java +78 -0
- data/src/main/java/org/sunflow/core/Filter.java +27 -0
- data/src/main/java/org/sunflow/core/GIEngine.java +42 -0
- data/src/main/java/org/sunflow/core/Geometry.java +157 -0
- data/src/main/java/org/sunflow/core/GlobalPhotonMapInterface.java +21 -0
- data/src/main/java/org/sunflow/core/ImageSampler.java +26 -0
- data/src/main/java/org/sunflow/core/Instance.java +224 -0
- data/src/main/java/org/sunflow/core/InstanceList.java +83 -0
- data/src/main/java/org/sunflow/core/IntersectionState.java +120 -0
- data/src/main/java/org/sunflow/core/LightSample.java +104 -0
- data/src/main/java/org/sunflow/core/LightServer.java +382 -0
- data/src/main/java/org/sunflow/core/LightSource.java +67 -0
- data/src/main/java/org/sunflow/core/Modifier.java +16 -0
- data/src/main/java/org/sunflow/core/Options.java +20 -0
- data/src/main/java/org/sunflow/core/ParameterList.java +758 -0
- data/src/main/java/org/sunflow/core/PhotonStore.java +62 -0
- data/src/main/java/org/sunflow/core/PrimitiveList.java +70 -0
- data/src/main/java/org/sunflow/core/Ray.java +219 -0
- data/src/main/java/org/sunflow/core/RenderObject.java +25 -0
- data/src/main/java/org/sunflow/core/Scene.java +377 -0
- data/src/main/java/org/sunflow/core/SceneParser.java +58 -0
- data/src/main/java/org/sunflow/core/Shader.java +30 -0
- data/src/main/java/org/sunflow/core/ShadingCache.java +84 -0
- data/src/main/java/org/sunflow/core/ShadingState.java +939 -0
- data/src/main/java/org/sunflow/core/Statistics.java +85 -0
- data/src/main/java/org/sunflow/core/Tesselatable.java +36 -0
- data/src/main/java/org/sunflow/core/Texture.java +128 -0
- data/src/main/java/org/sunflow/core/TextureCache.java +48 -0
- data/src/main/java/org/sunflow/core/accel/BoundingIntervalHierarchy.java +652 -0
- data/src/main/java/org/sunflow/core/accel/KDTree.java +833 -0
- data/src/main/java/org/sunflow/core/accel/NullAccelerator.java +30 -0
- data/src/main/java/org/sunflow/core/accel/UniformGrid.java +329 -0
- data/src/main/java/org/sunflow/core/bucket/BucketOrderFactory.java +26 -0
- data/src/main/java/org/sunflow/core/bucket/ColumnBucketOrder.java +21 -0
- data/src/main/java/org/sunflow/core/bucket/DiagonalBucketOrder.java +28 -0
- data/src/main/java/org/sunflow/core/bucket/HilbertBucketOrder.java +65 -0
- data/src/main/java/org/sunflow/core/bucket/InvertedBucketOrder.java +28 -0
- data/src/main/java/org/sunflow/core/bucket/RandomBucketOrder.java +49 -0
- data/src/main/java/org/sunflow/core/bucket/RowBucketOrder.java +21 -0
- data/src/main/java/org/sunflow/core/bucket/SpiralBucketOrder.java +43 -0
- data/src/main/java/org/sunflow/core/camera/FisheyeLens.java +25 -0
- data/src/main/java/org/sunflow/core/camera/PinholeLens.java +43 -0
- data/src/main/java/org/sunflow/core/camera/SphericalLens.java +22 -0
- data/src/main/java/org/sunflow/core/camera/ThinLens.java +107 -0
- data/src/main/java/org/sunflow/core/display/FastDisplay.java +119 -0
- data/src/main/java/org/sunflow/core/display/FileDisplay.java +83 -0
- data/src/main/java/org/sunflow/core/display/FrameDisplay.java +97 -0
- data/src/main/java/org/sunflow/core/display/ImgPipeDisplay.java +109 -0
- data/src/main/java/org/sunflow/core/filter/BlackmanHarrisFilter.java +28 -0
- data/src/main/java/org/sunflow/core/filter/BoxFilter.java +16 -0
- data/src/main/java/org/sunflow/core/filter/CatmullRomFilter.java +29 -0
- data/src/main/java/org/sunflow/core/filter/CubicBSpline.java +32 -0
- data/src/main/java/org/sunflow/core/filter/GaussianFilter.java +24 -0
- data/src/main/java/org/sunflow/core/filter/LanczosFilter.java +30 -0
- data/src/main/java/org/sunflow/core/filter/MitchellFilter.java +28 -0
- data/src/main/java/org/sunflow/core/filter/SincFilter.java +25 -0
- data/src/main/java/org/sunflow/core/filter/TriangleFilter.java +16 -0
- data/src/main/java/org/sunflow/core/gi/AmbientOcclusionGIEngine.java +57 -0
- data/src/main/java/org/sunflow/core/gi/FakeGIEngine.java +48 -0
- data/src/main/java/org/sunflow/core/gi/InstantGI.java +194 -0
- data/src/main/java/org/sunflow/core/gi/IrradianceCacheGIEngine.java +268 -0
- data/src/main/java/org/sunflow/core/gi/PathTracingGIEngine.java +65 -0
- data/src/main/java/org/sunflow/core/light/DirectionalSpotlight.java +103 -0
- data/src/main/java/org/sunflow/core/light/ImageBasedLight.java +303 -0
- data/src/main/java/org/sunflow/core/light/PointLight.java +72 -0
- data/src/main/java/org/sunflow/core/light/SphereLight.java +166 -0
- data/src/main/java/org/sunflow/core/light/SunSkyLight.java +362 -0
- data/src/main/java/org/sunflow/core/light/TriangleMeshLight.java +296 -0
- data/src/main/java/org/sunflow/core/modifiers/BumpMappingModifier.java +37 -0
- data/src/main/java/org/sunflow/core/modifiers/NormalMapModifier.java +34 -0
- data/src/main/java/org/sunflow/core/modifiers/PerlinModifier.java +80 -0
- data/src/main/java/org/sunflow/core/parser/Keyword.java +39 -0
- data/src/main/java/org/sunflow/core/parser/RA2Parser.java +107 -0
- data/src/main/java/org/sunflow/core/parser/RA3Parser.java +68 -0
- data/src/main/java/org/sunflow/core/parser/SCAbstractParser.java +299 -0
- data/src/main/java/org/sunflow/core/parser/SCAsciiParser.java +251 -0
- data/src/main/java/org/sunflow/core/parser/SCBinaryParser.java +156 -0
- data/src/main/java/org/sunflow/core/parser/SCParser.java +1403 -0
- data/src/main/java/org/sunflow/core/parser/ShaveRibParser.java +174 -0
- data/src/main/java/org/sunflow/core/parser/TriParser.java +79 -0
- data/src/main/java/org/sunflow/core/photonmap/CausticPhotonMap.java +429 -0
- data/src/main/java/org/sunflow/core/photonmap/GlobalPhotonMap.java +530 -0
- data/src/main/java/org/sunflow/core/photonmap/GridPhotonMap.java +308 -0
- data/src/main/java/org/sunflow/core/primitive/Background.java +55 -0
- data/src/main/java/org/sunflow/core/primitive/BanchoffSurface.java +100 -0
- data/src/main/java/org/sunflow/core/primitive/Box.java +210 -0
- data/src/main/java/org/sunflow/core/primitive/CornellBox.java +476 -0
- data/src/main/java/org/sunflow/core/primitive/CubeGrid.java +318 -0
- data/src/main/java/org/sunflow/core/primitive/Cylinder.java +104 -0
- data/src/main/java/org/sunflow/core/primitive/Hair.java +275 -0
- data/src/main/java/org/sunflow/core/primitive/JuliaFractal.java +266 -0
- data/src/main/java/org/sunflow/core/primitive/ParticleSurface.java +114 -0
- data/src/main/java/org/sunflow/core/primitive/Plane.java +163 -0
- data/src/main/java/org/sunflow/core/primitive/QuadMesh.java +413 -0
- data/src/main/java/org/sunflow/core/primitive/Sphere.java +101 -0
- data/src/main/java/org/sunflow/core/primitive/SphereFlake.java +234 -0
- data/src/main/java/org/sunflow/core/primitive/Torus.java +145 -0
- data/src/main/java/org/sunflow/core/primitive/TriangleMesh.java +849 -0
- data/src/main/java/org/sunflow/core/renderer/BucketRenderer.java +491 -0
- data/src/main/java/org/sunflow/core/renderer/MultipassRenderer.java +237 -0
- data/src/main/java/org/sunflow/core/renderer/ProgressiveRenderer.java +171 -0
- data/src/main/java/org/sunflow/core/renderer/SimpleRenderer.java +106 -0
- data/src/main/java/org/sunflow/core/shader/AmbientOcclusionShader.java +53 -0
- data/src/main/java/org/sunflow/core/shader/AnisotropicWardShader.java +216 -0
- data/src/main/java/org/sunflow/core/shader/ConstantShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/DiffuseShader.java +65 -0
- data/src/main/java/org/sunflow/core/shader/GlassShader.java +147 -0
- data/src/main/java/org/sunflow/core/shader/IDShader.java +27 -0
- data/src/main/java/org/sunflow/core/shader/MirrorShader.java +68 -0
- data/src/main/java/org/sunflow/core/shader/NormalShader.java +32 -0
- data/src/main/java/org/sunflow/core/shader/PhongShader.java +89 -0
- data/src/main/java/org/sunflow/core/shader/PrimIDShader.java +30 -0
- data/src/main/java/org/sunflow/core/shader/QuickGrayShader.java +63 -0
- data/src/main/java/org/sunflow/core/shader/ShinyDiffuseShader.java +98 -0
- data/src/main/java/org/sunflow/core/shader/SimpleShader.java +24 -0
- data/src/main/java/org/sunflow/core/shader/TexturedAmbientOcclusionShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedDiffuseShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedPhongShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedShinyDiffuseShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/TexturedWardShader.java +31 -0
- data/src/main/java/org/sunflow/core/shader/UVShader.java +27 -0
- data/src/main/java/org/sunflow/core/shader/UberShader.java +149 -0
- data/src/main/java/org/sunflow/core/shader/ViewCausticsShader.java +33 -0
- data/src/main/java/org/sunflow/core/shader/ViewGlobalPhotonsShader.java +25 -0
- data/src/main/java/org/sunflow/core/shader/ViewIrradianceShader.java +25 -0
- data/src/main/java/org/sunflow/core/shader/WireframeShader.java +83 -0
- data/src/main/java/org/sunflow/core/tesselatable/BezierMesh.java +254 -0
- data/src/main/java/org/sunflow/core/tesselatable/FileMesh.java +251 -0
- data/src/main/java/org/sunflow/core/tesselatable/Gumbo.java +1147 -0
- data/src/main/java/org/sunflow/core/tesselatable/Teapot.java +237 -0
- data/src/main/java/org/sunflow/image/Bitmap.java +15 -0
- data/src/main/java/org/sunflow/image/BitmapReader.java +39 -0
- data/src/main/java/org/sunflow/image/BitmapWriter.java +79 -0
- data/src/main/java/org/sunflow/image/BlackbodySpectrum.java +16 -0
- data/src/main/java/org/sunflow/image/ChromaticitySpectrum.java +55 -0
- data/src/main/java/org/sunflow/image/Color.java +374 -0
- data/src/main/java/org/sunflow/image/ColorEncoder.java +94 -0
- data/src/main/java/org/sunflow/image/ColorFactory.java +122 -0
- data/src/main/java/org/sunflow/image/ConstantSpectralCurve.java +21 -0
- data/src/main/java/org/sunflow/image/IrregularSpectralCurve.java +57 -0
- data/src/main/java/org/sunflow/image/RGBSpace.java +207 -0
- data/src/main/java/org/sunflow/image/RegularSpectralCurve.java +30 -0
- data/src/main/java/org/sunflow/image/SpectralCurve.java +118 -0
- data/src/main/java/org/sunflow/image/XYZColor.java +50 -0
- data/src/main/java/org/sunflow/image/formats/BitmapBlack.java +27 -0
- data/src/main/java/org/sunflow/image/formats/BitmapG8.java +36 -0
- data/src/main/java/org/sunflow/image/formats/BitmapGA8.java +30 -0
- data/src/main/java/org/sunflow/image/formats/BitmapRGB8.java +40 -0
- data/src/main/java/org/sunflow/image/formats/BitmapRGBA8.java +40 -0
- data/src/main/java/org/sunflow/image/formats/BitmapRGBE.java +60 -0
- data/src/main/java/org/sunflow/image/formats/BitmapXYZ.java +38 -0
- data/src/main/java/org/sunflow/image/formats/GenericBitmap.java +73 -0
- data/src/main/java/org/sunflow/image/readers/BMPBitmapReader.java +39 -0
- data/src/main/java/org/sunflow/image/readers/HDRBitmapReader.java +155 -0
- data/src/main/java/org/sunflow/image/readers/IGIBitmapReader.java +104 -0
- data/src/main/java/org/sunflow/image/readers/JPGBitmapReader.java +39 -0
- data/src/main/java/org/sunflow/image/readers/PNGBitmapReader.java +40 -0
- data/src/main/java/org/sunflow/image/readers/TGABitmapReader.java +141 -0
- data/src/main/java/org/sunflow/image/writers/EXRBitmapWriter.java +395 -0
- data/src/main/java/org/sunflow/image/writers/HDRBitmapWriter.java +54 -0
- data/src/main/java/org/sunflow/image/writers/IGIBitmapWriter.java +75 -0
- data/src/main/java/org/sunflow/image/writers/PNGBitmapWriter.java +39 -0
- data/src/main/java/org/sunflow/image/writers/TGABitmapWriter.java +63 -0
- data/src/main/java/org/sunflow/math/BoundingBox.java +340 -0
- data/src/main/java/org/sunflow/math/MathUtils.java +159 -0
- data/src/main/java/org/sunflow/math/Matrix4.java +573 -0
- data/src/main/java/org/sunflow/math/MovingMatrix4.java +119 -0
- data/src/main/java/org/sunflow/math/OrthoNormalBasis.java +110 -0
- data/src/main/java/org/sunflow/math/PerlinScalar.java +331 -0
- data/src/main/java/org/sunflow/math/PerlinVector.java +132 -0
- data/src/main/java/org/sunflow/math/Point2.java +36 -0
- data/src/main/java/org/sunflow/math/Point3.java +133 -0
- data/src/main/java/org/sunflow/math/QMC.java +209 -0
- data/src/main/java/org/sunflow/math/Solvers.java +142 -0
- data/src/main/java/org/sunflow/math/Vector3.java +197 -0
- data/src/main/java/org/sunflow/system/BenchmarkFramework.java +73 -0
- data/src/main/java/org/sunflow/system/BenchmarkTest.java +17 -0
- data/src/main/java/org/sunflow/system/ByteUtil.java +119 -0
- data/src/main/java/org/sunflow/system/FileUtils.java +27 -0
- data/src/main/java/org/sunflow/system/ImagePanel.java +282 -0
- data/src/main/java/org/sunflow/system/Memory.java +18 -0
- data/src/main/java/org/sunflow/system/Parser.java +162 -0
- data/src/main/java/org/sunflow/system/Plugins.java +142 -0
- data/src/main/java/org/sunflow/system/RenderGlobalsPanel.java +209 -0
- data/src/main/java/org/sunflow/system/SearchPath.java +67 -0
- data/src/main/java/org/sunflow/system/Timer.java +53 -0
- data/src/main/java/org/sunflow/system/UI.java +112 -0
- data/src/main/java/org/sunflow/system/UserInterface.java +46 -0
- data/src/main/java/org/sunflow/system/ui/ConsoleInterface.java +48 -0
- data/src/main/java/org/sunflow/system/ui/SilentInterface.java +28 -0
- data/src/main/java/org/sunflow/util/FastHashMap.java +220 -0
- data/src/main/java/org/sunflow/util/FloatArray.java +77 -0
- data/src/main/java/org/sunflow/util/IntArray.java +77 -0
- data/src/test/java/a_maintest.java +129 -0
- metadata +300 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package org.sunflow.core.parser;
|
|
2
|
+
/**
|
|
3
|
+
* Public enums should live in their own file, we could do more here I am sure
|
|
4
|
+
* including things like enumset getting String value etc.
|
|
5
|
+
* @author Martin Prout
|
|
6
|
+
*/
|
|
7
|
+
public enum Keyword {
|
|
8
|
+
RESET,
|
|
9
|
+
PARAMETER,
|
|
10
|
+
GEOMETRY,
|
|
11
|
+
INSTANCE,
|
|
12
|
+
SHADER,
|
|
13
|
+
MODIFIER,
|
|
14
|
+
LIGHT,
|
|
15
|
+
CAMERA,
|
|
16
|
+
OPTIONS,
|
|
17
|
+
INCLUDE,
|
|
18
|
+
REMOVE,
|
|
19
|
+
FRAME,
|
|
20
|
+
PLUGIN,
|
|
21
|
+
SEARCHPATH,
|
|
22
|
+
STRING,
|
|
23
|
+
BOOL,
|
|
24
|
+
INT,
|
|
25
|
+
FLOAT,
|
|
26
|
+
COLOR,
|
|
27
|
+
POINT,
|
|
28
|
+
VECTOR,
|
|
29
|
+
TEXCOORD,
|
|
30
|
+
MATRIX,
|
|
31
|
+
STRING_ARRAY,
|
|
32
|
+
INT_ARRAY,
|
|
33
|
+
FLOAT_ARRAY,
|
|
34
|
+
POINT_ARRAY,
|
|
35
|
+
VECTOR_ARRAY,
|
|
36
|
+
TEXCOORD_ARRAY,
|
|
37
|
+
MATRIX_ARRAY,
|
|
38
|
+
END_OF_FILE,
|
|
39
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
package org.sunflow.core.parser;
|
|
2
|
+
|
|
3
|
+
import java.io.File;
|
|
4
|
+
import java.io.FileInputStream;
|
|
5
|
+
import java.io.FileNotFoundException;
|
|
6
|
+
import java.io.IOException;
|
|
7
|
+
import java.nio.ByteOrder;
|
|
8
|
+
import java.nio.FloatBuffer;
|
|
9
|
+
import java.nio.MappedByteBuffer;
|
|
10
|
+
import java.nio.channels.FileChannel;
|
|
11
|
+
import java.util.logging.Level;
|
|
12
|
+
import java.util.logging.Logger;
|
|
13
|
+
|
|
14
|
+
import org.sunflow.SunflowAPI;
|
|
15
|
+
import org.sunflow.SunflowAPIInterface;
|
|
16
|
+
import org.sunflow.core.SceneParser;
|
|
17
|
+
import org.sunflow.math.Point3;
|
|
18
|
+
import org.sunflow.math.Vector3;
|
|
19
|
+
import org.sunflow.system.Parser;
|
|
20
|
+
import org.sunflow.system.UI;
|
|
21
|
+
import org.sunflow.system.UI.Module;
|
|
22
|
+
|
|
23
|
+
public class RA2Parser implements SceneParser {
|
|
24
|
+
|
|
25
|
+
@Override
|
|
26
|
+
public boolean parse(String filename, SunflowAPIInterface api) {
|
|
27
|
+
try {
|
|
28
|
+
UI.printInfo(Module.USER, "RA2 - Reading geometry: \"%s\" ...", filename);
|
|
29
|
+
File file = new File(filename);
|
|
30
|
+
float[] data;
|
|
31
|
+
try (FileInputStream stream = new FileInputStream(filename)) {
|
|
32
|
+
MappedByteBuffer map = stream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length());
|
|
33
|
+
map.order(ByteOrder.LITTLE_ENDIAN);
|
|
34
|
+
FloatBuffer buffer = map.asFloatBuffer();
|
|
35
|
+
data = new float[buffer.capacity()];
|
|
36
|
+
for (int i = 0; i < data.length; i++) {
|
|
37
|
+
data[i] = buffer.get(i);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
api.parameter("points", "point", "vertex", data);
|
|
41
|
+
int[] triangles = new int[3 * (data.length / 9)];
|
|
42
|
+
for (int i = 0; i < triangles.length; i++) {
|
|
43
|
+
triangles[i] = i;
|
|
44
|
+
}
|
|
45
|
+
// create geo
|
|
46
|
+
api.parameter("triangles", triangles);
|
|
47
|
+
api.geometry(filename, "triangle_mesh");
|
|
48
|
+
// create shader
|
|
49
|
+
api.shader(filename + ".shader", "simple");
|
|
50
|
+
// create instance
|
|
51
|
+
api.parameter("shaders", filename + ".shader");
|
|
52
|
+
api.instance(filename + ".instance", filename);
|
|
53
|
+
} catch (FileNotFoundException e) {
|
|
54
|
+
Logger.getLogger(RA2Parser.class.getName()).log(Level.SEVERE, null, e);
|
|
55
|
+
return false;
|
|
56
|
+
} catch (IOException e) {
|
|
57
|
+
Logger.getLogger(RA2Parser.class.getName()).log(Level.SEVERE, null, e);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
filename = filename.replace(".ra2", ".txt");
|
|
62
|
+
UI.printInfo(Module.USER, "RA2 - Reading camera : \"%s\" ...", filename);
|
|
63
|
+
Parser p = new Parser(filename);
|
|
64
|
+
Point3 eye = new Point3();
|
|
65
|
+
eye.x = p.getNextFloat();
|
|
66
|
+
eye.y = p.getNextFloat();
|
|
67
|
+
eye.z = p.getNextFloat();
|
|
68
|
+
Point3 to = new Point3();
|
|
69
|
+
to.x = p.getNextFloat();
|
|
70
|
+
to.y = p.getNextFloat();
|
|
71
|
+
to.z = p.getNextFloat();
|
|
72
|
+
Vector3 up = new Vector3();
|
|
73
|
+
switch (p.getNextInt()) {
|
|
74
|
+
case 0:
|
|
75
|
+
up.set(1, 0, 0);
|
|
76
|
+
break;
|
|
77
|
+
case 1:
|
|
78
|
+
up.set(0, 1, 0);
|
|
79
|
+
break;
|
|
80
|
+
case 2:
|
|
81
|
+
up.set(0, 0, 1);
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
UI.printWarning(Module.USER, "RA2 - Invalid up vector specification - using Z axis");
|
|
85
|
+
up.set(0, 0, 1);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
api.parameter("eye", eye);
|
|
89
|
+
api.parameter("target", to);
|
|
90
|
+
api.parameter("up", up);
|
|
91
|
+
String cameraName = filename + ".camera";
|
|
92
|
+
api.parameter(FOV, 80f);
|
|
93
|
+
api.camera(cameraName, "pinhole");
|
|
94
|
+
api.parameter("camera", cameraName);
|
|
95
|
+
api.parameter("resolutionX", 1024);
|
|
96
|
+
api.parameter("resolutionY", 1024);
|
|
97
|
+
api.options(SunflowAPI.DEFAULT_OPTIONS);
|
|
98
|
+
p.close();
|
|
99
|
+
} catch (FileNotFoundException e) {
|
|
100
|
+
UI.printWarning(Module.USER, "RA2 - Camera file not found");
|
|
101
|
+
} catch (IOException e) {
|
|
102
|
+
Logger.getLogger(RA2Parser.class.getName()).log(Level.SEVERE, null, e);
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
package org.sunflow.core.parser;
|
|
2
|
+
|
|
3
|
+
import java.io.File;
|
|
4
|
+
import java.io.FileInputStream;
|
|
5
|
+
import java.io.FileNotFoundException;
|
|
6
|
+
import java.io.IOException;
|
|
7
|
+
import java.nio.ByteOrder;
|
|
8
|
+
import java.nio.FloatBuffer;
|
|
9
|
+
import java.nio.IntBuffer;
|
|
10
|
+
import java.nio.MappedByteBuffer;
|
|
11
|
+
import java.nio.channels.FileChannel;
|
|
12
|
+
import java.util.logging.Level;
|
|
13
|
+
import java.util.logging.Logger;
|
|
14
|
+
|
|
15
|
+
import org.sunflow.SunflowAPIInterface;
|
|
16
|
+
import org.sunflow.core.SceneParser;
|
|
17
|
+
import org.sunflow.system.UI;
|
|
18
|
+
import org.sunflow.system.UI.Module;
|
|
19
|
+
|
|
20
|
+
public class RA3Parser implements SceneParser {
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
public boolean parse(String filename, SunflowAPIInterface api) {
|
|
24
|
+
try {
|
|
25
|
+
UI.printInfo(Module.USER, "RA3 - Reading geometry: \"%s\" ...", filename);
|
|
26
|
+
File file = new File(filename);
|
|
27
|
+
float[] verts;
|
|
28
|
+
int[] tris;
|
|
29
|
+
try (FileInputStream stream = new FileInputStream(filename)) {
|
|
30
|
+
MappedByteBuffer map = stream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length());
|
|
31
|
+
map.order(ByteOrder.LITTLE_ENDIAN);
|
|
32
|
+
IntBuffer ints = map.asIntBuffer();
|
|
33
|
+
FloatBuffer buffer = map.asFloatBuffer();
|
|
34
|
+
int numVerts = ints.get(0);
|
|
35
|
+
int numTris = ints.get(1);
|
|
36
|
+
UI.printInfo(Module.USER, "RA3 - * Reading %d vertices ...", numVerts);
|
|
37
|
+
verts = new float[3 * numVerts];
|
|
38
|
+
for (int i = 0; i < verts.length; i++) {
|
|
39
|
+
verts[i] = buffer.get(2 + i);
|
|
40
|
+
} UI.printInfo(Module.USER, "RA3 - * Reading %d triangles ...", numTris);
|
|
41
|
+
tris = new int[3 * numTris];
|
|
42
|
+
for (int i = 0; i < tris.length; i++) {
|
|
43
|
+
tris[i] = ints.get(2 + verts.length + i);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
UI.printInfo(Module.USER, "RA3 - * Creating mesh ...");
|
|
47
|
+
|
|
48
|
+
// create geometry
|
|
49
|
+
api.parameter("triangles", tris);
|
|
50
|
+
api.parameter("points", "point", "vertex", verts);
|
|
51
|
+
api.geometry(filename, "triangle_mesh");
|
|
52
|
+
|
|
53
|
+
// create default shader (this will simply error out if the shader
|
|
54
|
+
// already exists)
|
|
55
|
+
api.shader("ra3shader", "simple");
|
|
56
|
+
// create instance
|
|
57
|
+
api.parameter("shaders", "ra3shader");
|
|
58
|
+
api.instance(filename + ".instance", filename);
|
|
59
|
+
} catch (FileNotFoundException e) {
|
|
60
|
+
Logger.getLogger(RA3Parser.class.getName()).log(Level.SEVERE, null, e);
|
|
61
|
+
return false;
|
|
62
|
+
} catch (IOException e) {
|
|
63
|
+
Logger.getLogger(RA3Parser.class.getName()).log(Level.SEVERE, null, e);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
package org.sunflow.core.parser;
|
|
2
|
+
|
|
3
|
+
import java.io.EOFException;
|
|
4
|
+
import java.io.IOException;
|
|
5
|
+
import java.util.logging.Level;
|
|
6
|
+
import java.util.logging.Logger;
|
|
7
|
+
|
|
8
|
+
import org.sunflow.SunflowAPIInterface;
|
|
9
|
+
import org.sunflow.core.SceneParser;
|
|
10
|
+
import org.sunflow.core.ParameterList.InterpolationType;
|
|
11
|
+
import org.sunflow.image.ColorFactory;
|
|
12
|
+
import org.sunflow.math.Matrix4;
|
|
13
|
+
import org.sunflow.math.Point2;
|
|
14
|
+
import org.sunflow.math.Point3;
|
|
15
|
+
import org.sunflow.math.Vector3;
|
|
16
|
+
import org.sunflow.system.Timer;
|
|
17
|
+
import org.sunflow.system.UI;
|
|
18
|
+
import org.sunflow.system.UI.Module;
|
|
19
|
+
|
|
20
|
+
public abstract class SCAbstractParser implements SceneParser {
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public boolean parse(String filename, SunflowAPIInterface api) {
|
|
26
|
+
Timer timer = new Timer();
|
|
27
|
+
timer.start();
|
|
28
|
+
UI.printInfo(Module.API, "Parsing \"%s\" ...", filename);
|
|
29
|
+
try {
|
|
30
|
+
openParser(filename);
|
|
31
|
+
parseloop:
|
|
32
|
+
while (true) {
|
|
33
|
+
Keyword k = parseKeyword();
|
|
34
|
+
switch (k) {
|
|
35
|
+
case RESET:
|
|
36
|
+
api.reset();
|
|
37
|
+
break;
|
|
38
|
+
case PARAMETER:
|
|
39
|
+
parseParameter(api);
|
|
40
|
+
break;
|
|
41
|
+
case GEOMETRY: {
|
|
42
|
+
String name = parseString();
|
|
43
|
+
String type = parseString();
|
|
44
|
+
api.geometry(name, type);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case INSTANCE: {
|
|
48
|
+
String name = parseString();
|
|
49
|
+
String geoname = parseString();
|
|
50
|
+
api.instance(name, geoname);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case SHADER: {
|
|
54
|
+
String name = parseString();
|
|
55
|
+
String type = parseString();
|
|
56
|
+
api.shader(name, type);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case MODIFIER: {
|
|
60
|
+
String name = parseString();
|
|
61
|
+
String type = parseString();
|
|
62
|
+
api.modifier(name, type);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case LIGHT: {
|
|
66
|
+
String name = parseString();
|
|
67
|
+
String type = parseString();
|
|
68
|
+
api.light(name, type);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case CAMERA: {
|
|
72
|
+
String name = parseString();
|
|
73
|
+
String type = parseString();
|
|
74
|
+
api.camera(name, type);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case OPTIONS: {
|
|
78
|
+
api.options(parseString());
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case INCLUDE: {
|
|
82
|
+
String file = parseString();
|
|
83
|
+
UI.printInfo(Module.API, "Including: \"%s\" ...", file);
|
|
84
|
+
api.include(file);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
case REMOVE: {
|
|
88
|
+
api.remove(parseString());
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case FRAME: {
|
|
92
|
+
api.currentFrame(parseInt());
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case PLUGIN: {
|
|
96
|
+
String type = parseString();
|
|
97
|
+
String name = parseString();
|
|
98
|
+
String code = parseVerbatimString();
|
|
99
|
+
api.plugin(type, name, code);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case SEARCHPATH: {
|
|
103
|
+
String type = parseString();
|
|
104
|
+
api.searchpath(type, parseString());
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case END_OF_FILE: {
|
|
108
|
+
// clean exit
|
|
109
|
+
break parseloop;
|
|
110
|
+
}
|
|
111
|
+
default: {
|
|
112
|
+
UI.printWarning(Module.API, "Unexpected token %s", k);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
closeParser();
|
|
118
|
+
} catch (IOException e) {
|
|
119
|
+
// catch all exceptions
|
|
120
|
+
Logger.getLogger(SCAbstractParser.class.getName()).log(Level.SEVERE, null, e);
|
|
121
|
+
UI.printError(Module.API, "%s", e.getMessage());
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
timer.end();
|
|
125
|
+
UI.printInfo(Module.API, "Done parsing (took %s)", timer.toString());
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private void parseParameter(SunflowAPIInterface api) throws IOException {
|
|
130
|
+
String name = parseString();
|
|
131
|
+
Keyword k = parseKeyword();
|
|
132
|
+
switch (k) {
|
|
133
|
+
case STRING: {
|
|
134
|
+
api.parameter(name, parseString());
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case BOOL: {
|
|
138
|
+
api.parameter(name, parseBoolean());
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
case INT: {
|
|
142
|
+
api.parameter(name, parseInt());
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
case FLOAT: {
|
|
146
|
+
api.parameter(name, parseFloat());
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case COLOR: {
|
|
150
|
+
String colorspace = parseString();
|
|
151
|
+
int req = ColorFactory.getRequiredDataValues(colorspace);
|
|
152
|
+
if (req == -2) {
|
|
153
|
+
api.parameter(name, colorspace); // call just to generate
|
|
154
|
+
} // an error
|
|
155
|
+
else {
|
|
156
|
+
api.parameter(name, colorspace, parseFloatArray(req == -1 ? parseInt() : req));
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case POINT: {
|
|
161
|
+
api.parameter(name, parsePoint());
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
case VECTOR: {
|
|
165
|
+
api.parameter(name, parseVector());
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
case TEXCOORD: {
|
|
169
|
+
api.parameter(name, parseTexcoord());
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
case MATRIX: {
|
|
173
|
+
api.parameter(name, parseMatrix());
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case STRING_ARRAY: {
|
|
177
|
+
int n = parseInt();
|
|
178
|
+
api.parameter(name, parseStringArray(n));
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
case INT_ARRAY: {
|
|
182
|
+
int n = parseInt();
|
|
183
|
+
api.parameter(name, parseIntArray(n));
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
case FLOAT_ARRAY: {
|
|
187
|
+
String interp = parseInterpolationType().toString();
|
|
188
|
+
int n = parseInt();
|
|
189
|
+
api.parameter(name, "float", interp, parseFloatArray(n));
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case POINT_ARRAY: {
|
|
193
|
+
String interp = parseInterpolationType().toString();
|
|
194
|
+
int n = parseInt();
|
|
195
|
+
api.parameter(name, "point", interp, parseFloatArray(3 * n));
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
case VECTOR_ARRAY: {
|
|
199
|
+
String interp = parseInterpolationType().toString();
|
|
200
|
+
int n = parseInt();
|
|
201
|
+
api.parameter(name, "vector", interp, parseFloatArray(3 * n));
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case TEXCOORD_ARRAY: {
|
|
205
|
+
String interp = parseInterpolationType().toString();
|
|
206
|
+
int n = parseInt();
|
|
207
|
+
api.parameter(name, "texcoord", interp, parseFloatArray(2 * n));
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
case MATRIX_ARRAY: {
|
|
211
|
+
String interp = parseInterpolationType().toString();
|
|
212
|
+
int n = parseInt();
|
|
213
|
+
api.parameter(name, "matrix", interp, parseMatrixArray(n));
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
case END_OF_FILE:
|
|
217
|
+
throw new EOFException();
|
|
218
|
+
default: {
|
|
219
|
+
UI.printWarning(Module.API, "Unexpected keyword: %s", k);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private String[] parseStringArray(int size) throws IOException {
|
|
226
|
+
String[] data = new String[size];
|
|
227
|
+
for (int i = 0; i < size; i++) {
|
|
228
|
+
data[i] = parseString();
|
|
229
|
+
}
|
|
230
|
+
return data;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private int[] parseIntArray(int size) throws IOException {
|
|
234
|
+
int[] data = new int[size];
|
|
235
|
+
for (int i = 0; i < size; i++) {
|
|
236
|
+
data[i] = parseInt();
|
|
237
|
+
}
|
|
238
|
+
return data;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
protected float[] parseFloatArray(int size) throws IOException {
|
|
242
|
+
float[] data = new float[size];
|
|
243
|
+
for (int i = 0; i < size; i++) {
|
|
244
|
+
data[i] = parseFloat();
|
|
245
|
+
}
|
|
246
|
+
return data;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private float[] parseMatrixArray(int size) throws IOException {
|
|
250
|
+
float[] data = new float[16 * size];
|
|
251
|
+
for (int i = 0, offset = 0; i < size; i++, offset += 16) {
|
|
252
|
+
// copy the next matrix into a linear array - in row major order
|
|
253
|
+
float[] rowdata = parseMatrix().asRowMajor();
|
|
254
|
+
System.arraycopy(rowdata, 0, data, offset, 16);
|
|
255
|
+
}
|
|
256
|
+
return data;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
private Point3 parsePoint() throws IOException {
|
|
260
|
+
float x = parseFloat();
|
|
261
|
+
float y = parseFloat();
|
|
262
|
+
float z = parseFloat();
|
|
263
|
+
return new Point3(x, y, z);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
private Vector3 parseVector() throws IOException {
|
|
267
|
+
float x = parseFloat();
|
|
268
|
+
float y = parseFloat();
|
|
269
|
+
float z = parseFloat();
|
|
270
|
+
return new Vector3(x, y, z);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private Point2 parseTexcoord() throws IOException {
|
|
274
|
+
float x = parseFloat();
|
|
275
|
+
float y = parseFloat();
|
|
276
|
+
return new Point2(x, y);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
protected abstract InterpolationType parseInterpolationType() throws IOException;
|
|
280
|
+
|
|
281
|
+
// abstract methods - to be implemented by subclasses
|
|
282
|
+
protected abstract void openParser(String filename) throws IOException;
|
|
283
|
+
|
|
284
|
+
protected abstract void closeParser() throws IOException;
|
|
285
|
+
|
|
286
|
+
protected abstract Keyword parseKeyword() throws IOException;
|
|
287
|
+
|
|
288
|
+
protected abstract boolean parseBoolean() throws IOException;
|
|
289
|
+
|
|
290
|
+
protected abstract int parseInt() throws IOException;
|
|
291
|
+
|
|
292
|
+
protected abstract float parseFloat() throws IOException;
|
|
293
|
+
|
|
294
|
+
protected abstract String parseString() throws IOException;
|
|
295
|
+
|
|
296
|
+
protected abstract String parseVerbatimString() throws IOException;
|
|
297
|
+
|
|
298
|
+
protected abstract Matrix4 parseMatrix() throws IOException;
|
|
299
|
+
}
|