toxiclibs 0.2-java → 0.5.0-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.
Files changed (383) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +16 -0
  3. data/CHANGELOG.md +4 -0
  4. data/LICENSE +675 -0
  5. data/README.md +12 -5
  6. data/Rakefile +25 -82
  7. data/examples/attract_repel/attract_repel.rb +30 -0
  8. data/examples/attract_repel/attractor.rb +23 -0
  9. data/examples/attract_repel/particle.rb +27 -0
  10. data/examples/data/ti_yong.png +0 -0
  11. data/examples/force_directed/cluster.rb +76 -0
  12. data/examples/force_directed/force_directed_graph.rb +92 -0
  13. data/examples/force_directed/node.rb +26 -0
  14. data/examples/gray_scott_image.rb +75 -0
  15. data/examples/gray_scott_tone_map.rb +77 -0
  16. data/examples/implicit.rb +139 -0
  17. data/examples/inflate_mesh.rb +89 -0
  18. data/examples/model_align.rb +44 -0
  19. data/examples/povmesh/ftest.rb +46 -0
  20. data/examples/povmesh/tentacle.rb +73 -0
  21. data/examples/simple_cluster/cluster.rb +47 -0
  22. data/examples/simple_cluster/node.rb +27 -0
  23. data/examples/simple_cluster/simple_cluster.rb +60 -0
  24. data/examples/soft_body/blanket.rb +45 -0
  25. data/examples/soft_body/connection.rb +16 -0
  26. data/examples/soft_body/particle.rb +22 -0
  27. data/examples/soft_body/soft_body_square_adapted.rb +55 -0
  28. data/lib/toxiclibs.jar +0 -0
  29. data/lib/toxiclibs.rb +91 -32
  30. data/lib/toxiclibs/version.rb +1 -1
  31. data/pom.xml +122 -0
  32. data/src/com/toxi/net/ClientListener.java +41 -0
  33. data/src/com/toxi/net/ServerListener.java +70 -0
  34. data/src/com/toxi/net/ServerListenerAdapter.java +47 -0
  35. data/src/com/toxi/net/ServerState.java +18 -0
  36. data/src/com/toxi/net/UDPConnection.java +66 -0
  37. data/src/com/toxi/net/UDPSyncClient.java +81 -0
  38. data/src/com/toxi/net/UDPSyncServer.java +450 -0
  39. data/src/com/toxi/nio/UDPClient.java +121 -0
  40. data/src/com/toxi/nio/UDPClientState.java +32 -0
  41. data/src/com/toxi/nio/UDPServer.java +129 -0
  42. data/src/toxi/color/AccessCriteria.java +114 -0
  43. data/src/toxi/color/AlphaAccessor.java +67 -0
  44. data/src/toxi/color/CMYKAccessor.java +122 -0
  45. data/src/toxi/color/CMYKDistanceProxy.java +40 -0
  46. data/src/toxi/color/ColorGradient.java +260 -0
  47. data/src/toxi/color/ColorList.java +699 -0
  48. data/src/toxi/color/ColorRange.java +671 -0
  49. data/src/toxi/color/ColorTheme.java +163 -0
  50. data/src/toxi/color/DistanceProxy.java +44 -0
  51. data/src/toxi/color/HSVAccessor.java +113 -0
  52. data/src/toxi/color/HSVDistanceProxy.java +40 -0
  53. data/src/toxi/color/HistEntry.java +85 -0
  54. data/src/toxi/color/Histogram.java +185 -0
  55. data/src/toxi/color/Hue.java +249 -0
  56. data/src/toxi/color/LuminanceAccessor.java +78 -0
  57. data/src/toxi/color/NamedColor.java +935 -0
  58. data/src/toxi/color/ProximityComparator.java +70 -0
  59. data/src/toxi/color/RGBAccessor.java +113 -0
  60. data/src/toxi/color/RGBDistanceProxy.java +41 -0
  61. data/src/toxi/color/ReadonlyTColor.java +296 -0
  62. data/src/toxi/color/TColor.java +1677 -0
  63. data/src/toxi/color/TColorAdapter.java +68 -0
  64. data/src/toxi/color/ToneMap.java +218 -0
  65. data/src/toxi/color/theory/AnalogousStrategy.java +140 -0
  66. data/src/toxi/color/theory/ColorTheoryRegistry.java +139 -0
  67. data/src/toxi/color/theory/ColorTheoryStrategy.java +56 -0
  68. data/src/toxi/color/theory/ComplementaryStrategy.java +111 -0
  69. data/src/toxi/color/theory/CompoundTheoryStrategy.java +143 -0
  70. data/src/toxi/color/theory/LeftSplitComplementaryStrategy.java +82 -0
  71. data/src/toxi/color/theory/MonochromeTheoryStrategy.java +103 -0
  72. data/src/toxi/color/theory/RightSplitComplementaryStrategy.java +82 -0
  73. data/src/toxi/color/theory/SingleComplementStrategy.java +76 -0
  74. data/src/toxi/color/theory/SplitComplementaryStrategy.java +77 -0
  75. data/src/toxi/color/theory/TetradTheoryStrategy.java +114 -0
  76. data/src/toxi/color/theory/TriadTheoryStrategy.java +77 -0
  77. data/src/toxi/data/csv/CSVAdapter.java +74 -0
  78. data/src/toxi/data/csv/CSVFieldMapper.java +212 -0
  79. data/src/toxi/data/csv/CSVListener.java +61 -0
  80. data/src/toxi/data/csv/CSVParser.java +202 -0
  81. data/src/toxi/data/feeds/AtomAuthor.java +49 -0
  82. data/src/toxi/data/feeds/AtomContent.java +50 -0
  83. data/src/toxi/data/feeds/AtomEntry.java +111 -0
  84. data/src/toxi/data/feeds/AtomFeed.java +129 -0
  85. data/src/toxi/data/feeds/AtomLink.java +62 -0
  86. data/src/toxi/data/feeds/RSSChannel.java +88 -0
  87. data/src/toxi/data/feeds/RSSEnclosure.java +60 -0
  88. data/src/toxi/data/feeds/RSSFeed.java +99 -0
  89. data/src/toxi/data/feeds/RSSItem.java +104 -0
  90. data/src/toxi/data/feeds/util/EntityStripper.java +2480 -0
  91. data/src/toxi/data/feeds/util/Iso8601DateAdapter.java +101 -0
  92. data/src/toxi/data/feeds/util/Rfc822DateAdapter.java +93 -0
  93. data/src/toxi/geom/AABB.java +658 -0
  94. data/src/toxi/geom/Axis3D.java +116 -0
  95. data/src/toxi/geom/AxisAlignedCylinder.java +163 -0
  96. data/src/toxi/geom/BernsteinPolynomial.java +94 -0
  97. data/src/toxi/geom/BezierCurve2D.java +159 -0
  98. data/src/toxi/geom/BezierCurve3D.java +148 -0
  99. data/src/toxi/geom/BooleanShapeBuilder.java +185 -0
  100. data/src/toxi/geom/BoxIntersector.java +52 -0
  101. data/src/toxi/geom/Circle.java +230 -0
  102. data/src/toxi/geom/CircleIntersector.java +85 -0
  103. data/src/toxi/geom/Cone.java +150 -0
  104. data/src/toxi/geom/ConvexPolygonClipper.java +136 -0
  105. data/src/toxi/geom/CoordinateExtractor.java +16 -0
  106. data/src/toxi/geom/Ellipse.java +250 -0
  107. data/src/toxi/geom/GMatrix.java +2599 -0
  108. data/src/toxi/geom/GVector.java +833 -0
  109. data/src/toxi/geom/GlobalGridTesselator.java +54 -0
  110. data/src/toxi/geom/GridTesselator.java +108 -0
  111. data/src/toxi/geom/Intersector2D.java +49 -0
  112. data/src/toxi/geom/Intersector3D.java +51 -0
  113. data/src/toxi/geom/IsectData2D.java +103 -0
  114. data/src/toxi/geom/IsectData3D.java +103 -0
  115. data/src/toxi/geom/Line2D.java +534 -0
  116. data/src/toxi/geom/Line3D.java +471 -0
  117. data/src/toxi/geom/LineStrip2D.java +430 -0
  118. data/src/toxi/geom/LineStrip3D.java +230 -0
  119. data/src/toxi/geom/LocalGridTesselator.java +57 -0
  120. data/src/toxi/geom/Matrix3d.java +3048 -0
  121. data/src/toxi/geom/Matrix4f.java +3446 -0
  122. data/src/toxi/geom/Matrix4x4.java +1076 -0
  123. data/src/toxi/geom/MatrixSizeException.java +58 -0
  124. data/src/toxi/geom/OctreeVisitor.java +44 -0
  125. data/src/toxi/geom/Origin3D.java +148 -0
  126. data/src/toxi/geom/Plane.java +293 -0
  127. data/src/toxi/geom/PlaneIntersector.java +57 -0
  128. data/src/toxi/geom/PointCloud3D.java +253 -0
  129. data/src/toxi/geom/PointOctree.java +502 -0
  130. data/src/toxi/geom/PointQuadtree.java +375 -0
  131. data/src/toxi/geom/Polygon2D.java +1038 -0
  132. data/src/toxi/geom/PolygonClipper2D.java +45 -0
  133. data/src/toxi/geom/PolygonTesselator.java +20 -0
  134. data/src/toxi/geom/QuadtreeVisitor.java +44 -0
  135. data/src/toxi/geom/Quaternion.java +641 -0
  136. data/src/toxi/geom/Ray2D.java +146 -0
  137. data/src/toxi/geom/Ray3D.java +150 -0
  138. data/src/toxi/geom/Ray3DIntersector.java +75 -0
  139. data/src/toxi/geom/ReadonlyVec2D.java +575 -0
  140. data/src/toxi/geom/ReadonlyVec3D.java +628 -0
  141. data/src/toxi/geom/ReadonlyVec4D.java +431 -0
  142. data/src/toxi/geom/Rect.java +720 -0
  143. data/src/toxi/geom/Reflector3D.java +58 -0
  144. data/src/toxi/geom/Shape2D.java +94 -0
  145. data/src/toxi/geom/Shape3D.java +42 -0
  146. data/src/toxi/geom/SingularMatrixException.java +57 -0
  147. data/src/toxi/geom/SpatialBins.java +182 -0
  148. data/src/toxi/geom/SpatialIndex.java +61 -0
  149. data/src/toxi/geom/Sphere.java +224 -0
  150. data/src/toxi/geom/SphereIntersectorReflector.java +196 -0
  151. data/src/toxi/geom/Spline2D.java +349 -0
  152. data/src/toxi/geom/Spline3D.java +351 -0
  153. data/src/toxi/geom/SutherlandHodgemanClipper.java +151 -0
  154. data/src/toxi/geom/Triangle2D.java +422 -0
  155. data/src/toxi/geom/Triangle3D.java +456 -0
  156. data/src/toxi/geom/TriangleIntersector.java +105 -0
  157. data/src/toxi/geom/Vec2D.java +1328 -0
  158. data/src/toxi/geom/Vec3D.java +1832 -0
  159. data/src/toxi/geom/Vec4D.java +985 -0
  160. data/src/toxi/geom/VecMathUtil.java +100 -0
  161. data/src/toxi/geom/XAxisCylinder.java +64 -0
  162. data/src/toxi/geom/YAxisCylinder.java +65 -0
  163. data/src/toxi/geom/ZAxisCylinder.java +64 -0
  164. data/src/toxi/geom/mesh/BezierPatch.java +200 -0
  165. data/src/toxi/geom/mesh/BoxSelector.java +62 -0
  166. data/src/toxi/geom/mesh/DefaultSTLColorModel.java +67 -0
  167. data/src/toxi/geom/mesh/DefaultSelector.java +50 -0
  168. data/src/toxi/geom/mesh/Face.java +176 -0
  169. data/src/toxi/geom/mesh/LaplacianSmooth.java +80 -0
  170. data/src/toxi/geom/mesh/MaterialiseSTLColorModel.java +150 -0
  171. data/src/toxi/geom/mesh/Mesh3D.java +224 -0
  172. data/src/toxi/geom/mesh/MeshIntersector.java +91 -0
  173. data/src/toxi/geom/mesh/OBJWriter.java +194 -0
  174. data/src/toxi/geom/mesh/PLYWriter.java +167 -0
  175. data/src/toxi/geom/mesh/PlaneSelector.java +90 -0
  176. data/src/toxi/geom/mesh/STLColorModel.java +54 -0
  177. data/src/toxi/geom/mesh/STLReader.java +185 -0
  178. data/src/toxi/geom/mesh/STLWriter.java +323 -0
  179. data/src/toxi/geom/mesh/SphereFunction.java +156 -0
  180. data/src/toxi/geom/mesh/SphericalHarmonics.java +110 -0
  181. data/src/toxi/geom/mesh/SuperEllipsoid.java +110 -0
  182. data/src/toxi/geom/mesh/SurfaceFunction.java +75 -0
  183. data/src/toxi/geom/mesh/SurfaceMeshBuilder.java +149 -0
  184. data/src/toxi/geom/mesh/Terrain.java +451 -0
  185. data/src/toxi/geom/mesh/TriangleMesh.java +1201 -0
  186. data/src/toxi/geom/mesh/Vertex.java +78 -0
  187. data/src/toxi/geom/mesh/VertexSelector.java +193 -0
  188. data/src/toxi/geom/mesh/WEFace.java +100 -0
  189. data/src/toxi/geom/mesh/WEMeshFilterStrategy.java +51 -0
  190. data/src/toxi/geom/mesh/WETriangleMesh.java +761 -0
  191. data/src/toxi/geom/mesh/WEVertex.java +134 -0
  192. data/src/toxi/geom/mesh/WingedEdge.java +115 -0
  193. data/src/toxi/geom/mesh/subdiv/CentroidSubdiv.java +37 -0
  194. data/src/toxi/geom/mesh/subdiv/DisplacementSubdivision.java +85 -0
  195. data/src/toxi/geom/mesh/subdiv/DualDisplacementSubdivision.java +94 -0
  196. data/src/toxi/geom/mesh/subdiv/DualSubdivision.java +49 -0
  197. data/src/toxi/geom/mesh/subdiv/EdgeLengthComparator.java +50 -0
  198. data/src/toxi/geom/mesh/subdiv/FaceCountComparator.java +51 -0
  199. data/src/toxi/geom/mesh/subdiv/MidpointDisplacementSubdivision.java +80 -0
  200. data/src/toxi/geom/mesh/subdiv/MidpointSubdiv.java +42 -0
  201. data/src/toxi/geom/mesh/subdiv/MidpointSubdivision.java +48 -0
  202. data/src/toxi/geom/mesh/subdiv/NewSubdivStrategy.java +23 -0
  203. data/src/toxi/geom/mesh/subdiv/NormalDisplacementSubdivision.java +74 -0
  204. data/src/toxi/geom/mesh/subdiv/SubdivisionStrategy.java +83 -0
  205. data/src/toxi/geom/mesh/subdiv/TriSubdivision.java +51 -0
  206. data/src/toxi/geom/mesh2d/DelaunayTriangle.java +222 -0
  207. data/src/toxi/geom/mesh2d/DelaunayTriangulation.java +327 -0
  208. data/src/toxi/geom/mesh2d/DelaunayVertex.java +560 -0
  209. data/src/toxi/geom/mesh2d/Voronoi.java +149 -0
  210. data/src/toxi/geom/nurbs/BasicNurbsCurve.java +210 -0
  211. data/src/toxi/geom/nurbs/BasicNurbsSurface.java +233 -0
  212. data/src/toxi/geom/nurbs/ControlNet.java +148 -0
  213. data/src/toxi/geom/nurbs/CurveCreator.java +112 -0
  214. data/src/toxi/geom/nurbs/CurveUtils.java +259 -0
  215. data/src/toxi/geom/nurbs/InterpolationException.java +65 -0
  216. data/src/toxi/geom/nurbs/KnotVector.java +333 -0
  217. data/src/toxi/geom/nurbs/NurbsCreator.java +815 -0
  218. data/src/toxi/geom/nurbs/NurbsCurve.java +120 -0
  219. data/src/toxi/geom/nurbs/NurbsMeshCreator.java +145 -0
  220. data/src/toxi/geom/nurbs/NurbsSurface.java +147 -0
  221. data/src/toxi/image/util/Filter8bit.java +331 -0
  222. data/src/toxi/image/util/TiledFrameExporter.java +162 -0
  223. data/src/toxi/math/BezierInterpolation.java +102 -0
  224. data/src/toxi/math/CircularInterpolation.java +88 -0
  225. data/src/toxi/math/CosineInterpolation.java +51 -0
  226. data/src/toxi/math/DecimatedInterpolation.java +77 -0
  227. data/src/toxi/math/ExponentialInterpolation.java +68 -0
  228. data/src/toxi/math/InterpolateStrategy.java +60 -0
  229. data/src/toxi/math/Interpolation2D.java +93 -0
  230. data/src/toxi/math/LinearInterpolation.java +46 -0
  231. data/src/toxi/math/MathUtils.java +990 -0
  232. data/src/toxi/math/NonLinearScaleMap.java +101 -0
  233. data/src/toxi/math/ScaleMap.java +183 -0
  234. data/src/toxi/math/SigmoidInterpolation.java +78 -0
  235. data/src/toxi/math/SinCosLUT.java +141 -0
  236. data/src/toxi/math/ThresholdInterpolation.java +58 -0
  237. data/src/toxi/math/ZoomLensInterpolation.java +126 -0
  238. data/src/toxi/math/conversion/UnitTranslator.java +161 -0
  239. data/src/toxi/math/noise/PerlinNoise.java +281 -0
  240. data/src/toxi/math/noise/SimplexNoise.java +542 -0
  241. data/src/toxi/math/waves/AMFMSineWave.java +143 -0
  242. data/src/toxi/math/waves/AbstractWave.java +248 -0
  243. data/src/toxi/math/waves/ConstantWave.java +48 -0
  244. data/src/toxi/math/waves/FMHarmonicSquareWave.java +155 -0
  245. data/src/toxi/math/waves/FMSawtoothWave.java +144 -0
  246. data/src/toxi/math/waves/FMSineWave.java +142 -0
  247. data/src/toxi/math/waves/FMSquareWave.java +143 -0
  248. data/src/toxi/math/waves/FMTriangleWave.java +126 -0
  249. data/src/toxi/math/waves/SineWave.java +81 -0
  250. data/src/toxi/math/waves/Wave2D.java +68 -0
  251. data/src/toxi/math/waves/WaveState.java +69 -0
  252. data/src/toxi/music/scale/AbstractScale.java +117 -0
  253. data/src/toxi/music/scale/GenericScale.java +66 -0
  254. data/src/toxi/music/scale/MajorScale.java +41 -0
  255. data/src/toxi/newmesh/AttributedEdge.java +106 -0
  256. data/src/toxi/newmesh/AttributedFace.java +63 -0
  257. data/src/toxi/newmesh/IndexedTriangleMesh.java +809 -0
  258. data/src/toxi/newmesh/MeshAttributeCompiler.java +45 -0
  259. data/src/toxi/newmesh/MeshFaceNormalCompiler.java +52 -0
  260. data/src/toxi/newmesh/MeshUVCompiler.java +52 -0
  261. data/src/toxi/newmesh/MeshVertexColorCompiler.java +49 -0
  262. data/src/toxi/newmesh/MeshVertexCompiler.java +54 -0
  263. data/src/toxi/newmesh/MeshVertexNormalCompiler.java +55 -0
  264. data/src/toxi/newmesh/SpatialIndex.java +78 -0
  265. data/src/toxi/physics2d/ParticlePath2D.java +100 -0
  266. data/src/toxi/physics2d/ParticleString2D.java +184 -0
  267. data/src/toxi/physics2d/PullBackSpring2D.java +51 -0
  268. data/src/toxi/physics2d/VerletConstrainedSpring2D.java +89 -0
  269. data/src/toxi/physics2d/VerletMinDistanceSpring2D.java +57 -0
  270. data/src/toxi/physics2d/VerletParticle2D.java +457 -0
  271. data/src/toxi/physics2d/VerletPhysics2D.java +448 -0
  272. data/src/toxi/physics2d/VerletSpring2D.java +181 -0
  273. data/src/toxi/physics2d/behaviors/AttractionBehavior2D.java +212 -0
  274. data/src/toxi/physics2d/behaviors/ConstantForceBehavior2D.java +112 -0
  275. data/src/toxi/physics2d/behaviors/GravityBehavior2D.java +61 -0
  276. data/src/toxi/physics2d/behaviors/ParticleBehavior2D.java +66 -0
  277. data/src/toxi/physics2d/constraints/AngularConstraint.java +83 -0
  278. data/src/toxi/physics2d/constraints/AxisConstraint.java +71 -0
  279. data/src/toxi/physics2d/constraints/CircularConstraint.java +69 -0
  280. data/src/toxi/physics2d/constraints/MaxConstraint.java +66 -0
  281. data/src/toxi/physics2d/constraints/MinConstraint.java +66 -0
  282. data/src/toxi/physics2d/constraints/ParticleConstraint2D.java +47 -0
  283. data/src/toxi/physics2d/constraints/PolygonConstraint.java +93 -0
  284. data/src/toxi/physics2d/constraints/RectConstraint.java +114 -0
  285. data/src/toxi/physics3d/ParticlePath3D.java +100 -0
  286. data/src/toxi/physics3d/ParticleString3D.java +184 -0
  287. data/src/toxi/physics3d/PullBackSpring3D.java +50 -0
  288. data/src/toxi/physics3d/VerletConstrainedSpring3D.java +88 -0
  289. data/src/toxi/physics3d/VerletMinDistanceSpring3D.java +56 -0
  290. data/src/toxi/physics3d/VerletParticle3D.java +385 -0
  291. data/src/toxi/physics3d/VerletPhysics3D.java +417 -0
  292. data/src/toxi/physics3d/VerletSpring3D.java +180 -0
  293. data/src/toxi/physics3d/behaviors/AttractionBehavior3D.java +182 -0
  294. data/src/toxi/physics3d/behaviors/ConstantForceBehavior3D.java +92 -0
  295. data/src/toxi/physics3d/behaviors/GravityBehavior3D.java +61 -0
  296. data/src/toxi/physics3d/behaviors/ParticleBehavior3D.java +52 -0
  297. data/src/toxi/physics3d/constraints/AxisConstraint.java +68 -0
  298. data/src/toxi/physics3d/constraints/BoxConstraint.java +121 -0
  299. data/src/toxi/physics3d/constraints/CylinderConstraint.java +87 -0
  300. data/src/toxi/physics3d/constraints/MaxConstraint.java +65 -0
  301. data/src/toxi/physics3d/constraints/MinConstraint.java +65 -0
  302. data/src/toxi/physics3d/constraints/ParticleConstraint3D.java +49 -0
  303. data/src/toxi/physics3d/constraints/PlaneConstraint.java +78 -0
  304. data/src/toxi/physics3d/constraints/SoftBoxConstraint.java +87 -0
  305. data/src/toxi/physics3d/constraints/SphereConstraint.java +108 -0
  306. data/src/toxi/processing/ArrowModifier.java +116 -0
  307. data/src/toxi/processing/DashedLineModifier.java +48 -0
  308. data/src/toxi/processing/DeltaOrientationMapper.java +57 -0
  309. data/src/toxi/processing/Line2DRenderModifier.java +18 -0
  310. data/src/toxi/processing/MeshToVBO.java +94 -0
  311. data/src/toxi/processing/NormalMapper.java +18 -0
  312. data/src/toxi/processing/POVInterface.java +121 -0
  313. data/src/toxi/processing/POVMesh.java +219 -0
  314. data/src/toxi/processing/POVWriter.java +460 -0
  315. data/src/toxi/processing/RCOpaque.java +77 -0
  316. data/src/toxi/processing/RCTransp.java +78 -0
  317. data/src/toxi/processing/TextureBuilder.java +232 -0
  318. data/src/toxi/processing/Textures.java +110 -0
  319. data/src/toxi/processing/ToxiclibsSupport.java +1239 -0
  320. data/src/toxi/processing/Tracing.java +25 -0
  321. data/src/toxi/processing/XYZNormalMapper.java +30 -0
  322. data/src/toxi/sim/automata/CAMatrix.java +297 -0
  323. data/src/toxi/sim/automata/CARule.java +76 -0
  324. data/src/toxi/sim/automata/CARule2D.java +354 -0
  325. data/src/toxi/sim/automata/CAWolfram1D.java +309 -0
  326. data/src/toxi/sim/automata/EvolvableMatrix.java +61 -0
  327. data/src/toxi/sim/automata/MatrixEvolver.java +42 -0
  328. data/src/toxi/sim/dla/BottomUpOrder.java +76 -0
  329. data/src/toxi/sim/dla/DLA.java +497 -0
  330. data/src/toxi/sim/dla/DLAConfiguration.java +364 -0
  331. data/src/toxi/sim/dla/DLAEventAdapter.java +64 -0
  332. data/src/toxi/sim/dla/DLAEventListener.java +57 -0
  333. data/src/toxi/sim/dla/DLAGuideLines.java +219 -0
  334. data/src/toxi/sim/dla/DLAParticle.java +102 -0
  335. data/src/toxi/sim/dla/DLASegment.java +88 -0
  336. data/src/toxi/sim/dla/PipelineOrder.java +50 -0
  337. data/src/toxi/sim/dla/RadialDistanceOrder.java +92 -0
  338. data/src/toxi/sim/erosion/ErosionFunction.java +122 -0
  339. data/src/toxi/sim/erosion/TalusAngleErosion.java +145 -0
  340. data/src/toxi/sim/erosion/ThermalErosion.java +75 -0
  341. data/src/toxi/sim/fluids/FluidSolver2D.java +762 -0
  342. data/src/toxi/sim/fluids/FluidSolver3D.java +326 -0
  343. data/src/toxi/sim/grayscott/GrayScott.java +469 -0
  344. data/src/toxi/util/DateUtils.java +141 -0
  345. data/src/toxi/util/FileSequenceDescriptor.java +181 -0
  346. data/src/toxi/util/FileUtils.java +467 -0
  347. data/src/toxi/util/datatypes/ArraySet.java +128 -0
  348. data/src/toxi/util/datatypes/ArrayUtil.java +404 -0
  349. data/src/toxi/util/datatypes/BiasedDoubleRange.java +141 -0
  350. data/src/toxi/util/datatypes/BiasedFloatRange.java +141 -0
  351. data/src/toxi/util/datatypes/BiasedIntegerRange.java +141 -0
  352. data/src/toxi/util/datatypes/DoubleRange.java +251 -0
  353. data/src/toxi/util/datatypes/FloatRange.java +251 -0
  354. data/src/toxi/util/datatypes/GenericSet.java +215 -0
  355. data/src/toxi/util/datatypes/IntegerRange.java +247 -0
  356. data/src/toxi/util/datatypes/IntegerSet.java +149 -0
  357. data/src/toxi/util/datatypes/ItemIndex.java +72 -0
  358. data/src/toxi/util/datatypes/SingletonRegistry.java +91 -0
  359. data/src/toxi/util/datatypes/TypedProperties.java +291 -0
  360. data/src/toxi/util/datatypes/UndirectedGraph.java +134 -0
  361. data/src/toxi/util/datatypes/UniqueItemIndex.java +223 -0
  362. data/src/toxi/util/datatypes/WeightedRandomEntry.java +76 -0
  363. data/src/toxi/util/datatypes/WeightedRandomSet.java +125 -0
  364. data/src/toxi/util/events/EventDispatcher.java +86 -0
  365. data/src/toxi/volume/AdditiveBrush.java +19 -0
  366. data/src/toxi/volume/ArrayIsoSurface.java +297 -0
  367. data/src/toxi/volume/BoxBrush.java +100 -0
  368. data/src/toxi/volume/BrushMode.java +16 -0
  369. data/src/toxi/volume/HashIsoSurface.java +354 -0
  370. data/src/toxi/volume/IsoSurface.java +59 -0
  371. data/src/toxi/volume/MarchingCubesIndex.java +312 -0
  372. data/src/toxi/volume/MeshLatticeBuilder.java +358 -0
  373. data/src/toxi/volume/MeshVoxelizer.java +216 -0
  374. data/src/toxi/volume/MultiplyBrush.java +20 -0
  375. data/src/toxi/volume/PeakBrush.java +21 -0
  376. data/src/toxi/volume/ReplaceBrush.java +19 -0
  377. data/src/toxi/volume/RoundBrush.java +113 -0
  378. data/src/toxi/volume/VolumetricBrush.java +160 -0
  379. data/src/toxi/volume/VolumetricHashMap.java +179 -0
  380. data/src/toxi/volume/VolumetricSpace.java +195 -0
  381. data/src/toxi/volume/VolumetricSpaceArray.java +214 -0
  382. data/toxiclibs.gemspec +34 -0
  383. metadata +424 -27
