/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace AZ { namespace SceneAPI { namespace SceneData { void BlendShapeRuleBehavior::Activate() { Events::ManifestMetaInfoBus::Handler::BusConnect(); Events::AssetImportRequestBus::Handler::BusConnect(); } void BlendShapeRuleBehavior::Deactivate() { Events::AssetImportRequestBus::Handler::BusDisconnect(); Events::ManifestMetaInfoBus::Handler::BusDisconnect(); } void BlendShapeRuleBehavior::Reflect(ReflectContext* context) { SerializeContext* serializeContext = azrtti_cast(context); if (serializeContext) { serializeContext->Class()->Version(1); } } void BlendShapeRuleBehavior::InitializeObject(const Containers::Scene& scene, DataTypes::IManifestObject& target) { if (target.RTTI_IsTypeOf(DataTypes::ISkinGroup::TYPEINFO_Uuid())) { SceneData::SceneNodeSelectionList selection; size_t blendShapeCount = SelectBlendShapes(scene, selection); if (blendShapeCount > 0) { AZStd::shared_ptr blendShapeRule = AZStd::make_shared(); selection.CopyTo(blendShapeRule->GetNodeSelectionList()); DataTypes::ISkinGroup* skinGroup = azrtti_cast(&target); skinGroup->GetRuleContainer().AddRule(AZStd::move(blendShapeRule)); } } else if (target.RTTI_IsTypeOf(SceneData::BlendShapeRule::TYPEINFO_Uuid())) { SceneData::BlendShapeRule* rule = azrtti_cast(&target); SelectBlendShapes(scene, rule->GetSceneNodeSelectionList()); } } size_t BlendShapeRuleBehavior::SelectBlendShapes(const Containers::Scene& scene, DataTypes::ISceneNodeSelectionList& selection) const { Utilities::SceneGraphSelector::UnselectAll(scene.GetGraph(), selection); size_t blendShapeCount = 0; const Containers::SceneGraph& graph = scene.GetGraph(); auto contentStorage = graph.GetContentStorage(); auto nameStorage = graph.GetNameStorage(); auto keyValueView = Containers::Views::MakePairView(nameStorage, contentStorage); auto filteredView = Containers::Views::MakeFilterView(keyValueView, Containers::DerivedTypeFilter()); for (auto it = filteredView.begin(); it != filteredView.end(); ++it) { AZStd::set types; auto keyValueIterator = it.GetBaseIterator(); Containers::SceneGraph::NodeIndex index = graph.ConvertToNodeIndex(keyValueIterator.GetFirstIterator()); EBUS_EVENT(Events::GraphMetaInfoBus, GetVirtualTypes, types, scene, index); if (types.find(Events::GraphMetaInfo::s_ignoreVirtualType) == types.end()) { selection.AddSelectedNode(it->first.GetPath()); blendShapeCount++; } } return blendShapeCount; } Events::ProcessingResult BlendShapeRuleBehavior::UpdateManifest(Containers::Scene& scene, ManifestAction action, RequestingApplication /*requester*/) { if (action == ManifestAction::Update) { UpdateBlendShapeRules(scene); return Events::ProcessingResult::Success; } else { return Events::ProcessingResult::Ignored; } } void BlendShapeRuleBehavior::UpdateBlendShapeRules(Containers::Scene& scene) const { Containers::SceneManifest& manifest = scene.GetManifest(); auto valueStorage = manifest.GetValueStorage(); auto view = Containers::MakeDerivedFilterView(valueStorage); for (DataTypes::ISkinGroup& group : view) { AZ_TraceContext("Skin group", group.GetName()); const Containers::RuleContainer& rules = group.GetRuleContainer(); const size_t ruleCount = rules.GetRuleCount(); for (size_t index = 0; index < ruleCount; ++index) { SceneData::BlendShapeRule* rule = azrtti_cast(rules.GetRule(index).get()); if (rule) { Utilities::SceneGraphSelector::UpdateNodeSelection(scene.GetGraph(), rule->GetSceneNodeSelectionList()); } } } } } // namespace SceneData } // namespace SceneAPI } // namespace AZ