TurtleGL-3d 1.4.2__tar.gz → 1.5.1__tar.gz

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 (39) hide show
  1. {turtlegl_3d-1.4.2/src/TurtleGL_3d.egg-info → turtlegl_3d-1.5.1}/PKG-INFO +190 -9
  2. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/README.md +700 -519
  3. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/pyproject.toml +1 -1
  4. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/setup.py +1 -1
  5. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1/src/TurtleGL_3d.egg-info}/PKG-INFO +190 -9
  6. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/TurtleGL_3d.egg-info/SOURCES.txt +6 -1
  7. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/__init__.py +3 -1
  8. turtlegl_3d-1.5.1/src/turtleGL/example/black_hole_lowc.py +295 -0
  9. turtlegl_3d-1.5.1/src/turtleGL/example/block_world.py +695 -0
  10. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/example/christmas tree/turtleGL_christmas_tree_example.py +15 -0
  11. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/example/texture example/turtleGL_texture_example.py +15 -0
  12. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/example/turtleGL_anime_example.py +15 -0
  13. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/example/turtleGL_cabin_example.py +15 -0
  14. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/example/turtleGL_cube_example.py +15 -0
  15. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/example/turtleGL_focal_example.py +16 -2
  16. turtlegl_3d-1.5.1/src/turtleGL/example/turtleGL_force_example.py +64 -0
  17. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/example/turtleGL_from_file_example.py +17 -3
  18. turtlegl_3d-1.5.1/src/turtleGL/example/turtleGL_grating_example.py +88 -0
  19. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/example/turtleGL_obj_example.py +15 -0
  20. turtlegl_3d-1.5.1/src/turtleGL/example/turtleGL_plot3D_example.py +30 -0
  21. turtlegl_3d-1.5.1/src/turtleGL/example/turtleGL_relativity_example.py +76 -0
  22. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/example/turtleGL_volume_example.py +15 -0
  23. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/src/camera.py +284 -28
  24. turtlegl_3d-1.5.1/src/turtleGL/src/force.py +308 -0
  25. turtlegl_3d-1.5.1/src/turtleGL/src/raster.py +596 -0
  26. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/src/scene.py +3 -3
  27. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/src/volume.py +21 -0
  28. turtlegl_3d-1.4.2/src/turtleGL/example/turtleGL_grating_example.py +0 -29
  29. turtlegl_3d-1.4.2/src/turtleGL/example/turtleGL_light_example.py +0 -28
  30. turtlegl_3d-1.4.2/src/turtleGL/example/turtleGL_plot3D_example.py +0 -15
  31. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/LICENSE +0 -0
  32. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/setup.cfg +0 -0
  33. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/TurtleGL_3d.egg-info/dependency_links.txt +0 -0
  34. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/TurtleGL_3d.egg-info/requires.txt +0 -0
  35. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/TurtleGL_3d.egg-info/top_level.txt +0 -0
  36. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/example/airplane_game.py +0 -0
  37. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/example/racing_game.py +0 -0
  38. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/src/plot3d.py +0 -0
  39. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.1}/src/turtleGL/src/ray.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: TurtleGL-3d
3
- Version: 1.4.2
3
+ Version: 1.5.1
4
4
  Summary: A 3D grafics library based on turtle
5
5
  Home-page: https://github.com/MichaelHyan/turtleGL
6
6
  Author: Han Yan
@@ -243,6 +243,11 @@ An object-oriented, intuitive Python 3D graphics library based on the turtle lib
243
243
  - 🎬 **Image & Video Export** — OpenCV-based image export and video compositing.
244
244
  - 🔄 **Transform** — Spatial transformations: rotation, translation, scaling, etc.
245
245
  - 📊 **Depth Sorting** — Depth sorting algorithms for different projection modes.
246
+ - ⚡ **Ray-Traced Raster** — vectorized reverse ray-tracing backend with hard shadows; the legacy per-dot path is kept internal.
247
+ - 🌌 **Force Field & Relativity** — local light speed `c=c0/n(x)`, optical path time, Doppler / aberration / gravitational shift.
248
+ - ✂️ **Visibility Culling** — bulk back-face and frustum culling for non-raster drawing.
249
+ - 🧮 **Vectorized Projection** — cached camera matrix and batch `project_many`.
250
+ - 🌈 **Ray Bending** — null-geodesic / index-gradient curved rays, horizon & absorber masking, sky sampling on escape.
246
251
 
