Skip to content

Commit 7e54c65

Browse files
Enable Library Overrides
1 parent 7685320 commit 7e54c65

File tree

4 files changed

+128
-28
lines changed

4 files changed

+128
-28
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Blender Addon Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [Unreleased]
6+
7+
### Added
8+
9+
- Enable ability to override library assets' component data when instancing
10+
11+
### Changed
12+
13+
### Removed
14+
15+
## [0.1] - 2025-03-17
16+
17+
Initial Release of Blender Addon
18+
19+
[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/blender-v0.1.0...HEAD
20+
[0.0.1]: https://github.com/rust-adventure/skein/releases/tag/blender-v0.1.0

extension/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,23 @@ def register():
8989

9090
# set up per-object data types that are required to render panels
9191
bpy.types.Object.active_component_index = bpy.props.IntProperty(
92-
min=0
92+
min=0,
93+
override={"LIBRARY_OVERRIDABLE"},
9394
)
9495
bpy.types.Mesh.active_component_index = bpy.props.IntProperty(
95-
min=0
96+
min=0,
97+
override={"LIBRARY_OVERRIDABLE"},
9698
)
9799
bpy.types.Material.active_component_index = bpy.props.IntProperty(
98-
min=0
100+
min=0,
101+
override={"LIBRARY_OVERRIDABLE"},
99102
)
100103

101104
# TODO: move this to common property group for all object, material, mesh, etc extras
102105
bpy.types.WindowManager.selected_component = bpy.props.StringProperty(
103106
name="component type path",
104107
description="The component that will be added if selected",
105-
update=on_select_new_component
108+
update=on_select_new_component,
106109
)
107110
# skein_property_groups is a dict keyed by component type_path
108111
# each type_path's value is a PropertyGroup that we can introspect

extension/operators/fetch_bevy_type_registry.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ def process_registry(context, registry):
109109
# maybe we hash the type_paths in the future to contrain the length
110110
if len(type_path) <= 63:
111111
if inspect.get_annotations(property_group_or_property):
112-
fake_component_enum_annotations[type_path] = bpy.props.PointerProperty(type=property_group_or_property)
112+
fake_component_enum_annotations[type_path] = bpy.props.PointerProperty(
113+
type=property_group_or_property,
114+
override={"LIBRARY_OVERRIDABLE"},
115+
)
113116
else:
114117
fake_component_enum_annotations[type_path] = property_group_or_property
115118
else:
@@ -128,6 +131,15 @@ def process_registry(context, registry):
128131
bpy.utils.register_class(component_container)
129132

130133
# new component list data. Must be set to read component data from .blend file
131-
bpy.types.Object.skein_two = bpy.props.CollectionProperty(type=component_container)
132-
bpy.types.Mesh.skein_two = bpy.props.CollectionProperty(type=component_container)
133-
bpy.types.Material.skein_two = bpy.props.CollectionProperty(type=component_container)
134+
bpy.types.Object.skein_two = bpy.props.CollectionProperty(
135+
type=component_container,
136+
override={"LIBRARY_OVERRIDABLE"},
137+
)
138+
bpy.types.Mesh.skein_two = bpy.props.CollectionProperty(
139+
type=component_container,
140+
override={"LIBRARY_OVERRIDABLE"},
141+
)
142+
bpy.types.Material.skein_two = bpy.props.CollectionProperty(
143+
type=component_container,
144+
override={"LIBRARY_OVERRIDABLE"},
145+
)

extension/property_groups.py

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def make_property(
8686
# TODO: make an enum default value
8787
skein_property_groups[type_path] = bpy.props.EnumProperty(
8888
items=items,
89+
override={"LIBRARY_OVERRIDABLE"},
8990
)
9091

9192
return skein_property_groups[type_path]
@@ -104,6 +105,7 @@ def make_property(
104105
annotations["skein_enum_index"] = bpy.props.EnumProperty(
105106
name="variant",
106107
items=items,
108+
override={"LIBRARY_OVERRIDABLE"},
107109
)
108110

109111
for option in component["oneOf"]:
@@ -125,7 +127,10 @@ def make_property(
125127
option
126128
)
127129
if inspect.isclass(property):
128-
annotations[key] = bpy.props.PointerProperty(type=property)
130+
annotations[key] = bpy.props.PointerProperty(
131+
type=property,
132+
override={"LIBRARY_OVERRIDABLE"},
133+
)
129134
else:
130135
annotations[key] = property
131136

@@ -171,7 +176,10 @@ def make_property(
171176
component["properties"][key]["type"]["$ref"]
172177
)
173178
if inspect.isclass(property):
174-
annotations[key] = bpy.props.PointerProperty(type=property)
179+
annotations[key] = bpy.props.PointerProperty(
180+
type=property,
181+
override={"LIBRARY_OVERRIDABLE"},
182+
)
175183
else:
176184
annotations[key] = property
177185

@@ -224,18 +232,22 @@ def make_property(
224232
# print("- component[type]: ", component["type"])
225233
match component["type"]:
226234
case "boolean":
227-
return bpy.props.BoolProperty()
235+
return bpy.props.BoolProperty(
236+
override={"LIBRARY_OVERRIDABLE"}
237+
)
228238
case "uint":
229239
match type_path:
230240
case "u8":
231241
return bpy.props.IntProperty(
232242
min=0,
233243
max=255,
244+
override={"LIBRARY_OVERRIDABLE"},
234245
)
235246
case "u16":
236247
return bpy.props.IntProperty(
237248
min=0,
238249
max=65535,
250+
override={"LIBRARY_OVERRIDABLE"},
239251
)
240252
case "u32":
241253
return bpy.props.IntProperty(
@@ -244,6 +256,7 @@ def make_property(
244256
# 2^31, not 2^32, so not sure if we can even set
245257
# those numbers from inside blender
246258
# max=4294967295,
259+
override={"LIBRARY_OVERRIDABLE"},
247260
)
248261
case "u64":
249262
return bpy.props.IntProperty(
@@ -252,13 +265,15 @@ def make_property(
252265
# 2^31, not 2^32, so not sure if we can even set
253266
# those numbers from inside blender
254267
# max=4294967295,
268+
override={"LIBRARY_OVERRIDABLE"},
255269
)
256270
case "u128":
257271
return bpy.props.IntProperty(
258272
min=0,
259273
# blender actually sets the default hard maximum to
260274
# 2^31, not 2^32, so not sure if we can even set
261275
# numbers bigger than this for u128 in Blender
276+
override={"LIBRARY_OVERRIDABLE"},
262277
)
263278
case "usize":
264279
return bpy.props.IntProperty(
@@ -267,82 +282,132 @@ def make_property(
267282
# 2^31, not 2^32, so not sure if we can even set
268283
# those numbers from inside blender
269284
# max=4294967295,
285+
override={"LIBRARY_OVERRIDABLE"},
270286
)
271287
case _:
272288
print("unknown uint type: ", type_path)
273-
return bpy.props.IntProperty(min=0, )
289+
return bpy.props.IntProperty(
290+
min=0,
291+
override={"LIBRARY_OVERRIDABLE"}
292+
)
274293
case "int":
275294
match type_path:
276295
case "i8":
277296
return bpy.props.IntProperty(
278297
min=-128,
279298
max=127,
299+
override={"LIBRARY_OVERRIDABLE"},
280300
)
281301
case "i16":
282302
return bpy.props.IntProperty(
283303
min=-32_768,
284304
max=32_767,
305+
override={"LIBRARY_OVERRIDABLE"},
285306
)
286307
case "i32":
287308
return bpy.props.IntProperty(
288309
min=-2_147_483_648,
289310
max=2_147_483_647,
311+
override={"LIBRARY_OVERRIDABLE"},
290312
)
291313
case "i64":
292-
return bpy.props.IntProperty()
314+
return bpy.props.IntProperty(
315+
override={"LIBRARY_OVERRIDABLE"},
316+
)
293317
case "isize":
294-
return bpy.props.IntProperty()
318+
return bpy.props.IntProperty(
319+
override={"LIBRARY_OVERRIDABLE"},
320+
)
295321
case _:
296322
print("unknown iint type: ", type_path)
297-
return bpy.props.IntProperty(min=0, )
323+
return bpy.props.IntProperty(
324+
min=0,
325+
override={"LIBRARY_OVERRIDABLE"},
326+
)
298327
case "float":
299-
return bpy.props.FloatProperty()
328+
return bpy.props.FloatProperty(
329+
override={"LIBRARY_OVERRIDABLE"},
330+
)
300331
case "string":
301-
return bpy.props.StringProperty()
332+
return bpy.props.StringProperty(
333+
override={"LIBRARY_OVERRIDABLE"},
334+
)
302335
case "object":
303336
if debug:
304337
print("component: ", component)
305338
match component["typePath"]:
306339
case "core::num::NonZeroU8":
307-
return bpy.props.IntProperty(min=0, max=255, default=1)
340+
return bpy.props.IntProperty(
341+
min=0,
342+
max=255,
343+
default=1,
344+
override={"LIBRARY_OVERRIDABLE"},
345+
)
308346
case "core::num::NonZeroU16":
309-
return bpy.props.IntProperty(min=1, max=65535, default=1)
347+
return bpy.props.IntProperty(
348+
min=1,
349+
max=65535,
350+
default=1,
351+
override={"LIBRARY_OVERRIDABLE"},
352+
)
310353
case "core::num::NonZeroU32":
311-
return bpy.props.IntProperty(min=1, default=1)
354+
return bpy.props.IntProperty(
355+
min=1,
356+
default=1,
357+
override={"LIBRARY_OVERRIDABLE"},
358+
)
312359
case "core::num::NonZeroU64":
313-
return bpy.props.IntProperty(min=1, default=1)
360+
return bpy.props.IntProperty(
361+
min=1,
362+
default=1,
363+
override={"LIBRARY_OVERRIDABLE"},
364+
)
314365
# TODO: prevent 0 from being valid for NonZeroI* values, but how?
315366
case "core::num::NonZeroI8":
316367
return bpy.props.IntProperty(
317368
min=-128,
318369
max=127,
319-
default=1
370+
default=1,
371+
override={"LIBRARY_OVERRIDABLE"},
320372
)
321373
case "core::num::NonZeroI16":
322374
return bpy.props.IntProperty(
323375
min=-32_768,
324376
max=32_767,
325-
default=1
377+
default=1,
378+
override={"LIBRARY_OVERRIDABLE"},
326379
)
327380
case "core::num::NonZeroI32":
328381
return bpy.props.IntProperty(
329382
min=-2_147_483_648,
330383
max=2_147_483_647,
331-
default=1
384+
default=1,
385+
override={"LIBRARY_OVERRIDABLE"},
332386
)
333387
case "core::num::NonZeroI64":
334-
return bpy.props.IntProperty(default=1)
388+
return bpy.props.IntProperty(
389+
default=1,
390+
override={"LIBRARY_OVERRIDABLE"},
391+
)
335392
case "smol_str::SmolStr":
336-
return bpy.props.StringProperty()
393+
return bpy.props.StringProperty(
394+
override={"LIBRARY_OVERRIDABLE"},
395+
)
337396
case "alloc::borrow::Cow<str>":
338-
return bpy.props.StringProperty()
397+
return bpy.props.StringProperty(
398+
override={"LIBRARY_OVERRIDABLE"},
399+
)
339400
case "avian3d::collision::collider::parry::TrimeshFlags":
340401
# TODO: What do we do about this. hard coding third-party crate
341402
# primitive Value handling is... not great. Can we figure out
342403
# how to insert this data into the reflection information?
343404
# its opaque intentionally, so really this is a set of checkboxes
344405
# represented as a bitfield and the UI should reflect that.
345-
return bpy.props.IntProperty(min=0, max=255)
406+
return bpy.props.IntProperty(
407+
min=0,
408+
max=255,
409+
override={"LIBRARY_OVERRIDABLE"},
410+
)
346411
case "core::time::Duration":
347412
if debug:
348413
print("core::time::Duration is currently not handled")

0 commit comments

Comments
 (0)