mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
[USDZ] Support autoPlay and playbackMode Stage metadataum.
This commit is contained in:
@@ -231,6 +231,11 @@ static void RegisterStageMetas(
|
||||
// Type can be array. i.e. asset, asset[]
|
||||
metas["subLayers"] = AsciiParser::VariableDef(value::kAssetPath, "subLayers",
|
||||
/* allow array type */ true);
|
||||
|
||||
// USDZ extension
|
||||
metas["autoPlay"] = AsciiParser::VariableDef(value::kBool, "autoPlay");
|
||||
metas["playbackMode"] = AsciiParser::VariableDef(value::kToken, "playbackMode");
|
||||
|
||||
}
|
||||
|
||||
static void RegisterPrimMetas(
|
||||
|
||||
@@ -112,6 +112,9 @@ class AsciiParser {
|
||||
nonstd::optional<double> endTimeCode;
|
||||
nonstd::optional<double> framesPerSecond;
|
||||
|
||||
nonstd::optional<bool> autoPlay;
|
||||
nonstd::optional<value::token> playbackMode; // 'none' or 'loop'
|
||||
|
||||
std::map<std::string, MetaVariable> customLayerData; // `customLayerData`.
|
||||
std::vector<StringData> strings; // String only unregistered metadata.
|
||||
};
|
||||
|
||||
14
src/stage.cc
14
src/stage.cc
@@ -590,6 +590,20 @@ std::string Stage::ExportToString() const {
|
||||
ss << " defaultPrim = " << tinyusdz::quote(stage_metas.defaultPrim.str())
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
if (!stage_metas.autoPlay.authored()) {
|
||||
ss << " autoPlay = " << to_string(stage_metas.autoPlay.get_value()) << "\n";
|
||||
}
|
||||
|
||||
if (!stage_metas.playbackMode.authored()) {
|
||||
auto v = stage_metas.playbackMode.get_value();
|
||||
if (v == StageMetas::PlaybackMode::PlaybackModeLoop) {
|
||||
ss << " playbackMode = \"loop\"\n";
|
||||
} else { // None
|
||||
ss << " playbackMode = \"none\"\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (!stage_metas.comment.value.empty()) {
|
||||
ss << " comment = " << to_string(stage_metas.comment) << "\n";
|
||||
}
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
namespace tinyusdz {
|
||||
|
||||
struct StageMetas {
|
||||
enum class PlaybackMode {
|
||||
PlaybackModeNone,
|
||||
PlaybackModeLoop,
|
||||
};
|
||||
|
||||
// TODO: Support more predefined properties: reference = <pxrUSD>/pxr/usd/sdf/wrapLayer.cpp
|
||||
// Scene global setting
|
||||
TypedAttributeWithFallback<Axis> upAxis{Axis::Y}; // This can be changed by plugInfo.json in USD: https://graphics.pixar.com/usd/dev/api/group___usd_geom_up_axis__group.html#gaf16b05f297f696c58a086dacc1e288b5
|
||||
@@ -24,6 +29,10 @@ struct StageMetas {
|
||||
|
||||
CustomDataType customLayerData; // customLayerData
|
||||
|
||||
// USDZ extension
|
||||
TypedAttributeWithFallback<bool> autoPlay{true}; // default(or not authored) = auto play
|
||||
TypedAttributeWithFallback<PlaybackMode> playbackMode{PlaybackMode::PlaybackModeLoop};
|
||||
|
||||
// String only metadataum.
|
||||
// TODO: Represent as `MetaVariable`?
|
||||
std::vector<StringData> stringData;
|
||||
|
||||
@@ -610,6 +610,21 @@ class USDAReader::Impl {
|
||||
_stage.metas().framesPerSecond = metas.framesPerSecond.value();
|
||||
}
|
||||
|
||||
if (metas.autoPlay) {
|
||||
_stage.metas().autoPlay = metas.autoPlay.value();
|
||||
}
|
||||
|
||||
if (metas.playbackMode) {
|
||||
value::token tok = metas.playbackMode.value();
|
||||
if (tok.str() == "none") {
|
||||
_stage.metas().playbackMode = StageMetas::PlaybackMode::PlaybackModeNone;
|
||||
} else if (tok.str() == "loop") {
|
||||
_stage.metas().playbackMode = StageMetas::PlaybackMode::PlaybackModeLoop;
|
||||
} else {
|
||||
PUSH_ERROR_AND_RETURN("Unsupported playbackMode: " + tok.str());
|
||||
}
|
||||
}
|
||||
|
||||
_stage.metas().customLayerData = metas.customLayerData;
|
||||
|
||||
_stage.metas().stringData = metas.strings;
|
||||
|
||||
@@ -1415,6 +1415,32 @@ bool USDCReader::Impl::ReconstrcutStageMeta(
|
||||
fv.second.type_name() + "'");
|
||||
}
|
||||
DCOUT("endTimeCode = " << metas->endTimeCode.get_value());
|
||||
} else if (fv.first == "autoPlay") {
|
||||
if (auto vf = fv.second.get_value<bool>()) {
|
||||
metas->autoPlay = vf.value();
|
||||
} else {
|
||||
PUSH_ERROR_AND_RETURN(
|
||||
"`autoPlay` value must be bool "
|
||||
"type, but got '" +
|
||||
fv.second.type_name() + "'");
|
||||
}
|
||||
DCOUT("autoPlay = " << metas->autoPlay.get_value());
|
||||
} else if (fv.first == "playbackMode") {
|
||||
if (auto vf = fv.second.get_value<value::token>()) {
|
||||
if (vf.value().str() == "none") {
|
||||
metas->playbackMode = StageMetas::PlaybackMode::PlaybackModeNone;
|
||||
} else if (vf.value().str() == "loop") {
|
||||
metas->playbackMode = StageMetas::PlaybackMode::PlaybackModeLoop;
|
||||
} else {
|
||||
PUSH_ERROR_AND_RETURN(
|
||||
"Unsupported token value for `playbackMode`.");
|
||||
}
|
||||
} else {
|
||||
PUSH_ERROR_AND_RETURN(
|
||||
"`playbackMode` value must be token "
|
||||
"type, but got '" +
|
||||
fv.second.type_name() + "'");
|
||||
}
|
||||
} else if ((fv.first == "defaultPrim")) {
|
||||
auto v = fv.second.get_value<value::token>();
|
||||
if (!v) {
|
||||
|
||||
4
tests/usda/usdz-schema-autoplay-001.usda
Normal file
4
tests/usda/usdz-schema-autoplay-001.usda
Normal file
@@ -0,0 +1,4 @@
|
||||
#usda 1.0
|
||||
(
|
||||
autoPlay = false
|
||||
)
|
||||
4
tests/usda/usdz-schema-playbackmode-001.usda
Normal file
4
tests/usda/usdz-schema-playbackmode-001.usda
Normal file
@@ -0,0 +1,4 @@
|
||||
#usda 1.0
|
||||
(
|
||||
playbackMode = "loop"
|
||||
)
|
||||
BIN
tests/usdc/usdz-schema-autoplay-001.usdc
Normal file
BIN
tests/usdc/usdz-schema-autoplay-001.usdc
Normal file
Binary file not shown.
BIN
tests/usdc/usdz-schema-playbackmode-001.usdc
Normal file
BIN
tests/usdc/usdz-schema-playbackmode-001.usdc
Normal file
Binary file not shown.
Reference in New Issue
Block a user