TurtleGL-3d 1.4.2__tar.gz → 1.5.0__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 (50) hide show
  1. turtlegl_3d-1.5.0/MANIFEST.in +10 -0
  2. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/PKG-INFO +106 -218
  3. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/README.md +103 -8
  4. turtlegl_3d-1.5.0/README_zh.md +615 -0
  5. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/pyproject.toml +16 -7
  6. turtlegl_3d-1.5.0/setup.py +6 -0
  7. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/TurtleGL_3d.egg-info/PKG-INFO +106 -218
  8. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/TurtleGL_3d.egg-info/SOURCES.txt +16 -1
  9. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/TurtleGL_3d.egg-info/requires.txt +1 -0
  10. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/__init__.py +3 -1
  11. turtlegl_3d-1.5.0/src/turtleGL/example/christmas tree/tree.obj +2980 -0
  12. turtlegl_3d-1.5.0/src/turtleGL/example/christmas tree/tree1.obj +920 -0
  13. turtlegl_3d-1.5.0/src/turtleGL/example/christmas tree/tree2.obj +700 -0
  14. turtlegl_3d-1.5.0/src/turtleGL/example/christmas tree/tree3.obj +700 -0
  15. turtlegl_3d-1.5.0/src/turtleGL/example/christmas tree/tree4.obj +58 -0
  16. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/example/christmas tree/turtleGL_christmas_tree_example.py +15 -0
  17. turtlegl_3d-1.5.0/src/turtleGL/example/monkey.obj +2067 -0
  18. turtlegl_3d-1.5.0/src/turtleGL/example/test.obj +362 -0
  19. turtlegl_3d-1.5.0/src/turtleGL/example/texture example/grass_bottom.png +0 -0
  20. turtlegl_3d-1.5.0/src/turtleGL/example/texture example/grass_side.png +0 -0
  21. turtlegl_3d-1.5.0/src/turtleGL/example/texture example/grass_up.png +0 -0
  22. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/example/texture example/turtleGL_texture_example.py +15 -0
  23. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/example/turtleGL_anime_example.py +15 -0
  24. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/example/turtleGL_cabin_example.py +15 -0
  25. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/example/turtleGL_cube_example.py +15 -0
  26. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/example/turtleGL_focal_example.py +16 -2
  27. turtlegl_3d-1.5.0/src/turtleGL/example/turtleGL_force_example.py +64 -0
  28. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/example/turtleGL_from_file_example.py +17 -3
  29. turtlegl_3d-1.5.0/src/turtleGL/example/turtleGL_grating_example.py +88 -0
  30. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/example/turtleGL_obj_example.py +15 -0
  31. turtlegl_3d-1.5.0/src/turtleGL/example/turtleGL_plot3D_example.py +30 -0
  32. turtlegl_3d-1.5.0/src/turtleGL/example/turtleGL_relativity_example.py +76 -0
  33. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/example/turtleGL_volume_example.py +15 -0
  34. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/src/camera.py +278 -28
  35. turtlegl_3d-1.5.0/src/turtleGL/src/force.py +146 -0
  36. turtlegl_3d-1.5.0/src/turtleGL/src/raster.py +350 -0
  37. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/src/scene.py +3 -3
  38. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/src/volume.py +21 -0
  39. turtlegl_3d-1.4.2/setup.py +0 -26
  40. turtlegl_3d-1.4.2/src/turtleGL/example/turtleGL_grating_example.py +0 -29
  41. turtlegl_3d-1.4.2/src/turtleGL/example/turtleGL_light_example.py +0 -28
  42. turtlegl_3d-1.4.2/src/turtleGL/example/turtleGL_plot3D_example.py +0 -15
  43. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/LICENSE +0 -0
  44. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/setup.cfg +0 -0
  45. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/TurtleGL_3d.egg-info/dependency_links.txt +0 -0
  46. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/TurtleGL_3d.egg-info/top_level.txt +0 -0
  47. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/example/airplane_game.py +0 -0
  48. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/example/racing_game.py +0 -0
  49. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/src/plot3d.py +0 -0
  50. {turtlegl_3d-1.4.2 → turtlegl_3d-1.5.0}/src/turtleGL/src/ray.py +0 -0