247
252
  ---
248
253
 
@@ -671,18 +676,168 @@ get_value(point1, point2, point3) # Compute combined shading value for a triang
671
676
 
672
677
  ---
673
678
 
674
- ## 🧪 Experimental: Rasterization
679
+ ## 🖥️ Raster Rendering (Reverse Ray Tracing)
675
680
 
676
- Raster algorithm is experimental and not yet stable.
681
+ The raster path is a vectorized reverse ray tracer. It no longer walks the turtle per pixel and does not require `scene.sort_*`; occlusion is resolved by ray–triangle intersection.
677
682
 
678
683
  ```python
679
- scene.triangulation() # Triangulate faces (raster mode only supports triangles)
680
- camera.grating_size = [500, 400] # Set rendering area size
681
- camera.show_grating_limit() # Show rendering area border
682
- camera.grating(face, ray) # Execute raster calculation
684
+ camera.image_size = [480, 360]
685
+ camera.rend = 1 # 0 material / 1 lighting + hard shadow / 2 normals
686
+ camera.tile = 32 # tile size (speed vs memory)
687
+ camera.ambient = 0.18 # ambient floor
688
+ camera.grating(scene.face, ray) # draw into the turtle canvas
689
+ camera.grating_cv2(scene.face, ray) # draw into camera.image (OpenCV)
683
690
  ```
684
691
 