@@ -0,0 +1,1239 @@
1
+ /*
2
+ * __ .__ .__ ._____.
3
+ * _/ |_ _______ __|__| ____ | | |__\_ |__ ______
4
+ * \ __\/ _ \ \/ / |/ ___\| | | || __ \ / ___/
5
+ * | | ( <_> > <| \ \___| |_| || \_\ \\___ \
6
+ * |__| \____/__/\_ \__|\___ >____/__||___ /____ >
7
+ * \/ \/ \/ \/
8
+ *
9
+ * Copyright (c) 2006-2011 Karsten Schmidt
10
+ *
11
+ * This library is free software; you can redistribute it and/or
12
+ * modify it under the terms of the GNU Lesser General Public
13
+ * License as published by the Free Software Foundation; either
14
+ * version 2.1 of the License, or (at your option) any later version.
15
+ *
16
+ * http://creativecommons.org/licenses/LGPL/2.1/
17
+ *
18
+ * This library is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
+ * Lesser General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU Lesser General Public
24
+ * License along with this library; if not, write to the Free Software
25
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26
+ */
27
+
28
+ package toxi.processing;
29
+
30
+ import java.util.Iterator;
31
+ import java.util.List;
32
+ import java.util.logging.Level;
33
+ import java.util.logging.Logger;
34
+
35
+ import processing.core.PApplet;
36
+ import processing.core.PConstants;
37
+ import processing.core.PGraphics;
38
+ import processing.core.PImage;
39
+ import toxi.color.ReadonlyTColor;
40
+ import toxi.geom.AABB;
41
+ import toxi.geom.AxisAlignedCylinder;
42
+ import toxi.geom.Cone;
43
+ import toxi.geom.Ellipse;
44
+ import toxi.geom.Line2D;
45
+ import toxi.geom.Line3D;
46
+ import toxi.geom.LineStrip2D;
47
+ import toxi.geom.LineStrip3D;
48
+ import toxi.geom.Plane;
49
+ import toxi.geom.Polygon2D;
50
+ import toxi.geom.Ray2D;
51
+ import toxi.geom.Ray3D;
52
+ import toxi.geom.ReadonlyVec2D;
53
+ import toxi.geom.ReadonlyVec3D;
54
+ import toxi.geom.ReadonlyVec4D;
55
+ import toxi.geom.Rect;
56
+ import toxi.geom.Sphere;
57
+ import toxi.geom.Triangle2D;
58
+ import toxi.geom.Triangle3D;
59
+ import toxi.geom.Vec2D;
60
+ import toxi.geom.Vec3D;
61
+ import toxi.geom.Vec4D;
62
+ import toxi.geom.mesh.Mesh3D;
63
+
64
+ /**
65
+ * In addition to providing new drawing commands, this class provides wrappers
66
+ * for using datatypes of the toxiclibs core package directly with Processing's
67
+ * drawing commands. The class can be configured to work with any PGraphics
68
+ * instance (incl. offscreen buffers) using a constructor argument or the
69
+ * {@link #setGraphics(PGraphics)} method.
70
+ */
71
+ public class ToxiclibsSupport {
72
+
73
+ /**
74
+ *
75
+ */
76
+ protected static final Logger logger = Logger
77
+ .getLogger(ToxiclibsSupport.class.getName());
78
+
79
+ /**
80
+ *
81
+ */
82
+ protected PApplet app;
83
+
84
+ /**
85
+ *
86
+ */
87
+ protected PGraphics gfx;
88
+
89
+ /**
90
+ *
91
+ * @param app
92
+ */
93
+ public ToxiclibsSupport(PApplet app) {
94
+ this(app, app.g);
95
+ }
96
+
97
+ /**
98
+ *
99
+ * @param app
100
+ * @param gfx
101
+ */
102
+ public ToxiclibsSupport(PApplet app, PGraphics gfx) {
103
+ this.app = app;
104
+ this.gfx = gfx;
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @param box
110
+ */
111
+ public final void box(AABB box) {
112
+ mesh(box.toMesh(), false, 0);
113
+ }
114
+
115
+ /**
116
+ *
117
+ * @param box
118
+ * @param smooth
119
+ */
120
+ public final void box(AABB box, boolean smooth) {
121
+ Mesh3D mesh = box.toMesh();
122
+ if (smooth) {
123
+ mesh.computeVertexNormals();
124
+ }
125
+ mesh(mesh, smooth, 0);
126
+ }
127
+
128
+ /**
129
+ *
130
+ * @param isWireframe
131
+ * @param stroke
132
+ * @param fill
133
+ */
134
+ public final void chooseStrokeFill(boolean isWireframe,
135
+ ReadonlyTColor stroke, ReadonlyTColor fill) {
136
+ if (isWireframe) {
137
+ gfx.noFill();
138
+ gfx.stroke(stroke.toARGB());
139
+ } else {
140
+ gfx.noStroke();
141
+ gfx.fill(fill.toARGB());
142
+ }
143
+ }
144
+
145
+ /**
146
+ *
147
+ * @param p
148
+ * @param radius
149
+ */
150
+ public final void circle(Vec2D p, float radius) {
151
+ gfx.ellipse(p.x, p.y, radius, radius);
152
+ }
153
+
154
+ /**
155
+ *
156
+ * @param cone
157
+ */
158
+ public final void cone(Cone cone) {
159
+ mesh(cone.toMesh(null, 6, 0, true, true), false, 0);
160
+ }
161
+
162
+ /**
163
+ *
164
+ * @param cone
165
+ * @param topClosed
166
+ * @param bottomClosed
167
+ */
168
+ public final void cone(Cone cone, boolean topClosed, boolean bottomClosed) {
169
+ mesh(cone.toMesh(null, 6, 0, topClosed, bottomClosed), false, 0);
170
+ }
171
+
172
+ /**
173
+ *
174
+ * @param cone
175
+ * @param res
176
+ * @param smooth
177
+ */
178
+ public final void cone(Cone cone, int res, boolean smooth) {
179
+ cone(cone, res, true, true, smooth);
180
+ }
181
+
182
+ /**
183
+ *
184
+ * @param cone
185
+ * @param res
186
+ * @param topClosed
187
+ * @param bottomClosed
188
+ * @param smooth
189
+ */
190
+ public final void cone(Cone cone, int res, boolean topClosed,
191
+ boolean bottomClosed, boolean smooth) {
192
+ Mesh3D mesh = cone.toMesh(res);
193
+ if (smooth) {
194
+ mesh.computeVertexNormals();
195
+ }
196
+ mesh(mesh, smooth, 0);
197
+ }
198
+
199
+ /**
200
+ *
201
+ * @param cylinder
202
+ */
203
+ public final void cylinder(AxisAlignedCylinder cylinder) {
204
+ mesh(cylinder.toMesh(), false, 0);
205
+ }
206
+
207
+ /**
208
+ *
209
+ * @param cylinder
210
+ * @param res
211
+ * @param smooth
212
+ */
213
+ public final void cylinder(AxisAlignedCylinder cylinder, int res,
214
+ boolean smooth) {
215
+ Mesh3D mesh = cylinder.toMesh(res, 0);
216
+ if (smooth) {
217
+ mesh.computeVertexNormals();
218
+ }
219
+ mesh(mesh, smooth, 0);
220
+ }
221
+
222
+ /**
223
+ *
224
+ * @param e
225
+ */
226
+ public final void ellipse(Ellipse e) {
227
+ Vec2D r = e.getRadii();
228
+ switch (gfx.ellipseMode) {
229
+ case PConstants.CENTER:
230
+ gfx.ellipse(e.x, e.y, r.x * 2, r.y * 2);
231
+ break;
232
+ case PConstants.RADIUS:
233
+ gfx.ellipse(e.x, e.y, r.x, r.y);
234
+ break;
235
+ case PConstants.CORNER:
236
+ case PConstants.CORNERS:
237
+ gfx.ellipse(e.x - r.x, e.y - r.y, r.x * 2, r.y * 2);
238
+ break;
239
+ default:
240
+ logger.log(Level.WARNING, "invalid ellipse mode: {0}", gfx.ellipseMode);
241
+ }
242
+ }
243
+
244
+ /**
245
+ *
246
+ * @param col
247
+ */
248
+ public final void fill(ReadonlyTColor col) {
249
+ gfx.fill(col.toARGB());
250
+ }
251
+
252
+ /**
253
+ * @return the gfx
254
+ */
255
+ public final PGraphics getGraphics() {
256
+ return gfx;
257
+ }
258
+
259
+ /**
260
+ *
261
+ * @param line
262
+ */
263
+ public final void line(Line2D line) {
264
+ gfx.line(line.a.x, line.a.y, line.b.x, line.b.y);
265
+ }
266
+
267
+ /**
268
+ *
269
+ * @param l
270
+ * @param modifier
271
+ */
272
+ public final void line(Line2D l, Line2DRenderModifier modifier) {
273
+ modifier.apply(this, l.a, l.b);
274
+ }
275
+
276
+ /**
277
+ *
278
+ * @param line
279
+ */
280
+ public final void line(Line3D line) {
281
+ gfx.line(line.a.x, line.a.y, line.a.z, line.b.x, line.b.y, line.b.z);
282
+ }
283
+
284
+ /**
285
+ *
286
+ * @param a
287
+ * @param b
288
+ */
289
+ public final void line(ReadonlyVec2D a, ReadonlyVec2D b) {
290
+ gfx.line(a.x(), a.y(), b.x(), b.y());
291
+ }
292
+
293
+ /**
294
+ *
295
+ * @param a
296
+ * @param b
297
+ * @param modifier
298
+ */
299
+ public final void line(ReadonlyVec2D a, ReadonlyVec2D b,
300
+ Line2DRenderModifier modifier) {
301
+ modifier.apply(this, a, b);
302
+ }
303
+
304
+ /**
305
+ *
306
+ * @param a
307
+ * @param b
308
+ */
309
+ public final void line(ReadonlyVec3D a, ReadonlyVec3D b) {
310
+ gfx.line(a.x(), a.y(), a.z(), b.x(), b.y(), b.z());
311
+ }
312
+
313
+ /**
314
+ *
315
+ * @param a
316
+ * @param b
317
+ */
318
+ public final void line(ReadonlyVec4D a, ReadonlyVec4D b) {
319
+ gfx.line(a.x(), a.y(), a.z(), b.x(), b.y(), b.z());
320
+ }
321
+
322
+ /**
323
+ *
324
+ * @param a
325
+ * @param b
326
+ */
327
+ public final void line(Vec2D a, Vec2D b) {
328
+ gfx.line(a.x, a.y, b.x, b.y);
329
+ }
330
+
331
+ /**
332
+ *
333
+ * @param a
334
+ * @param b
335
+ */
336
+ public final void line(Vec3D a, Vec3D b) {
337
+ gfx.line(a.x, a.y, a.z, b.x, b.y, b.z);
338
+ }
339
+
340
+ /**
341
+ *
342
+ * @param a
343
+ * @param b
344
+ */
345
+ public final void line(Vec4D a, Vec4D b) {
346
+ gfx.line(a.x, a.y, a.z, b.x, b.y, b.z);
347
+ }
348
+
349
+ /**
350
+ *
351
+ * @param lines
352
+ */
353
+ public final void lines2D(List<? extends Line2D> lines) {
354
+ lines.stream().forEach((l) -> {
355
+ gfx.line(l.a.x, l.a.y, l.b.x, l.b.y);
356
+ });
357
+ }
358
+
359
+ /**
360
+ *
361
+ * @param lines
362
+ */
363
+ public final void lines3D(List<? extends Line3D> lines) {
364
+ lines.stream().forEach((l) -> {
365
+ gfx.line(l.a.x, l.a.y, l.a.z, l.b.x, l.b.y, l.b.z);
366
+ });
367
+ }
368
+
369
+ /**
370
+ *
371
+ * @param strip
372
+ */
373
+ public final void lineStrip2D(LineStrip2D strip) {
374
+ lineStrip2D(strip.getVertices());
375
+ }
376
+
377
+ /**
378
+ * Draws a 2D line strip using all points in the given list of vectors.
379
+ *
380
+ * @param points
381
+ * point list
382
+ */
383
+ public final void lineStrip2D(List<? extends Vec2D> points) {
384
+ boolean isFilled = gfx.fill;
385
+ gfx.fill = false;
386
+ processVertices2D(points.iterator(), PConstants.POLYGON, false);
387
+ gfx.fill = isFilled;
388
+ }
389
+
390
+ /**
391
+ *
392
+ * @param points
393
+ * @param scale
394
+ */
395
+ public final void lineStrip2D(List<? extends Vec2D> points, float scale) {
396
+ boolean isFilled = gfx.fill;
397
+ gfx.fill = false;
398
+ processVertices2D(points.iterator(), PConstants.POLYGON, false, scale);
399
+ gfx.fill = isFilled;
400
+ }
401
+
402
+ /**
403
+ *
404
+ * @param strip
405
+ */
406
+ public final void lineStrip3D(LineStrip3D strip) {
407
+ lineStrip3D(strip.getVertices());
408
+ }
409
+
410
+ /**
411
+ * Draws a 3D line strip using all points in the given list of vectors.
412
+ *
413
+ * @param points
414
+ * point list
415
+ */
416
+ public final void lineStrip3D(List<? extends Vec3D> points) {
417
+ boolean isFilled = gfx.fill;
418
+ gfx.fill = false;
419
+ processVertices3D(points.iterator(), PConstants.POLYGON, false);
420
+ gfx.fill = isFilled;
421
+ }
422
+
423
+ /**
424
+ *
425
+ * @param points
426
+ * @param scale
427
+ */
428
+ public final void lineStrip3D(List<? extends Vec3D> points, float scale) {
429
+ boolean isFilled = gfx.fill;
430
+ gfx.fill = false;
431
+ processVertices3D(points.iterator(), PConstants.POLYGON, false, scale);
432
+ gfx.fill = isFilled;
433
+ }
434
+
435
+ /**
436
+ * Draws a 3D line strip using all points in the given list of 4D vectors.
437
+ * The w component of the vectors is ignored.
438
+ *
439
+ * @param points
440
+ * point list
441
+ */
442
+ public final void lineStrip4D(List<? extends Vec4D> points) {
443
+ boolean isFilled = gfx.fill;
444
+ gfx.fill = false;
445
+ processVertices4D(points.iterator(), PConstants.POLYGON, false);
446
+ gfx.fill = isFilled;
447
+ }
448
+
449
+ /**
450
+ *
451
+ * @param points
452
+ * @param scale
453
+ */
454
+ public final void lineStrip4D(List<? extends Vec4D> points, float scale) {
455
+ boolean isFilled = gfx.fill;
456
+ gfx.fill = false;
457
+ processVertices4D(points.iterator(), PConstants.POLYGON, false, scale);
458
+ gfx.fill = isFilled;
459
+ }
460
+
461
+ /**
462
+ * Draws a mesh instance using flat shading.
463
+ *
464
+ * @param mesh
465
+ */
466
+ public final void mesh(Mesh3D mesh) {
467
+ mesh(mesh, false, 0);
468
+ }
469
+
470
+ /**
471
+ * Draws a mesh instance.
472
+ *
473
+ * @param mesh
474
+ * @param smooth
475
+ * true to enable Gouraud shading (uses vertex normals, which
476
+ * should have been computed beforehand) or false for flat
477
+ * shading
478
+ */
479
+ public final void mesh(Mesh3D mesh, boolean smooth) {
480
+ mesh(mesh, smooth, 0);
481
+ }
482
+
483
+ /**
484
+ * Draws a mesh instance.
485
+ *
486
+ * @param mesh
487
+ * @param smooth
488
+ * true to enable gouroud shading (uses vertex normals, which
489
+ * should have been computed beforehand) or false for flat
490
+ * shading
491
+ * @param normalLength
492
+ * if >0 then face (or vertex) normals are rendered at this
493
+ * length
494
+ */
495
+ public final void mesh(Mesh3D mesh, boolean smooth, float normalLength) {
496
+ gfx.beginShape(PConstants.TRIANGLES);
497
+ if (smooth) {
498
+ mesh.getFaces().stream().map((f) -> {
499
+ gfx.normal(f.a.normal.x, f.a.normal.y, f.a.normal.z);
500
+ return f;
501
+ }).map((f) -> {
502
+ gfx.vertex(f.a.x, f.a.y, f.a.z);
503
+ return f;
504
+ }).map((f) -> {
505
+ gfx.normal(f.b.normal.x, f.b.normal.y, f.b.normal.z);
506
+ return f;
507
+ }).map((f) -> {
508
+ gfx.vertex(f.b.x, f.b.y, f.b.z);
509
+ return f;
510
+ }).map((f) -> {
511
+ gfx.normal(f.c.normal.x, f.c.normal.y, f.c.normal.z);
512
+ return f;
513
+ }).forEach((f) -> {
514
+ gfx.vertex(f.c.x, f.c.y, f.c.z);
515
+ });
516
+ } else {
517
+ mesh.getFaces().stream().map((f) -> {
518
+ gfx.normal(f.normal.x, f.normal.y, f.normal.z);
519
+ return f;
520
+ }).map((f) -> {
521
+ gfx.vertex(f.a.x, f.a.y, f.a.z);
522
+ return f;
523
+ }).map((f) -> {
524
+ gfx.vertex(f.b.x, f.b.y, f.b.z);
525
+ return f;
526
+ }).forEach((f) -> {
527
+ gfx.vertex(f.c.x, f.c.y, f.c.z);
528
+ });
529
+ }
530
+ gfx.endShape();
531
+ if (normalLength > 0) {
532
+ int strokeCol = 0;
533
+ boolean isStroked = gfx.stroke;
534
+ if (isStroked) {
535
+ strokeCol = gfx.strokeColor;
536
+ }
537
+ if (smooth) {
538
+ mesh.getVertices().stream().forEach((v) -> {
539
+ Vec3D w = v.add(v.normal.scale(normalLength));
540
+ Vec3D n = v.normal.scale(127);
541
+ gfx.stroke(n.x + 128, n.y + 128, n.z + 128);
542
+ gfx.line(v.x, v.y, v.z, w.x, w.y, w.z);
543
+ });
544
+ } else {
545
+ float third = 1f / 3;
546
+ mesh.getFaces().stream().forEach((f) -> {
547
+ Vec3D c = f.a.add(f.b).addSelf(f.c).scaleSelf(third);
548
+ Vec3D d = c.add(f.normal.scale(normalLength));
549
+ Vec3D n = f.normal.scale(127);
550
+ gfx.stroke(n.x + 128, n.y + 128, n.z + 128);
551
+ gfx.line(c.x, c.y, c.z, d.x, d.y, d.z);
552
+ });
553
+ }
554
+ if (isStroked) {
555
+ gfx.stroke(strokeCol);
556
+ } else {
557
+ gfx.noStroke();
558
+ }
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Draws the given mesh with each face or vertex tinted using its related
564
+ * normal vector as RGB color. Normals can also optionally be shown as
565
+ * lines.
566
+ *
567
+ * @param mesh
568
+ * @param vertexNormals
569
+ * true, if using vertex normals (else face normals only)
570
+ */
571
+ public final void meshNormalMapped(Mesh3D mesh, boolean vertexNormals) {
572
+ meshNormalMapped(mesh, new XYZNormalMapper(), vertexNormals);
573
+ }
574
+
575
+ /**
576
+ *
577
+ * @param mesh
578
+ * @param mapper
579
+ * @param vertexNormals
580
+ */
581
+ public final void meshNormalMapped(Mesh3D mesh, NormalMapper mapper,
582
+ boolean vertexNormals) {
583
+ final boolean isWireframe = gfx.stroke;
584
+ gfx.beginShape(PConstants.TRIANGLES);
585
+ if (vertexNormals) {
586
+ mesh.getFaces().stream().map((f) -> {
587
+ setStrokeFill(isWireframe, mapper.getRGBForNormal(f.a.normal));
588
+ return f;
589
+ }).map((f) -> {
590
+ gfx.normal(f.a.normal.x, f.a.normal.y, f.a.normal.z);
591
+ return f;
592
+ }).map((f) -> {
593
+ gfx.vertex(f.a.x, f.a.y, f.a.z);
594
+ return f;
595
+ }).map((f) -> {
596
+ setStrokeFill(isWireframe, mapper.getRGBForNormal(f.b.normal));
597
+ return f;
598
+ }).map((f) -> {
599
+ gfx.normal(f.b.normal.x, f.b.normal.y, f.b.normal.z);
600
+ return f;
601
+ }).map((f) -> {
602
+ gfx.vertex(f.b.x, f.b.y, f.b.z);
603
+ return f;
604
+ }).map((f) -> {
605
+ setStrokeFill(isWireframe, mapper.getRGBForNormal(f.c.normal));
606
+ return f;
607
+ }).map((f) -> {
608
+ gfx.normal(f.c.normal.x, f.c.normal.y, f.c.normal.z);
609
+ return f;
610
+ }).forEach((f) -> {
611
+ gfx.vertex(f.c.x, f.c.y, f.c.z);
612
+ });
613
+ } else {
614
+ mesh.getFaces().stream().map((f) -> {
615
+ setStrokeFill(isWireframe, mapper.getRGBForNormal(f.normal));
616
+ return f;
617
+ }).map((f) -> {
618
+ gfx.normal(f.normal.x, f.normal.y, f.normal.z);
619
+ return f;
620
+ }).map((f) -> {
621
+ gfx.vertex(f.a.x, f.a.y, f.a.z);
622
+ return f;
623
+ }).map((f) -> {
624
+ gfx.vertex(f.b.x, f.b.y, f.b.z);
625
+ return f;
626
+ }).forEach((f) -> {
627
+ gfx.vertex(f.c.x, f.c.y, f.c.z);
628
+ });
629
+ }
630
+ gfx.endShape();
631
+ }
632
+
633
+ /**
634
+ *
635
+ * @param len
636
+ */
637
+ public void origin(float len) {
638
+ origin(Vec3D.ZERO, len);
639
+ }
640
+
641
+ /**
642
+ * Draws the major axes from the given point.
643
+ *
644
+ * @param o
645
+ * origin point
646
+ * @param len
647
+ * axis length
648
+ */
649
+ public final void origin(ReadonlyVec3D o, float len) {
650
+ final float x = o.x();
651
+ final float y = o.y();
652
+ final float z = o.z();
653
+ gfx.stroke(255, 0, 0);
654
+ gfx.line(x, y, z, x + len, y, z);
655
+ gfx.stroke(0, 255, 0);
656
+ gfx.line(x, y, z, x, y + len, z);
657
+ gfx.stroke(0, 0, 255);
658
+ gfx.line(x, y, z, x, y, z + len);
659
+ }
660
+
661
+ /**
662
+ * Draws a square section of a plane at the given size.
663
+ *
664
+ * @param plane
665
+ * plane to draw
666
+ * @param size
667
+ * edge length
668
+ */
669
+ public final void plane(Plane plane, float size) {
670
+ mesh(plane.toMesh(size), false, 0);
671
+ }
672
+
673
+ /**
674
+ *
675
+ * @param v
676
+ */
677
+ public final void point(ReadonlyVec2D v) {
678
+ gfx.point(v.x(), v.y());
679
+ }
680
+
681
+ /**
682
+ *
683
+ * @param v
684
+ */
685
+ public final void point(ReadonlyVec3D v) {
686
+ gfx.point(v.x(), v.y(), v.z());
687
+ }
688
+
689
+ /**
690
+ *
691
+ * @param v
692
+ */
693
+ public final void point(ReadonlyVec4D v) {
694
+ gfx.point(v.x(), v.y(), v.z());
695
+ }
696
+
697
+ /**
698
+ * Draws a 2D point at the given position.
699
+ *
700
+ * @param v
701
+ */
702
+ public final void point(Vec2D v) {
703
+ gfx.point(v.x, v.y);
704
+ }
705
+
706
+ /**
707
+ * Draws a 3D point at the given position.
708
+ *
709
+ * @param v
710
+ */
711
+ public final void point(Vec3D v) {
712
+ gfx.point(v.x, v.y, v.z);
713
+ }
714
+
715
+ /**
716
+ *
717
+ * @param v
718
+ */
719
+ public final void point(Vec4D v) {
720
+ gfx.point(v.x, v.y, v.z);
721
+ }
722
+
723
+ /**
724
+ *
725
+ * @param iterator
726
+ */
727
+ public final void points2D(Iterator<? extends Vec2D> iterator) {
728
+ processVertices2D(iterator, PConstants.POINTS, false);
729
+ }
730
+
731
+ /**
732
+ *
733
+ * @param points
734
+ */
735
+ public final void points2D(List<? extends Vec2D> points) {
736
+ processVertices2D(points.iterator(), PConstants.POINTS, false);
737
+ }
738
+
739
+ /**
740
+ *
741
+ * @param points
742
+ * @param scale
743
+ */
744
+ public final void points2D(List<? extends Vec2D> points, float scale) {
745
+ processVertices2D(points.iterator(), PConstants.POINTS, false, scale);
746
+ }
747
+
748
+ /**
749
+ *
750
+ * @param iterator
751
+ */
752
+ public final void points3D(Iterator<? extends Vec3D> iterator) {
753
+ processVertices3D(iterator, PConstants.POINTS, false);
754
+ }
755
+
756
+ /**
757
+ *
758
+ * @param points
759
+ */
760
+ public final void points3D(List<? extends Vec3D> points) {
761
+ processVertices3D(points.iterator(), PConstants.POINTS, false);
762
+ }
763
+
764
+ /**
765
+ *
766
+ * @param points
767
+ * @param scale
768
+ */
769
+ public final void points3D(List<? extends Vec3D> points, float scale) {
770
+ processVertices3D(points.iterator(), PConstants.POINTS, false, scale);
771
+ }
772
+
773
+ /**
774
+ *
775
+ * @param iterator
776
+ */
777
+ public final void points4D(Iterator<? extends Vec4D> iterator) {
778
+ processVertices4D(iterator, PConstants.POINTS, false);
779
+ }
780
+
781
+ /**
782
+ *
783
+ * @param points
784
+ */
785
+ public final void points4D(List<? extends Vec4D> points) {
786
+ processVertices4D(points.iterator(), PConstants.POINTS, false);
787
+ }
788
+
789
+ /**
790
+ *
791
+ * @param points
792
+ * @param scale
793
+ */
794
+ public final void points4D(List<? extends Vec4D> points, float scale) {
795
+ processVertices4D(points.iterator(), PConstants.POINTS, false, scale);
796
+ }
797
+
798
+ /**
799
+ *
800
+ * @param poly
801
+ */
802
+ public final void polygon2D(Polygon2D poly) {
803
+ processVertices2D(poly.vertices.iterator(), PConstants.POLYGON, true);
804
+ }
805
+
806
+ /**
807
+ *
808
+ * @param iterator
809
+ * @param shapeID
810
+ * @param closed
811
+ */
812
+ public final void processVertices2D(Iterator<? extends Vec2D> iterator,
813
+ int shapeID, boolean closed) {
814
+ gfx.beginShape(shapeID);
815
+ while (iterator.hasNext()) {
816
+ Vec2D v = iterator.next();
817
+ gfx.vertex(v.x, v.y);
818
+ }
819
+ if (closed) {
820
+ gfx.endShape(PConstants.CLOSE);
821
+ } else {
822
+ gfx.endShape();
823
+ }
824
+ }
825
+
826
+ /**
827
+ *
828
+ * @param iterator
829
+ * @param shapeID
830
+ * @param closed
831
+ * @param scale
832
+ */
833
+ public final void processVertices2D(Iterator<? extends Vec2D> iterator,
834
+ int shapeID, boolean closed, float scale) {
835
+ gfx.beginShape(shapeID);
836
+ while (iterator.hasNext()) {
837
+ Vec2D v = iterator.next();
838
+ gfx.vertex(v.x * scale, v.y * scale);
839
+ }
840
+ if (closed) {
841
+ gfx.endShape(PConstants.CLOSE);
842
+ } else {
843
+ gfx.endShape();
844
+ }
845
+ }
846
+
847
+ /**
848
+ *
849
+ * @param iterator
850
+ * @param shapeID
851
+ * @param closed
852
+ */
853
+ public final void processVertices3D(Iterator<? extends Vec3D> iterator,
854
+ int shapeID, boolean closed) {
855
+ gfx.beginShape(shapeID);
856
+ while (iterator.hasNext()) {
857
+ Vec3D v = iterator.next();
858
+ gfx.vertex(v.x, v.y, v.z);
859
+ }
860
+ if (closed) {
861
+ gfx.endShape(PConstants.CLOSE);
862
+ } else {
863
+ gfx.endShape();
864
+ }
865
+ }
866
+
867
+ /**
868
+ *
869
+ * @param iterator
870
+ * @param shapeID
871
+ * @param closed
872
+ * @param scale
873
+ */
874
+ public final void processVertices3D(Iterator<? extends Vec3D> iterator,
875
+ int shapeID, boolean closed, float scale) {
876
+ gfx.beginShape(shapeID);
877
+ while (iterator.hasNext()) {
878
+ Vec3D v = iterator.next();
879
+ gfx.vertex(v.x * scale, v.y * scale, v.z * scale);
880
+ }
881
+ if (closed) {
882
+ gfx.endShape(PConstants.CLOSE);
883
+ } else {
884
+ gfx.endShape();
885
+ }
886
+ }
887
+
888
+ /**
889
+ *
890
+ * @param iterator
891
+ * @param shapeID
892
+ * @param closed
893
+ */
894
+ public final void processVertices4D(Iterator<? extends Vec4D> iterator,
895
+ int shapeID, boolean closed) {
896
+ gfx.beginShape(shapeID);
897
+ while (iterator.hasNext()) {
898
+ Vec4D v = iterator.next();
899
+ gfx.vertex(v.x, v.y, v.z);
900
+ }
901
+ if (closed) {
902
+ gfx.endShape(PConstants.CLOSE);
903
+ } else {
904
+ gfx.endShape();
905
+ }
906
+ }
907
+
908
+ /**
909
+ *
910
+ * @param iterator
911
+ * @param shapeID
912
+ * @param closed
913
+ * @param scale
914
+ */
915
+ public final void processVertices4D(Iterator<? extends Vec4D> iterator,
916
+ int shapeID, boolean closed, float scale) {
917
+ gfx.beginShape(shapeID);
918
+ while (iterator.hasNext()) {
919
+ Vec4D v = iterator.next();
920
+ gfx.vertex(v.x * scale, v.y * scale, v.z * scale);
921
+ }
922
+ if (closed) {
923
+ gfx.endShape(PConstants.CLOSE);
924
+ } else {
925
+ gfx.endShape();
926
+ }
927
+ }
928
+
929
+ /**
930
+ *
931
+ * @param ray
932
+ * @param length
933
+ */
934
+ public final void ray(Ray2D ray, float length) {
935
+ Vec2D e = ray.getPointAtDistance(length);
936
+ gfx.line(ray.x, ray.y, e.x, e.y);
937
+ }
938
+
939
+ /**
940
+ *
941
+ * @param ray
942
+ * @param length
943
+ */
944
+ public final void ray(Ray3D ray, float length) {
945
+ Vec3D e = ray.getPointAtDistance(length);
946
+ gfx.line(ray.x, ray.y, ray.z, e.x, e.y, e.z);
947
+ }
948
+
949
+ /**
950
+ *
951
+ * @param r
952
+ */
953
+ public final void rect(Rect r) {
954
+ switch (gfx.rectMode) {
955
+ case PConstants.CORNER:
956
+ gfx.rect(r.x, r.y, r.width, r.height);
957
+ break;
958
+ case PConstants.CORNERS:
959
+ gfx.rect(r.x, r.y, r.x + r.width, r.y + r.height);
960
+ break;
961
+ case PConstants.CENTER:
962
+ gfx.rect(r.x + r.width * 0.5f, r.y + r.height * 0.5f, r.width,
963
+ r.height);
964
+ break;
965
+ case PConstants.RADIUS:
966
+ float rw = r.width * 0.5f;
967
+ float rh = r.height * 0.5f;
968
+ gfx.rect(r.x + rw, r.y + rh, rw, rh);
969
+ break;
970
+ default:
971
+ logger.log(Level.WARNING, "invalid rect mode: {0}", gfx.rectMode);
972
+ }
973
+ }
974
+
975
+ /**
976
+ *
977
+ * @param theta
978
+ * @param v
979
+ */
980
+ public final void rotate(float theta, ReadonlyVec3D v) {
981
+ gfx.rotate(theta, v.x(), v.y(), v.z());
982
+ }
983
+
984
+ /**
985
+ *
986
+ * @param v
987
+ */
988
+ public final void scale(ReadonlyVec2D v) {
989
+ gfx.scale(v.x(), v.y());
990
+ }
991
+
992
+ /**
993
+ *
994
+ * @param v
995
+ */
996
+ public final void scale(ReadonlyVec3D v) {
997
+ gfx.scale(v.x(), v.y(), v.z());
998
+ }
999
+
1000
+ /**
1001
+ *
1002
+ * @param v
1003
+ */
1004
+ public final void scale(Vec2D v) {
1005
+ gfx.scale(v.x, v.y);
1006
+ }
1007
+
1008
+ /**
1009
+ *
1010
+ * @param v
1011
+ */
1012
+ public final void scale(Vec3D v) {
1013
+ gfx.scale(v.x, v.y, v.z);
1014
+ }
1015
+
1016
+ /**
1017
+ * @param gfx
1018
+ * the gfx to set
1019
+ */
1020
+ public final void setGraphics(PGraphics gfx) {
1021
+ this.gfx = gfx;
1022
+ }
1023
+
1024
+ /**
1025
+ *
1026
+ * @param isWireframe
1027
+ * @param r
1028
+ * @param g
1029
+ * @param b
1030
+ */
1031
+ public final void setStrokeFill(final boolean isWireframe, final float r,
1032
+ final float g, final float b) {
1033
+ if (isWireframe) {
1034
+ gfx.fill(r, g, b);
1035
+ } else {
1036
+ gfx.stroke(r, g, b);
1037
+ }
1038
+ }
1039
+
1040
+ /**
1041
+ *
1042
+ * @param isWireframe
1043
+ * @param col
1044
+ */
1045
+ public final void setStrokeFill(final boolean isWireframe,
1046
+ final ReadonlyTColor col) {
1047
+ if (isWireframe) {
1048
+ gfx.stroke(col.toARGB());
1049
+ } else {
1050
+ gfx.fill(col.toARGB());
1051
+ }
1052
+ }
1053
+
1054
+ /**
1055
+ *
1056
+ * @param sphere
1057
+ * @param res
1058
+ */
1059
+ public final void sphere(Sphere sphere, int res) {
1060
+ mesh(sphere.toMesh(res));
1061
+ }
1062
+
1063
+ /**
1064
+ *
1065
+ * @param sphere
1066
+ * @param res
1067
+ * @param smooth
1068
+ */
1069
+ public final void sphere(Sphere sphere, int res, boolean smooth) {
1070
+ mesh(sphere.toMesh(res), smooth);
1071
+ }
1072
+
1073
+ /**
1074
+ *
1075
+ * @param col
1076
+ */
1077
+ public final void stroke(ReadonlyTColor col) {
1078
+ gfx.stroke(col.toARGB());
1079
+ }
1080
+
1081
+ /**
1082
+ *
1083
+ * @param mesh
1084
+ * @param tex
1085
+ * @param smooth
1086
+ */
1087
+ public final void texturedMesh(Mesh3D mesh, PImage tex, boolean smooth) {
1088
+ gfx.beginShape(PConstants.TRIANGLES);
1089
+ gfx.texture(tex);
1090
+ if (smooth) {
1091
+ mesh.getFaces().stream().forEach((f) -> {
1092
+ if (f.uvA != null && f.uvB != null && f.uvC != null) {
1093
+ gfx.normal(f.a.normal.x, f.a.normal.y, f.a.normal.z);
1094
+ gfx.vertex(f.a.x, f.a.y, f.a.z, f.uvA.x, f.uvA.y);
1095
+ gfx.normal(f.b.normal.x, f.b.normal.y, f.b.normal.z);
1096
+ gfx.vertex(f.b.x, f.b.y, f.b.z, f.uvB.x, f.uvB.y);
1097
+ gfx.normal(f.c.normal.x, f.c.normal.y, f.c.normal.z);
1098
+ gfx.vertex(f.c.x, f.c.y, f.c.z, f.uvC.x, f.uvC.y);
1099
+ } else {
1100
+ gfx.vertex(f.a.x, f.a.y, f.a.z);
1101
+ gfx.vertex(f.b.x, f.b.y, f.b.z);
1102
+ gfx.vertex(f.c.x, f.c.y, f.c.z);
1103
+ }
1104
+ });
1105
+ } else {
1106
+ mesh.getFaces().stream().map((f) -> {
1107
+ gfx.normal(f.normal.x, f.normal.y, f.normal.z);
1108
+ return f;
1109
+ }).forEach((f) -> {
1110
+ if (f.uvA != null && f.uvB != null && f.uvC != null) {
1111
+ gfx.vertex(f.a.x, f.a.y, f.a.z, f.uvA.x, f.uvA.y);
1112
+ gfx.vertex(f.b.x, f.b.y, f.b.z, f.uvB.x, f.uvB.y);
1113
+ gfx.vertex(f.c.x, f.c.y, f.c.z, f.uvC.x, f.uvC.y);
1114
+ } else {
1115
+ gfx.vertex(f.a.x, f.a.y, f.a.z);
1116
+ gfx.vertex(f.b.x, f.b.y, f.b.z);
1117
+ gfx.vertex(f.c.x, f.c.y, f.c.z);
1118
+ }
1119
+ });
1120
+ }
1121
+ gfx.endShape();
1122
+ }
1123
+
1124
+ /**
1125
+ *
1126
+ * @param v
1127
+ */
1128
+ public final void translate(ReadonlyVec2D v) {
1129
+ gfx.translate(v.x(), v.y());
1130
+ }
1131
+
1132
+ /**
1133
+ *
1134
+ * @param v
1135
+ */
1136
+ public final void translate(ReadonlyVec3D v) {
1137
+ gfx.translate(v.x(), v.y(), v.z());
1138
+ }
1139
+
1140
+ /**
1141
+ *
1142
+ * @param v
1143
+ */
1144
+ public final void translate(Vec2D v) {
1145
+ gfx.translate(v.x, v.y);
1146
+ }
1147
+
1148
+ /**
1149
+ *
1150
+ * @param v
1151
+ */
1152
+ public final void translate(Vec3D v) {
1153
+ gfx.translate(v.x, v.y, v.z);
1154
+ }
1155
+
1156
+ /**
1157
+ *
1158
+ * @param tri
1159
+ */
1160
+ public final void triangle(Triangle2D tri) {
1161
+ triangle(tri, true);
1162
+ }
1163
+
1164
+ /**
1165
+ *
1166
+ * @param tri
1167
+ * @param isFullShape
1168
+ */
1169
+ public final void triangle(Triangle2D tri, boolean isFullShape) {
1170
+ if (isFullShape) {
1171
+ gfx.beginShape(PConstants.TRIANGLES);
1172
+ }
1173
+ gfx.vertex(tri.a.x, tri.a.y);
1174
+ gfx.vertex(tri.b.x, tri.b.y);
1175
+ gfx.vertex(tri.c.x, tri.c.y);
1176
+ if (isFullShape) {
1177
+ gfx.endShape();
1178
+ }
1179
+ }
1180
+
1181
+ /**
1182
+ *
1183
+ * @param tri
1184
+ */
1185
+ public final void triangle(Triangle3D tri) {
1186
+ triangle(tri, true);
1187
+ }
1188
+
1189
+ /**
1190
+ *
1191
+ * @param tri
1192
+ * @param isFullShape
1193
+ */
1194
+ public final void triangle(Triangle3D tri, boolean isFullShape) {
1195
+ if (isFullShape) {
1196
+ gfx.beginShape(PConstants.TRIANGLES);
1197
+ }
1198
+ Vec3D n = tri.computeNormal();
1199
+ gfx.normal(n.x, n.y, n.z);
1200
+ gfx.vertex(tri.a.x, tri.a.y, tri.a.z);
1201
+ gfx.vertex(tri.b.x, tri.b.y, tri.b.z);
1202
+ gfx.vertex(tri.c.x, tri.c.y, tri.c.z);
1203
+ if (isFullShape) {
1204
+ gfx.endShape();
1205
+ }
1206
+ }
1207
+
1208
+ /**
1209
+ *
1210
+ * @param v
1211
+ */
1212
+ public final void vertex(ReadonlyVec2D v) {
1213
+ gfx.vertex(v.x(), v.y());
1214
+ }
1215
+
1216
+ /**
1217
+ *
1218
+ * @param v
1219
+ */
1220
+ public final void vertex(ReadonlyVec3D v) {
1221
+ gfx.vertex(v.x(), v.y(), v.z());
1222
+ }
1223
+
1224
+ /**
1225
+ *
1226
+ * @param v
1227
+ */
1228
+ public final void vertex(Vec2D v) {
1229
+ gfx.vertex(v.x, v.y);
1230
+ }
1231
+
1232
+ /**
1233
+ *
1234
+ * @param v
1235
+ */
1236
+ public final void vertex(Vec3D v) {
1237
+ gfx.vertex(v.x, v.y, v.z);
1238
+ }
1239
+ }