@@ -0,0 +1,10 @@
1
+ include LICENSE
2
+ include README.md
3
+ include README_zh.md
4
+
5
+ # 模型与贴图需要随包分发;视频/其他演示素材不打包
6
+ recursive-include src/turtleGL/example *.obj
7
+ recursive-include src/turtleGL/example *.png
8
+
9
+ global-exclude *.py[cod]
10
+ global-exclude __pycache__
@@ -1,226 +1,19 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: TurtleGL-3d
3
- Version: 1.4.2
3
+ Version: 1.5.0
4
4
  Summary: A 3D grafics library based on turtle
5
- Home-page: https://github.com/MichaelHyan/turtleGL
6
- Author: Han Yan
7
5
  Author-email: Han Yan <3367461801@qq.com>
8
- License:
9
- Apache License
10
- Version 2.0, January 2004
11
- http://www.apache.org/licenses/
12
-
13
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
14
-
15
- 1. Definitions.
16
-
17
- "License" shall mean the terms and conditions for use, reproduction,
18
- and distribution as defined by Sections 1 through 9 of this document.
19
-
20
- "Licensor" shall mean the copyright owner or entity authorized by
21
- the copyright owner that is granting the License.
22
-
23
- "Legal Entity" shall mean the union of the acting entity and all
24
- other entities that control, are controlled by, or are under common
25
- control with that entity. For the purposes of this definition,
26
- "control" means (i) the power, direct or indirect, to cause the
27
- direction or management of such entity, whether by contract or
28
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
29
- outstanding shares, or (iii) beneficial ownership of such entity.
30
-
31
- "You" (or "Your") shall mean an individual or Legal Entity
32
- exercising permissions granted by this License.
33
-
34
- "Source" form shall mean the preferred form for making modifications,
35
- including but not limited to software source code, documentation
36
- source, and configuration files.
37
-
38
- "Object" form shall mean any form resulting from mechanical
39
- transformation or translation of a Source form, including but
40
- not limited to compiled object code, generated documentation,
41
- and conversions to other media types.
42
-
43
- "Work" shall mean the work of authorship, whether in Source or
44
- Object form, made available under the License, as indicated by a
45
- copyright notice that is included in or attached to the work
46
- (an example is provided in the Appendix below).
47
-
48
- "Derivative Works" shall mean any work, whether in Source or Object
49
- form, that is based on (or derived from) the Work and for which the
50
- editorial revisions, annotations, elaborations, or other modifications
51
- represent, as a whole, an original work of authorship. For the purposes
52
- of this License, Derivative Works shall not include works that remain
53
- separable from, or merely link (or bind by name) to the interfaces of,
54
- the Work and Derivative Works thereof.
55
-
56
- "Contribution" shall mean any work of authorship, including
57
- the original version of the Work and any modifications or additions
58
- to that Work or Derivative Works thereof, that is intentionally
59
- submitted to Licensor for inclusion in the Work by the copyright owner
60
- or by an individual or Legal Entity authorized to submit on behalf of
61
- the copyright owner. For the purposes of this definition, "submitted"
62
- means any form of electronic, verbal, or written communication sent
63
- to the Licensor or its representatives, including but not limited to
64
- communication on electronic mailing lists, source code control systems,
65
- and issue tracking systems that are managed by, or on behalf of, the
66
- Licensor for the purpose of discussing and improving the Work, but
67
- excluding communication that is conspicuously marked or otherwise
68
- designated in writing by the copyright owner as "Not a Contribution."
69
-
70
- "Contributor" shall mean Licensor and any individual or Legal Entity
71
- on behalf of whom a Contribution has been received by Licensor and
72
- subsequently incorporated within the Work.
73
-
74
- 2. Grant of Copyright License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- copyright license to reproduce, prepare Derivative Works of,
78
- publicly display, publicly perform, sublicense, and distribute the
79
- Work and such Derivative Works in Source or Object form.
80
-
81
- 3. Grant of Patent License. Subject to the terms and conditions of
82
- this License, each Contributor hereby grants to You a perpetual,
83
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
84
- (except as stated in this section) patent license to make, have made,
85
- use, offer to sell, sell, import, and otherwise transfer the Work,
86
- where such license applies only to those patent claims licensable
87
- by such Contributor that are necessarily infringed by their
88
- Contribution(s) alone or by combination of their Contribution(s)
89
- with the Work to which such Contribution(s) was submitted. If You
90
- institute patent litigation against any entity (including a
91
- cross-claim or counterclaim in a lawsuit) alleging that the Work
92
- or a Contribution incorporated within the Work constitutes direct
93
- or contributory patent infringement, then any patent licenses
94
- granted to You under this License for that Work shall terminate
95
- as of the date such litigation is filed.
96
-
97
- 4. Redistribution. You may reproduce and distribute copies of the
98
- Work or Derivative Works thereof in any medium, with or without
99
- modifications, and in Source or Object form, provided that You
100
- meet the following conditions:
101
-
102
- (a) You must give any other recipients of the Work or
103
- Derivative Works a copy of this License; and
104
-
105
- (b) You must cause any modified files to carry prominent notices
106
- stating that You changed the files; and
107
-
108
- (c) You must retain, in the Source form of any Derivative Works
109
- that You distribute, all copyright, patent, trademark, and
110
- attribution notices from the Source form of the Work,
111
- excluding those notices that do not pertain to any part of
112
- the Derivative Works; and
113
-
114
- (d) If the Work includes a "NOTICE" text file as part of its
115
- distribution, then any Derivative Works that You distribute must
116
- include a readable copy of the attribution notices contained
117
- within such NOTICE file, excluding those notices that do not
118
- pertain to any part of the Derivative Works, in at least one
119
- of the following places: within a NOTICE text file distributed
120
- as part of the Derivative Works; within the Source form or
121
- documentation, if provided along with the Derivative Works; or,
122
- within a display generated by the Derivative Works, if and
123
- wherever such third-party notices normally appear. The contents
124
- of the NOTICE file are for informational purposes only and
125
- do not modify the License. You may add Your own attribution
126
- notices within Derivative Works that You distribute, alongside
127
- or as an addendum to the NOTICE text from the Work, provided
128
- that such additional attribution notices cannot be construed
129
- as modifying the License.
130
-
131
- You may add Your own copyright statement to Your modifications and
132
- may provide additional or different license terms and conditions
133
- for use, reproduction, or distribution of Your modifications, or
134
- for any such Derivative Works as a whole, provided Your use,
135
- reproduction, and distribution of the Work otherwise complies with
136
- the conditions stated in this License.
137
-
138
- 5. Submission of Contributions. Unless You explicitly state otherwise,
139
- any Contribution intentionally submitted for inclusion in the Work
140
- by You to the Licensor shall be under the terms and conditions of
141
- this License, without any additional terms or conditions.
142
- Notwithstanding the above, nothing herein shall supersede or modify
143
- the terms of any separate license agreement you may have executed
144
- with Licensor regarding such Contributions.
145
-
146
- 6. Trademarks. This License does not grant permission to use the trade
147
- names, trademarks, service marks, or product names of the Licensor,
148
- except as required for reasonable and customary use in describing the
149
- origin of the Work and reproducing the content of the NOTICE file.
150
-
151
- 7. Disclaimer of Warranty. Unless required by applicable law or
152
- agreed to in writing, Licensor provides the Work (and each
153
- Contributor provides its Contributions) on an "AS IS" BASIS,
154
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
155
- implied, including, without limitation, any warranties or conditions
156
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
157
- PARTICULAR PURPOSE. You are solely responsible for determining the
158
- appropriateness of using or redistributing the Work and assume any
159
- risks associated with Your exercise of permissions under this License.
160
-
161
- 8. Limitation of Liability. In no event and under no legal theory,
162
- whether in tort (including negligence), contract, or otherwise,
163
- unless required by applicable law (such as deliberate and grossly
164
- negligent acts) or agreed to in writing, shall any Contributor be
165
- liable to You for damages, including any direct, indirect, special,
166
- incidental, or consequential damages of any character arising as a
167
- result of this License or out of the use or inability to use the
168
- Work (including but not limited to damages for loss of goodwill,
169
- work stoppage, computer failure or malfunction, or any and all
170
- other commercial damages or losses), even if such Contributor
171
- has been advised of the possibility of such damages.
172
-
173
- 9. Accepting Warranty or Additional Liability. While redistributing
174
- the Work or Derivative Works thereof, You may choose to offer,
175
- and charge a fee for, acceptance of support, warranty, indemnity,
176
- or other liability obligations and/or rights consistent with this
177
- License. However, in accepting such obligations, You may act only
178
- on Your own behalf and on Your sole responsibility, not on behalf
179
- of any other Contributor, and only if You agree to indemnify,
180
- defend, and hold each Contributor harmless for any liability
181
- incurred by, or claims asserted against, such Contributor by reason
182
- of your accepting any such warranty or additional liability.
183
-
184
- END OF TERMS AND CONDITIONS
185
-
186
- APPENDIX: How to apply the Apache License to your work.
187
-
188
- To apply the Apache License to your work, attach the following
189
- boilerplate notice, with the fields enclosed by brackets "[]"
190
- replaced with your own identifying information. (Don't include
191
- the brackets!) The text should be enclosed in the appropriate
192
- comment syntax for the file format. We also recommend that a
193
- file or class name and description of purpose be included on the
194
- same "printed page" as the copyright notice for easier
195
- identification within third-party archives.
196
-
197
- Copyright [yyyy] [name of copyright owner]
198
-
199
- Licensed under the Apache License, Version 2.0 (the "License");
200
- you may not use this file except in compliance with the License.
201
- You may obtain a copy of the License at
202
-
203
- http://www.apache.org/licenses/LICENSE-2.0
204
-
205
- Unless required by applicable law or agreed to in writing, software
206
- distributed under the License is distributed on an "AS IS" BASIS,
207
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
208
- See the License for the specific language governing permissions and
209
- limitations under the License.
210
-
6
+ License-Expression: Apache-2.0
211
7
  Project-URL: Homepage, https://github.com/MichaelHyan/turtleGL