685
- In rendering mode `rend=1`, raster mode uses the `ray` lighting object to compute light paths and shadows.
692
+ `grating` / `grating_cv2` accept optional positional or keyword arguments:
693
+
694
+ | Position | Keyword | Default | Meaning |
695
+ |----------|---------|---------|---------|
696
+ | 0 | `face` / `sce` | — | triangular face data |
697
+ | 1 | `ray` / `ray_object` | empty ray | light sources |
698
+ | 2 | `field` | `camera.field` | force field |
699
+ | 3 | `position` | unchanged | temporary camera position |
700
+
701
+ The same variable-argument convention applies to `draw_from_scene` / `draw_from_scene_cv2`.
702
+
703
+ ## 🌌 Force Field & Special Relativity
704
+
705
+ `force_field` defines a spatially varying index of refraction `n(x)`, so the local light speed is `c(x)=c0/n(x)`. It drives the gravitational/refractive shift `g=n_obs/n_emit`, the special-relativistic Doppler and aberration, and surface brightness `I ∝ g^3`.
706
+
707
+ ```python
708
+ ff = turtleGL.force_field(c0=1.0)
709
+ ff.add_sphere([0, 0, 0], 260, n_in=2.2, k=0.8)
710
+ ff.add_gradient([0, 0, -300], [0, 0, 1], n0=1.0, dn=0.003)
711
+ ff.add_plane([0, 0, 0], [0, 0, 1], n_in=1.5)
712
+
713
+ ff.relativity = True # master switch
714
+ ff.doppler = True # Doppler blue / red shift
715
+ ff.aberration = True # relativistic aberration
716
+ ff.gravity_shift = True # g = n_obs / n_emit
717
+ ff.intensity_shift = True # surface brightness ~ g^3
718
+
719
+ camera.field = ff
720
+ camera.velocity = [0, 0, 0.6] # camera speed as a fraction of c (turtle coords)
721
+ camera.grating(scene.face, ray, ff)
722
+ ```
723
+
724
+ ### Force Field Object
725
+
726
+ | Attribute | Default | Meaning |
727
+ |-----------|---------|---------|
728
+ | `c0` | `1.0` | global light-speed constant |
729
+ | `enabled` | `True` | enable / disable the field |
730
+ | `relativity` | `True` | master relativity switch |
731
+ | `doppler` | `True` | special-relativistic Doppler |
732
+ | `aberration` | `False` | relativistic aberration |
733
+ | `gravity_shift` | `True` | `g = n_obs / n_emit` |
734
+ | `intensity_shift` | `True` | surface brightness `I ∝ g^3` |
735
+ | `bend_geometry` | `False` | bend rays through the index gradient (slow) |
736
+
737
+ | Method | Meaning |
738
+ |--------|---------|
739
+ | `add_sphere(center, radius, n_in, k)` | Gaussian sphere field |
740
+ | `add_plane(point, normal, n_in)` | half-space step index |
741
+ | `add_gradient(origin, direction, n0, dn)` | linear index gradient |
742
+ | `clear()` | remove all regions |
743
+ | `index(P)` / `speed(P)` | evaluate `n` / `c` at points |
744
+ | `travel_time(p0, p1, samples)` | optical path time `T = ∫ n ds / c0` |
745
+ | `shift(n_obs, n_emit, beta, cos_theta)` | frequency ratio `g` |
746
+
747
+ ## 🌈 Ray Bending (Gravitational Lensing)
748
+
749
+ The raster backend can leave the straight-line path and integrate curved photons. Everything is driven by the force field; no extra renderer class is needed:
750
+
751
+ ```python
752
+ import turtleGL
753
+
754
+ ff = turtleGL.force_field(c0=1.0)
755
+ ff.add_black_hole([0, 0, 0], 1.0, capture_radius=2.05, escape_radius=90.0)
756
+ ff.add_sphere([0, 0, 0], 26.0, n_in=1.42, k=1.10) # refractive-index well
757
+ ff.bend_geometry = True # master switch for curved rays
758
+ ff.refraction = True # index-gradient bending
759
+ ff.absorb_black = True # horizon / absorbers are unobservable
760
+ ff.lens_escape = 90.0 # escape radius (None -> auto from scene scale)
761
+
762
+ camera.bg = '#000000'
763
+ camera.sky = sky_fn # f(dirs) -> (N, 3) rgb sampled on escape
764
+ camera.bend_step = 0.05 # step = bend_step x distance to nearest centre
765
+ camera.bend_steps = 420 # max integration steps per ray
766
+ camera.lens_exhaust = 'black' # 'black' unobservable / 'sky' treat as escaped
767
+
768
+ camera.create_image('#000000')
769
+ camera.grating_cv2(scene.face, None, ff)
770
+ print(camera.lens_stats) # hit / dark / sky / exhausted counters
771
+ ```
772
+
773
+ `bend_geometry` switches `render()` onto the lensed path (`raster._render_lensed`), where the whole frame is integrated per ray with RK4 — far more expensive than the straight path, so keep `bend_steps` and the image size modest.
774
+
775
+ ### Acceleration Model
776
+
777
+ `force_field.bend_accel(P, V)` returns the per-ray acceleration as the sum of two terms:
778
+
779
+ | Term | Formula | Applies to |
780
+ |------|---------|-----------|
781
+ | Null geodesic | `a = -3 M h^2 r / r^5`, with `h = norm(r x V)` | every `add_black_hole` region |
782
+ | Refraction | `d v_hat / ds = (grad n - (grad n . v_hat) v_hat) / n` | sphere / gradient regions (planes only change `n`) |
783
+
784
+ Light always bends toward the higher index, i.e. toward the slower local speed `c = c0 / n`.
785
+
786
+ ### Ray Termination
787
+
788
+ | Condition | Result |
789
+ |-----------|--------|
790
+ | the segment hits a scene triangle | shaded with the normal raster rules |
791
+ | inside a capture radius or an absorber | black (`absorb_black`) |
792
+ | beyond `lens_escape` | `camera.sky(dirs)` |
793
+ | `bend_steps` exhausted | `camera.lens_exhaust`: `'black'` (default) or `'sky'` |
794
+
795
+ `camera.lens_stats` reports how many rays ended in each state — handy for tuning `bend_step` / `bend_steps`.
796
+
797
+ ### Bending Members
798
+
799
+ | Member | Default | Meaning |
800
+ |--------|---------|---------|
801
+ | `bend_geometry` | `False` | enable curved rays in the raster backend |
802
+ | `refraction` | `True` | index-gradient term inside `bend_accel` |
803
+ | `absorb_black` | `True` | horizons / absorbers render pure black |
804
+ | `lens_escape` | `None` | global escape radius, `None` -> `16 x scene radius` |
805
+
806
+ | Method | Meaning |
807
+ |--------|---------|
808
+ | `add_black_hole(center, mass, capture_radius=None, escape_radius=None)` | add a Schwarzschild region, capture radius defaults to `2M` |
809
+ | `add_absorber(center, radius)` | opaque ball: rays entering it are lost |
810
+ | `bend_accel(P, V)` | total acceleration (geodesic + refraction) |
811
+ | `photon_accel(P, V)` / `photon_accel_h(P, h2)` | geodesic term only, `h^2` can be cached |
812
+ | `captured(P)` | mask of points inside a horizon / absorber |
813
+ | `step_hint(P)` | distance to the nearest field centre, for adaptive steps |
814
+ | `lens_regions()` / `absorb_regions()` / `refract_regions()` / `has_lens()` | region queries |
815
+
816
+ > Coordinates: the raster backend works in `(x, z, y)`, so `bend_accel` / `captured` receive points in that order. `camera.sky(dirs)` uses the same layout.
817
+
818
+ ### Camera Additions
819
+
820
+ | Attribute | Default | Meaning |
821
+ |-----------|---------|---------|
822
+ | `bg` | `None` | background colour (`'#RRGGBB'` or RGB), `None` -> white |
823
+ | `sky` | `None` | `f(dirs) -> (N,3)` background sampled by escaping rays |
824
+ | `bend_step` | `0.05` | adaptive step ratio |
825
+ | `bend_steps` | `700` | max integration steps per ray |
826
+ | `lens_exhaust` | `'black'` | step-budget-exhausted policy |
827
+ | `lens_stats` | `{}` | stats of the last bent render |
828
+
829
+ ## ✂️ Visibility Culling
830
+
831
+ `draw_from_scene` / `draw_from_scene_cv2` filter invisible elements in bulk before drawing:
832
+
833
+ ```python
834
+ camera.cull = True # master switch
835
+ camera.cull_backface = True # drop back-facing faces
836
+ camera.cull_frustum = True # drop faces / lines entirely off-screen
837
+ camera.cull_margin = 4.0 # off-screen margin in pixels
838
+ ```
839
+
840
+ Batch projection: `camera.project_many(vertices) -> (uv, visible)`.
686
841
 
