phg-vis 1.2.0__tar.gz → 1.3.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 (31) hide show
  1. phg_vis-1.3.0/PKG-INFO +607 -0
  2. phg_vis-1.3.0/README.md +592 -0
  3. phg_vis-1.3.0/phg/__init__.py +82 -0
  4. phg_vis-1.3.0/phg/phg_to_shader.py +433 -0
  5. phg_vis-1.3.0/phg/shader_render.py +425 -0
  6. phg_vis-1.3.0/phg/vis/GCU.dll +0 -0
  7. phg_vis-1.3.0/phg/vis/vis.exe +0 -0
  8. phg_vis-1.3.0/phg_vis.egg-info/PKG-INFO +607 -0
  9. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg_vis.egg-info/SOURCES.txt +2 -0
  10. {phg_vis-1.2.0 → phg_vis-1.3.0}/setup.py +2 -2
  11. phg_vis-1.2.0/PKG-INFO +0 -136
  12. phg_vis-1.2.0/README.md +0 -121
  13. phg_vis-1.2.0/phg/__init__.py +0 -4
  14. phg_vis-1.2.0/phg/vis/GCU.dll +0 -0
  15. phg_vis-1.2.0/phg/vis/vis.exe +0 -0
  16. phg_vis-1.2.0/phg_vis.egg-info/PKG-INFO +0 -136
  17. {phg_vis-1.2.0 → phg_vis-1.3.0}/LICENSE +0 -0
  18. {phg_vis-1.2.0 → phg_vis-1.3.0}/MANIFEST.in +0 -0
  19. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg/vis/dragpad.exe +0 -0
  20. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg/vis/dragpad_config.ini +0 -0
  21. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg/vis/freeglut.dll +0 -0
  22. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg/vis/imgui/main.lua +0 -0
  23. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg/vis/lua.dll +0 -0
  24. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg/vis/script.phg +0 -0
  25. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg/vis/sqlite3.dll +0 -0
  26. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg/vis/vis.ini +0 -0
  27. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg/vis/zlib1.dll +0 -0
  28. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg/visphg.py +0 -0
  29. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg_vis.egg-info/dependency_links.txt +0 -0
  30. {phg_vis-1.2.0 → phg_vis-1.3.0}/phg_vis.egg-info/top_level.txt +0 -0
  31. {phg_vis-1.2.0 → phg_vis-1.3.0}/setup.cfg +0 -0