212
8
  Classifier: Programming Language :: Python :: 3
213
- Classifier: License :: OSI Approved :: MIT License
214
9
  Classifier: Operating System :: OS Independent
215
10
  Requires-Python: >=3.8
216
11
  Description-Content-Type: text/markdown
217
12
  License-File: LICENSE
218
13
  Requires-Dist: numpy>=1.24.4
219
14
  Requires-Dist: opencv-python>=4.12.0
220
- Dynamic: author
221
- Dynamic: home-page
15
+ Requires-Dist: Pillow>=9.0.0
222
16
  Dynamic: license-file
223
- Dynamic: requires-python
224
17
 
225
18
  # 🐢 TurtleGL-3d
226
19
 
@@ -243,6 +36,10 @@ An object-oriented, intuitive Python 3D graphics library based on the turtle lib
243
36
  - 🎬 **Image & Video Export** — OpenCV-based image export and video compositing.
244
37
  - 🔄 **Transform** — Spatial transformations: rotation, translation, scaling, etc.
245
38
  - 📊 **Depth Sorting** — Depth sorting algorithms for different projection modes.
39
+ - ⚡ **Ray-Traced Raster** — vectorized reverse ray-tracing backend with hard shadows; the legacy per-dot path is kept internal.
40
+ - 🌌 **Force Field & Relativity** — local light speed `c=c0/n(x)`, optical path time, Doppler / aberration / gravitational shift.
41
+ - ✂️ **Visibility Culling** — bulk back-face and frustum culling for non-raster drawing.
42
+ - 🧮 **Vectorized Projection** — cached camera matrix and batch `project_many`.
246
43
 
