phg-vis 1.3.0__tar.gz → 1.3.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.
- {phg_vis-1.3.0/phg_vis.egg-info → phg_vis-1.3.1}/PKG-INFO +124 -8
- {phg_vis-1.3.0 → phg_vis-1.3.1}/README.md +123 -7
- phg_vis-1.3.1/phg/__init__.py +113 -0
- phg_vis-1.3.1/phg/pipe_string_phg.py +285 -0
- phg_vis-1.3.1/phg/vis/vis.ini +4 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1/phg_vis.egg-info}/PKG-INFO +124 -8
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg_vis.egg-info/SOURCES.txt +1 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/setup.py +1 -1
- phg_vis-1.3.0/phg/__init__.py +0 -82
- phg_vis-1.3.0/phg/vis/vis.ini +0 -4
- {phg_vis-1.3.0 → phg_vis-1.3.1}/LICENSE +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/MANIFEST.in +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/phg_to_shader.py +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/shader_render.py +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/vis/GCU.dll +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/vis/dragpad.exe +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/vis/dragpad_config.ini +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/vis/freeglut.dll +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/vis/imgui/main.lua +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/vis/lua.dll +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/vis/script.phg +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/vis/sqlite3.dll +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/vis/vis.exe +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/vis/zlib1.dll +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg/visphg.py +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg_vis.egg-info/dependency_links.txt +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/phg_vis.egg-info/top_level.txt +0 -0
- {phg_vis-1.3.0 → phg_vis-1.3.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: phg_vis
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.1
|
|
4
4
|
Summary: A package for the PHG modeling language and 3D visualization tool.
|
|
5
5
|
Home-page: https://github.com/panguojun/Coordinate-System
|
|
6
6
|
Author: romeosoft
|
|
@@ -13,20 +13,21 @@ Requires-Python: >=3.8
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
15
|
|
|
16
|
-
# PHG -
|
|
16
|
+
# PHG - Python Hypergraphics Library
|
|
17
17
|
|
|
18
|
-
PHG (
|
|
18
|
+
PHG (Python Hypergraphics) is a powerful 3D modeling and visualization library that combines a minimalist modeling language with Python integration. It provides procedural 3D scene generation, shader-based rendering, and specialized pipe system visualization.
|
|
19
19
|
|
|
20
20
|
---
|
|
21
21
|
|
|
22
22
|
## 🌟 Features
|
|
23
23
|
|
|
24
|
-
- **Minimalist Syntax** - Declarative node tree description
|
|
24
|
+
- **Minimalist Syntax** - Declarative node tree description for 3D scenes
|
|
25
25
|
- **Hierarchical Modeling** - Support for nested nodes and transform inheritance
|
|
26
26
|
- **Parametric Design** - Flexible property system and function definitions
|
|
27
|
-
- **
|
|
28
|
-
- **
|
|
29
|
-
- **
|
|
27
|
+
- **Pipe Visualization** - Specialized system for visualizing pipe structures with world/local coordinate support
|
|
28
|
+
- **Shader Conversion** - Convert PHG scripts to GLSL shaders for GPU rendering
|
|
29
|
+
- **Dual Rendering Modes** - Both real-time visualization (vis.exe) and offscreen rendering
|
|
30
|
+
- **Python Integration** - Comprehensive Python API for all features
|
|
30
31
|
|
|
31
32
|
---
|
|
32
33
|
|
|
@@ -402,6 +403,122 @@ for size in [5, 10, 15, 20]:
|
|
|
402
403
|
|
|
403
404
|
---
|
|
404
405
|
|
|
406
|
+
## 🔧 Pipe Visualization System
|
|
407
|
+
|
|
408
|
+
PHG includes a specialized pipe visualization system for creating 3D pipe structures from simple string commands.
|
|
409
|
+
|
|
410
|
+
### Pipe String Commands
|
|
411
|
+
|
|
412
|
+
- **F** - Forward (move forward in current direction)
|
|
413
|
+
- **B** - Back (move backward in current direction)
|
|
414
|
+
- **R** - Right (turn right and move)
|
|
415
|
+
- **L** - Left (turn left and move)
|
|
416
|
+
- **U** - Up (turn up and move)
|
|
417
|
+
- **D** - Down (turn down and move)
|
|
418
|
+
|
|
419
|
+
### World Coordinate System
|
|
420
|
+
|
|
421
|
+
World coordinate pipes use absolute directions regardless of current orientation:
|
|
422
|
+
|
|
423
|
+
```python
|
|
424
|
+
import phg
|
|
425
|
+
from coordinate_system import vec3, quat, coord3
|
|
426
|
+
|
|
427
|
+
# Create a pipe in world coordinates
|
|
428
|
+
# F moves along world Z+, R moves along world X+, etc.
|
|
429
|
+
start_pos = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
|
|
430
|
+
phg_script = phg.world_pipestr_vis("FFRRUD", start_pos)
|
|
431
|
+
|
|
432
|
+
# Custom pipe appearance
|
|
433
|
+
phg.world_pipestr_vis(
|
|
434
|
+
"FFLLUU",
|
|
435
|
+
start_pos,
|
|
436
|
+
pipe_color=(255, 100, 50), # Orange pipe
|
|
437
|
+
pipe_radius=0.5 # Thicker pipe
|
|
438
|
+
)
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### Local Coordinate System
|
|
442
|
+
|
|
443
|
+
Local coordinate pipes use directions relative to current orientation:
|
|
444
|
+
|
|
445
|
+
```python
|
|
446
|
+
import phg
|
|
447
|
+
from coordinate_system import vec3, quat, coord3
|
|
448
|
+
|
|
449
|
+
# Create a pipe in local coordinates
|
|
450
|
+
# F moves forward relative to current orientation
|
|
451
|
+
start_pos = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
|
|
452
|
+
phg_script = phg.local_pipestr_vis("FFRRUD", start_pos)
|
|
453
|
+
|
|
454
|
+
# The same string produces different results in local vs world coordinates
|
|
455
|
+
phg.local_pipestr_vis(
|
|
456
|
+
"FFRRFF", # Forward, Forward, Right turn, Right turn, Forward, Forward
|
|
457
|
+
start_pos,
|
|
458
|
+
pipe_color=(0, 255, 100) # Green pipe
|
|
459
|
+
)
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
### Direct PHG Script Generation
|
|
463
|
+
|
|
464
|
+
For advanced use cases, you can generate PHG scripts without immediate visualization:
|
|
465
|
+
|
|
466
|
+
```python
|
|
467
|
+
import phg
|
|
468
|
+
from coordinate_system import vec3, quat, coord3
|
|
469
|
+
|
|
470
|
+
start = coord3(vec3(5, 0, 0), quat(1, 0, 0, 0))
|
|
471
|
+
|
|
472
|
+
# Generate PHG script for world coordinates
|
|
473
|
+
world_phg = phg.world_pipe_to_phg("FFRUD", start)
|
|
474
|
+
|
|
475
|
+
# Generate PHG script for local coordinates
|
|
476
|
+
local_phg = phg.local_pipe_to_phg("FFRUD", start)
|
|
477
|
+
|
|
478
|
+
# Visualize later
|
|
479
|
+
phg.vis(world_phg)
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### Example: Complex Pipe System
|
|
483
|
+
|
|
484
|
+
```python
|
|
485
|
+
import phg
|
|
486
|
+
from coordinate_system import vec3, quat, coord3
|
|
487
|
+
|
|
488
|
+
# Create a complex pipe network
|
|
489
|
+
def create_pipe_network():
|
|
490
|
+
# Main pipeline
|
|
491
|
+
main_pipe = phg.world_pipestr_vis(
|
|
492
|
+
"FFFFRRFFRRUUFFLLFF",
|
|
493
|
+
coord3(vec3(0, 0, 0), quat(1, 0, 0, 0)),
|
|
494
|
+
pipe_color=(100, 100, 255),
|
|
495
|
+
pipe_radius=0.5
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
# Branch 1
|
|
499
|
+
branch1 = phg.world_pipestr_vis(
|
|
500
|
+
"RRUUFFFF",
|
|
501
|
+
coord3(vec3(4, 0, 0), quat(1, 0, 0, 0)),
|
|
502
|
+
pipe_color=(255, 100, 100),
|
|
503
|
+
pipe_radius=0.3
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
# Branch 2
|
|
507
|
+
branch2 = phg.local_pipestr_vis(
|
|
508
|
+
"FFLLDDFF",
|
|
509
|
+
coord3(vec3(8, 2, 2), quat(1, 0, 0, 0)),
|
|
510
|
+
pipe_color=(100, 255, 100),
|
|
511
|
+
pipe_radius=0.3
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
return main_pipe, branch1, branch2
|
|
515
|
+
|
|
516
|
+
# Create and visualize the network
|
|
517
|
+
pipes = create_pipe_network()
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
---
|
|
521
|
+
|
|
405
522
|
## 💡 Complete Examples
|
|
406
523
|
|
|
407
524
|
### Example 1: Simple Geometry
|
|
@@ -581,7 +698,6 @@ Recommended maximum resolution is **4096 x 4096**. Excessively large resolutions
|
|
|
581
698
|
## 🔗 Links
|
|
582
699
|
|
|
583
700
|
- [PyPI Package](https://pypi.org/project/phg/)
|
|
584
|
-
- [Official Documentation](https://your.documentation.link)
|
|
585
701
|
- [Mathematical Foundation](https://github.com/panguojun/Coordinate-System)
|
|
586
702
|
|
|
587
703
|
---
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
# PHG -
|
|
1
|
+
# PHG - Python Hypergraphics Library
|
|
2
2
|
|
|
3
|
-
PHG (
|
|
3
|
+
PHG (Python Hypergraphics) is a powerful 3D modeling and visualization library that combines a minimalist modeling language with Python integration. It provides procedural 3D scene generation, shader-based rendering, and specialized pipe system visualization.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
## 🌟 Features
|
|
8
8
|
|
|
9
|
-
- **Minimalist Syntax** - Declarative node tree description
|
|
9
|
+
- **Minimalist Syntax** - Declarative node tree description for 3D scenes
|
|
10
10
|
- **Hierarchical Modeling** - Support for nested nodes and transform inheritance
|
|
11
11
|
- **Parametric Design** - Flexible property system and function definitions
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
12
|
+
- **Pipe Visualization** - Specialized system for visualizing pipe structures with world/local coordinate support
|
|
13
|
+
- **Shader Conversion** - Convert PHG scripts to GLSL shaders for GPU rendering
|
|
14
|
+
- **Dual Rendering Modes** - Both real-time visualization (vis.exe) and offscreen rendering
|
|
15
|
+
- **Python Integration** - Comprehensive Python API for all features
|
|
15
16
|
|
|
16
17
|
---
|
|
17
18
|
|
|
@@ -387,6 +388,122 @@ for size in [5, 10, 15, 20]:
|
|
|
387
388
|
|
|
388
389
|
---
|
|
389
390
|
|
|
391
|
+
## 🔧 Pipe Visualization System
|
|
392
|
+
|
|
393
|
+
PHG includes a specialized pipe visualization system for creating 3D pipe structures from simple string commands.
|
|
394
|
+
|
|
395
|
+
### Pipe String Commands
|
|
396
|
+
|
|
397
|
+
- **F** - Forward (move forward in current direction)
|
|
398
|
+
- **B** - Back (move backward in current direction)
|
|
399
|
+
- **R** - Right (turn right and move)
|
|
400
|
+
- **L** - Left (turn left and move)
|
|
401
|
+
- **U** - Up (turn up and move)
|
|
402
|
+
- **D** - Down (turn down and move)
|
|
403
|
+
|
|
404
|
+
### World Coordinate System
|
|
405
|
+
|
|
406
|
+
World coordinate pipes use absolute directions regardless of current orientation:
|
|
407
|
+
|
|
408
|
+
```python
|
|
409
|
+
import phg
|
|
410
|
+
from coordinate_system import vec3, quat, coord3
|
|
411
|
+
|
|
412
|
+
# Create a pipe in world coordinates
|
|
413
|
+
# F moves along world Z+, R moves along world X+, etc.
|
|
414
|
+
start_pos = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
|
|
415
|
+
phg_script = phg.world_pipestr_vis("FFRRUD", start_pos)
|
|
416
|
+
|
|
417
|
+
# Custom pipe appearance
|
|
418
|
+
phg.world_pipestr_vis(
|
|
419
|
+
"FFLLUU",
|
|
420
|
+
start_pos,
|
|
421
|
+
pipe_color=(255, 100, 50), # Orange pipe
|
|
422
|
+
pipe_radius=0.5 # Thicker pipe
|
|
423
|
+
)
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
### Local Coordinate System
|
|
427
|
+
|
|
428
|
+
Local coordinate pipes use directions relative to current orientation:
|
|
429
|
+
|
|
430
|
+
```python
|
|
431
|
+
import phg
|
|
432
|
+
from coordinate_system import vec3, quat, coord3
|
|
433
|
+
|
|
434
|
+
# Create a pipe in local coordinates
|
|
435
|
+
# F moves forward relative to current orientation
|
|
436
|
+
start_pos = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
|
|
437
|
+
phg_script = phg.local_pipestr_vis("FFRRUD", start_pos)
|
|
438
|
+
|
|
439
|
+
# The same string produces different results in local vs world coordinates
|
|
440
|
+
phg.local_pipestr_vis(
|
|
441
|
+
"FFRRFF", # Forward, Forward, Right turn, Right turn, Forward, Forward
|
|
442
|
+
start_pos,
|
|
443
|
+
pipe_color=(0, 255, 100) # Green pipe
|
|
444
|
+
)
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Direct PHG Script Generation
|
|
448
|
+
|
|
449
|
+
For advanced use cases, you can generate PHG scripts without immediate visualization:
|
|
450
|
+
|
|
451
|
+
```python
|
|
452
|
+
import phg
|
|
453
|
+
from coordinate_system import vec3, quat, coord3
|
|
454
|
+
|
|
455
|
+
start = coord3(vec3(5, 0, 0), quat(1, 0, 0, 0))
|
|
456
|
+
|
|
457
|
+
# Generate PHG script for world coordinates
|
|
458
|
+
world_phg = phg.world_pipe_to_phg("FFRUD", start)
|
|
459
|
+
|
|
460
|
+
# Generate PHG script for local coordinates
|
|
461
|
+
local_phg = phg.local_pipe_to_phg("FFRUD", start)
|
|
462
|
+
|
|
463
|
+
# Visualize later
|
|
464
|
+
phg.vis(world_phg)
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
### Example: Complex Pipe System
|
|
468
|
+
|
|
469
|
+
```python
|
|
470
|
+
import phg
|
|
471
|
+
from coordinate_system import vec3, quat, coord3
|
|
472
|
+
|
|
473
|
+
# Create a complex pipe network
|
|
474
|
+
def create_pipe_network():
|
|
475
|
+
# Main pipeline
|
|
476
|
+
main_pipe = phg.world_pipestr_vis(
|
|
477
|
+
"FFFFRRFFRRUUFFLLFF",
|
|
478
|
+
coord3(vec3(0, 0, 0), quat(1, 0, 0, 0)),
|
|
479
|
+
pipe_color=(100, 100, 255),
|
|
480
|
+
pipe_radius=0.5
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
# Branch 1
|
|
484
|
+
branch1 = phg.world_pipestr_vis(
|
|
485
|
+
"RRUUFFFF",
|
|
486
|
+
coord3(vec3(4, 0, 0), quat(1, 0, 0, 0)),
|
|
487
|
+
pipe_color=(255, 100, 100),
|
|
488
|
+
pipe_radius=0.3
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
# Branch 2
|
|
492
|
+
branch2 = phg.local_pipestr_vis(
|
|
493
|
+
"FFLLDDFF",
|
|
494
|
+
coord3(vec3(8, 2, 2), quat(1, 0, 0, 0)),
|
|
495
|
+
pipe_color=(100, 255, 100),
|
|
496
|
+
pipe_radius=0.3
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
return main_pipe, branch1, branch2
|
|
500
|
+
|
|
501
|
+
# Create and visualize the network
|
|
502
|
+
pipes = create_pipe_network()
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
---
|
|
506
|
+
|
|
390
507
|
## 💡 Complete Examples
|
|
391
508
|
|
|
392
509
|
### Example 1: Simple Geometry
|
|
@@ -566,7 +683,6 @@ Recommended maximum resolution is **4096 x 4096**. Excessively large resolutions
|
|
|
566
683
|
## 🔗 Links
|
|
567
684
|
|
|
568
685
|
- [PyPI Package](https://pypi.org/project/phg/)
|
|
569
|
-
- [Official Documentation](https://your.documentation.link)
|
|
570
686
|
- [Mathematical Foundation](https://github.com/panguojun/Coordinate-System)
|
|
571
687
|
|
|
572
688
|
---
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PHG - Python Hypergraphics Library
|
|
3
|
+
===================================
|
|
4
|
+
|
|
5
|
+
A powerful graphics library for procedural 3D visualization using PHG scripts.
|
|
6
|
+
|
|
7
|
+
Main Features:
|
|
8
|
+
- PHG script visualization via vis.exe
|
|
9
|
+
- Shader-based rendering with GLSL conversion
|
|
10
|
+
- Pipe system visualization with world/local coordinate systems
|
|
11
|
+
- Real-time and image rendering capabilities
|
|
12
|
+
|
|
13
|
+
Version: 0.2.0
|
|
14
|
+
Author: PanGuoJun
|
|
15
|
+
License: MIT
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from .visphg import vis, image
|
|
19
|
+
from .shader_render import ShaderRenderer, render_shader
|
|
20
|
+
from .phg_to_shader import PHGToShaderConverter, phg_to_shader
|
|
21
|
+
from .pipe_string_phg import (
|
|
22
|
+
world_pipe_to_phg,
|
|
23
|
+
local_pipe_to_phg,
|
|
24
|
+
world_pipestr_vis,
|
|
25
|
+
local_pipestr_vis
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
# Extend ShaderRenderer class to support direct PHG rendering
|
|
29
|
+
class PHGShaderRenderer(ShaderRenderer):
|
|
30
|
+
"""Shader renderer that supports direct PHG rendering"""
|
|
31
|
+
|
|
32
|
+
def render_phg(self, phg_script: str, duration=0, interactive=True):
|
|
33
|
+
"""
|
|
34
|
+
Render PHG script
|
|
35
|
+
|
|
36
|
+
Parameters:
|
|
37
|
+
phg_script: PHG script code
|
|
38
|
+
duration: Render duration
|
|
39
|
+
interactive: Whether to allow interaction
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
success: Whether rendering was successful
|
|
43
|
+
"""
|
|
44
|
+
converter = PHGToShaderConverter()
|
|
45
|
+
shader_code = converter.generate_shader_code(phg_script)
|
|
46
|
+
|
|
47
|
+
if not shader_code:
|
|
48
|
+
print("Error: PHG conversion failed")
|
|
49
|
+
return False
|
|
50
|
+
|
|
51
|
+
return self.render_shader(shader_code, duration, interactive)
|
|
52
|
+
|
|
53
|
+
# Convenience functions
|
|
54
|
+
def render_phg(phg_script: str, width=800, height=600, duration=0, title="PHG Renderer"):
|
|
55
|
+
"""
|
|
56
|
+
Directly render PHG script
|
|
57
|
+
|
|
58
|
+
Parameters:
|
|
59
|
+
phg_script: PHG script code
|
|
60
|
+
width: Window width
|
|
61
|
+
height: Window height
|
|
62
|
+
duration: Render duration
|
|
63
|
+
title: Window title
|
|
64
|
+
"""
|
|
65
|
+
renderer = PHGShaderRenderer(width, height, title)
|
|
66
|
+
success = renderer.render_phg(phg_script, duration)
|
|
67
|
+
renderer.close()
|
|
68
|
+
return success
|
|
69
|
+
|
|
70
|
+
def convert_phg_to_shader(phg_script: str) -> str:
|
|
71
|
+
"""
|
|
72
|
+
Convert PHG script to GLSL shader code
|
|
73
|
+
|
|
74
|
+
Parameters:
|
|
75
|
+
phg_script: PHG script
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
shader_code: GLSL shader code
|
|
79
|
+
"""
|
|
80
|
+
return phg_to_shader(phg_script)
|
|
81
|
+
|
|
82
|
+
__all__ = [
|
|
83
|
+
# Core visualization functions
|
|
84
|
+
'vis',
|
|
85
|
+
'image',
|
|
86
|
+
|
|
87
|
+
# Shader rendering
|
|
88
|
+
'ShaderRenderer',
|
|
89
|
+
'render_shader',
|
|
90
|
+
'render_phg',
|
|
91
|
+
'PHGShaderRenderer',
|
|
92
|
+
|
|
93
|
+
# PHG conversion
|
|
94
|
+
'PHGToShaderConverter',
|
|
95
|
+
'phg_to_shader',
|
|
96
|
+
'convert_phg_to_shader',
|
|
97
|
+
|
|
98
|
+
# Pipe visualization
|
|
99
|
+
'world_pipe_to_phg',
|
|
100
|
+
'local_pipe_to_phg',
|
|
101
|
+
'world_pipestr_vis',
|
|
102
|
+
'local_pipestr_vis',
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
__version__ = "1.3.1"
|
|
106
|
+
__author__ = "PanGuoJun"
|
|
107
|
+
__description__ = "Python Hypergraphics Library"
|
|
108
|
+
|
|
109
|
+
# Package initialization information
|
|
110
|
+
print(f"PHG {__version__} - {__description__}")
|
|
111
|
+
print("[OK] Visualization module loaded")
|
|
112
|
+
print("[OK] Shader converter loaded")
|
|
113
|
+
print("[OK] Pipe visualization loaded")
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pipe String to PHG Converter
|
|
3
|
+
============================
|
|
4
|
+
|
|
5
|
+
该模块提供了管道字符串转换为PHG(Python Graphics)脚本的功能。
|
|
6
|
+
支持世界坐标系和局部坐标系两种管道描述方式。
|
|
7
|
+
|
|
8
|
+
主要功能:
|
|
9
|
+
- world_pipe_to_phg: 世界坐标系管道转换
|
|
10
|
+
- local_pipe_to_phg: 局部坐标系管道转换
|
|
11
|
+
- world_pipestr_vis: 世界坐标系管道直接可视化
|
|
12
|
+
- local_pipestr_vis: 局部坐标系管道直接可视化
|
|
13
|
+
|
|
14
|
+
管道字符串格式:
|
|
15
|
+
- F: 前进 (Forward)
|
|
16
|
+
- B: 后退 (Back)
|
|
17
|
+
- R: 右转 (Right)
|
|
18
|
+
- L: 左转 (Left)
|
|
19
|
+
- U: 上转 (Up)
|
|
20
|
+
- D: 下转 (Down)
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import phg
|
|
24
|
+
from coordinate_system import vec3, quat, coord3
|
|
25
|
+
|
|
26
|
+
# 默认颜色和管径
|
|
27
|
+
DEFAULT_PIPE_COLOR = (0, 55, 255)
|
|
28
|
+
DEFAULT_PIPE_RADIUS = 0.3
|
|
29
|
+
|
|
30
|
+
def world_pipe_to_phg(world_pipe_str, start_c, pipe_color=DEFAULT_PIPE_COLOR, pipe_radius=DEFAULT_PIPE_RADIUS):
|
|
31
|
+
"""
|
|
32
|
+
将世界坐标系下的管道字符串转换为PHG脚本
|
|
33
|
+
|
|
34
|
+
参数:
|
|
35
|
+
world_pipe_str: 世界坐标系管道字符串(如 "FFRUD")
|
|
36
|
+
start_c: 起始坐标系
|
|
37
|
+
pipe_color: 管道颜色,格式为(R, G, B)元组
|
|
38
|
+
pipe_radius: 管道半径
|
|
39
|
+
|
|
40
|
+
返回:
|
|
41
|
+
PHG脚本字符串
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
# 世界坐标系方向定义
|
|
45
|
+
world_directions = {
|
|
46
|
+
'F': vec3(0, 0, 1), # 前(世界Z+)
|
|
47
|
+
'B': vec3(0, 0, -1), # 后(世界Z-)
|
|
48
|
+
'R': vec3(1, 0, 0), # 右(世界X+)
|
|
49
|
+
'L': vec3(-1, 0, 0), # 左(世界X-)
|
|
50
|
+
'U': vec3(0, 1, 0), # 上(世界Y+)
|
|
51
|
+
'D': vec3(0, -1, 0) # 下(世界Y-)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
# 解析颜色
|
|
55
|
+
r, g, b = pipe_color
|
|
56
|
+
|
|
57
|
+
# 管道部件映射(所有部件使用固定长度1.0)
|
|
58
|
+
pipe_components = {
|
|
59
|
+
'F': f'{{{{rgb:{r},{g},{b};md:cylinder {pipe_radius} 1.0;rx:90;z:-0.5;}};z:1.0}}',
|
|
60
|
+
'B': f'{{{{rgb:{r},{g},{b};md:cylinder {pipe_radius} 1.0;rx:-90;z:{-1.0-0.5};}};z:1.0}}',
|
|
61
|
+
'R': f'{{{{{{rgb:{r},{g},{b};md:elbow 90 0.5 {pipe_radius};x:0.5;z:0.5;}}ry:90;x:1.0;z:-1.0}}}},{{x:1.0;ry:-90;}}',
|
|
62
|
+
'L': f'{{{{{{rgb:{r},{g},{b};md:elbow 90 0.5 {pipe_radius};x:0.5;z:0.5;}}ry:-90;m:x;z:-1.0;x:-1.0}}}},{{x:-1.0;ry:90;}}',
|
|
63
|
+
'U': f'{{{{{{rgb:{r},{g},{b};md:elbow 90 0.5 {pipe_radius};x:0.5;z:0.5;}}rz:90;y:1.0;z:-1}}}},{{y:1.0;rx:90;}}',
|
|
64
|
+
'D': f'{{{{{{rgb:{r},{g},{b};md:elbow 90 0.5 {pipe_radius};x:0.5;z:0.5;}}rz:-90;y:-1;z:-1}}}},{{y:-1.0;rx:-90;}}'
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# 初始化当前坐标系(使用起始坐标系)
|
|
68
|
+
cur_c = coord3(start_c.o, start_c.Q())
|
|
69
|
+
|
|
70
|
+
# 存储所有管道部件的脚本
|
|
71
|
+
script_parts = []
|
|
72
|
+
|
|
73
|
+
# 遍历管道字符串中的每个字符
|
|
74
|
+
for move_char in world_pipe_str:
|
|
75
|
+
if move_char not in pipe_components:
|
|
76
|
+
print(f"警告: 未知的管道字符 '{move_char}',已跳过")
|
|
77
|
+
continue
|
|
78
|
+
|
|
79
|
+
# 获取当前移动在世界坐标系中的方向
|
|
80
|
+
world_dir = world_directions[move_char]
|
|
81
|
+
|
|
82
|
+
# 将世界方向转换到当前局部坐标系
|
|
83
|
+
local_dir = vec3(
|
|
84
|
+
world_dir.dot(cur_c.ux), # 在局部X轴的分量
|
|
85
|
+
world_dir.dot(cur_c.uy), # 在局部Y轴的分量
|
|
86
|
+
world_dir.dot(cur_c.uz) # 在局部Z轴的分量
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# 找到绝对值最大的分量来确定主要移动方向
|
|
90
|
+
abs_components = [abs(local_dir.x), abs(local_dir.y), abs(local_dir.z)]
|
|
91
|
+
max_idx = abs_components.index(max(abs_components))
|
|
92
|
+
|
|
93
|
+
# 根据最大分量确定局部移动方向
|
|
94
|
+
if max_idx == 0: # X轴
|
|
95
|
+
local_move = 'R' if local_dir.x > 0 else 'L'
|
|
96
|
+
elif max_idx == 1: # Y轴
|
|
97
|
+
local_move = 'U' if local_dir.y > 0 else 'D'
|
|
98
|
+
else: # Z轴
|
|
99
|
+
local_move = 'F' if local_dir.z > 0 else 'B'
|
|
100
|
+
|
|
101
|
+
# 添加对应的管道部件脚本
|
|
102
|
+
script_parts.append(pipe_components[local_move])
|
|
103
|
+
|
|
104
|
+
# 更新当前坐标系(模拟移动后的新位置和方向)
|
|
105
|
+
if local_move == 'F':
|
|
106
|
+
# 前进:沿局部Z轴正方向移动1.0单位
|
|
107
|
+
cur_c = cur_c * coord3(vec3(0, 0, 1.0))
|
|
108
|
+
elif local_move == 'B':
|
|
109
|
+
# 后退:沿局部Z轴负方向移动1.0单位
|
|
110
|
+
cur_c = cur_c * coord3(vec3(0, 0, -1.0))
|
|
111
|
+
elif local_move == 'R':
|
|
112
|
+
# 右转:绕Y轴旋转-90度,然后沿X轴移动1.0单位
|
|
113
|
+
rotation = quat(-3.1416 / 2, cur_c.uy)
|
|
114
|
+
cur_c = cur_c * rotation
|
|
115
|
+
cur_c = cur_c * coord3(vec3(1.0, 0, 0))
|
|
116
|
+
elif local_move == 'L':
|
|
117
|
+
# 左转:绕Y轴旋转90度,然后沿X轴移动1.0单位
|
|
118
|
+
rotation = quat(3.1416 / 2, cur_c.uy)
|
|
119
|
+
cur_c = cur_c * rotation
|
|
120
|
+
cur_c = cur_c * coord3(vec3(-1.0, 0, 0))
|
|
121
|
+
elif local_move == 'U':
|
|
122
|
+
# 上转:绕X轴旋转90度,然后沿Y轴移动1.0单位
|
|
123
|
+
rotation = quat(3.1416 / 2, cur_c.ux)
|
|
124
|
+
cur_c = cur_c * rotation
|
|
125
|
+
cur_c = cur_c * coord3(vec3(0, 1.0, 0))
|
|
126
|
+
elif local_move == 'D':
|
|
127
|
+
# 下转:绕X轴旋转-90度,然后沿Y轴移动1.0单位
|
|
128
|
+
rotation = quat(-3.1416 / 2, cur_c.ux)
|
|
129
|
+
cur_c = cur_c * rotation
|
|
130
|
+
cur_c = cur_c * coord3(vec3(0, -1.0, 0))
|
|
131
|
+
|
|
132
|
+
# 组合所有管道部件的脚本
|
|
133
|
+
inner_script = ',\n'.join(script_parts)
|
|
134
|
+
|
|
135
|
+
# 获取起始坐标系的四元数
|
|
136
|
+
q = start_c.Q()
|
|
137
|
+
|
|
138
|
+
# 构建完整的PHG脚本
|
|
139
|
+
complete_script = f"""{{
|
|
140
|
+
{{xyz:{start_c.o.x},{start_c.o.y},{start_c.o.z};q:{q.w},{q.x},{q.y},{q.z};s:0.5;
|
|
141
|
+
<{inner_script}>}}
|
|
142
|
+
}}"""
|
|
143
|
+
|
|
144
|
+
return complete_script
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def local_pipe_to_phg(local_pipe_str, start_c, pipe_color=DEFAULT_PIPE_COLOR, pipe_radius=DEFAULT_PIPE_RADIUS):
|
|
148
|
+
"""
|
|
149
|
+
将局部坐标系下的管道字符串转换为PHG脚本
|
|
150
|
+
|
|
151
|
+
参数:
|
|
152
|
+
local_pipe_str: 局部坐标系管道字符串(如 "FFRUD")
|
|
153
|
+
start_c: 起始坐标系
|
|
154
|
+
pipe_color: 管道颜色,格式为(R, G, B)元组
|
|
155
|
+
pipe_radius: 管道半径
|
|
156
|
+
|
|
157
|
+
返回:
|
|
158
|
+
PHG脚本字符串
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
# 解析颜色
|
|
162
|
+
r, g, b = pipe_color
|
|
163
|
+
|
|
164
|
+
# 管道部件映射(所有部件使用固定长度1.0)
|
|
165
|
+
pipe_components = {
|
|
166
|
+
'F': f'{{{{rgb:{r},{g},{b};md:cylinder {pipe_radius} 1.0;rx:90;z:-0.5;}};z:1.0}}',
|
|
167
|
+
'B': f'{{{{rgb:{r},{g},{b};md:cylinder {pipe_radius} 1.0;rx:-90;z:{-1.0-0.5};}};z:1.0}}',
|
|
168
|
+
'R': f'{{{{{{rgb:{r},{g},{b};md:elbow 90 0.5 {pipe_radius};x:0.5;z:0.5;}}ry:90;x:1.0;z:-1.0}}}},{{x:1.0;ry:-90;}}',
|
|
169
|
+
'L': f'{{{{{{rgb:{r},{g},{b};md:elbow 90 0.5 {pipe_radius};x:0.5;z:0.5;}}ry:-90;m:x;z:-1.0;x:-1.0}}}},{{x:-1.0;ry:90;}}',
|
|
170
|
+
'U': f'{{{{{{rgb:{r},{g},{b};md:elbow 90 0.5 {pipe_radius};x:0.5;z:0.5;}}rz:90;y:1.0;z:-1}}}},{{y:1.0;rx:90;}}',
|
|
171
|
+
'D': f'{{{{{{rgb:{r},{g},{b};md:elbow 90 0.5 {pipe_radius};x:0.5;z:0.5;}}rz:-90;y:-1;z:-1}}}},{{y:-1.0;rx:-90;}}'
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
# 存储所有管道部件的脚本
|
|
175
|
+
script_parts = []
|
|
176
|
+
|
|
177
|
+
# 遍历管道字符串中的每个字符
|
|
178
|
+
for move_char in local_pipe_str:
|
|
179
|
+
if move_char not in pipe_components:
|
|
180
|
+
print(f"警告: 未知的管道字符 '{move_char}',已跳过")
|
|
181
|
+
continue
|
|
182
|
+
|
|
183
|
+
# 直接使用局部坐标系的移动命令
|
|
184
|
+
script_parts.append(pipe_components[move_char])
|
|
185
|
+
|
|
186
|
+
# 组合所有管道部件的脚本
|
|
187
|
+
inner_script = ',\n'.join(script_parts)
|
|
188
|
+
|
|
189
|
+
# 获取起始坐标系的四元数
|
|
190
|
+
q = start_c.Q()
|
|
191
|
+
|
|
192
|
+
# 构建完整的PHG脚本
|
|
193
|
+
complete_script = f"""{{
|
|
194
|
+
{{xyz:{start_c.o.x},{start_c.o.y},{start_c.o.z};q:{q.w},{q.x},{q.y},{q.z};s:0.5;
|
|
195
|
+
<{inner_script}>}}
|
|
196
|
+
}}"""
|
|
197
|
+
|
|
198
|
+
return complete_script
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def world_pipestr_vis(world_pipe_str, start_c=None, pipe_color=DEFAULT_PIPE_COLOR, pipe_radius=DEFAULT_PIPE_RADIUS):
|
|
202
|
+
"""
|
|
203
|
+
世界坐标系管道字符串直接可视化
|
|
204
|
+
|
|
205
|
+
参数:
|
|
206
|
+
world_pipe_str: 世界坐标系管道字符串(如 "FFRUD")
|
|
207
|
+
start_c: 起始坐标系,默认为原点
|
|
208
|
+
pipe_color: 管道颜色,格式为(R, G, B)元组
|
|
209
|
+
pipe_radius: 管道半径
|
|
210
|
+
|
|
211
|
+
返回:
|
|
212
|
+
PHG脚本字符串
|
|
213
|
+
"""
|
|
214
|
+
# 如果没有提供起始坐标系,使用默认原点
|
|
215
|
+
if start_c is None:
|
|
216
|
+
start_c = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
|
|
217
|
+
|
|
218
|
+
# 生成PHG脚本
|
|
219
|
+
phg_script = world_pipe_to_phg(world_pipe_str, start_c, pipe_color, pipe_radius)
|
|
220
|
+
|
|
221
|
+
# 调用可视化函数
|
|
222
|
+
try:
|
|
223
|
+
from .visphg import vis
|
|
224
|
+
vis(phg_script)
|
|
225
|
+
except ImportError:
|
|
226
|
+
print("警告: 无法导入可视化模块,返回PHG脚本")
|
|
227
|
+
|
|
228
|
+
return phg_script
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def local_pipestr_vis(local_pipe_str, start_c=None, pipe_color=DEFAULT_PIPE_COLOR, pipe_radius=DEFAULT_PIPE_RADIUS):
|
|
232
|
+
"""
|
|
233
|
+
局部坐标系管道字符串直接可视化
|
|
234
|
+
|
|
235
|
+
参数:
|
|
236
|
+
local_pipe_str: 局部坐标系管道字符串(如 "FFRUD")
|
|
237
|
+
start_c: 起始坐标系,默认为原点
|
|
238
|
+
pipe_color: 管道颜色,格式为(R, G, B)元组
|
|
239
|
+
pipe_radius: 管道半径
|
|
240
|
+
|
|
241
|
+
返回:
|
|
242
|
+
PHG脚本字符串
|
|
243
|
+
"""
|
|
244
|
+
# 如果没有提供起始坐标系,使用默认原点
|
|
245
|
+
if start_c is None:
|
|
246
|
+
start_c = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
|
|
247
|
+
|
|
248
|
+
# 生成PHG脚本
|
|
249
|
+
phg_script = local_pipe_to_phg(local_pipe_str, start_c, pipe_color, pipe_radius)
|
|
250
|
+
|
|
251
|
+
# 调用可视化函数
|
|
252
|
+
try:
|
|
253
|
+
from .visphg import vis
|
|
254
|
+
vis(phg_script)
|
|
255
|
+
except ImportError:
|
|
256
|
+
print("警告: 无法导入可视化模块,返回PHG脚本")
|
|
257
|
+
|
|
258
|
+
return phg_script
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
# 使用示例
|
|
262
|
+
if __name__ == "__main__":
|
|
263
|
+
# 创建起始坐标系(示例)
|
|
264
|
+
start_coord = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
|
|
265
|
+
|
|
266
|
+
# 示例1: 世界坐标系管道字符串
|
|
267
|
+
example_world_pipe = "FFRUD" # 前进2次,右转,上转,下转
|
|
268
|
+
print("世界坐标系管道示例:")
|
|
269
|
+
phg_script = world_pipe_to_phg(example_world_pipe, start_coord)
|
|
270
|
+
print("生成的PHG脚本:")
|
|
271
|
+
print(phg_script)
|
|
272
|
+
print()
|
|
273
|
+
|
|
274
|
+
# 示例2: 局部坐标系管道字符串
|
|
275
|
+
example_local_pipe = "FFRUD" # 在局部坐标系中的移动
|
|
276
|
+
print("局部坐标系管道示例:")
|
|
277
|
+
phg_script = local_pipe_to_phg(example_local_pipe, start_coord)
|
|
278
|
+
print("生成的PHG脚本:")
|
|
279
|
+
print(phg_script)
|
|
280
|
+
print()
|
|
281
|
+
|
|
282
|
+
# 示例3: 直接可视化
|
|
283
|
+
print("直接可视化示例:")
|
|
284
|
+
# world_pipestr_vis(example_world_pipe) # 世界坐标系可视化
|
|
285
|
+
# local_pipestr_vis(example_local_pipe) # 局部坐标系可视化
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: phg_vis
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.1
|
|
4
4
|
Summary: A package for the PHG modeling language and 3D visualization tool.
|
|
5
5
|
Home-page: https://github.com/panguojun/Coordinate-System
|
|
6
6
|
Author: romeosoft
|
|
@@ -13,20 +13,21 @@ Requires-Python: >=3.8
|
|
|
13
13
|
Description-Content-Type: text/markdown
|
|
14
14
|
License-File: LICENSE
|
|
15
15
|
|
|
16
|
-
# PHG -
|
|
16
|
+
# PHG - Python Hypergraphics Library
|
|
17
17
|
|
|
18
|
-
PHG (
|
|
18
|
+
PHG (Python Hypergraphics) is a powerful 3D modeling and visualization library that combines a minimalist modeling language with Python integration. It provides procedural 3D scene generation, shader-based rendering, and specialized pipe system visualization.
|
|
19
19
|
|
|
20
20
|
---
|
|
21
21
|
|
|
22
22
|
## 🌟 Features
|
|
23
23
|
|
|
24
|
-
- **Minimalist Syntax** - Declarative node tree description
|
|
24
|
+
- **Minimalist Syntax** - Declarative node tree description for 3D scenes
|
|
25
25
|
- **Hierarchical Modeling** - Support for nested nodes and transform inheritance
|
|
26
26
|
- **Parametric Design** - Flexible property system and function definitions
|
|
27
|
-
- **
|
|
28
|
-
- **
|
|
29
|
-
- **
|
|
27
|
+
- **Pipe Visualization** - Specialized system for visualizing pipe structures with world/local coordinate support
|
|
28
|
+
- **Shader Conversion** - Convert PHG scripts to GLSL shaders for GPU rendering
|
|
29
|
+
- **Dual Rendering Modes** - Both real-time visualization (vis.exe) and offscreen rendering
|
|
30
|
+
- **Python Integration** - Comprehensive Python API for all features
|
|
30
31
|
|
|
31
32
|
---
|
|
32
33
|
|
|
@@ -402,6 +403,122 @@ for size in [5, 10, 15, 20]:
|
|
|
402
403
|
|
|
403
404
|
---
|
|
404
405
|
|
|
406
|
+
## 🔧 Pipe Visualization System
|
|
407
|
+
|
|
408
|
+
PHG includes a specialized pipe visualization system for creating 3D pipe structures from simple string commands.
|
|
409
|
+
|
|
410
|
+
### Pipe String Commands
|
|
411
|
+
|
|
412
|
+
- **F** - Forward (move forward in current direction)
|
|
413
|
+
- **B** - Back (move backward in current direction)
|
|
414
|
+
- **R** - Right (turn right and move)
|
|
415
|
+
- **L** - Left (turn left and move)
|
|
416
|
+
- **U** - Up (turn up and move)
|
|
417
|
+
- **D** - Down (turn down and move)
|
|
418
|
+
|
|
419
|
+
### World Coordinate System
|
|
420
|
+
|
|
421
|
+
World coordinate pipes use absolute directions regardless of current orientation:
|
|
422
|
+
|
|
423
|
+
```python
|
|
424
|
+
import phg
|
|
425
|
+
from coordinate_system import vec3, quat, coord3
|
|
426
|
+
|
|
427
|
+
# Create a pipe in world coordinates
|
|
428
|
+
# F moves along world Z+, R moves along world X+, etc.
|
|
429
|
+
start_pos = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
|
|
430
|
+
phg_script = phg.world_pipestr_vis("FFRRUD", start_pos)
|
|
431
|
+
|
|
432
|
+
# Custom pipe appearance
|
|
433
|
+
phg.world_pipestr_vis(
|
|
434
|
+
"FFLLUU",
|
|
435
|
+
start_pos,
|
|
436
|
+
pipe_color=(255, 100, 50), # Orange pipe
|
|
437
|
+
pipe_radius=0.5 # Thicker pipe
|
|
438
|
+
)
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
### Local Coordinate System
|
|
442
|
+
|
|
443
|
+
Local coordinate pipes use directions relative to current orientation:
|
|
444
|
+
|
|
445
|
+
```python
|
|
446
|
+
import phg
|
|
447
|
+
from coordinate_system import vec3, quat, coord3
|
|
448
|
+
|
|
449
|
+
# Create a pipe in local coordinates
|
|
450
|
+
# F moves forward relative to current orientation
|
|
451
|
+
start_pos = coord3(vec3(0, 0, 0), quat(1, 0, 0, 0))
|
|
452
|
+
phg_script = phg.local_pipestr_vis("FFRRUD", start_pos)
|
|
453
|
+
|
|
454
|
+
# The same string produces different results in local vs world coordinates
|
|
455
|
+
phg.local_pipestr_vis(
|
|
456
|
+
"FFRRFF", # Forward, Forward, Right turn, Right turn, Forward, Forward
|
|
457
|
+
start_pos,
|
|
458
|
+
pipe_color=(0, 255, 100) # Green pipe
|
|
459
|
+
)
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
### Direct PHG Script Generation
|
|
463
|
+
|
|
464
|
+
For advanced use cases, you can generate PHG scripts without immediate visualization:
|
|
465
|
+
|
|
466
|
+
```python
|
|
467
|
+
import phg
|
|
468
|
+
from coordinate_system import vec3, quat, coord3
|
|
469
|
+
|
|
470
|
+
start = coord3(vec3(5, 0, 0), quat(1, 0, 0, 0))
|
|
471
|
+
|
|
472
|
+
# Generate PHG script for world coordinates
|
|
473
|
+
world_phg = phg.world_pipe_to_phg("FFRUD", start)
|
|
474
|
+
|
|
475
|
+
# Generate PHG script for local coordinates
|
|
476
|
+
local_phg = phg.local_pipe_to_phg("FFRUD", start)
|
|
477
|
+
|
|
478
|
+
# Visualize later
|
|
479
|
+
phg.vis(world_phg)
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### Example: Complex Pipe System
|
|
483
|
+
|
|
484
|
+
```python
|
|
485
|
+
import phg
|
|
486
|
+
from coordinate_system import vec3, quat, coord3
|
|
487
|
+
|
|
488
|
+
# Create a complex pipe network
|
|
489
|
+
def create_pipe_network():
|
|
490
|
+
# Main pipeline
|
|
491
|
+
main_pipe = phg.world_pipestr_vis(
|
|
492
|
+
"FFFFRRFFRRUUFFLLFF",
|
|
493
|
+
coord3(vec3(0, 0, 0), quat(1, 0, 0, 0)),
|
|
494
|
+
pipe_color=(100, 100, 255),
|
|
495
|
+
pipe_radius=0.5
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
# Branch 1
|
|
499
|
+
branch1 = phg.world_pipestr_vis(
|
|
500
|
+
"RRUUFFFF",
|
|
501
|
+
coord3(vec3(4, 0, 0), quat(1, 0, 0, 0)),
|
|
502
|
+
pipe_color=(255, 100, 100),
|
|
503
|
+
pipe_radius=0.3
|
|
504
|
+
)
|
|
505
|
+
|
|
506
|
+
# Branch 2
|
|
507
|
+
branch2 = phg.local_pipestr_vis(
|
|
508
|
+
"FFLLDDFF",
|
|
509
|
+
coord3(vec3(8, 2, 2), quat(1, 0, 0, 0)),
|
|
510
|
+
pipe_color=(100, 255, 100),
|
|
511
|
+
pipe_radius=0.3
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
return main_pipe, branch1, branch2
|
|
515
|
+
|
|
516
|
+
# Create and visualize the network
|
|
517
|
+
pipes = create_pipe_network()
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
---
|
|
521
|
+
|
|
405
522
|
## 💡 Complete Examples
|
|
406
523
|
|
|
407
524
|
### Example 1: Simple Geometry
|
|
@@ -581,7 +698,6 @@ Recommended maximum resolution is **4096 x 4096**. Excessively large resolutions
|
|
|
581
698
|
## 🔗 Links
|
|
582
699
|
|
|
583
700
|
- [PyPI Package](https://pypi.org/project/phg/)
|
|
584
|
-
- [Official Documentation](https://your.documentation.link)
|
|
585
701
|
- [Mathematical Foundation](https://github.com/panguojun/Coordinate-System)
|
|
586
702
|
|
|
587
703
|
---
|
phg_vis-1.3.0/phg/__init__.py
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
__init__.py
|
|
3
|
-
PHG主库 - 集成PHG到Shader转换功能
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from .visphg import vis, image
|
|
7
|
-
from .shader_render import ShaderRenderer, render_shader
|
|
8
|
-
from .phg_to_shader import PHGToShaderConverter, phg_to_shader
|
|
9
|
-
|
|
10
|
-
# 扩展ShaderRenderer类以支持PHG直接渲染
|
|
11
|
-
class PHGShaderRenderer(ShaderRenderer):
|
|
12
|
-
"""支持PHG直接渲染的Shader渲染器"""
|
|
13
|
-
|
|
14
|
-
def render_phg(self, phg_script: str, duration=0, interactive=True):
|
|
15
|
-
"""
|
|
16
|
-
渲染PHG脚本
|
|
17
|
-
|
|
18
|
-
参数:
|
|
19
|
-
phg_script: PHG脚本代码
|
|
20
|
-
duration: 渲染持续时间
|
|
21
|
-
interactive: 是否允许交互
|
|
22
|
-
|
|
23
|
-
返回:
|
|
24
|
-
success: 是否成功渲染
|
|
25
|
-
"""
|
|
26
|
-
converter = PHGToShaderConverter()
|
|
27
|
-
shader_code = converter.generate_shader_code(phg_script)
|
|
28
|
-
|
|
29
|
-
if not shader_code:
|
|
30
|
-
print("错误: PHG转换失败")
|
|
31
|
-
return False
|
|
32
|
-
|
|
33
|
-
return self.render_shader(shader_code, duration, interactive)
|
|
34
|
-
|
|
35
|
-
# 便捷函数
|
|
36
|
-
def render_phg(phg_script: str, width=800, height=600, duration=0, title="PHG Renderer"):
|
|
37
|
-
"""
|
|
38
|
-
直接渲染PHG脚本
|
|
39
|
-
|
|
40
|
-
参数:
|
|
41
|
-
phg_script: PHG脚本代码
|
|
42
|
-
width: 窗口宽度
|
|
43
|
-
height: 窗口高度
|
|
44
|
-
duration: 渲染持续时间
|
|
45
|
-
title: 窗口标题
|
|
46
|
-
"""
|
|
47
|
-
renderer = PHGShaderRenderer(width, height, title)
|
|
48
|
-
success = renderer.render_phg(phg_script, duration)
|
|
49
|
-
renderer.close()
|
|
50
|
-
return success
|
|
51
|
-
|
|
52
|
-
def convert_phg_to_shader(phg_script: str) -> str:
|
|
53
|
-
"""
|
|
54
|
-
将PHG脚本转换为GLSL着色器代码
|
|
55
|
-
|
|
56
|
-
参数:
|
|
57
|
-
phg_script: PHG脚本
|
|
58
|
-
|
|
59
|
-
返回:
|
|
60
|
-
shader_code: GLSL着色器代码
|
|
61
|
-
"""
|
|
62
|
-
return phg_to_shader(phg_script)
|
|
63
|
-
|
|
64
|
-
__all__ = [
|
|
65
|
-
'vis',
|
|
66
|
-
'image',
|
|
67
|
-
'ShaderRenderer',
|
|
68
|
-
'render_shader',
|
|
69
|
-
'PHGToShaderConverter',
|
|
70
|
-
'PHGShaderRenderer',
|
|
71
|
-
'render_phg',
|
|
72
|
-
'convert_phg_to_shader',
|
|
73
|
-
'phg_to_shader'
|
|
74
|
-
]
|
|
75
|
-
|
|
76
|
-
__version__ = "0.2.0"
|
|
77
|
-
__author__ = "PHG Development Team"
|
|
78
|
-
__description__ = "Python Graphics Library with PHG to Shader conversion"
|
|
79
|
-
|
|
80
|
-
# 包初始化信息
|
|
81
|
-
print(f"PHG {__version__} - {__description__}")
|
|
82
|
-
print("PHG to Shader转换器已加载")
|
phg_vis-1.3.0/phg/vis/vis.ini
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|