procfunc 0.30.0__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.
- procfunc/__init__.py +87 -0
- procfunc/color.py +57 -0
- procfunc/compute_graph/__init__.py +28 -0
- procfunc/compute_graph/compute_graph.py +115 -0
- procfunc/compute_graph/node.py +200 -0
- procfunc/compute_graph/operators_info.py +92 -0
- procfunc/compute_graph/proxy.py +173 -0
- procfunc/compute_graph/util.py +282 -0
- procfunc/context.py +115 -0
- procfunc/control.py +174 -0
- procfunc/nodes/__init__.py +66 -0
- procfunc/nodes/bindings_util.py +196 -0
- procfunc/nodes/bpy_node_info.py +280 -0
- procfunc/nodes/compositor.py +2242 -0
- procfunc/nodes/execute/construct_nodes.py +571 -0
- procfunc/nodes/execute/construct_special_cases.py +246 -0
- procfunc/nodes/execute/execute.py +548 -0
- procfunc/nodes/execute/infer_runtime_data_type.py +195 -0
- procfunc/nodes/execute/util.py +247 -0
- procfunc/nodes/func.py +1417 -0
- procfunc/nodes/geo.py +4240 -0
- procfunc/nodes/manifest.json +8769 -0
- procfunc/nodes/math.py +644 -0
- procfunc/nodes/node_function.py +160 -0
- procfunc/nodes/shader.py +2359 -0
- procfunc/nodes/types.py +347 -0
- procfunc/ops/__init__.py +35 -0
- procfunc/ops/_util.py +275 -0
- procfunc/ops/addons.py +59 -0
- procfunc/ops/attr.py +426 -0
- procfunc/ops/collection.py +90 -0
- procfunc/ops/curve.py +18 -0
- procfunc/ops/file.py +126 -0
- procfunc/ops/manifest.json +39149 -0
- procfunc/ops/mesh.py +1510 -0
- procfunc/ops/modifier.py +603 -0
- procfunc/ops/object.py +258 -0
- procfunc/ops/primitives/__init__.py +31 -0
- procfunc/ops/primitives/camera.py +45 -0
- procfunc/ops/primitives/curve.py +71 -0
- procfunc/ops/primitives/light.py +114 -0
- procfunc/ops/primitives/mesh.py +358 -0
- procfunc/ops/uv.py +271 -0
- procfunc/random.py +247 -0
- procfunc/tracer/__init__.py +43 -0
- procfunc/tracer/decorator.py +121 -0
- procfunc/tracer/patch.py +494 -0
- procfunc/tracer/proxy.py +127 -0
- procfunc/tracer/trace.py +222 -0
- procfunc/transforms/__init__.py +49 -0
- procfunc/transforms/cleanup.py +214 -0
- procfunc/transforms/convert.py +20 -0
- procfunc/transforms/distribution.py +191 -0
- procfunc/transforms/extract_materials.py +116 -0
- procfunc/transforms/infer_distribution.py +326 -0
- procfunc/transforms/parameters.py +15 -0
- procfunc/transforms/util.py +35 -0
- procfunc/transpiler/__init__.py +24 -0
- procfunc/transpiler/bpy_to_computegraph.py +1348 -0
- procfunc/transpiler/codegen.py +919 -0
- procfunc/transpiler/identifiers.py +595 -0
- procfunc/transpiler/main.py +299 -0
- procfunc/types.py +380 -0
- procfunc/util/__init__.py +0 -0
- procfunc/util/bpy_info.py +145 -0
- procfunc/util/camera.py +0 -0
- procfunc/util/keyframe.py +70 -0
- procfunc/util/log.py +96 -0
- procfunc/util/manifest.py +121 -0
- procfunc/util/pytree.py +343 -0
- procfunc/util/teardown.py +37 -0
- procfunc-0.30.0.dist-info/METADATA +120 -0
- procfunc-0.30.0.dist-info/RECORD +76 -0
- procfunc-0.30.0.dist-info/WHEEL +5 -0
- procfunc-0.30.0.dist-info/licenses/LICENSE.md +11 -0
- procfunc-0.30.0.dist-info/top_level.txt +1 -0
procfunc/ops/file.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
import bpy
|
|
5
|
+
|
|
6
|
+
from procfunc import types as t
|
|
7
|
+
from procfunc.util.log import Suppress
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def load_blend(input_path: Path | str):
|
|
13
|
+
if isinstance(input_path, Path):
|
|
14
|
+
input_path = str(input_path)
|
|
15
|
+
|
|
16
|
+
bpy.ops.wm.open_mainfile(filepath=input_path)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def save_blend(
|
|
20
|
+
output_path: Path | str,
|
|
21
|
+
autopack: bool = False,
|
|
22
|
+
):
|
|
23
|
+
logger.info(f"Saving blend to {output_path}")
|
|
24
|
+
|
|
25
|
+
if isinstance(output_path, Path):
|
|
26
|
+
output_path = str(output_path)
|
|
27
|
+
|
|
28
|
+
with Suppress():
|
|
29
|
+
if autopack:
|
|
30
|
+
bpy.ops.file.autopack_toggle()
|
|
31
|
+
bpy.ops.wm.save_as_mainfile(filepath=output_path)
|
|
32
|
+
if autopack:
|
|
33
|
+
bpy.ops.file.autopack_toggle()
|
|
34
|
+
|
|
35
|
+
return output_path
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def import_mesh(path: Path, **kwargs):
|
|
39
|
+
ext = path.suffix.lower()
|
|
40
|
+
|
|
41
|
+
funcs = {
|
|
42
|
+
".obj": bpy.ops.wm.obj_import,
|
|
43
|
+
".fbx": bpy.ops.import_scene.fbx,
|
|
44
|
+
".stl": bpy.ops.import_mesh.stl,
|
|
45
|
+
".ply": bpy.ops.wm.ply_import,
|
|
46
|
+
".usdc": bpy.ops.wm.usd_import,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if ext not in funcs:
|
|
50
|
+
raise ValueError(
|
|
51
|
+
f"{import_mesh.__name__} does not yet support extension {ext}, please contact the developer"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
funcs[ext](filepath=str(path), **kwargs)
|
|
55
|
+
|
|
56
|
+
if len(bpy.context.selected_objects) > 1 if ext != "usdc" else 2:
|
|
57
|
+
logger.warning(
|
|
58
|
+
f"Warning: {ext.upper()} Import produced {len(bpy.context.selected_objects)} objects, "
|
|
59
|
+
f"but only the first is returned by import_obj"
|
|
60
|
+
)
|
|
61
|
+
if ext != "usdc":
|
|
62
|
+
return bpy.context.selected_objects[0]
|
|
63
|
+
else:
|
|
64
|
+
return next(o for o in bpy.context.selected_objects if o.type != "EMPTY")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def save_mesh(
|
|
68
|
+
output_path: Path,
|
|
69
|
+
objects: list[t.Object | t.Object] | None = None,
|
|
70
|
+
**kwargs,
|
|
71
|
+
) -> Path:
|
|
72
|
+
funcs = {
|
|
73
|
+
".obj": bpy.ops.wm.obj_export,
|
|
74
|
+
".fbx": bpy.ops.export_scene.fbx,
|
|
75
|
+
".stl": bpy.ops.export_mesh.stl,
|
|
76
|
+
".ply": bpy.ops.wm.ply_export,
|
|
77
|
+
".usdc": bpy.ops.wm.usd_export,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if output_path.suffix not in funcs:
|
|
81
|
+
raise ValueError(
|
|
82
|
+
f"{save_mesh.__name__} does not yet support extension {output_path.suffix}, "
|
|
83
|
+
" please contact the developer"
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
if objects is not None:
|
|
87
|
+
for obj in bpy.data.objects:
|
|
88
|
+
obj.select_set(False)
|
|
89
|
+
for obj in objects:
|
|
90
|
+
if isinstance(obj, t.Object):
|
|
91
|
+
obj = obj.item()
|
|
92
|
+
obj.select_set(True)
|
|
93
|
+
use_selection = objects is not None
|
|
94
|
+
|
|
95
|
+
match output_path.suffix:
|
|
96
|
+
case ".obj":
|
|
97
|
+
bpy.ops.wm.obj_export(
|
|
98
|
+
filepath=str(output_path),
|
|
99
|
+
export_selected_objects=use_selection,
|
|
100
|
+
**kwargs,
|
|
101
|
+
)
|
|
102
|
+
case ".fbx":
|
|
103
|
+
bpy.ops.export_scene.fbx(
|
|
104
|
+
filepath=str(output_path), use_selection=use_selection, **kwargs
|
|
105
|
+
)
|
|
106
|
+
case ".stl":
|
|
107
|
+
bpy.ops.export_mesh.stl(
|
|
108
|
+
filepath=str(output_path), use_selection=use_selection, **kwargs
|
|
109
|
+
)
|
|
110
|
+
case ".ply":
|
|
111
|
+
bpy.ops.wm.ply_export(
|
|
112
|
+
filepath=str(output_path),
|
|
113
|
+
export_selected_objects=use_selection,
|
|
114
|
+
**kwargs,
|
|
115
|
+
)
|
|
116
|
+
case ".usdc":
|
|
117
|
+
bpy.ops.wm.usd_export(
|
|
118
|
+
filepath=str(output_path), selected_objects_only=use_selection, **kwargs
|
|
119
|
+
)
|
|
120
|
+
case _:
|
|
121
|
+
raise ValueError(f"Unknown extension {output_path.suffix}")
|
|
122
|
+
|
|
123
|
+
if not output_path.exists():
|
|
124
|
+
raise FileNotFoundError(f"Failed to save mesh to {output_path}")
|
|
125
|
+
|
|
126
|
+
return output_path
|