247
44
  ---
248
45
 
@@ -671,18 +468,86 @@ get_value(point1, point2, point3) # Compute combined shading value for a triang
671
468
 
672
469
  ---
673
470
 
674
- ## 🧪 Experimental: Rasterization
471
+ ## 🖥️ Raster Rendering (Reverse Ray Tracing)
675
472
 
676
- Raster algorithm is experimental and not yet stable.
473
+ 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
474
 
678
475
  ```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
476
+ camera.image_size = [480, 360]
477
+ camera.rend = 1 # 0 material / 1 lighting + hard shadow / 2 normals
478
+ camera.tile = 32 # tile size (speed vs memory)
479
+ camera.ambient = 0.18 # ambient floor
480
+ camera.grating(scene.face, ray) # draw into the turtle canvas
481
+ camera.grating_cv2(scene.face, ray) # draw into camera.image (OpenCV)
683
482
  ```
684
483
 
685
- In rendering mode `rend=1`, raster mode uses the `ray` lighting object to compute light paths and shadows.
484
+ `grating` / `grating_cv2` accept optional positional or keyword arguments:
485
+
486
+ | Position | Keyword | Default | Meaning |
487
+ |----------|---------|---------|---------|
488
+ | 0 | `face` / `sce` | — | triangular face data |
489
+ | 1 | `ray` / `ray_object` | empty ray | light sources |
490
+ | 2 | `field` | `camera.field` | force field |
491
+ | 3 | `position` | unchanged | temporary camera position |
492
+
493
+ The same variable-argument convention applies to `draw_from_scene` / `draw_from_scene_cv2`.
494
+
495
+ ## 🌌 Force Field & Special Relativity
496
+
497
+ `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`.
498
+
499
+ ```python
500
+ ff = turtleGL.force_field(c0=1.0)
501
+ ff.add_sphere([0, 0, 0], 260, n_in=2.2, k=0.8)
502
+ ff.add_gradient([0, 0, -300], [0, 0, 1], n0=1.0, dn=0.003)
503
+ ff.add_plane([0, 0, 0], [0, 0, 1], n_in=1.5)
504
+
505
+ ff.relativity = True # master switch
506
+ ff.doppler = True # Doppler blue / red shift
507
+ ff.aberration = True # relativistic aberration
508
+ ff.gravity_shift = True # g = n_obs / n_emit
509
+ ff.intensity_shift = True # surface brightness ~ g^3
510
+
511
+ camera.field = ff
512
+ camera.velocity = [0, 0, 0.6] # camera speed as a fraction of c (turtle coords)
513
+ camera.grating(scene.face, ray, ff)
514
+ ```
515
+
516
+ ### Force Field Object
517
+
518
+ | Attribute | Default | Meaning |
519
+ |-----------|---------|---------|
520
+ | `c0` | `1.0` | global light-speed constant |
521
+ | `enabled` | `True` | enable / disable the field |
522
+ | `relativity` | `True` | master relativity switch |
523
+ | `doppler` | `True` | special-relativistic Doppler |
524
+ | `aberration` | `False` | relativistic aberration |
525
+ | `gravity_shift` | `True` | `g = n_obs / n_emit` |
526
+ | `intensity_shift` | `True` | surface brightness `I ∝ g^3` |
527
+ | `bend_geometry` | `False` | bend rays through the index gradient (slow) |
528
+
529
+ | Method | Meaning |
530
+ |--------|---------|
531
+ | `add_sphere(center, radius, n_in, k)` | Gaussian sphere field |
532
+ | `add_plane(point, normal, n_in)` | half-space step index |
533
+ | `add_gradient(origin, direction, n0, dn)` | linear index gradient |
534
+ | `clear()` | remove all regions |
535
+ | `index(P)` / `speed(P)` | evaluate `n` / `c` at points |
536
+ | `travel_time(p0, p1, samples)` | optical path time `T = ∫ n ds / c0` |
537
+ | `shift(n_obs, n_emit, beta, cos_theta)` | frequency ratio `g` |
538
+
539
+ ## ✂️ Visibility Culling
540
+
541
+ `draw_from_scene` / `draw_from_scene_cv2` filter invisible elements in bulk before drawing:
542
+
543
+ ```python
544
+ camera.cull = True # master switch
545
+ camera.cull_backface = True # drop back-facing faces
546
+ camera.cull_frustum = True # drop faces / lines entirely off-screen
547
+ camera.cull_margin = 4.0 # off-screen margin in pixels
548
+ ```
549
+
550
+ Batch projection: `camera.project_many(vertices) -> (uv, visible)`.
686
551
 
