USD: Support building against USD 21.11+
For 3.2 USD will be bumped to a newer version with some slight API changes, however since we cannot simultaneously land the libs for all platforms as well as these code changes, we'll have to support both 21.02 and 21.11+ for at least a short period of time making the code slightly more messy than it could have been. Differential Revision: https://developer.blender.org/D14184 Reviewed by: sybren
This commit is contained in:
@@ -9,8 +9,6 @@
|
||||
#include "DNA_light_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include <pxr/usd/usdLux/light.h>
|
||||
|
||||
#include <pxr/usd/usdLux/diskLight.h>
|
||||
#include <pxr/usd/usdLux/distantLight.h>
|
||||
#include <pxr/usd/usdLux/rectLight.h>
|
||||
@@ -40,14 +38,17 @@ void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime
|
||||
if (!prim_) {
|
||||
return;
|
||||
}
|
||||
#if PXR_VERSION >= 2111
|
||||
pxr::UsdLuxLightAPI light_api(prim_);
|
||||
#else
|
||||
pxr::UsdLuxLight light_api(prim_);
|
||||
#endif
|
||||
|
||||
pxr::UsdLuxLight light_prim(prim_);
|
||||
|
||||
if (!light_prim) {
|
||||
if (!light_api) {
|
||||
return;
|
||||
}
|
||||
|
||||
pxr::UsdLuxShapingAPI shaping_api(light_prim);
|
||||
pxr::UsdLuxShapingAPI shaping_api;
|
||||
|
||||
/* Set light type. */
|
||||
|
||||
@@ -63,6 +64,8 @@ void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime
|
||||
else if (prim_.IsA<pxr::UsdLuxSphereLight>()) {
|
||||
blight->type = LA_LOCAL;
|
||||
|
||||
shaping_api = pxr::UsdLuxShapingAPI(prim_);
|
||||
|
||||
if (shaping_api && shaping_api.GetShapingConeAngleAttr().IsAuthored()) {
|
||||
blight->type = LA_SPOT;
|
||||
}
|
||||
@@ -73,7 +76,7 @@ void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime
|
||||
|
||||
/* Set light values. */
|
||||
|
||||
if (pxr::UsdAttribute intensity_attr = light_prim.GetIntensityAttr()) {
|
||||
if (pxr::UsdAttribute intensity_attr = light_api.GetIntensityAttr()) {
|
||||
float intensity = 0.0f;
|
||||
if (intensity_attr.Get(&intensity, motionSampleTime)) {
|
||||
blight->energy = intensity * this->import_params_.light_intensity_scale;
|
||||
@@ -92,14 +95,14 @@ void USDLightReader::read_object_data(Main *bmain, const double motionSampleTime
|
||||
light_prim.GetDiffuseAttr().Get(&diffuse, motionSampleTime);
|
||||
#endif
|
||||
|
||||
if (pxr::UsdAttribute spec_attr = light_prim.GetSpecularAttr()) {
|
||||
if (pxr::UsdAttribute spec_attr = light_api.GetSpecularAttr()) {
|
||||
float spec = 0.0f;
|
||||
if (spec_attr.Get(&spec, motionSampleTime)) {
|
||||
blight->spec_fac = spec;
|
||||
}
|
||||
}
|
||||
|
||||
if (pxr::UsdAttribute color_attr = light_prim.GetColorAttr()) {
|
||||
if (pxr::UsdAttribute color_attr = light_api.GetColorAttr()) {
|
||||
pxr::GfVec3f color;
|
||||
if (color_attr.Get(&color, motionSampleTime)) {
|
||||
blight->r = color[0];
|
||||
|
@@ -18,7 +18,13 @@
|
||||
#include <pxr/usd/usdGeom/nurbsCurves.h>
|
||||
#include <pxr/usd/usdGeom/scope.h>
|
||||
#include <pxr/usd/usdGeom/xform.h>
|
||||
#include <pxr/usd/usdLux/light.h>
|
||||
|
||||
#if PXR_VERSION >= 2111
|
||||
# include <pxr/usd/usdLux/boundableLightBase.h>
|
||||
# include <pxr/usd/usdLux/nonboundableLightBase.h>
|
||||
#else
|
||||
# include <pxr/usd/usdLux/light.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -55,7 +61,12 @@ USDPrimReader *USDStageReader::create_reader_if_allowed(const pxr::UsdPrim &prim
|
||||
if (params_.import_meshes && prim.IsA<pxr::UsdGeomMesh>()) {
|
||||
return new USDMeshReader(prim, params_, settings_);
|
||||
}
|
||||
#if PXR_VERSION >= 2111
|
||||
if (params_.import_lights && (prim.IsA<pxr::UsdLuxBoundableLightBase>() ||
|
||||
prim.IsA<pxr::UsdLuxNonboundableLightBase>())) {
|
||||
#else
|
||||
if (params_.import_lights && prim.IsA<pxr::UsdLuxLight>()) {
|
||||
#endif
|
||||
return new USDLightReader(prim, params_, settings_);
|
||||
}
|
||||
if (params_.import_volumes && prim.IsA<pxr::UsdVolVolume>()) {
|
||||
@@ -82,7 +93,11 @@ USDPrimReader *USDStageReader::create_reader(const pxr::UsdPrim &prim)
|
||||
if (prim.IsA<pxr::UsdGeomMesh>()) {
|
||||
return new USDMeshReader(prim, params_, settings_);
|
||||
}
|
||||
#if PXR_VERSION >= 2111
|
||||
if (prim.IsA<pxr::UsdLuxBoundableLightBase>() || prim.IsA<pxr::UsdLuxNonboundableLightBase>()) {
|
||||
#else
|
||||
if (prim.IsA<pxr::UsdLuxLight>()) {
|
||||
#endif
|
||||
return new USDLightReader(prim, params_, settings_);
|
||||
}
|
||||
if (prim.IsA<pxr::UsdVolVolume>()) {
|
||||
|
@@ -131,7 +131,7 @@ bool USDXformReader::is_root_xform_prim() const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (prim_.IsInMaster()) {
|
||||
if (prim_.IsInPrototype()) {
|
||||
/* We don't consider prototypes to be root prims,
|
||||
* because we never want to apply global scaling
|
||||
* or rotations to the prototypes themselves. */
|
||||
|
@@ -33,7 +33,12 @@ void USDLightWriter::do_write(HierarchyContext &context)
|
||||
pxr::UsdTimeCode timecode = get_export_time_code();
|
||||
|
||||
Light *light = static_cast<Light *>(context.object->data);
|
||||
pxr::UsdLuxLight usd_light;
|
||||
#if PXR_VERSION >= 2111
|
||||
pxr::UsdLuxLightAPI usd_light_api;
|
||||
#else
|
||||
pxr::UsdLuxLight usd_light_api;
|
||||
|
||||
#endif
|
||||
|
||||
switch (light->type) {
|
||||
case LA_AREA:
|
||||
@@ -42,21 +47,33 @@ void USDLightWriter::do_write(HierarchyContext &context)
|
||||
case LA_AREA_ELLIPSE: { /* An ellipse light will deteriorate into a disk light. */
|
||||
pxr::UsdLuxDiskLight disk_light = pxr::UsdLuxDiskLight::Define(stage, usd_path);
|
||||
disk_light.CreateRadiusAttr().Set(light->area_size, timecode);
|
||||
usd_light = disk_light;
|
||||
#if PXR_VERSION >= 2111
|
||||
usd_light_api = disk_light.LightAPI();
|
||||
#else
|
||||
usd_light_api = disk_light;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case LA_AREA_RECT: {
|
||||
pxr::UsdLuxRectLight rect_light = pxr::UsdLuxRectLight::Define(stage, usd_path);
|
||||
rect_light.CreateWidthAttr().Set(light->area_size, timecode);
|
||||
rect_light.CreateHeightAttr().Set(light->area_sizey, timecode);
|
||||
usd_light = rect_light;
|
||||
#if PXR_VERSION >= 2111
|
||||
usd_light_api = rect_light.LightAPI();
|
||||
#else
|
||||
usd_light_api = rect_light;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case LA_AREA_SQUARE: {
|
||||
pxr::UsdLuxRectLight rect_light = pxr::UsdLuxRectLight::Define(stage, usd_path);
|
||||
rect_light.CreateWidthAttr().Set(light->area_size, timecode);
|
||||
rect_light.CreateHeightAttr().Set(light->area_size, timecode);
|
||||
usd_light = rect_light;
|
||||
#if PXR_VERSION >= 2111
|
||||
usd_light_api = rect_light.LightAPI();
|
||||
#else
|
||||
usd_light_api = rect_light;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -64,12 +81,23 @@ void USDLightWriter::do_write(HierarchyContext &context)
|
||||
case LA_LOCAL: {
|
||||
pxr::UsdLuxSphereLight sphere_light = pxr::UsdLuxSphereLight::Define(stage, usd_path);
|
||||
sphere_light.CreateRadiusAttr().Set(light->area_size, timecode);
|
||||
usd_light = sphere_light;
|
||||
#if PXR_VERSION >= 2111
|
||||
usd_light_api = sphere_light.LightAPI();
|
||||
#else
|
||||
usd_light_api = sphere_light;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case LA_SUN:
|
||||
usd_light = pxr::UsdLuxDistantLight::Define(stage, usd_path);
|
||||
case LA_SUN: {
|
||||
pxr::UsdLuxDistantLight distant_light = pxr::UsdLuxDistantLight::Define(stage, usd_path);
|
||||
/* TODO(makowalski): set angle attribute here. */
|
||||
#if PXR_VERSION >= 2111
|
||||
usd_light_api = distant_light.LightAPI();
|
||||
#else
|
||||
usd_light_api = distant_light;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BLI_assert_msg(0, "is_supported() returned true for unsupported light type");
|
||||
}
|
||||
@@ -85,10 +113,10 @@ void USDLightWriter::do_write(HierarchyContext &context)
|
||||
else {
|
||||
usd_intensity = light->energy / 100.0f;
|
||||
}
|
||||
usd_light.CreateIntensityAttr().Set(usd_intensity, timecode);
|
||||
usd_light_api.CreateIntensityAttr().Set(usd_intensity, timecode);
|
||||
|
||||
usd_light.CreateColorAttr().Set(pxr::GfVec3f(light->r, light->g, light->b), timecode);
|
||||
usd_light.CreateSpecularAttr().Set(light->spec_fac, timecode);
|
||||
usd_light_api.CreateColorAttr().Set(pxr::GfVec3f(light->r, light->g, light->b), timecode);
|
||||
usd_light_api.CreateSpecularAttr().Set(light->spec_fac, timecode);
|
||||
}
|
||||
|
||||
} // namespace blender::io::usd
|
||||
|
@@ -163,7 +163,7 @@ void create_usd_preview_surface_material(const USDExporterContext &usd_export_co
|
||||
created_shader = create_usd_preview_shader(usd_export_context, usd_material, input_node);
|
||||
|
||||
preview_surface.CreateInput(input_spec.input_name, input_spec.input_type)
|
||||
.ConnectToSource(created_shader, input_spec.source_name);
|
||||
.ConnectToSource(created_shader.ConnectableAPI(), input_spec.source_name);
|
||||
}
|
||||
else if (input_spec.set_default_value) {
|
||||
/* Set hardcoded value. */
|
||||
@@ -217,7 +217,7 @@ void create_usd_viewport_material(const USDExporterContext &usd_export_context,
|
||||
shader.CreateInput(usdtokens::metallic, pxr::SdfValueTypeNames->Float).Set(material->metallic);
|
||||
|
||||
/* Connect the shader and the material together. */
|
||||
usd_material.CreateSurfaceOutput().ConnectToSource(shader, usdtokens::surface);
|
||||
usd_material.CreateSurfaceOutput().ConnectToSource(shader.ConnectableAPI(), usdtokens::surface);
|
||||
}
|
||||
|
||||
/* Return USD Preview Surface input map singleton. */
|
||||
@@ -293,12 +293,12 @@ static void create_uvmap_shader(const USDExporterContext &usd_export_context,
|
||||
uv_shader.CreateInput(usdtokens::varname, pxr::SdfValueTypeNames->Token)
|
||||
.Set(pxr::TfToken(uv_set));
|
||||
usd_tex_shader.CreateInput(usdtokens::st, pxr::SdfValueTypeNames->Float2)
|
||||
.ConnectToSource(uv_shader, usdtokens::result);
|
||||
.ConnectToSource(uv_shader.ConnectableAPI(), usdtokens::result);
|
||||
}
|
||||
else {
|
||||
uv_shader.CreateInput(usdtokens::varname, pxr::SdfValueTypeNames->Token).Set(default_uv);
|
||||
usd_tex_shader.CreateInput(usdtokens::st, pxr::SdfValueTypeNames->Float2)
|
||||
.ConnectToSource(uv_shader, usdtokens::result);
|
||||
.ConnectToSource(uv_shader.ConnectableAPI(), usdtokens::result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ static void create_uvmap_shader(const USDExporterContext &usd_export_context,
|
||||
if (uv_shader.GetPrim().IsValid()) {
|
||||
uv_shader.CreateInput(usdtokens::varname, pxr::SdfValueTypeNames->Token).Set(default_uv);
|
||||
usd_tex_shader.CreateInput(usdtokens::st, pxr::SdfValueTypeNames->Float2)
|
||||
.ConnectToSource(uv_shader, usdtokens::result);
|
||||
.ConnectToSource(uv_shader.ConnectableAPI(), usdtokens::result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,7 +488,7 @@ static pxr::UsdShadeShader create_usd_preview_shader(const USDExporterContext &u
|
||||
case SH_NODE_BSDF_DIFFUSE:
|
||||
case SH_NODE_BSDF_PRINCIPLED: {
|
||||
shader.CreateIdAttr(pxr::VtValue(usdtokens::preview_surface));
|
||||
material.CreateSurfaceOutput().ConnectToSource(shader, usdtokens::surface);
|
||||
material.CreateSurfaceOutput().ConnectToSource(shader.ConnectableAPI(), usdtokens::surface);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user