When an asset is represented as directory in Blender (for example fluid
simulation caches), that directory is traced and each file is considered
an asset.
This makes it considerably easier for Shaman clients, as they need to
compute the SHA256 checksum of each file. The logic to transform a
directory path to a list of the contained files is now in BAT itself.
Add functions to interpret the data in a `BlendFileBlock` as either `bytes`
or `string`. This is used to obtain the contents of a `char*` (instead
of an embedded `char[N]` array).
Previously the `callback.trace_blendfile()` callback was called just before
tracing its dependencies would start, i.e. after opening it. This is now
changed to before opening it, because that can take a long time (to load
SDNA). this will make any UI (like the Flamenco add-on) report the right
filename when waiting for big files, instead of lingering on the
last-opened (potentially very small) blend file.
In some unexpected situations BAT would just show that the
`bfile_pp is not None` assertion failed. Now it also shows which file is
the one causing this issue, aiding in debugging the situation.
---
The blendfile module within BAT supports reading data from structs, such
as the Count property on an array modifier. However, blendfile only
supports modifying structs with type "char". This patch adds support for
writing structs of more types in blendfile blocks. Now, writing is
supported for ushort, short, uint, int, float, and ulong types.
The use case that inspired this patch was an instance where a file had
several array modifiers that prevented the file from being opened in
Blender on machines without large amounts of RAM. A solution using the
blendfile module may look like:
```
from blender_asset_tracer import blendfile
from pathlib import Path
b = blendfile.open_cached(Path('flag.blend'), mode='rb+')
for block in b.blocks:
if 'ArrayModifierData' in block.__str__():
try:
print('previous:', block.get(b'count'))
block.set(b'count', 1)
print('current:', block.get(b'count'))
except KeyError:
continue
b.close()
```
This would fail with the exception
`blender_asset_tracer.blendfile.exceptions.NoWriterImplemented: Setting
type Struct(b'int') is not supported for ArrayModifierData.count`. With
this patch, the above code succeeds and the count struct can be set to
a lower number that allows the file to be opened.
This solution implements missing functionality without adding any new
interfaces. A few details are:
* When deciding what type to write to the struct, the value is inferred
from what is given by the caller. If the caller gives a Python int, the
exact type is inferred from the DNA type ID. If they give a float, a
float is written. Otherwise, the existing logic is used to determine
whether to write a string or byte sequence.
* A \_write method was added to dna\_io.py that takes a Python struct
object and a value to write a byte sequence to the file object. This
method is used by public methods appropriately named to indicate what
type they will write.
* The check for whether the caller is trying to write an unsupported
type is left in place, but it has been changed to include types which
are now supported.
* Tests have been added that provide a mock file object, call the new
methods, and confirm that the correct bytes were written.
Reviewed By: sybren
Differential Revision: https://developer.blender.org/D14374
Decided to *not* support the Shaman API of Flamenco 3.x in BAT. The
support for that protocol will be implemented in the Flamenco 3.x add-on
for Blender, and not in BAT itself.
A future version of BAT will remove the Shaman API support altogether.
Avoiding late imports helps to isolate Blender add-ons bundling BAT from
each other.
There was one late/lazy import to avoid a dependency cycle. This was
solved by simply copying that one tiny function.
File permissions are no longer copied when packing. This means that
read-only source files can still be packed without errors, even when
they have to be rewritten (due to changed paths).
Reviewed by: sybren
Differential Revision: https://developer.blender.org/D13128
BAT now can take advantage of the `zstandard` module to handle Blender
3.0+ compressed blend files.
If the module is not installed, the blend files cannot be opened but
GZip-compressed and uncompressed files can still be handled.
Add support for linked collections that are used as input in a Geometry
Nodes modifier. This requires iterating over the geometry nodes modifier
settings, which consists of ID properties. If such an ID property is of
type `IDP_ID`, its pointer is followed and the pointed-to datablock +
its library are visited.
This following of pointers happens in the 'expand' phase, which was only
done for linked library blend files. Since this commit, the old
behaviour of simply looping over all non-`DATA` datablocks of the
to-be-packed blend file is not enough, and datablock expansion is done
for all local datablocks as well.