687
842
  ---
688
843
 
@@ -725,7 +880,9 @@ turtleGL-3d/
725
880
  │ ├── scene.py # Scene object
726
881
  │ ├── plot3d.py # 3D function plot object
727
882
  │ ├── ray.py # Lighting object
728
- │ └── volume.py # Volume calculation object
883
+ │ ├── volume.py # Volume calculation object
884
+ │ ├── force.py # Force field / relativity
885
+ │ └── raster.py # Ray-tracing raster backend
729
886
  └── example/
730
887
  ```
731
888
 
@@ -737,6 +894,30 @@ This project is licensed under the Apache License 2.0 — see the [LICENSE](LICE
737
894
 
738
895
  ---
739
896
 
897
+ ## 🧩 Examples
898
+
899
+ One example per feature, under `src/turtleGL/example/` (copies in the repo root for quick runs):
900
+
901
+ | File | Feature |
902
+ |------|---------|
903
+ | `turtleGL_focal_example.py` | Perspective projection basics |
904
+ | `turtleGL_cabin_example.py` | Cabinet projection |
905
+ | `turtleGL_anime_example.py` | Rotation animation |
906
+ | `turtleGL_obj_example.py` | OBJ import + animation |
907
+ | `turtleGL_from_file_example.py` | CSV line/face import & export |
908
+ | `turtleGL_plot3D_example.py` | 3D function surface |
909
+ | `turtleGL_volume_example.py` | Volume sampling |
910
+ | `turtleGL_grating_example.py` | Raster (reverse ray tracing) |
911
+ | `turtleGL_force_example.py` | Force field |
912
+ | `turtleGL_relativity_example.py` | Special relativity |
913
+ | `black_hole_lowc.py` | Low-speed-of-light black hole (standalone geodesics) |
914
+ | `black_hole_geodesic.py` / `black_hole_fields.py` | Ray-bent black hole via the library (repo root) |
915
+ | `ring_flyer.py` | Ray-traced tunnel runner (repo root) |
916
+ | `turtleGL_cube_example.py` | Rubik's cube (interaction) |
917
+ | `christmas tree/` | Complex OBJ scene |
918
+ | `texture example/` | Texture mapping |
919
+ | `airplane_game.py` / `racing_game.py` | Playable demos |
920
+
740
921
  ## 🔗 Links
741
922
 
742
923
  - **Homepage**: [https://github.com/MichaelHyan/turtleGL](https://github.com/MichaelHyan/turtleGL)