687
552
  ---
688
553
 
@@ -725,7 +590,9 @@ turtleGL-3d/
725
590
  │ ├── scene.py # Scene object
726
591
  │ ├── plot3d.py # 3D function plot object
727
592
  │ ├── ray.py # Lighting object
728
- │ └── volume.py # Volume calculation object
593
+ │ ├── volume.py # Volume calculation object
594
+ │ ├── force.py # Force field / relativity
595
+ │ └── raster.py # Ray-tracing raster backend
729
596
  └── example/
730
597
  ```
731
598
 
@@ -737,6 +604,27 @@ This project is licensed under the Apache License 2.0 — see the [LICENSE](LICE
737
604
 
738
605
  ---
739
606
 
607
+ ## 🧩 Examples
608
+
609
+ One example per feature, under `src/turtleGL/example/` (copies in the repo root for quick runs):
610
+
611
+ | File | Feature |
612
+ |------|---------|
613
+ | `turtleGL_focal_example.py` | Perspective projection basics |
614
+ | `turtleGL_cabin_example.py` | Cabinet projection |
615
+ | `turtleGL_anime_example.py` | Rotation animation |
616
+ | `turtleGL_obj_example.py` | OBJ import + animation |
617
+ | `turtleGL_from_file_example.py` | CSV line/face import & export |
618
+ | `turtleGL_plot3D_example.py` | 3D function surface |
619
+ | `turtleGL_volume_example.py` | Volume sampling |
620
+ | `turtleGL_grating_example.py` | Raster (reverse ray tracing) |
621
+ | `turtleGL_force_example.py` | Force field |
622
+ | `turtleGL_relativity_example.py` | Special relativity |
623
+ | `turtleGL_cube_example.py` | Rubik's cube (interaction) |
624
+ | `christmas tree/` | Complex OBJ scene |
625
+ | `texture example/` | Texture mapping |
626
+ | `airplane_game.py` / `racing_game.py` | Playable demos |
627
+
740
628
  ## 🔗 Links
741
629
 
742
630
  - **Homepage**: [https://github.com/MichaelHyan/turtleGL](https://github.com/MichaelHyan/turtleGL)
@@ -19,6 +19,10 @@ An object-oriented, intuitive Python 3D graphics library based on the turtle lib
19
19
  - 🎬 **Image & Video Export** — OpenCV-based image export and video compositing.
20
20
  - 🔄 **Transform** — Spatial transformations: rotation, translation, scaling, etc.
21
21
  - 📊 **Depth Sorting** — Depth sorting algorithms for different projection modes.
22
+ - ⚡ **Ray-Traced Raster** — vectorized reverse ray-tracing backend with hard shadows; the legacy per-dot path is kept internal.
23
+ - 🌌 **Force Field & Relativity** — local light speed `c=c0/n(x)`, optical path time, Doppler / aberration / gravitational shift.
24
+ - ✂️ **Visibility Culling** — bulk back-face and frustum culling for non-raster drawing.
25
+ - 🧮 **Vectorized Projection** — cached camera matrix and batch `project_many`.
22
26
 
23
27
  ---
24
28
 
@@ -447,18 +451,86 @@ get_value(point1, point2, point3) # Compute combined shading value for a triang
447
451
 
448
452
  ---
449
453
 
450
- ## 🧪 Experimental: Rasterization
454
+ ## 🖥️ Raster Rendering (Reverse Ray Tracing)
451
455
 
452
- Raster algorithm is experimental and not yet stable.
456
+ 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.
453
457
 
454
458
  ```python
