From 7477233ff548d6be246eb41aa933cc13a3c2a740 Mon Sep 17 00:00:00 2001 From: Matt Benic Date: Fri, 9 Sep 2016 16:12:15 +0200 Subject: [PATCH 1/2] Add GetSkeletonBoneNode to allow getting node without exposing skeleton and bone to script --- Source/Atomic/Graphics/AnimatedModel.cpp | 6 ++++++ Source/Atomic/Graphics/AnimatedModel.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Source/Atomic/Graphics/AnimatedModel.cpp b/Source/Atomic/Graphics/AnimatedModel.cpp index 29f732c755..f253eec73b 100644 --- a/Source/Atomic/Graphics/AnimatedModel.cpp +++ b/Source/Atomic/Graphics/AnimatedModel.cpp @@ -688,6 +688,12 @@ void AnimatedModel::ResetMorphWeights() MarkNetworkUpdate(); } +Node* AnimatedModel::GetSkeletonBoneNode(const String & boneName) +{ + Bone* bone = skeleton_.GetBone(boneName); + return (bone) ? bone->node_ : NULL; +} + float AnimatedModel::GetMorphWeight(unsigned index) const { return index < morphs_.Size() ? morphs_[index].weight_ : 0.0f; diff --git a/Source/Atomic/Graphics/AnimatedModel.h b/Source/Atomic/Graphics/AnimatedModel.h index dccf16678e..28415d002e 100644 --- a/Source/Atomic/Graphics/AnimatedModel.h +++ b/Source/Atomic/Graphics/AnimatedModel.h @@ -99,6 +99,8 @@ class ATOMIC_API AnimatedModel : public StaticModel /// Return skeleton. Skeleton& GetSkeleton() { return skeleton_; } + /// Return the node of a skeleton bone (for script access) + Node* GetSkeletonBoneNode(const String& boneName); /// Return all animation states. const Vector >& GetAnimationStates() const { return animationStates_; } From 793ea2c29fb19d99ecbfa4628f1aaaa4f9d79ba7 Mon Sep 17 00:00:00 2001 From: Matt Benic Date: Tue, 13 Sep 2016 09:39:22 +0200 Subject: [PATCH 2/2] Re-add subscription tp CSComponentAssemblyReference, along with re-run check This is necessary because .Net may not load assemblies for types not directly referenced in the executing assembly, so components in additional dlls were unavailable. --- .../AtomicNET/Scene/CSComponentCore.cs | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/Script/AtomicNET/AtomicNET/Scene/CSComponentCore.cs b/Script/AtomicNET/AtomicNET/Scene/CSComponentCore.cs index 4037079888..0b04ceb784 100644 --- a/Script/AtomicNET/AtomicNET/Scene/CSComponentCore.cs +++ b/Script/AtomicNET/AtomicNET/Scene/CSComponentCore.cs @@ -332,6 +332,21 @@ void HandleComponentLoad(uint eventType, ScriptVariantMap eventData) } + void HandleComponentAssemblyReference(uint eventType, ScriptVariantMap eventData) + { +#if ATOMIC_DESKTOP || ATOMIC_ANDROID + string assemblyPath = eventData["AssemblyPath"]; + + string assemblyName = Path.GetFileNameWithoutExtension(assemblyPath); + if (componentCache.ContainsKey(assemblyName)) + return; + + Assembly assembly = Assembly.LoadFrom(assemblyPath); + + ParseAssembly(assembly); +#endif + } + void ParseComponents() { #if ATOMIC_DESKTOP || ATOMIC_ANDROID @@ -340,27 +355,33 @@ void ParseComponents() foreach (Assembly assembly in assemblies) { - String assemblyPath = assembly.GetName().Name; + ParseAssembly(assembly); + } +#endif + } + + void ParseAssembly(Assembly assembly) + { +#if ATOMIC_DESKTOP || ATOMIC_ANDROID + String assemblyPath = assembly.GetName().Name; - Dictionary assemblyTypes = null; + Dictionary assemblyTypes = null; - if (!componentCache.TryGetValue(assemblyPath, out assemblyTypes)) - { - componentCache[assemblyPath] = assemblyTypes = new Dictionary(); - } + if (!componentCache.TryGetValue(assemblyPath, out assemblyTypes)) + { + componentCache[assemblyPath] = assemblyTypes = new Dictionary(); + } - Type[] types = assembly.GetTypes(); + Type[] types = assembly.GetTypes(); - foreach (var type in types) + foreach (var type in types) + { + if (type.IsSubclassOf(typeof(CSComponent))) { - if (type.IsSubclassOf(typeof(CSComponent))) - { - var csinfo = new CSComponentInfo(type); - csinfoLookup[csinfo.Type] = csinfo; - assemblyTypes[type.Name] = csinfo; - } + var csinfo = new CSComponentInfo(type); + csinfoLookup[csinfo.Type] = csinfo; + assemblyTypes[type.Name] = csinfo; } - } #endif } @@ -370,7 +391,8 @@ internal static void Initialize() instance = new CSComponentCore(); instance.ParseComponents(); - + + instance.SubscribeToEvent("CSComponentAssemblyReference", instance.HandleComponentAssemblyReference); instance.SubscribeToEvent("CSComponentLoad", instance.HandleComponentLoad); instance.SubscribeToEvent("Update", instance.HandleUpdate);