joonsrenderer 1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- 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,67 @@
|
|
1
|
+
package org.sunflow.core;
|
2
|
+
|
3
|
+
import org.sunflow.image.Color;
|
4
|
+
import org.sunflow.math.Point3;
|
5
|
+
import org.sunflow.math.Vector3;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* This interface is used to represent any light emitting primitive. It permits
|
9
|
+
* efficient sampling of direct illumination and photon shooting.
|
10
|
+
*/
|
11
|
+
public interface LightSource extends RenderObject {
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Get the maximum number of samples that can be taken from this light
|
15
|
+
* source. This is currently only used for statistics reporting.
|
16
|
+
*
|
17
|
+
* @return maximum number of samples to be taken from this light source
|
18
|
+
*/
|
19
|
+
public int getNumSamples();
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Samples the light source to compute direct illumination. Light samples
|
23
|
+
* can be created using the {@link LightSample} class and added to the
|
24
|
+
* current {@link ShadingState}. This method is responsible for the shooting
|
25
|
+
* of shadow rays which allows for non-physical lights that don't cast
|
26
|
+
* shadows. It is recommended that only a single shadow ray be shot if
|
27
|
+
* {@link ShadingState#getDiffuseDepth()} is greater than 0. This avoids an
|
28
|
+
* exponential number of shadow rays from being traced.
|
29
|
+
*
|
30
|
+
* @param state current state, including point to be shaded
|
31
|
+
* @see LightSample
|
32
|
+
*/
|
33
|
+
public void getSamples(ShadingState state);
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Gets a photon to emit from this light source by setting each of the
|
37
|
+
* arguments. The two sampling parameters are points on the unit square that
|
38
|
+
* can be used to sample a position and/or direction for the emitted photon.
|
39
|
+
*
|
40
|
+
* @param randX1 sampling parameter
|
41
|
+
* @param randY1 sampling parameter
|
42
|
+
* @param randX2 sampling parameter
|
43
|
+
* @param randY2 sampling parameter
|
44
|
+
* @param p position to shoot the photon from
|
45
|
+
* @param dir direction to shoot the photon in
|
46
|
+
* @param power power of the photon
|
47
|
+
*/
|
48
|
+
public void getPhoton(double randX1, double randY1, double randX2, double randY2, Point3 p, Vector3 dir, Color power);
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Get the total power emitted by this light source. Lights that have 0
|
52
|
+
* power will not emit any photons.
|
53
|
+
*
|
54
|
+
* @return light source power
|
55
|
+
*/
|
56
|
+
public float getPower();
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Create an instance which represents the geometry of this light source.
|
60
|
+
* This instance will be created just before and removed immediately after
|
61
|
+
* rendering. Non-area light sources can return
|
62
|
+
* <code>null</code> to indicate that no geometry needs to be created.
|
63
|
+
*
|
64
|
+
* @return an instance describing the light source
|
65
|
+
*/
|
66
|
+
public Instance createInstance();
|
67
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
package org.sunflow.core;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* This represents a surface modifier. This is run on each instance prior to
|
5
|
+
* shading and can modify the shading state in arbitrary ways to provide effects
|
6
|
+
* such as bump mapping.
|
7
|
+
*/
|
8
|
+
public interface Modifier extends RenderObject {
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Modify the shading state for the point to be shaded.
|
12
|
+
*
|
13
|
+
* @param state shading state to modify
|
14
|
+
*/
|
15
|
+
public void modify(ShadingState state);
|
16
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
package org.sunflow.core;
|
2
|
+
|
3
|
+
import org.sunflow.SunflowAPI;
|
4
|
+
import org.sunflow.util.FastHashMap;
|
5
|
+
|
6
|
+
/**
|
7
|
+
* This holds rendering objects as key, value pairs.
|
8
|
+
*/
|
9
|
+
public final class Options extends ParameterList implements RenderObject {
|
10
|
+
|
11
|
+
@Override
|
12
|
+
public boolean update(ParameterList pl, SunflowAPI api) {
|
13
|
+
// take all attributes, and update them into the current set
|
14
|
+
for (FastHashMap.Entry<String, Parameter> e : pl.list) {
|
15
|
+
list.put(e.getKey(), e.getValue());
|
16
|
+
e.getValue().check();
|
17
|
+
}
|
18
|
+
return true;
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,758 @@
|
|
1
|
+
package org.sunflow.core;
|
2
|
+
|
3
|
+
import java.util.Locale;
|
4
|
+
|
5
|
+
import org.sunflow.image.Color;
|
6
|
+
import org.sunflow.math.Matrix4;
|
7
|
+
import org.sunflow.math.MovingMatrix4;
|
8
|
+
import org.sunflow.math.Point2;
|
9
|
+
import org.sunflow.math.Point3;
|
10
|
+
import org.sunflow.math.Vector3;
|
11
|
+
import org.sunflow.system.UI;
|
12
|
+
import org.sunflow.system.UI.Module;
|
13
|
+
import org.sunflow.util.FastHashMap;
|
14
|
+
|
15
|
+
/**
|
16
|
+
* This class holds a list of "parameters". These are defined and then passed
|
17
|
+
* onto rendering objects through the API. They can hold arbitrary typed and
|
18
|
+
* named variables as a unified way of getting data into user objects.
|
19
|
+
*/
|
20
|
+
public class ParameterList {
|
21
|
+
|
22
|
+
protected final FastHashMap<String, Parameter> list;
|
23
|
+
private int numVerts, numFaces, numFaceVerts;
|
24
|
+
|
25
|
+
private enum ParameterType {
|
26
|
+
|
27
|
+
STRING, INT, BOOL, FLOAT, POINT, VECTOR, TEXCOORD, MATRIX, COLOR
|
28
|
+
}
|
29
|
+
|
30
|
+
public enum InterpolationType {
|
31
|
+
|
32
|
+
NONE, FACE, VERTEX, FACEVARYING
|
33
|
+
}
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Creates an empty ParameterList.
|
37
|
+
*/
|
38
|
+
public ParameterList() {
|
39
|
+
list = new FastHashMap<String, Parameter>();
|
40
|
+
numVerts = numFaces = numFaceVerts = 0;
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Clears the list of all its members. If some members were never used, a
|
45
|
+
* warning will be printed to remind the user something may be wrong.
|
46
|
+
*/
|
47
|
+
public void clear(boolean showUnused) {
|
48
|
+
if (showUnused) {
|
49
|
+
for (FastHashMap.Entry<String, Parameter> e : list) {
|
50
|
+
if (!e.getValue().checked) {
|
51
|
+
UI.printWarning(Module.API, "Unused parameter: %s - %s", e.getKey(), e.getValue());
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
list.clear();
|
56
|
+
numVerts = numFaces = numFaceVerts = 0;
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Setup how many faces should be used to check member count on "face"
|
61
|
+
* interpolated parameters.
|
62
|
+
*
|
63
|
+
* @param numFaces number of faces
|
64
|
+
*/
|
65
|
+
public void setFaceCount(int numFaces) {
|
66
|
+
this.numFaces = numFaces;
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Setup how many vertices should be used to check member count of "vertex"
|
71
|
+
* interpolated parameters.
|
72
|
+
*
|
73
|
+
* @param numVerts number of vertices
|
74
|
+
*/
|
75
|
+
public void setVertexCount(int numVerts) {
|
76
|
+
this.numVerts = numVerts;
|
77
|
+
}
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Setup how many "face-vertices" should be used to check member count of
|
81
|
+
* "facevarying" interpolated parameters. This should be equal to the sum of
|
82
|
+
* the number of vertices on each face.
|
83
|
+
*
|
84
|
+
* @param numFaceVerts number of "face-vertices"
|
85
|
+
*/
|
86
|
+
public void setFaceVertexCount(int numFaceVerts) {
|
87
|
+
this.numFaceVerts = numFaceVerts;
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Add the specified string as a parameter.
|
92
|
+
* <code>null</code> values are not permitted.
|
93
|
+
*
|
94
|
+
* @param name parameter name
|
95
|
+
* @param value parameter value
|
96
|
+
*/
|
97
|
+
public void addString(String name, String value) {
|
98
|
+
add(name, new Parameter(value));
|
99
|
+
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Add the specified integer as a parameter.
|
103
|
+
* <code>null</code> values are not permitted.
|
104
|
+
*
|
105
|
+
* @param name parameter name
|
106
|
+
* @param value parameter value
|
107
|
+
*/
|
108
|
+
public void addInteger(String name, int value) {
|
109
|
+
add(name, new Parameter(value));
|
110
|
+
}
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Add the specified boolean as a parameter.
|
114
|
+
* <code>null</code> values are not permitted.
|
115
|
+
*
|
116
|
+
* @param name parameter name
|
117
|
+
* @param value parameter value
|
118
|
+
*/
|
119
|
+
public void addBoolean(String name, boolean value) {
|
120
|
+
add(name, new Parameter(value));
|
121
|
+
}
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Add the specified float as a parameter.
|
125
|
+
* <code>null</code> values are not permitted.
|
126
|
+
*
|
127
|
+
* @param name parameter name
|
128
|
+
* @param value parameter value
|
129
|
+
*/
|
130
|
+
public void addFloat(String name, float value) {
|
131
|
+
add(name, new Parameter(value));
|
132
|
+
}
|
133
|
+
|
134
|
+
/**
|
135
|
+
* Add the specified color as a parameter.
|
136
|
+
* <code>null</code> values are not permitted.
|
137
|
+
*
|
138
|
+
* @param name parameter name
|
139
|
+
* @param value parameter value
|
140
|
+
*/
|
141
|
+
public void addColor(String name, Color value) {
|
142
|
+
if (value == null) {
|
143
|
+
throw new NullPointerException();
|
144
|
+
}
|
145
|
+
add(name, new Parameter(value));
|
146
|
+
}
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Add the specified array of integers as a parameter.
|
150
|
+
* <code>null</code> values are not permitted.
|
151
|
+
*
|
152
|
+
* @param name parameter name
|
153
|
+
* @param array parameter value
|
154
|
+
*/
|
155
|
+
public void addIntegerArray(String name, int[] array) {
|
156
|
+
if (array == null) {
|
157
|
+
throw new NullPointerException();
|
158
|
+
}
|
159
|
+
add(name, new Parameter(array));
|
160
|
+
}
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Add the specified array of integers as a parameter.
|
164
|
+
* <code>null</code> values are not permitted.
|
165
|
+
*
|
166
|
+
* @param name parameter name
|
167
|
+
* @param array parameter value
|
168
|
+
*/
|
169
|
+
public void addStringArray(String name, String[] array) {
|
170
|
+
if (array == null) {
|
171
|
+
throw new NullPointerException();
|
172
|
+
}
|
173
|
+
add(name, new Parameter(array));
|
174
|
+
}
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Add the specified floats as a parameter.
|
178
|
+
* <code>null</code> values are not permitted.
|
179
|
+
*
|
180
|
+
* @param name parameter name
|
181
|
+
* @param interp interpolation type
|
182
|
+
* @param data parameter value
|
183
|
+
*/
|
184
|
+
public void addFloats(String name, InterpolationType interp, float[] data) {
|
185
|
+
if (data == null) {
|
186
|
+
UI.printError(Module.API, "Cannot create float parameter %s -- invalid data length", name);
|
187
|
+
return;
|
188
|
+
}
|
189
|
+
add(name, new Parameter(ParameterType.FLOAT, interp, data));
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Add the specified points as a parameter.
|
194
|
+
* <code>null</code> values are not permitted.
|
195
|
+
*
|
196
|
+
* @param name parameter name
|
197
|
+
* @param interp interpolation type
|
198
|
+
* @param data parameter value
|
199
|
+
*/
|
200
|
+
public void addPoints(String name, InterpolationType interp, float[] data) {
|
201
|
+
if (data == null || data.length % 3 != 0) {
|
202
|
+
UI.printError(Module.API, "Cannot create point parameter %s -- invalid data length", name);
|
203
|
+
return;
|
204
|
+
}
|
205
|
+
add(name, new Parameter(ParameterType.POINT, interp, data));
|
206
|
+
}
|
207
|
+
|
208
|
+
/**
|
209
|
+
* Add the specified vectors as a parameter.
|
210
|
+
* <code>null</code> values are not permitted.
|
211
|
+
*
|
212
|
+
* @param name parameter name
|
213
|
+
* @param interp interpolation type
|
214
|
+
* @param data parameter value
|
215
|
+
*/
|
216
|
+
public void addVectors(String name, InterpolationType interp, float[] data) {
|
217
|
+
if (data == null || data.length % 3 != 0) {
|
218
|
+
UI.printError(Module.API, "Cannot create vector parameter %s -- invalid data length", name);
|
219
|
+
return;
|
220
|
+
}
|
221
|
+
add(name, new Parameter(ParameterType.VECTOR, interp, data));
|
222
|
+
}
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Add the specified texture coordinates as a parameter.
|
226
|
+
* <code>null</code> values are not permitted.
|
227
|
+
*
|
228
|
+
* @param name parameter name
|
229
|
+
* @param interp interpolation type
|
230
|
+
* @param data parameter value
|
231
|
+
*/
|
232
|
+
public void addTexCoords(String name, InterpolationType interp, float[] data) {
|
233
|
+
if (data == null || data.length % 2 != 0) {
|
234
|
+
UI.printError(Module.API, "Cannot create texcoord parameter %s -- invalid data length", name);
|
235
|
+
return;
|
236
|
+
}
|
237
|
+
add(name, new Parameter(ParameterType.TEXCOORD, interp, data));
|
238
|
+
}
|
239
|
+
|
240
|
+
/**
|
241
|
+
* Add the specified matrices as a parameter.
|
242
|
+
* <code>null</code> values are not permitted.
|
243
|
+
*
|
244
|
+
* @param name parameter name
|
245
|
+
* @param interp interpolation type
|
246
|
+
* @param data parameter value
|
247
|
+
*/
|
248
|
+
public void addMatrices(String name, InterpolationType interp, float[] data) {
|
249
|
+
if (data == null || data.length % 16 != 0) {
|
250
|
+
UI.printError(Module.API, "Cannot create matrix parameter %s -- invalid data length", name);
|
251
|
+
return;
|
252
|
+
}
|
253
|
+
add(name, new Parameter(ParameterType.MATRIX, interp, data));
|
254
|
+
}
|
255
|
+
|
256
|
+
private void add(String name, Parameter param) {
|
257
|
+
if (name == null) {
|
258
|
+
UI.printError(Module.API, "Cannot declare parameter with null name");
|
259
|
+
} else if (list.put(name, param) != null) {
|
260
|
+
UI.printWarning(Module.API, "Parameter %s was already defined -- overwriting", name);
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Get the specified string parameter from this list.
|
266
|
+
*
|
267
|
+
* @param name name of the parameter
|
268
|
+
* @param defaultValue value to return if not found
|
269
|
+
* @return the value of the parameter specified or default value if not
|
270
|
+
* found
|
271
|
+
*/
|
272
|
+
public String getString(String name, String defaultValue) {
|
273
|
+
Parameter p = list.get(name);
|
274
|
+
if (isValidParameter(name, ParameterType.STRING, InterpolationType.NONE, 1, p)) {
|
275
|
+
return p.getStringValue();
|
276
|
+
}
|
277
|
+
return defaultValue;
|
278
|
+
}
|
279
|
+
|
280
|
+
/**
|
281
|
+
* Get the specified string array parameter from this list.
|
282
|
+
*
|
283
|
+
* @param name name of the parameter
|
284
|
+
* @param defaultValue value to return if not found
|
285
|
+
* @return the value of the parameter specified or default value if not
|
286
|
+
* found
|
287
|
+
*/
|
288
|
+
public String[] getStringArray(String name, String[] defaultValue) {
|
289
|
+
Parameter p = list.get(name);
|
290
|
+
if (isValidParameter(name, ParameterType.STRING, InterpolationType.NONE, -1, p)) {
|
291
|
+
return p.getStrings();
|
292
|
+
}
|
293
|
+
return defaultValue;
|
294
|
+
}
|
295
|
+
|
296
|
+
/**
|
297
|
+
* Get the specified integer parameter from this list.
|
298
|
+
*
|
299
|
+
* @param name name of the parameter
|
300
|
+
* @param defaultValue value to return if not found
|
301
|
+
* @return the value of the parameter specified or default value if not
|
302
|
+
* found
|
303
|
+
*/
|
304
|
+
public int getInt(String name, int defaultValue) {
|
305
|
+
Parameter p = list.get(name);
|
306
|
+
if (isValidParameter(name, ParameterType.INT, InterpolationType.NONE, 1, p)) {
|
307
|
+
return p.getIntValue();
|
308
|
+
}
|
309
|
+
return defaultValue;
|
310
|
+
}
|
311
|
+
|
312
|
+
/**
|
313
|
+
* Get the specified integer array parameter from this list.
|
314
|
+
*
|
315
|
+
* @param name name of the parameter
|
316
|
+
* @return the value of the parameter specified or <code>null</code> if not
|
317
|
+
* found
|
318
|
+
*/
|
319
|
+
public int[] getIntArray(String name) {
|
320
|
+
Parameter p = list.get(name);
|
321
|
+
if (isValidParameter(name, ParameterType.INT, InterpolationType.NONE, -1, p)) {
|
322
|
+
return p.getInts();
|
323
|
+
}
|
324
|
+
return null;
|
325
|
+
}
|
326
|
+
|
327
|
+
/**
|
328
|
+
* Get the specified boolean parameter from this list.
|
329
|
+
*
|
330
|
+
* @param name name of the parameter
|
331
|
+
* @param defaultValue value to return if not found
|
332
|
+
* @return the value of the parameter specified or default value if not
|
333
|
+
* found
|
334
|
+
*/
|
335
|
+
public boolean getBoolean(String name, boolean defaultValue) {
|
336
|
+
Parameter p = list.get(name);
|
337
|
+
if (isValidParameter(name, ParameterType.BOOL, InterpolationType.NONE, 1, p)) {
|
338
|
+
return p.getBoolValue();
|
339
|
+
}
|
340
|
+
return defaultValue;
|
341
|
+
}
|
342
|
+
|
343
|
+
/**
|
344
|
+
* Get the specified float parameter from this list.
|
345
|
+
*
|
346
|
+
* @param name name of the parameter
|
347
|
+
* @param defaultValue value to return if not found
|
348
|
+
* @return the value of the parameter specified or default value if not
|
349
|
+
* found
|
350
|
+
*/
|
351
|
+
public float getFloat(String name, float defaultValue) {
|
352
|
+
Parameter p = list.get(name);
|
353
|
+
if (isValidParameter(name, ParameterType.FLOAT, InterpolationType.NONE, 1, p)) {
|
354
|
+
return p.getFloatValue();
|
355
|
+
}
|
356
|
+
return defaultValue;
|
357
|
+
}
|
358
|
+
|
359
|
+
/**
|
360
|
+
* Get the specified color parameter from this list.
|
361
|
+
*
|
362
|
+
* @param name name of the parameter
|
363
|
+
* @param defaultValue value to return if not found
|
364
|
+
* @return the value of the parameter specified or default value if not
|
365
|
+
* found
|
366
|
+
*/
|
367
|
+
public Color getColor(String name, Color defaultValue) {
|
368
|
+
Parameter p = list.get(name);
|
369
|
+
if (isValidParameter(name, ParameterType.COLOR, InterpolationType.NONE, 1, p)) {
|
370
|
+
return p.getColor();
|
371
|
+
}
|
372
|
+
return defaultValue;
|
373
|
+
}
|
374
|
+
|
375
|
+
/**
|
376
|
+
* Get the specified point parameter from this list.
|
377
|
+
*
|
378
|
+
* @param name name of the parameter
|
379
|
+
* @param defaultValue value to return if not found
|
380
|
+
* @return the value of the parameter specified or default value if not
|
381
|
+
* found
|
382
|
+
*/
|
383
|
+
public Point3 getPoint(String name, Point3 defaultValue) {
|
384
|
+
Parameter p = list.get(name);
|
385
|
+
if (isValidParameter(name, ParameterType.POINT, InterpolationType.NONE, 1, p)) {
|
386
|
+
return p.getPoint();
|
387
|
+
}
|
388
|
+
return defaultValue;
|
389
|
+
}
|
390
|
+
|
391
|
+
/**
|
392
|
+
* Get the specified vector parameter from this list.
|
393
|
+
*
|
394
|
+
* @param name name of the parameter
|
395
|
+
* @param defaultValue value to return if not found
|
396
|
+
* @return the value of the parameter specified or default value if not
|
397
|
+
* found
|
398
|
+
*/
|
399
|
+
public Vector3 getVector(String name, Vector3 defaultValue) {
|
400
|
+
Parameter p = list.get(name);
|
401
|
+
if (isValidParameter(name, ParameterType.VECTOR, InterpolationType.NONE, 1, p)) {
|
402
|
+
return p.getVector();
|
403
|
+
}
|
404
|
+
return defaultValue;
|
405
|
+
}
|
406
|
+
|
407
|
+
/**
|
408
|
+
* Get the specified texture coordinate parameter from this list.
|
409
|
+
*
|
410
|
+
* @param name name of the parameter
|
411
|
+
* @param defaultValue value to return if not found
|
412
|
+
* @return the value of the parameter specified or default value if not
|
413
|
+
* found
|
414
|
+
*/
|
415
|
+
public Point2 getTexCoord(String name, Point2 defaultValue) {
|
416
|
+
Parameter p = list.get(name);
|
417
|
+
if (isValidParameter(name, ParameterType.TEXCOORD, InterpolationType.NONE, 1, p)) {
|
418
|
+
return p.getTexCoord();
|
419
|
+
}
|
420
|
+
return defaultValue;
|
421
|
+
}
|
422
|
+
|
423
|
+
/**
|
424
|
+
* Get the specified matrix parameter from this list.
|
425
|
+
*
|
426
|
+
* @param name name of the parameter
|
427
|
+
* @param defaultValue value to return if not found
|
428
|
+
* @return the value of the parameter specified or default value if not
|
429
|
+
* found
|
430
|
+
*/
|
431
|
+
public Matrix4 getMatrix(String name, Matrix4 defaultValue) {
|
432
|
+
Parameter p = list.get(name);
|
433
|
+
if (isValidParameter(name, ParameterType.MATRIX, InterpolationType.NONE, 1, p)) {
|
434
|
+
return p.getMatrix();
|
435
|
+
}
|
436
|
+
return defaultValue;
|
437
|
+
}
|
438
|
+
|
439
|
+
/**
|
440
|
+
* Get the specified float array parameter from this list.
|
441
|
+
*
|
442
|
+
* @param name name of the parameter
|
443
|
+
* @return the value of the parameter specified or <code>null</code> if not
|
444
|
+
* found
|
445
|
+
*/
|
446
|
+
public FloatParameter getFloatArray(String name) {
|
447
|
+
return getFloatParameter(name, ParameterType.FLOAT, list.get(name));
|
448
|
+
}
|
449
|
+
|
450
|
+
/**
|
451
|
+
* Get the specified point array parameter from this list.
|
452
|
+
*
|
453
|
+
* @param name name of the parameter
|
454
|
+
* @return the value of the parameter specified or <code>null</code> if not
|
455
|
+
* found
|
456
|
+
*/
|
457
|
+
public FloatParameter getPointArray(String name) {
|
458
|
+
return getFloatParameter(name, ParameterType.POINT, list.get(name));
|
459
|
+
}
|
460
|
+
|
461
|
+
/**
|
462
|
+
* Get the specified vector array parameter from this list.
|
463
|
+
*
|
464
|
+
* @param name name of the parameter
|
465
|
+
* @return the value of the parameter specified or <code>null</code> if not
|
466
|
+
* found
|
467
|
+
*/
|
468
|
+
public FloatParameter getVectorArray(String name) {
|
469
|
+
return getFloatParameter(name, ParameterType.VECTOR, list.get(name));
|
470
|
+
}
|
471
|
+
|
472
|
+
/**
|
473
|
+
* Get the specified texture coordinate array parameter from this list.
|
474
|
+
*
|
475
|
+
* @param name name of the parameter
|
476
|
+
* @return the value of the parameter specified or <code>null</code> if not
|
477
|
+
* found
|
478
|
+
*/
|
479
|
+
public FloatParameter getTexCoordArray(String name) {
|
480
|
+
return getFloatParameter(name, ParameterType.TEXCOORD, list.get(name));
|
481
|
+
}
|
482
|
+
|
483
|
+
/**
|
484
|
+
* Get the specified matrix array parameter from this list.
|
485
|
+
*
|
486
|
+
* @param name name of the parameter
|
487
|
+
* @return the value of the parameter specified or <code>null</code> if not
|
488
|
+
* found
|
489
|
+
*/
|
490
|
+
public FloatParameter getMatrixArray(String name) {
|
491
|
+
return getFloatParameter(name, ParameterType.MATRIX, list.get(name));
|
492
|
+
}
|
493
|
+
|
494
|
+
private boolean isValidParameter(String name, ParameterType type, InterpolationType interp, int requestedSize, Parameter p) {
|
495
|
+
if (p == null) {
|
496
|
+
return false;
|
497
|
+
}
|
498
|
+
if (p.type != type) {
|
499
|
+
UI.printWarning(Module.API, "Parameter %s requested as a %s - declared as %s", name, type.name().toLowerCase(Locale.ENGLISH), p.type.name().toLowerCase(Locale.ENGLISH));
|
500
|
+
return false;
|
501
|
+
}
|
502
|
+
if (p.interp != interp) {
|
503
|
+
UI.printWarning(Module.API, "Parameter %s requested as a %s - declared as %s", name, interp.name().toLowerCase(Locale.ENGLISH), p.interp.name().toLowerCase(Locale.ENGLISH));
|
504
|
+
return false;
|
505
|
+
}
|
506
|
+
if (requestedSize > 0 && p.size() != requestedSize) {
|
507
|
+
UI.printWarning(Module.API, "Parameter %s requires %d %s - declared with %d", name, requestedSize, requestedSize == 1 ? "value" : "values", p.size());
|
508
|
+
return false;
|
509
|
+
}
|
510
|
+
p.checked = true;
|
511
|
+
return true;
|
512
|
+
}
|
513
|
+
|
514
|
+
private FloatParameter getFloatParameter(String name, ParameterType type, Parameter p) {
|
515
|
+
if (p == null) {
|
516
|
+
return null;
|
517
|
+
}
|
518
|
+
switch (p.interp) {
|
519
|
+
case NONE:
|
520
|
+
if (!isValidParameter(name, type, p.interp, -1, p)) {
|
521
|
+
return null;
|
522
|
+
}
|
523
|
+
break;
|
524
|
+
case VERTEX:
|
525
|
+
if (!isValidParameter(name, type, p.interp, numVerts, p)) {
|
526
|
+
return null;
|
527
|
+
}
|
528
|
+
break;
|
529
|
+
case FACE:
|
530
|
+
if (!isValidParameter(name, type, p.interp, numFaces, p)) {
|
531
|
+
return null;
|
532
|
+
}
|
533
|
+
break;
|
534
|
+
case FACEVARYING:
|
535
|
+
if (!isValidParameter(name, type, p.interp, numFaceVerts, p)) {
|
536
|
+
return null;
|
537
|
+
}
|
538
|
+
break;
|
539
|
+
default:
|
540
|
+
return null;
|
541
|
+
}
|
542
|
+
return p.getFloats();
|
543
|
+
}
|
544
|
+
|
545
|
+
/**
|
546
|
+
* Represents an array of floating point values. This can store single
|
547
|
+
* float, points, vectors, texture coordinates or matrices. The parameter
|
548
|
+
* should be interpolated over the surface according to the interp parameter
|
549
|
+
* when applicable.
|
550
|
+
*/
|
551
|
+
public static final class FloatParameter {
|
552
|
+
|
553
|
+
public final InterpolationType interp;
|
554
|
+
public final float[] data;
|
555
|
+
|
556
|
+
public FloatParameter() {
|
557
|
+
this(InterpolationType.NONE, null);
|
558
|
+
}
|
559
|
+
|
560
|
+
public FloatParameter(float f) {
|
561
|
+
this(InterpolationType.NONE, new float[]{f});
|
562
|
+
}
|
563
|
+
|
564
|
+
private FloatParameter(InterpolationType interp, float[] data) {
|
565
|
+
this.interp = interp;
|
566
|
+
this.data = data;
|
567
|
+
}
|
568
|
+
}
|
569
|
+
|
570
|
+
public final MovingMatrix4 getMovingMatrix(String name, MovingMatrix4 defaultValue) {
|
571
|
+
// step 1: check for a non-moving specification:
|
572
|
+
Matrix4 m = getMatrix(name, null);
|
573
|
+
if (m != null) {
|
574
|
+
return new MovingMatrix4(m);
|
575
|
+
}
|
576
|
+
// step 2: check to see if the time range has been updated
|
577
|
+
FloatParameter times = getFloatArray(name + ".times");
|
578
|
+
if (times != null) {
|
579
|
+
if (times.data.length <= 1) {
|
580
|
+
defaultValue.updateTimes(0, 0);
|
581
|
+
} else {
|
582
|
+
if (times.data.length != 2) {
|
583
|
+
UI.printWarning(Module.API, "Time value specification using only endpoints of %d values specified", times.data.length);
|
584
|
+
}
|
585
|
+
// get endpoint times - we might allow multiple time values
|
586
|
+
// later
|
587
|
+
float t0 = times.data[0];
|
588
|
+
float t1 = times.data[times.data.length - 1];
|
589
|
+
defaultValue.updateTimes(t0, t1);
|
590
|
+
}
|
591
|
+
} else {
|
592
|
+
// time range stays at default
|
593
|
+
}
|
594
|
+
// step 3: check to see if a number of steps has been specified
|
595
|
+
int steps = getInt(name + ".steps", 0);
|
596
|
+
if (steps <= 0) {
|
597
|
+
// not specified - return default value
|
598
|
+
} else {
|
599
|
+
// update each element
|
600
|
+
defaultValue.setSteps(steps);
|
601
|
+
for (int i = 0; i < steps; i++) {
|
602
|
+
defaultValue.updateData(i, getMatrix(String.format("%s[%d]", name, i), defaultValue.getData(i)));
|
603
|
+
}
|
604
|
+
}
|
605
|
+
return defaultValue;
|
606
|
+
}
|
607
|
+
|
608
|
+
protected static final class Parameter {
|
609
|
+
|
610
|
+
private ParameterType type;
|
611
|
+
private InterpolationType interp;
|
612
|
+
private Object obj;
|
613
|
+
private boolean checked;
|
614
|
+
|
615
|
+
private Parameter(String value) {
|
616
|
+
type = ParameterType.STRING;
|
617
|
+
interp = InterpolationType.NONE;
|
618
|
+
obj = new String[]{value};
|
619
|
+
checked = false;
|
620
|
+
}
|
621
|
+
|
622
|
+
private Parameter(int value) {
|
623
|
+
type = ParameterType.INT;
|
624
|
+
interp = InterpolationType.NONE;
|
625
|
+
obj = new int[]{value};
|
626
|
+
checked = false;
|
627
|
+
}
|
628
|
+
|
629
|
+
private Parameter(boolean value) {
|
630
|
+
type = ParameterType.BOOL;
|
631
|
+
interp = InterpolationType.NONE;
|
632
|
+
obj = value;
|
633
|
+
checked = false;
|
634
|
+
}
|
635
|
+
|
636
|
+
private Parameter(float value) {
|
637
|
+
type = ParameterType.FLOAT;
|
638
|
+
interp = InterpolationType.NONE;
|
639
|
+
obj = new float[]{value};
|
640
|
+
checked = false;
|
641
|
+
}
|
642
|
+
|
643
|
+
private Parameter(int[] array) {
|
644
|
+
type = ParameterType.INT;
|
645
|
+
interp = InterpolationType.NONE;
|
646
|
+
obj = array;
|
647
|
+
checked = false;
|
648
|
+
}
|
649
|
+
|
650
|
+
private Parameter(String[] array) {
|
651
|
+
type = ParameterType.STRING;
|
652
|
+
interp = InterpolationType.NONE;
|
653
|
+
obj = array;
|
654
|
+
checked = false;
|
655
|
+
}
|
656
|
+
|
657
|
+
private Parameter(Color c) {
|
658
|
+
type = ParameterType.COLOR;
|
659
|
+
interp = InterpolationType.NONE;
|
660
|
+
obj = c;
|
661
|
+
checked = false;
|
662
|
+
}
|
663
|
+
|
664
|
+
private Parameter(ParameterType type, InterpolationType interp, float[] data) {
|
665
|
+
this.type = type;
|
666
|
+
this.interp = interp;
|
667
|
+
obj = data;
|
668
|
+
checked = false;
|
669
|
+
}
|
670
|
+
|
671
|
+
private int size() {
|
672
|
+
// number of elements
|
673
|
+
switch (type) {
|
674
|
+
case STRING:
|
675
|
+
return ((String[]) obj).length;
|
676
|
+
case INT:
|
677
|
+
return ((int[]) obj).length;
|
678
|
+
case BOOL:
|
679
|
+
return 1;
|
680
|
+
case FLOAT:
|
681
|
+
return ((float[]) obj).length;
|
682
|
+
case POINT:
|
683
|
+
return ((float[]) obj).length / 3;
|
684
|
+
case VECTOR:
|
685
|
+
return ((float[]) obj).length / 3;
|
686
|
+
case TEXCOORD:
|
687
|
+
return ((float[]) obj).length / 2;
|
688
|
+
case MATRIX:
|
689
|
+
return ((float[]) obj).length / 16;
|
690
|
+
case COLOR:
|
691
|
+
return 1;
|
692
|
+
default:
|
693
|
+
return -1;
|
694
|
+
}
|
695
|
+
}
|
696
|
+
|
697
|
+
protected void check() {
|
698
|
+
checked = true;
|
699
|
+
}
|
700
|
+
|
701
|
+
@Override
|
702
|
+
public String toString() {
|
703
|
+
return String.format("%s%s[%d]", interp == InterpolationType.NONE ? "" : interp.name().toLowerCase() + " ", type.name().toLowerCase(), size());
|
704
|
+
}
|
705
|
+
|
706
|
+
private String getStringValue() {
|
707
|
+
return ((String[]) obj)[0];
|
708
|
+
}
|
709
|
+
|
710
|
+
private boolean getBoolValue() {
|
711
|
+
return (Boolean) obj;
|
712
|
+
}
|
713
|
+
|
714
|
+
private int getIntValue() {
|
715
|
+
return ((int[]) obj)[0];
|
716
|
+
}
|
717
|
+
|
718
|
+
private int[] getInts() {
|
719
|
+
return (int[]) obj;
|
720
|
+
}
|
721
|
+
|
722
|
+
private String[] getStrings() {
|
723
|
+
return (String[]) obj;
|
724
|
+
}
|
725
|
+
|
726
|
+
private float getFloatValue() {
|
727
|
+
return ((float[]) obj)[0];
|
728
|
+
}
|
729
|
+
|
730
|
+
private FloatParameter getFloats() {
|
731
|
+
return new FloatParameter(interp, (float[]) obj);
|
732
|
+
}
|
733
|
+
|
734
|
+
private Point3 getPoint() {
|
735
|
+
float[] floats = (float[]) obj;
|
736
|
+
return new Point3(floats[0], floats[1], floats[2]);
|
737
|
+
}
|
738
|
+
|
739
|
+
private Vector3 getVector() {
|
740
|
+
float[] floats = (float[]) obj;
|
741
|
+
return new Vector3(floats[0], floats[1], floats[2]);
|
742
|
+
}
|
743
|
+
|
744
|
+
private Point2 getTexCoord() {
|
745
|
+
float[] floats = (float[]) obj;
|
746
|
+
return new Point2(floats[0], floats[1]);
|
747
|
+
}
|
748
|
+
|
749
|
+
private Matrix4 getMatrix() {
|
750
|
+
float[] floats = (float[]) obj;
|
751
|
+
return new Matrix4(floats, true);
|
752
|
+
}
|
753
|
+
|
754
|
+
private Color getColor() {
|
755
|
+
return (Color) obj;
|
756
|
+
}
|
757
|
+
}
|
758
|
+
}
|