phg_vis-1.3.0/PKG-INFO ADDED
@@ -0,0 +1,607 @@
1
+ Metadata-Version: 2.1
2
+ Name: phg_vis
3
+ Version: 1.3.0
4
+ Summary: A package for the PHG modeling language and 3D visualization tool.
5
+ Home-page: https://github.com/panguojun/Coordinate-System
6
+ Author: romeosoft
7
+ Author-email: 18858146@qq.com
8
+ Platform: Windows
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: Microsoft :: Windows
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+
16
+ # PHG - Minimalist 3D Modeling Language
17
+
18
+ PHG (Bacteriophage) is a specialized modeling language for describing 3D scene node trees. Combining concepts from group theory, it provides custom overloading capabilities for variables and operations, making it particularly suitable for describing complex 3D scenes and 2D sprite structures.
19
+
20
+ ---
21
+
22
+ ## 🌟 Features
23
+
24
+ - **Minimalist Syntax** - Declarative node tree description
25
+ - **Hierarchical Modeling** - Support for nested nodes and transform inheritance
26
+ - **Parametric Design** - Flexible property system and function definitions
27
+ - **Topological Structures** - Two organization methods: sequence and array composition
28
+ - **Visualization Rendering** - Powerful offscreen rendering and screenshot capabilities
29
+ - **Python Integration** - Convenient Python API
30
+
31
+ ---
32
+
33
+ ## 📦 Installation
34
+
35
+ ```bash
36
+ pip install phg_vis
37
+ ```
38
+
39
+ Or install from source:
40
+ ```bash
41
+ pip install phg
42
+ ```
43
+
44
+ ---
45
+
46
+ ## 🚀 Quick Start
47
+
48
+ ### Python Usage
49
+
50
+ ```python
51
+ import phg
52
+
53
+ # Define PHG code
54
+ phg_code = """
55
+ {
56
+ # Create a simple cylinder
57
+ base{md:cylinder 5 10; rgb:100,150,200}
58
+ }setup_draw();
59
+ """
60
+
61
+ # Execute PHG code
62
+ phg.run(phg_code)
63
+ ```
64
+
65
+ ### Visualization Rendering
66
+
67
+ ```python
68
+ import phg
69
+
70
+ # Method 1: Direct rendering
71
+ phg.image("box(10);", filename="cube.png")
72
+
73
+ # Method 2: Complex scene rendering
74
+ scene = """
75
+ {
76
+ base{md:cylinder 10 2; rgb:100,100,100}
77
+ column{md:cylinder 5 20; y:2; rgb:200,200,200}
78
+ top{md:cone 5 3 3; y:22; rgb:150,150,150}
79
+ structure{[base,column,top]}
80
+ }setup_draw(structure);
81
+ """
82
+ phg.image(scene, filename="tower.png")
83
+
84
+ # Method 3: Multi-view rendering
85
+ phg.image("sphere(5);|||view=2 width=1920 height=1080", filename="top_view.png")
86
+ ```
87
+
88
+ ---
89
+
90
+ ## 📖 Syntax Reference
91
+
92
+ ### 1. Basic Structure
93
+
94
+ ```phg
95
+ {
96
+ # Scene node definitions
97
+ node definitions...
98
+ }setup();draw(); # or setup_draw();
99
+ ```
100
+
101
+ **Key Points:**
102
+ - All nodes must be defined within the root node (anonymous braces)
103
+ - Call `setup();draw();` or `setup_draw()` at the end for scene rendering
104
+ - Use `#` for single-line comments
105
+
106
+ ### 2. Node Definition
107
+
108
+ #### 2.1 Basic Syntax
109
+ ```phg
110
+ nodeName{attributes and content}
111
+ ```
112
+
113
+ #### 2.2 Node Attributes
114
+
115
+ | Attribute Type | Syntax | Description |
116
+ |----------------|--------|-------------|
117
+ | Position | `x:value` `y:value` `z:value` | Single-axis position |
118
+ | Position (Combined) | `xyz:x,y,z` | Three-axis position |
119
+ | Rotation | `rx:angle` `ry:angle` `rz:angle` | Single-axis rotation (degrees) |
120
+ | Rotation (Combined) | `rxyz:x,y,z` | Three-axis rotation |
121
+ | Scale | `s:scale` | Uniform scaling |
122
+ | Color | `rgb:red,green,blue` | RGB color (0-255) |
123
+ | Tessellation | `ts:subdivisions` | Curve/surface subdivision level |
124
+
125
+ **Examples:**
126
+ ```phg
127
+ node1{x:10; y:20; z:30; rx:45; ry:90; rz:0}
128
+ node2{xyz:10,20,30; rxyz:45,90,0; s:2.0}
129
+ node3{rgb:255,128,0; ts:32}
130
+ ```
131
+
132
+ #### 2.3 Node Composition Methods
133
+
134
+ **Sequence Composition (Transform Propagation):**
135
+ ```phg
136
+ parent{<child1,child2,child3>}
137
+ ```
138
+ - Use angle brackets `<>` for sequences
139
+ - Parent node transforms are **propagated sequentially** to child nodes
140
+ - Commonly used for creating repetitive patterns (turbine blades, gear teeth)
141
+
142
+ **Array Composition (Independent Transforms):**
143
+ ```phg
144
+ group{[item1,item2,item3]}
145
+ ```
146
+ - Use square brackets `[]` for arrays
147
+ - Each child node maintains **independent transforms**
148
+ - Used for combining unrelated components
149
+
150
+ **Comparison Example:**
151
+ ```phg
152
+ {
153
+ # Sequence: Each box accumulates rotation
154
+ gear1{<box1,box1,box1,box1>; rz:90} # Four boxes at 0°, 90°, 180°, 270°
155
+
156
+ # Array: Each box has independent transform
157
+ gear2{[box1{rz:0},box1{rz:90},box1{rz:180},box1{rz:270}]}
158
+ }
159
+ ```
160
+
161
+ #### 2.4 Node Reference and Reuse
162
+
163
+ ```phg
164
+ # Define template node
165
+ template{md:cylinder 10 20}
166
+
167
+ # Reference node
168
+ instance1{template; x:10} # Inherit template and add translation
169
+ instance2{{template; s:0.5}; y:20} # Scale first, then translate
170
+ ```
171
+
172
+ ---
173
+
174
+ ### 3. Model Definition (md Command)
175
+
176
+ #### 3.1 Basic Syntax
177
+ ```phg
178
+ {md:commandName param1 param2 ...}
179
+ ```
180
+
181
+ #### 3.2 2D Shapes
182
+
183
+ | Command | Syntax | Description |
184
+ |---------|--------|-------------|
185
+ | Rectangle | `md:rect width height` | Rectangle |
186
+ | Circle | `md:circle radius` | Circle |
187
+ | Ellipse | `md:ellipse2d majorAxis minorAxis` | Ellipse |
188
+ | Polygon | `md:poly x1,y1,z1 x2,y2,z2 ...` | Arbitrary polygon |
189
+
190
+ **Examples:**
191
+ ```phg
192
+ rect1{md:rect 10 20}
193
+ circle1{md:circle 5; ts:64} # 64 subdivisions
194
+ triangle{md:poly 0,0,0 10,0,0 5,10,0}
195
+ ```
196
+
197
+ #### 3.3 3D Primitives
198
+
199
+ | Command | Syntax | Description |
200
+ |---------|--------|-------------|
201
+ | Cylinder | `md:cylinder radius height` | Cylinder |
202
+ | Cone | `md:cone bottomRadius topRadius height` | Cone/Frustum |
203
+ | Spherical Crown | `md:sphericalcrown radiusX radiusY radiusZ` | Spherical cap/hemisphere |
204
+ | Box | `md:box length width height` | Box |
205
+
206
+ **Examples:**
207
+ ```phg
208
+ cylinder1{md:cylinder 5 10}
209
+ cone1{md:cone 5 2 8}
210
+ hemisphere{md:sphericalcrown 3 3 1.5}
211
+ box1{md:box 10 5 2}
212
+ ```
213
+
214
+ #### 3.4 Curve Commands
215
+
216
+ **Interpolated Curves:**
217
+ ```phg
218
+ {md:ccurve interpolationType startNode endNode}
219
+ ```
220
+
221
+ Interpolation Types:
222
+ - `lerpTX` - Linear interpolation (tangent X direction)
223
+ - `lerpTY` - Linear interpolation (tangent Y direction)
224
+ - `lerpTZ` - Linear interpolation (tangent Z direction)
225
+ - `lerp` - Standard linear interpolation
226
+
227
+ **Example:**
228
+ ```phg
229
+ {
230
+ p1{} p2{x:10; rz:15}
231
+ curve1{md:ccurve lerpTX p1 p2}
232
+ }
233
+ ```
234
+
235
+ #### 3.5 Surface Commands
236
+
237
+ **Patch:**
238
+ ```phg
239
+ {md:face interpolationType curve1 curve2}
240
+ ```
241
+
242
+ **Extrusion:**
243
+ ```phg
244
+ {md:extrudex profile xStart yStart length}
245
+ ```
246
+
247
+ **Loft:**
248
+ ```phg
249
+ {md:loft profile1 profile2 path parameters}
250
+ ```
251
+
252
+ ---
253
+
254
+ ### 4. Data Structures
255
+
256
+ #### 4.1 Location Data (Locations)
257
+ ```phg
258
+ {md:Locations;
259
+ list:"
260
+ 1
261
+ 1 0 0 # x coordinate
262
+ 0 1 0 # y coordinate
263
+ 0 0 1 # z coordinate
264
+ "
265
+ }
266
+ ```
267
+
268
+ #### 4.2 Curve Data (Curves)
269
+ ```phg
270
+ {md:Curves;
271
+ list:"
272
+ type param1 param2 param3 dirX dirY dirZ
273
+ "
274
+ }
275
+ ```
276
+
277
+ ---
278
+
279
+ ### 5. Control Statements
280
+
281
+ #### 5.1 Conditional Statement
282
+ ```phg
283
+ ?(condition) { statement } : { else_statement };
284
+ ```
285
+
286
+ #### 5.2 Loop Statement
287
+ ```phg
288
+ @n { statement1 ? (_i = x) ~; statement2; }
289
+ ```
290
+
291
+ #### 5.3 Function Definition
292
+ ```phg
293
+ $functionName(args...) { statement; $return }
294
+ ```
295
+
296
+ ---
297
+
298
+ ### 6. Scene Rendering Functions
299
+
300
+ ```phg
301
+ setup();draw(); # Setup and draw entire scene
302
+ setup_draw(); # Combined call
303
+ setup_draw(node1); # Draw specified node
304
+ setup_draw(node1,node2,...); # Draw multiple specified nodes
305
+ ```
306
+
307
+ ---
308
+
309
+ ## 🎨 Visualization Features
310
+
311
+ ### 1. Interactive Screenshot (UI Button)
312
+
313
+ Click the **Shot** button in the 3D view interface to take a screenshot.
314
+
315
+ **Features:**
316
+ - One-click operation with auto-generated timestamped filename
317
+ - Default save location: Desktop as `screenshot_YYYYMMDD_HHMMSS.png`
318
+ - Real-time notification of screenshot results
319
+
320
+ ### 2. Python API Rendering (Recommended)
321
+
322
+ ```python
323
+ import phg
324
+
325
+ # Default screenshot (shot.png)
326
+ phg.image("box(10);")
327
+
328
+ # Specify filename
329
+ phg.image("box(10);", filename="cube_render.png")
330
+
331
+ # Full path
332
+ phg.image("box(10);", filename="C:/output/result.png")
333
+
334
+ # Advanced: Custom resolution and view
335
+ phg_code = "box(10);"
336
+ phg.image(phg_code + "|||width=1920 height=1080 view=2")
337
+ ```
338
+
339
+ ### 3. HTTP API
340
+
341
+ **Save to File:**
342
+ ```http
343
+ POST http://127.0.0.1:5088/phg_img
344
+ Content-Type: text/plain
345
+
346
+ box(10);|||file=output.png width=1920 height=1080 view=0
347
+ ```
348
+
349
+ **Return Binary Data:**
350
+ ```http
351
+ POST http://127.0.0.1:5088/phg_img
352
+ Content-Type: text/plain
353
+
354
+ box(10);|||width=800 height=600
355
+ ```
356
+
357
+ ### 4. Rendering Parameters
358
+
359
+ **Request Body Format:**
360
+ ```
361
+ <PHG_CODE>|||<PARAMETERS>
362
+ ```
363
+
364
+ **Available Parameters:**
365
+
366
+ | Parameter | Type | Default | Description |
367
+ |-----------|------|---------|-------------|
368
+ | `file` | string | - | Output filename, omit for binary return |
369
+ | `width` | int | 1288 | Render width (pixels) |
370
+ | `height` | int | 800 | Render height (pixels) |
371
+ | `view` | int | 3 | View mode (see table below) |
372
+ | `quality` | string | high | Render quality: high/low |
373
+
374
+ **View Modes:**
375
+
376
+ | Value | Mode | Description |
377
+ |-------|------|-------------|
378
+ | 0 | Front | Front view (orthographic projection) |
379
+ | 1 | Right | Right view (orthographic projection) |
380
+ | 2 | Top | Top view (orthographic projection) |
381
+ | 3 | Perspective | **Perspective view (default)** |
382
+
383
+ ### 5. Batch Rendering Example
384
+
385
+ ```python
386
+ import phg
387
+
388
+ # Batch generate different views
389
+ views = [(0,"front"), (1,"right"), (2,"top"), (3,"perspective")]
390
+ phg_code = "box(10);"
391
+
392
+ for view_id, view_name in views:
393
+ phg.image(
394
+ f"{phg_code}|||view={view_id}",
395
+ filename=f"cube_{view_name}.png"
396
+ )
397
+
398
+ # Batch render different sizes
399
+ for size in [5, 10, 15, 20]:
400
+ phg.image(f"box({size});", filename=f"box_{size}.png")
401
+ ```
402
+
403
+ ---
404
+
405
+ ## 💡 Complete Examples
406
+
407
+ ### Example 1: Simple Geometry
408
+ ```phg
409
+ {
410
+ # Create a cylinder with base
411
+ base{md:cylinder 10 2; rgb:100,100,100}
412
+ column{md:cylinder 5 20; y:2; rgb:200,200,200}
413
+ top{md:cone 5 3 3; y:22; rgb:150,150,150}
414
+
415
+ structure{[base,column,top]}
416
+ }setup_draw(structure);
417
+ ```
418
+
419
+ ### Example 2: Parametric Gear
420
+ ```phg
421
+ {
422
+ # Create gear tooth
423
+ tooth{md:box 2 5 3; z:10}
424
+
425
+ # Create gear by rotating around center (8 teeth)
426
+ gear{
427
+ <tooth,tooth,tooth,tooth,tooth,tooth,tooth,tooth>
428
+ rz:45 # Each tooth automatically rotates 45° (360/8)
429
+ }
430
+
431
+ # Center shaft
432
+ shaft{md:cylinder 3 10; rgb:50,50,50}
433
+
434
+ # Assembly
435
+ assembly{[gear,shaft]; rx:90}
436
+ }setup_draw(assembly);
437
+ ```
438
+
439
+ ### Example 3: Turbine Blade (Complex Assembly)
440
+ ```phg
441
+ {
442
+ # Define control points
443
+ p1{}
444
+ p2{x:4; rz:15}
445
+ p3{x:4; rz:-15}
446
+
447
+ # Create curves
448
+ c1{{md:ccurve lerpTX p1 p2}{md:ccurve lerpTX p1 p3}}
449
+ c2{c1; z:14; rz:75; s:0.75}
450
+
451
+ # Create blade surface
452
+ blade{{md:face lerp c1 c2; z:2; rz:90}ry:15}
453
+
454
+ # Create impeller (24 blades)
455
+ wheel{<blade,blade,blade,blade,blade,blade,blade,blade,
456
+ blade,blade,blade,blade,blade,blade,blade,blade,
457
+ blade,blade,blade,blade,blade,blade,blade,blade>}
458
+
459
+ # Hub
460
+ hub{md:cylinder 8 5; rgb:80,80,80}
461
+
462
+ # Assembly
463
+ turbine{[wheel,hub]}
464
+ }setup_draw(turbine);
465
+ ```
466
+
467
+ ### Example 4: Python Rendering Workflow
468
+ ```python
469
+ import phg
470
+
471
+ # Define complex scene
472
+ scene = """
473
+ {
474
+ # Ground
475
+ ground{md:cylinder 20 0.5; rgb:80,80,80}
476
+
477
+ # Main structure
478
+ base{md:cylinder 5 2; y:0.5; rgb:150,150,150}
479
+ column{md:cylinder 2 10; y:3.5; rgb:200,200,200}
480
+ top{md:cone 3 0 2; y:9; rgb:180,180,180}
481
+
482
+ # Decoration
483
+ ring1{md:cylinder 4 0.3; y:5; rgb:255,200,0}
484
+ ring2{md:cylinder 4 0.3; y:7; rgb:255,200,0}
485
+
486
+ # Assembly
487
+ monument{[ground,base,column,top,ring1,ring2]}
488
+ }setup_draw(monument);
489
+ """
490
+
491
+ # Render multiple views
492
+ phg.image(scene + "|||view=3", filename="monument_perspective.png")
493
+ phg.image(scene + "|||view=0", filename="monument_front.png")
494
+ phg.image(scene + "|||view=2 width=2560 height=1440", filename="monument_top_4k.png")
495
+ ```
496
+
497
+ ---
498
+
499
+ ## 🎯 Best Practices
500
+
501
+ ### 1. Naming Conventions
502
+ - Use meaningful node names
503
+ - Use lowercase letters and underscores
504
+ - Avoid using PHG keywords as node names
505
+
506
+ ### 2. Structure Organization
507
+ - Group related nodes together
508
+ - Use comments to explain complex structures
509
+ - Use node references to reduce repetition
510
+
511
+ ### 3. Performance Optimization
512
+ - Set appropriate tessellation levels (`ts` parameter)
513
+ - Reuse node definitions instead of recreating
514
+ - Use sequence and array composition appropriately
515
+
516
+ ### 4. Debugging Tips
517
+ - Build complex models incrementally
518
+ - Use `setup_draw(nodeName)` to test nodes individually
519
+ - Check coordinate system and transform order
520
+
521
+ ---
522
+
523
+ ## 📚 Built-in Functions
524
+
525
+ ### Math Functions
526
+ - `rnd()` - Random number
527
+ - `sin()` - Sine
528
+ - `cos()` - Cosine
529
+
530
+ ### Node Operations
531
+ - `im()` - Image operations
532
+ - `on()` - Enable node
533
+ - `wak()` - Wake node
534
+ - `dump()` - Dump node data
535
+
536
+ ### Data Conversion
537
+ - `tojson()` - Convert to JSON format
538
+
539
+ ---
540
+
541
+ ## 🔧 Coordinate System
542
+
543
+ ### Coordinate System
544
+ - Uses **right-hand coordinate system**
545
+ - X-axis: Right
546
+ - Y-axis: Up
547
+ - Z-axis: Forward
548
+
549
+ ### Rotation Rules
550
+ - Rotation angle unit is **degrees**
551
+ - Positive rotation follows **right-hand rule**
552
+
553
+ ### Transform Order
554
+ - Transform order: **Scale → Rotation → Translation**
555
+ - Child node transforms are applied on top of parent transforms
556
+
557
+ ---
558
+
559
+ ## ❓ FAQ
560
+
561
+ ### Q1: What's the difference between sequences and arrays?
562
+ - **Sequence** `<a,b,c>` equals `{a {b {c}}}` - Transforms accumulate
563
+ - **Array** `[a,b,c]` equals `{{a}{b}{c}}` - Transforms are independent
564
+
565
+ ### Q2: How to create repetitive structures?
566
+ Use sequence composition `<>` with rotation:
567
+ ```phg
568
+ # Create 8 evenly distributed elements
569
+ element{md:box 2 2 2; z:10; rz:45}
570
+ ring{<element,element,element,element,element,element,element,element>}
571
+ ```
572
+
573
+ ### Q3: How to set transparent background?
574
+ Currently the rendering engine uses RGB format and doesn't support transparent backgrounds. For transparency, remove the background color in post-processing.
575
+
576
+ ### Q4: Is there a resolution limit for rendering?
577
+ Recommended maximum resolution is **4096 x 4096**. Excessively large resolutions may cause insufficient GPU memory or rendering failures.
578
+
579
+ ---
580
+
581
+ ## 🔗 Links
582
+
583
+ - [PyPI Package](https://pypi.org/project/phg/)
584
+ - [Official Documentation](https://your.documentation.link)
585
+ - [Mathematical Foundation](https://github.com/panguojun/Coordinate-System)
586
+
587
+ ---
588
+
589
+ ## 📄 License
590
+
591
+ This project is licensed under the MIT License.
592
+
593
+ ---
594
+
595
+ ## 🙏 Acknowledgments
596
+
597
+ PHG is inspired by concepts from group theory, aiming to provide a flexible way to describe complex data structures in programming. Special thanks to all developers who have contributed to the PHG ecosystem.
598
+
599
+ ---
600
+
601
+ ## 🤝 Contributing
602
+
603
+ Contributions are welcome! Please feel free to submit issues or pull requests.
604
+
605
+ ---
606
+
607
+ **© 2025 PHG - Minimalist 3D Modeling Language**