-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ScenePreview.py
141 lines (135 loc) · 4.79 KB
/
ScenePreview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
__version__ = "2.0"
from meshroom.core import desc
import os.path
currentDir = os.path.dirname(os.path.abspath(__file__))
class ScenePreview(desc.CommandLineNode):
commandLine = '{blenderCmdValue} -b --python {scriptValue} -- {allParams}'
size = desc.DynamicNodeSize('cameras')
parallelization = desc.Parallelization(blockSize=40)
commandLineRange = '--rangeStart {rangeStart} --rangeSize {rangeBlockSize}'
category = 'Utils'
documentation = '''
This node uses Blender to visualize a 3D model from a given set of cameras.
The cameras must be a SfMData file in JSON format.
For the 3D model it supports both point clouds in Alembic format and meshes in OBJ format.
One frame per viewpoint will be rendered, and the undistorted views can optionally be used as background.
'''
inputs = [
desc.File(
name="blenderCmd",
label="Blender Command",
description="Command to launch Blender.",
value="blender",
invalidate=False,
group="",
),
desc.File(
name="script",
label="Script",
description="Path to the internal script for rendering in Blender.",
value=os.path.join(currentDir, "scripts", "preview.py"),
invalidate=False,
group="",
advanced=True,
),
desc.File(
name="cameras",
label="Cameras",
description="SfMData with the views, poses and intrinsics to use (in JSON format).",
value="",
),
desc.File(
name="model",
label="Model",
description="Point cloud (.abc) or mesh (.obj) to render.",
value="",
),
desc.BoolParam(
name="useBackground",
label="Display Background",
description="Use the undistorted images as background.",
value=True,
),
desc.File(
name="undistortedImages",
label="Undistorted Images",
description="Folder containing the undistorted images.",
value="",
enabled=lambda node: node.useBackground.value,
),
desc.BoolParam(
name="useMasks",
label="Apply Masks",
description="Apply mask to the rendered geometry.",
value=True,
),
desc.File(
name="masks",
label="Masks",
description="Folder containing the masks.",
value="",
enabled=lambda node: node.useMasks.value,
),
desc.GroupAttribute(
name="pointCloudParams",
label="Point Cloud Settings",
group=None,
enabled=lambda node: node.model.value.lower().endswith(".abc"),
description="Settings for point cloud rendering.",
groupDesc=[
desc.FloatParam(
name="particleSize",
label="Particle Size",
description="Scale of particles used for the point cloud.",
value=0.01,
range=(0.01, 1.0, 0.01),
),
desc.ChoiceParam(
name="particleColor",
label="Particle Color",
description="Color of particles used for the point cloud.",
value="Red",
values=["Grey", "White", "Red", "Green", "Magenta"],
),
],
),
desc.GroupAttribute(
name="meshParams",
label="Mesh Settings",
group=None,
enabled=lambda node: node.model.value.lower().endswith(".obj"),
description="Setting for mesh rendering.",
groupDesc=[
desc.ChoiceParam(
name="shading",
label="Shading",
description="Shading method for visualizing the mesh.",
value="wireframe",
values=["wireframe", "line_art"],
),
desc.ChoiceParam(
name="edgeColor",
label="Edge Color",
description="Color of the mesh edges.",
value="Red",
values=["Grey", "White", "Red", "Green", "Magenta"],
),
],
),
]
outputs = [
desc.File(
name="output",
label="Output",
description="Output folder.",
value=desc.Node.internalFolder,
),
desc.File(
name="frames",
label="Frames",
description="Frames rendered in Blender.",
semantic="image",
value=desc.Node.internalFolder + "<FILESTEM>_preview.jpg",
group="",
),
]