phg-vis 1.4.0__tar.gz → 1.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. {phg_vis-1.4.0/phg_vis.egg-info → phg_vis-1.4.1}/PKG-INFO +1 -1
  2. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/__init__.py +2 -2
  3. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/ai_bridge.py +57 -13
  4. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/web_three.py +11 -3
  5. {phg_vis-1.4.0 → phg_vis-1.4.1/phg_vis.egg-info}/PKG-INFO +1 -1
  6. {phg_vis-1.4.0 → phg_vis-1.4.1}/setup.py +1 -1
  7. {phg_vis-1.4.0 → phg_vis-1.4.1}/LICENSE +0 -0
  8. {phg_vis-1.4.0 → phg_vis-1.4.1}/MANIFEST.in +0 -0
  9. {phg_vis-1.4.0 → phg_vis-1.4.1}/README.md +0 -0
  10. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/gcu_api.py +0 -0
  11. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/phg_to_shader.py +0 -0
  12. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/pipe_string_phg.py +0 -0
  13. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/shader_render.py +0 -0
  14. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/vis/GCU.dll +0 -0
  15. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/vis/dragpad.exe +0 -0
  16. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/vis/dragpad_config.ini +0 -0
  17. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/vis/freeglut.dll +0 -0
  18. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/vis/imgui/main.lua +0 -0
  19. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/vis/lua.dll +0 -0
  20. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/vis/script.phg +0 -0
  21. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/vis/sqlite3.dll +0 -0
  22. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/vis/vis.exe +0 -0
  23. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/vis/vis.ini +0 -0
  24. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/vis/zlib1.dll +0 -0
  25. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg/visphg.py +0 -0
  26. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg_vis.egg-info/SOURCES.txt +0 -0
  27. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg_vis.egg-info/dependency_links.txt +0 -0
  28. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg_vis.egg-info/requires.txt +0 -0
  29. {phg_vis-1.4.0 → phg_vis-1.4.1}/phg_vis.egg-info/top_level.txt +0 -0
  30. {phg_vis-1.4.0 → phg_vis-1.4.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: phg_vis
3
- Version: 1.4.0
3
+ Version: 1.4.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
@@ -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.0
14
+ Version: 1.4.1
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.0"
390
+ __version__ = "1.4.1"
391
391
  __author__ = "PanGuoJun"
392
392
  __description__ = "Python Hypergraphics Library"
393
393
 
@@ -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
- proc = _run_ai_cli(["dump", phg_path, "--out", json_path], ai_root=ai_root)
60
- if proc.returncode != 0:
61
- raise RuntimeError(proc.stderr.strip() or proc.stdout.strip() or "AI dump failed")
62
- with open(json_path, "r", encoding="utf-8") as f:
63
- return json.load(f)
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
- proc = _run_ai_cli(["export", phg_path, "--out", out_obj], ai_root=ai_root)
152
- if proc.returncode != 0:
153
- raise RuntimeError(proc.stderr.strip() or proc.stdout.strip() or "AI export failed")
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
- try:
156
- os.remove(phg_path)
157
- except OSError:
158
- pass
202
+ pass
159
203
  return out_obj
160
204
 
161
205
 
@@ -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 "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js";
72
- import {{ OrbitControls }} from "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/controls/OrbitControls.js";
73
- import {{ OBJLoader }} from "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/loaders/OBJLoader.js";
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: phg_vis
3
- Version: 1.4.0
3
+ Version: 1.4.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
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='phg_vis',
5
- version='1.4.0',
5
+ version='1.4.1',
6
6
  packages=find_packages(),
7
7
  include_package_data=True,
8
8
  description='A package for the PHG modeling language and 3D visualization tool.',
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
File without changes