455
- scene.triangulation() # Triangulate faces (raster mode only supports triangles)
456
- camera.grating_size = [500, 400] # Set rendering area size
457
- camera.show_grating_limit() # Show rendering area border
458
- camera.grating(face, ray) # Execute raster calculation
459
+ camera.image_size = [480, 360]
460
+ camera.rend = 1 # 0 material / 1 lighting + hard shadow / 2 normals
461
+ camera.tile = 32 # tile size (speed vs memory)
462
+ camera.ambient = 0.18 # ambient floor
463
+ camera.grating(scene.face, ray) # draw into the turtle canvas
464
+ camera.grating_cv2(scene.face, ray) # draw into camera.image (OpenCV)
459
465
  ```
460
466
 
461
- In rendering mode `rend=1`, raster mode uses the `ray` lighting object to compute light paths and shadows.
467
+ `grating` / `grating_cv2` accept optional positional or keyword arguments:
468
+
469
+ | Position | Keyword | Default | Meaning |
470
+ |----------|---------|---------|---------|
471
+ | 0 | `face` / `sce` | — | triangular face data |
472
+ | 1 | `ray` / `ray_object` | empty ray | light sources |
473
+ | 2 | `field` | `camera.field` | force field |
474
+ | 3 | `position` | unchanged | temporary camera position |
475
+
476
+ The same variable-argument convention applies to `draw_from_scene` / `draw_from_scene_cv2`.
477
+
478
+ ## 🌌 Force Field & Special Relativity
479
+
480
+ `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`.
481
+
482
+ ```python
483
+ ff = turtleGL.force_field(c0=1.0)
484
+ ff.add_sphere([0, 0, 0], 260, n_in=2.2, k=0.8)
485
+ ff.add_gradient([0, 0, -300], [0, 0, 1], n0=1.0, dn=0.003)
486
+ ff.add_plane([0, 0, 0], [0, 0, 1], n_in=1.5)
487
+
488
+ ff.relativity = True # master switch
489
+ ff.doppler = True # Doppler blue / red shift
490
+ ff.aberration = True # relativistic aberration
491
+ ff.gravity_shift = True # g = n_obs / n_emit
492
+ ff.intensity_shift = True # surface brightness ~ g^3
493
+
494
+ camera.field = ff
495
+ camera.velocity = [0, 0, 0.6] # camera speed as a fraction of c (turtle coords)
496
+ camera.grating(scene.face, ray, ff)
497
+ ```
498
+
499
+ ### Force Field Object
500
+
501
+ | Attribute | Default | Meaning |
502
+ |-----------|---------|---------|
503
+ | `c0` | `1.0` | global light-speed constant |
504
+ | `enabled` | `True` | enable / disable the field |
505
+ | `relativity` | `True` | master relativity switch |
506
+ | `doppler` | `True` | special-relativistic Doppler |
507
+ | `aberration` | `False` | relativistic aberration |
508
+ | `gravity_shift` | `True` | `g = n_obs / n_emit` |
509
+ | `intensity_shift` | `True` | surface brightness `I ∝ g^3` |
510
+ | `bend_geometry` | `False` | bend rays through the index gradient (slow) |
511
+
512
+ | Method | Meaning |
513
+ |--------|---------|
514
+ | `add_sphere(center, radius, n_in, k)` | Gaussian sphere field |
515
+ | `add_plane(point, normal, n_in)` | half-space step index |
516
+ | `add_gradient(origin, direction, n0, dn)` | linear index gradient |
517
+ | `clear()` | remove all regions |
518
+ | `index(P)` / `speed(P)` | evaluate `n` / `c` at points |
519
+ | `travel_time(p0, p1, samples)` | optical path time `T = ∫ n ds / c0` |
520
+ | `shift(n_obs, n_emit, beta, cos_theta)` | frequency ratio `g` |
521
+
522
+ ## ✂️ Visibility Culling
523
+
524
+ `draw_from_scene` / `draw_from_scene_cv2` filter invisible elements in bulk before drawing:
525
+
526
+ ```python
527
+ camera.cull = True # master switch
528
+ camera.cull_backface = True # drop back-facing faces
529
+ camera.cull_frustum = True # drop faces / lines entirely off-screen
530
+ camera.cull_margin = 4.0 # off-screen margin in pixels
531
+ ```
532
+
533
+ Batch projection: `camera.project_many(vertices) -> (uv, visible)`.
462
534
 
463
535
  ---
464
536
 
@@ -501,7 +573,9 @@ turtleGL-3d/
501
573
  │ ├── scene.py # Scene object
502
574
  │ ├── plot3d.py # 3D function plot object
503
575
  │ ├── ray.py # Lighting object
504
- │ └── volume.py # Volume calculation object
576
+ │ ├── volume.py # Volume calculation object
577
+ │ ├── force.py # Force field / relativity
578
+ │ └── raster.py # Ray-tracing raster backend
505
579
  └── example/
506
580
  ```
