Fix: USD: Particle hair has wrong/missing materials assignments

The particle material slot was not used by Hydra, and USD export did not
bind a material at all.

Pull Request: https://projects.blender.org/blender/blender/pulls/160433
This commit is contained in:
Brecht Van Lommel 2026-05-28 05:19:31 +02:00
parent 1cdf15ae4f
commit 3edc7cc0ea
46 changed files with 78 additions and 110 deletions

View file

@ -318,8 +318,7 @@ void emit_hair_for_object(PopulateContext &ctx, Object *object, EmittedObject &e
if (hair.curve_vertex_counts.empty()) {
continue;
}
/* TODO: Using only first material. Add support for multi-material. */
const CurvesMaterial mat = resolve_curves_material(ctx, object, 1);
const CurvesMaterial mat = resolve_curves_material(ctx, object, psys.part->omat);
if (mat.material) {
emitted.materials.append_non_duplicates(mat.material);
}
@ -351,7 +350,7 @@ void emit_hair_proto(PopulateContext &ctx, Object *source)
if (hair.curve_vertex_counts.empty()) {
continue;
}
const CurvesMaterial mat = resolve_curves_material(ctx, source, 1);
const CurvesMaterial mat = resolve_curves_material(ctx, source, psys.part->omat);
char ps_name[32];
SNPRINTF(ps_name, "PS_%p", &psys);

View file

@ -6,12 +6,15 @@
#include <pxr/usd/usdGeom/basisCurves.h>
#include <pxr/usd/usdGeom/tokens.h>
#include <pxr/usd/usdShade/materialBindingAPI.h>
#include "BKE_material.hh"
#include "BKE_particle.h"
#include "BLI_math_matrix.hh"
#include "BLI_math_vector_types.hh"
#include "DNA_material_types.h"
#include "DNA_object_types.h"
#include "DNA_particle_types.h"
@ -83,9 +86,35 @@ void USDHairWriter::do_write(HierarchyContext &context)
write_id_properties(prim, psys->part->id, time);
}
assign_material(context, curves, psys->part->omat);
this->author_extent(curves, time);
}
void USDHairWriter::assign_material(const HierarchyContext &context,
const pxr::UsdGeomBasisCurves &curves,
const int material_slot)
{
if (!usd_export_context_.export_params.export_materials) {
return;
}
Material *material = BKE_object_material_get_eval(context.object, material_slot);
if (material == nullptr) {
return;
}
pxr::UsdShadeMaterial usd_material = ensure_usd_material(context, material);
if (!usd_material) {
return;
}
auto curves_prim = curves.GetPrim();
pxr::UsdShadeMaterialBindingAPI binding(curves_prim);
binding.Bind(usd_material);
pxr::UsdShadeMaterialBindingAPI::Apply(curves_prim);
}
bool USDHairWriter::check_is_animated(const HierarchyContext & /*context*/) const
{
return true;

View file

@ -14,6 +14,9 @@ class USDHairWriter : public USDAbstractWriter {
protected:
void do_write(HierarchyContext &context) override;
void assign_material(const HierarchyContext &context,
const pxr::UsdGeomBasisCurves &curves,
const int material_slot);
bool check_is_animated(const HierarchyContext &context) const override;
};

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:01c8cdbcb5449cd507d5415b595c9c90659daba4e394cd6e4e64e5672be877e5
size 1515

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9b7ab6c9963d06799036f6d36e81a08c376cf1f6a7f85b7da8ac4009fdeb1ffb
size 1721

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8e2761df7d51aea2cd64d076eb7036ab3f0b38095afc4810d2f05e8e436ab12f
size 3282

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7b8000bfca8ba862373e2d4d0c04098d986cbf0e5e3520d6b8a8e4849e80376c
size 9217

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:84eb0a305ff8735f5b85d70ac240fed6baab44372bff2846c9cdf5ac93e73200
size 1672

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ddf6b8c64f12f38dcbebc4295c79b1fc7af9e48ba757c19f1d0f19d9c63544cc
size 8136

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a0f84f69857ff581b1c585779fb14b282c9f48b0c9b175c8a1b2b719183b0cd6
size 4644

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3111f869630758a4e399614ffa772a7664434e1c750bf73b778aec412effa990
size 1728

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:585df505d209c010b785525e58a3e62ea55d7ed12809eb059510aa43cb87a7e0
size 4646

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0fcd6442477c475715e3d2abe26134a666b781ef5be7fded1bdeabf00fd3cde4
size 11884

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:09eed4f5db2855bb4cbe2ea29efe33f3371e251f56ef257989b2f331b964dd7d
size 11889

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:18bb866d0483ad3a2af070da1e75ed0a931088845998088c5a45ccfe967613f0
size 1487
oid sha256:26ae8291479051b0ea47e619cd077b5ded5bac784691f0e243e0d3a06b1665e6
size 1541

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:80eb07336eec80945fa6071272fb5ed89ee2c48b74543be3848312808141f544
size 1683
oid sha256:479971b93b2a19805071659a4ca91dd0af32febeac5803411fa7769da3da59b7
size 1876

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7e1c54c34f9545cc549827cd67941c50d6de73743bb964940a70ca8e74c02dbf
size 3111
oid sha256:f9eaacead9443a561ddae73cfb95a2851be4509758881119a9f5ad8622284125
size 3458

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:fa4a518c50d13a82057cc8a2387bbb54c128c5e5207faea26ae95c7a8438099c
size 11570
oid sha256:dc9b590735a0a4204b55bdb73b40e9deb7aa3204b6993ee94f311809c45215dc
size 9228

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7fc7e76a1b167871f4ea7380377b5c52ae09af511b76fe0bf7e9a6ed8f096830
size 1690
oid sha256:a0ec024dde612328f026e161a5e36b33a93f4abf7c9503ed6f9e871cf6a7af7c
size 1883

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a88409c33674d8ea30bb3cb8a0680c374bd490ff031acaa949f93cffd365e98e
size 10825
oid sha256:43bcbb6ec9cd2abcbf634754c29d7c2425f0d4c90587e3858146345f454537d0
size 8180

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:da271b5e9edf0563efb0a592a3a439a4140c82e3462394473411e4d6d1f996be
size 4519
oid sha256:3e41bc9fc85b2c24af69d916092feec1e7f1393f18e653a8eace114ff03d1758
size 4644

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b53689af07cc1c6ac1ebc33994ac4e4c743d9ad2fae0085017e00dc9ce9d0735
size 1690
oid sha256:4f2793b1b37237c6712a0130e07198a898b22c298bff4313d73096e93927248e
size 1883

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2adc652c4b884d473389397675d195de4b7235b8fa15c423c851e5da54871bd6
size 4521
oid sha256:0e648f3419e5ae1c26a01f4cb6f789b91dd8057f84fafe280564b225ba4e855b
size 4646

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9cc9a13955a8f2c576c60d326be97daf82f3604df3674187246cc91cfa4469e3
size 13986
oid sha256:ef5420aac19f1b0fc6f6db69ee1758a23001a1af9704a963e2e078f72a3dbf82
size 11866

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e8f24c8dc27a3bcacc533dbf8ba6a7e573e4d010edd1c9f015c28819360975ea
size 13991
oid sha256:7cac1e06cac24b6a181c55de44c62d475702711de1ed056e223a93b650b3a45b
size 11871

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:458b7960aa09a7ebf4b4f4cdb7c0f30096644b6e3435b84c6d0843b1c5a5cd33
size 11721
oid sha256:9da83f5319755e6c2bd276ebde7ac563e4427ccab233b5d0847a464b2520695c
size 13075

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:51769bc82568a34f2aba55871e30d052d063cd4b029b3e01b0f42e7ffef81da8
size 2262

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9967b6204bf14090efaa3882c38cb4e3906f49d4f0268f3cc0887a72ef912308
size 2262

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:2496954211adaa47b957ce0bda3757d77e26d3c705fed7b6c3105c429d89ce18
size 2261

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:f8adee833950ffa70de3cbeffa97a50424c8cba1cbba0f22f214d0e748b778fa
size 2261

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6316f2853c704bc788a79b2c13e1656879e07297b72de50f55ff6c5b3fdb92ce
size 9733

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:684498ad7927c951da19c0dc82f71a960461fb8ef32095025625790c71bb551e
size 2158
oid sha256:e732c74e11ee174168170314405d89cd0cb4e9fbf8988b7069141e0ab700ecf8
size 2295

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:89f242cd74f85a2794bd4b72f4a394965c176d58e3ae48d76b21534c9e98a448
size 2158
oid sha256:194a3100a09b0952cef2dd48e2515e15ebf67a0c3d5cc84be8c7dd381cd70c42
size 2295

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7ba26d789a13d6a143a0d256f171abd010fa63f39178432e173c0642dae1ba72
size 2157
oid sha256:03e99aef3c7c79a2439ee7821d2c6f73e607b760a2ec2eccd1e862c58019cf79
size 2294

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5023b923e4cbbf688caa2301b95f59d6b9d37a0697a8ce99c0d27ed4cb753d37
size 2157
oid sha256:e67882b16f1266e60e534f00dce4621f735671df7d64f70aeb6992b6f049004e
size 2294

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:5f689c8ad59f3e4670db79502f7e7b6b26f9da15ac00adce64dc79f09bff75eb
size 9950
oid sha256:7d3582899ac3dd501787ba9a523937310a0ad696087ccd8a50f79d1ad36d925d
size 9747

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:a1746e593cd6ba29f63726741dbb3e51c1e649b58a20754e84d9c4f055244c3c
size 7498

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:12301f3313b92a48b77731e74076e06babffc08152a661bc99e9d9e211fc6799
size 7498

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e34f63d58ad93681d41553e65fc99e19662f4fc2a4268c89faf37bfb7b5c2f7a
size 7498

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:188cd1d943ebba2fe7a797bc9b598e8f583e2c1ca1f1128bb33fc34b9de95c62
size 7498

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ec27de182225dcb495e5a1c2755465f5caddf6add2f5391a9003334b87ad710b
size 7993
oid sha256:cf8894808754d922641da42e578ecdd727f454b77a951283395e6bfd0118ccd9
size 7517

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1e142cf8f7946ba728c6961d3f30dd2dd9a4095b3a41d6c62aef0fa431f93275
size 7993
oid sha256:29a7e17b13da11f4a8e1179d85cb0a313b2653e6fb5b5ddcb1e9c5b0762f6281
size 7517

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:720e9da0765e37c12247d0959d9ec90869e95234fa699364a29104c34c7f6c3c
size 7993
oid sha256:17bd740a8c9f9ef97cba8c3b17ac4329a32fb22f0c38225c1b24b5cb55e7e6f0
size 7517

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7f0b99fc51d861190e593802552b9aa33866bba4ee900ca9c828d6b35ceeead0
size 7993
oid sha256:73b6506d3ed544ce028f52021bce972cece3994e1416696b15264bb759e279e8
size 7517

View file

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:281a5c29f3e3e97c1c28719b4e3b1599a577fd4302330bedaa1248c205f87035
size 5519

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d46fdefd9c66892bcf4c958a3e34c594692e1c054841f4e955c463277d9940dd
size 5618
oid sha256:d6e7cf8990b800d8fcc834c15a74ae331ad6f3aeec7805b60d7fb0a99a94f39c
size 5543