Skip to content

Commit eafad39

Browse files
authored
Add properties for uv name and enable unwrap (#15)
1 parent 5ebb8d2 commit eafad39

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ Download this repo as a zip file and install through the Blender addons.
2121

2222
### Inputs
2323

24-
| Field | Description |
25-
| ----------- | ------------------------------------------------------ |
26-
| Name | Name used for baked images and material |
27-
| Mode | What to do with images after bake |
28-
| Size | Bake image size in pixels |
29-
| Save Images | Save images to external directory |
30-
| Layers | Enable baking of different layers, one image per layer |
24+
| Field | Description |
25+
| ------------- | ------------------------------------------------------ |
26+
| Name | Name used for baked images and material |
27+
| Mode | What to do with images after bake |
28+
| Size | Bake image size in pixels |
29+
| Bake UV | UV layer name used for baking |
30+
| Unwrap Object | Unwrap the object using smart project before baking |
31+
| Save Images | Save images to external directory |
32+
| Layers | Enable baking of different layers, one image per layer |
3133

3234
Mode has the following options
3335

docs/panel.png

3.06 KB
Loading

quickbake/op.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,17 @@ def execute(self, context: bpy.types.Context):
214214
return {"FINISHED"}
215215

216216
def unwrap_object(self, mesh: bpy.types.Mesh) -> bpy.types.MeshUVLoopLayer:
217-
uv_name = "bake_uv"
218-
_log.debug("Unwrapping mesh %s with uv layer %s", mesh.name, uv_name)
217+
_log.debug("Unwrapping mesh %s with uv layer %s", mesh.name, self.props.uv_name)
219218

220219
# Use existing or create new uv layer for baking
221-
bake_uv = mesh.uv_layers.get(uv_name)
220+
bake_uv = mesh.uv_layers.get(self.props.uv_name)
222221
if bake_uv is None:
223-
_log.info("Creating new uv layer %s", uv_name)
224-
bake_uv = mesh.uv_layers.new(name=uv_name)
222+
_log.info("Creating new uv layer %s", self.props.uv_name)
223+
bake_uv = mesh.uv_layers.new(name=self.props.uv_name)
225224
else:
226-
_log.debug("Reusing existing uv layer %s", uv_name)
225+
_log.debug("Reusing existing uv layer %s", self.props.uv_name)
226+
if not self.props.unwrap_object:
227+
return bake_uv
227228

228229
# Store currently active layer
229230
active_layer = None

quickbake/panel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ def draw(self, context):
2525
props = scene.QuickBakeToolPropertyGroup # type: ignore
2626

2727
layout.prop(props, "bake_name")
28-
layout.prop(props, "mat_mode")
2928
layout.prop(props, "bake_size")
29+
layout.prop(props, "uv_name")
30+
layout.prop(props, "unwrap_object")
31+
layout.prop(props, "mat_mode")
3032
layout.prop(props, "save_img")
3133

3234
row = layout.row()

quickbake/properties.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ class QuickBakeToolPropertyGroup(bpy.types.PropertyGroup):
2828
step=1024, # not yet implemented
2929
)
3030

31+
uv_name: bpy.props.StringProperty(
32+
name="Bake UV",
33+
description="UV layer name used for bake texture",
34+
default="bake_uv",
35+
)
36+
37+
unwrap_object: bpy.props.BoolProperty(
38+
name="Unwrap Object",
39+
description=(
40+
"Unwrap object using smart project before baking. "
41+
"If the uv layer does not exist, the object will be unwrapped regardless of this option."
42+
),
43+
default=True,
44+
)
45+
3146
mat_mode: bpy.props.EnumProperty(
3247
name="Mode",
3348
description="What to do with images after baking",

0 commit comments

Comments
 (0)