507
581
 
@@ -513,6 +587,27 @@ This project is licensed under the Apache License 2.0 — see the [LICENSE](LICE
513
587
 
514
588
  ---
515
589
 
590
+ ## 🧩 Examples
591
+
592
+ One example per feature, under `src/turtleGL/example/` (copies in the repo root for quick runs):
593
+
594
+ | File | Feature |
595
+ |------|---------|
596
+ | `turtleGL_focal_example.py` | Perspective projection basics |
597
+ | `turtleGL_cabin_example.py` | Cabinet projection |
598
+ | `turtleGL_anime_example.py` | Rotation animation |
599
+ | `turtleGL_obj_example.py` | OBJ import + animation |
600
+ | `turtleGL_from_file_example.py` | CSV line/face import & export |
601
+ | `turtleGL_plot3D_example.py` | 3D function surface |
602
+ | `turtleGL_volume_example.py` | Volume sampling |
603
+ | `turtleGL_grating_example.py` | Raster (reverse ray tracing) |
604
+ | `turtleGL_force_example.py` | Force field |
605
+ | `turtleGL_relativity_example.py` | Special relativity |
606
+ | `turtleGL_cube_example.py` | Rubik's cube (interaction) |
607
+ | `christmas tree/` | Complex OBJ scene |
608
+ | `texture example/` | Texture mapping |
609
+ | `airplane_game.py` / `racing_game.py` | Playable demos |
610
+
516
611
  ## 🔗 Links
517
612
 
518
613
  - **Homepage**: [https://github.com/MichaelHyan/turtleGL](https://github.com/MichaelHyan/turtleGL)