Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAras Pranckevicius <aras@nesnausk.org>2022-07-06 13:29:59 +0300
committerAras Pranckevicius <aras@nesnausk.org>2022-07-06 13:30:15 +0300
commit94323bb427480aaaeea52f6833173866fbacf2e1 (patch)
tree3ed0e5fe0692d294ce2b42ab31dc5bfe076e4471 /source/blender/blenkernel/BKE_material.h
parent4b0e7fe511b14aecad105d83115592f43d27dbc0 (diff)
IO: speed up import of large Alembic/USD/OBJ scenes by optimizing material assignment
The importer parts that were doing assignment of materials to the imported objects/meshes were essentially having a quadratic complexity in terms of scene object count. For each material assigned to each object, they were scanning the whole scene, checking which other Objects use the same Mesh data, in order to resize their material arrays to match the size. Performance details (Windows, Ryzen 5950X): - Import OBJ Blender 3.0 splash scene (24k objects): 43.0s -> 32.9s - Import USD Disney Moana scene (260k objects): saves two hours (~7400s). Note that later on this crashes when trying to render the imported result; crashes in the same way/place both in master and this patch. Implementation details: The importers were doing "scan the world" basically twice for each object, for each material: once when creating a new material slot (assigns an empty material), and then again when assigning the material. However, all these importers (USD, Alembic, OBJ) always create one Object for one Mesh. So that whole quadratic complexity resulting from "scan the world for possible other users of this obdata" is completely not needed; it just never finds anything. So add a new dedicated function BKE_object_material_assign_single_obdata that skips the expensive part, but should only be used when the caller knows that the obdata has exactly one user (the passed object). Reviewed By: Bastien Montagne, Michael Kowalski Differential Revision: https://developer.blender.org/D15145
Diffstat (limited to 'source/blender/blenkernel/BKE_material.h')
-rw-r--r--source/blender/blenkernel/BKE_material.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index 05e502f06c2..ab14fa92514 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -87,6 +87,17 @@ struct Material *BKE_object_material_get(struct Object *ob, short act);
void BKE_id_material_assign(struct Main *bmain, struct ID *id, struct Material *ma, short act);
void BKE_object_material_assign(
struct Main *bmain, struct Object *ob, struct Material *ma, short act, int assign_type);
+
+/**
+ * Similar to #BKE_object_material_assign with #BKE_MAT_ASSIGN_OBDATA type,
+ * but does not scan whole Main for other usages of the same obdata. Only
+ * use in cases where you know that the object's obdata is only used by this one
+ * object.
+ */
+void BKE_object_material_assign_single_obdata(struct Main *bmain,
+ struct Object *ob,
+ struct Material *ma,
+ short act);
/**
* \warning this calls many more update calls per object then are needed, could be optimized.
*/