phg-vis 1.4.0__py3-none-any.whl → 1.4.2__py3-none-any.whl
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/__init__.py +2 -2
- phg/ai_bridge.py +57 -13
- phg/pipe_string_phg.py +2 -2
- phg/web_three.py +11 -3
- {phg_vis-1.4.0.dist-info → phg_vis-1.4.2.dist-info}/METADATA +1 -1
- {phg_vis-1.4.0.dist-info → phg_vis-1.4.2.dist-info}/RECORD +9 -9
- {phg_vis-1.4.0.dist-info → phg_vis-1.4.2.dist-info}/LICENSE +0 -0
- {phg_vis-1.4.0.dist-info → phg_vis-1.4.2.dist-info}/WHEEL +0 -0
- {phg_vis-1.4.0.dist-info → phg_vis-1.4.2.dist-info}/top_level.txt +0 -0
phg/__init__.py
CHANGED
|
@@ -11,7 +11,7 @@ Main Features:
|
|
|
11
11
|
- Multiple pipe visualization support
|
|
12
12
|
- Real-time and image rendering capabilities
|
|
13
13
|
|
|
14
|
-
Version: 1.4.
|
|
14
|
+
Version: 1.4.2
|
|
15
15
|
Author: PanGuoJun
|
|
16
16
|
License: MIT
|
|
17
17
|
"""
|
|
@@ -387,7 +387,7 @@ __all__ = [
|
|
|
387
387
|
'visualize_pipe_with_transformations',
|
|
388
388
|
]
|
|
389
389
|
|
|
390
|
-
__version__ = "1.4.
|
|
390
|
+
__version__ = "1.4.2"
|
|
391
391
|
__author__ = "PanGuoJun"
|
|
392
392
|
__description__ = "Python Hypergraphics Library"
|
|
393
393
|
|
phg/ai_bridge.py
CHANGED
|
@@ -4,6 +4,8 @@ AI bridge for PHG (DGE++ parser -> normalized PHG -> vis.exe / web).
|
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
|
+
import importlib
|
|
8
|
+
import importlib.util
|
|
7
9
|
import json
|
|
8
10
|
import os
|
|
9
11
|
import subprocess
|
|
@@ -15,6 +17,8 @@ from .visphg import vis as _vis, image as _image
|
|
|
15
17
|
from .web_three import write_three_view_html
|
|
16
18
|
|
|
17
19
|
DEFAULT_AI_ROOT = r"C:\Users\18858\Documents\_AILab\DGE++\PHG"
|
|
20
|
+
_AI_MODULE = None
|
|
21
|
+
_AI_MODULE_ROOT = None
|
|
18
22
|
|
|
19
23
|
|
|
20
24
|
def resolve_ai_root(ai_root: Optional[str] = None) -> str:
|
|
@@ -40,6 +44,33 @@ def _run_ai_cli(args: List[str], ai_root: Optional[str] = None, timeout: int = 1
|
|
|
40
44
|
)
|
|
41
45
|
|
|
42
46
|
|
|
47
|
+
def _load_ai_module(ai_root: Optional[str] = None):
|
|
48
|
+
global _AI_MODULE, _AI_MODULE_ROOT
|
|
49
|
+
root = resolve_ai_root(ai_root)
|
|
50
|
+
if _AI_MODULE is not None and _AI_MODULE_ROOT == root:
|
|
51
|
+
return _AI_MODULE
|
|
52
|
+
|
|
53
|
+
pkg_dir = os.path.join(root, "phg")
|
|
54
|
+
init_path = os.path.join(pkg_dir, "__init__.py")
|
|
55
|
+
if not os.path.isfile(init_path):
|
|
56
|
+
raise FileNotFoundError(f"AI PHG package not found: {init_path}")
|
|
57
|
+
|
|
58
|
+
spec = importlib.util.spec_from_file_location(
|
|
59
|
+
"phg_ai",
|
|
60
|
+
init_path,
|
|
61
|
+
submodule_search_locations=[pkg_dir],
|
|
62
|
+
)
|
|
63
|
+
if spec is None or spec.loader is None:
|
|
64
|
+
raise ImportError("Failed to load AI PHG package")
|
|
65
|
+
|
|
66
|
+
module = importlib.util.module_from_spec(spec)
|
|
67
|
+
sys.modules["phg_ai"] = module
|
|
68
|
+
spec.loader.exec_module(module)
|
|
69
|
+
_AI_MODULE = module
|
|
70
|
+
_AI_MODULE_ROOT = root
|
|
71
|
+
return module
|
|
72
|
+
|
|
73
|
+
|
|
43
74
|
def _write_temp_phg(script: str) -> str:
|
|
44
75
|
fd, path = tempfile.mkstemp(suffix=".phg")
|
|
45
76
|
os.close(fd)
|
|
@@ -56,11 +87,22 @@ def dump_scene(script: str, ai_root: Optional[str] = None) -> Dict[str, Any]:
|
|
|
56
87
|
fd, json_path = tempfile.mkstemp(suffix=".json")
|
|
57
88
|
os.close(fd)
|
|
58
89
|
try:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
90
|
+
try:
|
|
91
|
+
ai = _load_ai_module(ai_root)
|
|
92
|
+
engine_mod = importlib.import_module("phg_ai.engine")
|
|
93
|
+
engine = engine_mod.Engine()
|
|
94
|
+
engine.run(script)
|
|
95
|
+
if "setup" not in engine.calls:
|
|
96
|
+
engine.setup()
|
|
97
|
+
if "draw" not in engine.calls:
|
|
98
|
+
engine.draw()
|
|
99
|
+
return engine._scene_to_dict(engine.scene.root)
|
|
100
|
+
except Exception:
|
|
101
|
+
proc = _run_ai_cli(["dump", phg_path, "--out", json_path], ai_root=ai_root)
|
|
102
|
+
if proc.returncode != 0:
|
|
103
|
+
raise RuntimeError(proc.stderr.strip() or proc.stdout.strip() or "AI dump failed")
|
|
104
|
+
with open(json_path, "r", encoding="utf-8") as f:
|
|
105
|
+
return json.load(f)
|
|
64
106
|
finally:
|
|
65
107
|
for p in (phg_path, json_path):
|
|
66
108
|
try:
|
|
@@ -146,16 +188,18 @@ def image_ai(script: str, filename: str = "shot.png", ai_root: Optional[str] = N
|
|
|
146
188
|
|
|
147
189
|
|
|
148
190
|
def export_ai_obj(script: str, out_obj: str, ai_root: Optional[str] = None) -> str:
|
|
149
|
-
phg_path = _write_temp_phg(script)
|
|
150
191
|
try:
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
192
|
+
ai = _load_ai_module(ai_root)
|
|
193
|
+
engine_mod = importlib.import_module("phg_ai.engine")
|
|
194
|
+
engine = engine_mod.Engine()
|
|
195
|
+
engine.run(script)
|
|
196
|
+
if "setup" not in engine.calls:
|
|
197
|
+
engine.setup()
|
|
198
|
+
if "draw" not in engine.calls:
|
|
199
|
+
engine.draw()
|
|
200
|
+
engine.export_obj(out_obj)
|
|
154
201
|
finally:
|
|
155
|
-
|
|
156
|
-
os.remove(phg_path)
|
|
157
|
-
except OSError:
|
|
158
|
-
pass
|
|
202
|
+
pass
|
|
159
203
|
return out_obj
|
|
160
204
|
|
|
161
205
|
|
phg/pipe_string_phg.py
CHANGED
|
@@ -71,8 +71,8 @@ def world_to_local_pipe_str(world_pipe_str, start_c):
|
|
|
71
71
|
'D': vec3(0, -1, 0) # Down (local Y-)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
# Initialize local coordinate system
|
|
75
|
-
cur_c = start_c
|
|
74
|
+
# Initialize local coordinate system (coord3, not quat)
|
|
75
|
+
cur_c = start_c
|
|
76
76
|
local_pipe_str = ""
|
|
77
77
|
|
|
78
78
|
for i, move in enumerate(world_pipe_str):
|
phg/web_three.py
CHANGED
|
@@ -67,10 +67,18 @@ def write_three_view_html(obj_path: str, out_html: str, title: str = "PHG Web Vi
|
|
|
67
67
|
<div>OBJ: {html.escape(os.path.basename(obj_path))}</div>
|
|
68
68
|
<div>Controls: LMB rotate, RMB pan, wheel zoom</div>
|
|
69
69
|
</div>
|
|
70
|
+
<script type="importmap">
|
|
71
|
+
{{
|
|
72
|
+
"imports": {{
|
|
73
|
+
"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js",
|
|
74
|
+
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/"
|
|
75
|
+
}}
|
|
76
|
+
}}
|
|
77
|
+
</script>
|
|
70
78
|
<script type="module">
|
|
71
|
-
import * as THREE from "
|
|
72
|
-
import {{ OrbitControls }} from "
|
|
73
|
-
import {{ OBJLoader }} from "
|
|
79
|
+
import * as THREE from "three";
|
|
80
|
+
import {{ OrbitControls }} from "three/addons/controls/OrbitControls.js";
|
|
81
|
+
import {{ OBJLoader }} from "three/addons/loaders/OBJLoader.js";
|
|
74
82
|
|
|
75
83
|
const container = document.getElementById("app");
|
|
76
84
|
const scene = new THREE.Scene();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
phg/__init__.py,sha256=
|
|
2
|
-
phg/ai_bridge.py,sha256=
|
|
1
|
+
phg/__init__.py,sha256=tqMl_2W5wT3huW7P9Q3i2PyaWfuxB0RiG_pUD5zc6kg,13241
|
|
2
|
+
phg/ai_bridge.py,sha256=6cAewSwrruS-Sdr6ffhqYP6ti72FZz8FhkSuLHfMpSA,6671
|
|
3
3
|
phg/gcu_api.py,sha256=yjCWAJPyIAL_fAdj2umX39wNmw56-LmkcmUPqt3V8DI,22957
|
|
4
4
|
phg/phg_to_shader.py,sha256=rb_LnGE1Py08oz72ES5CnjyCDbjVWDU3If0cYZq4SUU,15172
|
|
5
|
-
phg/pipe_string_phg.py,sha256=
|
|
5
|
+
phg/pipe_string_phg.py,sha256=Dg1rhhXvnWIZqV37BsCytpxxXIOQi1XRpK_uIUE0wFA,16602
|
|
6
6
|
phg/shader_render.py,sha256=ncQQHp5OMlOVeTsoIHOL2xnc6SQct7B8YRKPA-D9FlM,17278
|
|
7
7
|
phg/visphg.py,sha256=TpT6icBoBmPCbCm212qKC9zft9MQ2UK2dWvmgnlupwQ,2163
|
|
8
|
-
phg/web_three.py,sha256=
|
|
8
|
+
phg/web_three.py,sha256=LU6zi1kxk5ARMKV-xCo-1sKVEJCq5a2oWhJQ4lpCZEw,5086
|
|
9
9
|
phg/vis/GCU.dll,sha256=k_slWZ5nOzZNi9zCe0_SKc0F7zXoLyRuRDomyirPY4I,2687488
|
|
10
10
|
phg/vis/dragpad.exe,sha256=4qWG4VH1vginIGpKkBHwEBFlpTY8G6xPejeloJurNkE,51712
|
|
11
11
|
phg/vis/dragpad_config.ini,sha256=MD5no-RjzzcBxyz3JWuI88qH5Q4WVivRLqk_1GE5VQY,78
|
|
@@ -18,8 +18,8 @@ phg/vis/vis.exe,sha256=9LGgETiO4lwhz_gJzdUg6gPP9EwGLT5SuLjN3wR2sso,1388032
|
|
|
18
18
|
phg/vis/vis.ini,sha256=IjS0Av2BqresPR2oGCOoq5zliXN2wFRMK3rXcU15vKs,161
|
|
19
19
|
phg/vis/zlib1.dll,sha256=oVw_r326ve3oveVZhlSiF8BloZQ6lfqXJEAhUYfMjOQ,89088
|
|
20
20
|
phg/vis/imgui/main.lua,sha256=AIB5dpGrPHXuRiNW7Bg7eu5Lpi2DDcn6n4JS7OS1Hdk,4742
|
|
21
|
-
phg_vis-1.4.
|
|
22
|
-
phg_vis-1.4.
|
|
23
|
-
phg_vis-1.4.
|
|
24
|
-
phg_vis-1.4.
|
|
25
|
-
phg_vis-1.4.
|
|
21
|
+
phg_vis-1.4.2.dist-info/LICENSE,sha256=tDnRkJxBYPzWdfh2gArRqrUPJxQZRZHJVs68qqBHIq4,1083
|
|
22
|
+
phg_vis-1.4.2.dist-info/METADATA,sha256=Y47er0A8ONwutNpML6hf5yBANW6ZxACzlSzvkUUYhP8,19424
|
|
23
|
+
phg_vis-1.4.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
24
|
+
phg_vis-1.4.2.dist-info/top_level.txt,sha256=5GGhpTP8yi-zTXwW2HrI-zcxKxIM_nHXhL7r0iIDE_k,4
|
|
25
|
+
phg_vis-1.4.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|