[Bf-blender-cvs] [ec3eec1] asset-experiments: Add load_pre callback to RNA, and stupid dummy code in Amber to make quick test of it.
Bastien Montagne
noreply at git.blender.org
Thu Mar 12 19:42:05 CET 2015
Commit: ec3eec1ac5d1d56ca21047d0d3b4dd78ada4b030
Author: Bastien Montagne
Date: Thu Mar 12 19:41:12 2015 +0100
Branches: asset-experiments
https://developer.blender.org/rBec3eec1ac5d1d56ca21047d0d3b4dd78ada4b030
Add load_pre callback to RNA, and stupid dummy code in Amber to make quick test of it.
===================================================================
M release/scripts/startup/bl_operators/amber.py
M source/blender/blenkernel/BKE_asset.h
M source/blender/blenkernel/intern/asset.c
M source/blender/editors/space_file/file_ops.c
M source/blender/makesdna/DNA_space_types.h
M source/blender/makesrna/intern/rna_asset.c
===================================================================
diff --git a/release/scripts/startup/bl_operators/amber.py b/release/scripts/startup/bl_operators/amber.py
index 897a2a8..c42c01d 100644
--- a/release/scripts/startup/bl_operators/amber.py
+++ b/release/scripts/startup/bl_operators/amber.py
@@ -37,6 +37,7 @@ class AssetEngineAmber(AssetEngine):
def __init__(self):
self.jobs = {}
+ self.uuids = {}
def status(self, job_id):
if job_id:
@@ -57,13 +58,26 @@ class AssetEngineAmber(AssetEngine):
if len(entries.entries) == 0:
entry = entries.entries.add()
entry.type = {'BLENDER'}
- entry.relpath="foobar"
+ entry.relpath = "foobar.blend"
+ entry.name = "MyLittleTest"
+ entry.uuid = entry.relpath.encode()[:8] + b"|0000000001"
+ self.uuids[entry.uuid] = "/home/i74700deb64/Téléchargements/wall_UE_D_01.blend"
variant = entry.variants.add()
entry.variants.active = variant
rev = variant.revisions.add()
variant.revisions.active = rev
return 1
+ def load_pre(self, uuids, entries):
+ # Not quite sure this engine will need it in the end, but for sake of testing...
+ entries.root_path = "/"
+ for uuid in uuids.uuids[:1]:
+ entry = entries.entries.add()
+ entry.type = {'BLENDER'}
+ entry.relpath = self.uuids[uuid.uuid_asset]
+ return True
+
+
if __name__ == "__main__": # only for live edit.
bpy.utils.register_module(__name__)
bpy.utils.register_class(AssetEngineFlame)
diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index c37a1b5..c26797d 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -40,6 +40,7 @@ extern "C" {
struct AssetEngine;
struct AssetEngineType;
+struct AssetUUIDList;
struct FileDirEntryArr;
struct FileDirEntry;
struct FileDirEntryVariant;
@@ -75,8 +76,7 @@ typedef void (*ae_kill)(struct AssetEngine *engine, const int job_id);
/* Return (list) everything available at given root path. */
typedef int (*ae_list_dir)(struct AssetEngine *engine, const int job_id, struct FileDirEntryArr *entries_r);
/* Ensure given direntries are really available for append/link (some kind of 'anticipated loading'...). */
-typedef int (*ae_ensure_entries)(struct AssetEngine *engine, const int job_id,
- char (*uuids)[3][ASSET_UUID_LENGTH], const int nbr_uuids);
+typedef int (*ae_ensure_entries)(struct AssetEngine *engine, const int job_id, struct AssetUUIDList *uuids);
/* ***** All callbacks below are blocking. They shall be completed upon return. ***** */
@@ -88,7 +88,7 @@ typedef int (*ae_ensure_entries)(struct AssetEngine *engine, const int job_id,
* active revision is used, no need to bother with variants, previews, etc.
* This allows to present 'fake' entries to user, and then import actual data.
*/
-typedef bool (*ae_load_pre)(struct AssetEngine *engine, char (*uuids)[3][ASSET_UUID_LENGTH], const int nbr_uuids,
+typedef bool (*ae_load_pre)(struct AssetEngine *engine, struct AssetUUIDList *uuids,
struct FileDirEntryArr *entries_r);
/* 'post-loading' hook, called after opening/appending/linking given entries.
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index 7cfae41..12b35ec 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -141,26 +141,33 @@ void BKE_asset_engine_free(AssetEngine *engine)
void BKE_asset_engine_load_pre(AssetEngine *engine, FileDirEntryArr *r_entries)
{
if (engine->type->load_pre) {
+ AssetUUIDList *uuids = MEM_mallocN(sizeof(*uuids), __func__);
FileDirEntry *en;
- char (*uuids)[3][ASSET_UUID_LENGTH] = MEM_mallocN(sizeof(*uuids) * r_entries->nbr_entries, __func__);
- int nbr_entries = r_entries->nbr_entries;
+ const int nbr_entries = r_entries->nbr_entries;
int i;
+ uuids->uuids = MEM_mallocN(sizeof(*uuids->uuids) * nbr_entries, __func__);
+ uuids->nbr_uuids = nbr_entries;
+
for (i = 0, en = r_entries->entries.first; en; i++, en = en->next) {
FileDirEntryVariant *var = BLI_findlink(&en->variants, en->act_variant);
- char (*uuid)[3][ASSET_UUID_LENGTH] = &uuids[i];
+ AssetUUID *uuid = &uuids->uuids[i];
- memcpy(uuid[0], en->uuid, sizeof(*uuid[0]));
+ memcpy(uuid->uuid_asset, en->uuid, sizeof(uuid->uuid_asset));
BLI_assert(var);
- memcpy(uuid[1], var, sizeof(*uuid[1]));
+ memcpy(uuid->uuid_variant, var->uuid, sizeof(uuid->uuid_variant));
- memcpy(uuid[2], en->entry, sizeof(*uuid[2]));
+ memcpy(uuid->uuid_revision, en->entry->uuid, sizeof(uuid->uuid_revision));
}
BKE_filedir_entryarr_clear(r_entries);
- engine->type->load_pre(engine, uuids, nbr_entries, r_entries);
+ if (!engine->type->load_pre(engine, uuids, r_entries)) {
+ /* If load_pre returns false (i.e. fails), clear all paths! */
+ /* TODO: report!!! */
+ BKE_filedir_entryarr_clear(r_entries);
+ }
MEM_freeN(uuids);
}
@@ -237,6 +244,7 @@ FileDirEntry *BKE_filedir_entry_copy(FileDirEntry *entry)
}
/* For now, consider FileDirEntryRevision::poin as not owned here, so no need to do anything about it */
+ entry_new->entry = NULL;
if (!BLI_listbase_is_empty(&entry->variants)) {
FileDirEntryVariant *var;
int act_var;
@@ -263,7 +271,7 @@ FileDirEntry *BKE_filedir_entry_copy(FileDirEntry *entry)
BLI_addtail(&var_new->revisions, rev_new);
if (is_act_var && is_act_rev) {
- entry->entry = rev_new;
+ entry_new->entry = rev_new;
}
}
@@ -275,6 +283,8 @@ FileDirEntry *BKE_filedir_entry_copy(FileDirEntry *entry)
entry_new->entry = MEM_dupallocN(entry->entry);
}
+ BLI_assert(entry_new->entry != NULL);
+
/* TODO: tags! */
return entry_new;
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 9b3611f..59263f8 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -882,8 +882,6 @@ static void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char filepa
RNA_property_string_set(op->ptr, prop, filepath);
}
- printf("%s, %s, %s, %lu\n", selection->root, filename, filepath, sizeof(filepath));
-
/* some ops have multiple files to select */
/* this is called on operators check() so clear collections first since
* they may be already set. */
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 10b2246..5747e96 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -749,6 +749,18 @@ typedef enum eDirEntry_SelectFlag {
/* ***** Related to file browser, but never saved in DNA, only here to help with RNA. ***** */
+/* For RNA only, used to communicate with asset engines outside of 'import' context. */
+typedef struct AssetUUID {
+ char uuid_asset[24]; /* ASSET_UUID_LENGTH */
+ char uuid_variant[24]; /* ASSET_UUID_LENGTH */
+ char uuid_revision[24]; /* ASSET_UUID_LENGTH */
+} AssetUUID;
+
+typedef struct AssetUUIDList {
+ AssetUUID *uuids;
+ int nbr_uuids, pad;
+} AssetUUIDList;
+
/* Container for a revision, only relevant in asset context. */
typedef struct FileDirEntryRevision {
struct FileDirEntryRevision *next, *prev;
diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c
index f44ff82..ad0e154 100644
--- a/source/blender/makesrna/intern/rna_asset.c
+++ b/source/blender/makesrna/intern/rna_asset.c
@@ -405,6 +405,34 @@ static int rna_ae_list_dir(AssetEngine *engine, const int id, FileDirEntryArr *e
return ret_job_id;
}
+static bool rna_ae_load_pre(AssetEngine *engine, AssetUUIDList *uuids, struct FileDirEntryArr *entries_r)
+{
+ extern FunctionRNA rna_AssetEngine_load_pre_func;
+ PointerRNA ptr;
+ PropertyRNA *parm;
+ ParameterList list;
+ FunctionRNA *func;
+
+ void *ret;
+ bool ret_success;
+
+ RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
+ func = &rna_AssetEngine_load_pre_func;
+
+ RNA_parameter_list_create(&list, &ptr, func);
+ RNA_parameter_set_lookup(&list, "uuids", &uuids);
+ RNA_parameter_set_lookup(&list, "entries", &entries_r);
+ engine->type->ext.call(NULL, &ptr, func, &list);
+
+ parm = RNA_function_find_parameter(NULL, func, "success_return");
+ RNA_parameter_get(&list, parm, &ret);
+ ret_success = (bool)*(int *)ret;
+
+ RNA_parameter_list_free(&list);
+
+ return ret_success;
+}
+
/* AssetEngine registration */
static void rna_AssetEngine_unregister(Main *UNUSED(bmain), StructRNA *type)
@@ -426,7 +454,7 @@ static StructRNA *rna_AssetEngine_register(Main *bmain, ReportList *reports, voi
AssetEngineType *aet, dummyaet = {NULL};
AssetEngine dummyengine = {NULL};
PointerRNA dummyptr;
- int have_function[4];
+ int have_function[5];
/* setup dummy engine & engine type to store static properties in */
dummyengine.type = &dummyaet;
@@ -465,6 +493,8 @@ static StructRNA *rna_AssetEngine_register(Main *bmain, ReportList *reports, voi
aet->list_dir = (have_function[3]) ? rna_ae_list_dir : NULL;
+ aet->load_pre = (have_function[4]) ? rna_ae_load_pre : NULL;
+
BLI_addtail(&asset_engines, aet);
return aet->ext.srna;
@@ -484,6 +514,43 @@ static StructRNA *rna_AssetEngine_refine(PointerRNA *ptr)
#else /* RNA_RUNTIME */
+/* Much lighter version of asset/variant/revision identifier. */
+static void rna_def_asset_uuid(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "AssetUUID", NULL);
+ RNA_def_struct_sdna(srna, "AssetUUID");
+ RNA_def_struct_ui_text(srna, "Asset UUID", "A unique identifier of an asset (asset engine dependent!)");
+
+ prop = RNA_def_property(srna, "uuid_asset", PROP_STRING, PROP_BYTESTRING);
+ RNA_def_property_ui_text(prop, "Asset UUID", "Unique identifier of this asset");
+
+ prop = RNA_def_property(srna, "uuid_variant", PROP_STRING, PROP_BYTESTRING);
+ RNA_def_property_ui_text(prop, "Variant UUID", "Unique identifier of this asset's variant");
+
+ prop = RNA_def_property(srna, "uuid_revision", P
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list