Эх сурвалжийг харах

Support scaling of skeletal animation which works when in scene/prefab

Josh Engebretson 10 жил өмнө
parent
commit
7e5a7dd3ed

+ 3 - 0
Script/TypeScript/Atomic.d.ts

@@ -3740,6 +3740,7 @@ declare module Atomic {
       updateInvisible: boolean;
       numAnimationStates: number;
       numMorphs: number;
+      boneCreationEnabled: boolean;
 
       // Construct.
       constructor();
@@ -3772,6 +3773,8 @@ declare module Atomic {
       getNumMorphs(): number;
       // Return whether is the master (first) animated model.
       isMaster(): boolean;
+      // Globally enable/disable bone creation, useful for when in the editor
+      setBoneCreationEnabled(enabled: boolean): void;
 
    }
 

+ 10 - 0
Source/Atomic/Atomic3D/AnimatedModel.cpp

@@ -56,6 +56,8 @@ static bool CompareAnimationOrder(const SharedPtr<AnimationState>& lhs, const Sh
 
 static const unsigned MAX_ANIMATION_STATES = 256;
 
+bool AnimatedModel::boneCreationEnabled_ = true;
+
 AnimatedModel::AnimatedModel(Context* context) :
     StaticModel(context),
     animationLodFrameNumber_(0),
@@ -649,6 +651,9 @@ void AnimatedModel::SetSkeleton(const Skeleton& skeleton, bool createBones)
         return;
     }
 
+    if (createBones && !boneCreationEnabled_)
+        createBones = false;
+
     if (isMaster_)
     {
         // Check if bone structure has stayed compatible (reloading the model.) In that case retain the old bones and animations
@@ -1320,4 +1325,9 @@ void AnimatedModel::HandleModelReloadFinished(StringHash eventType, VariantMap&
     SetModel(currentModel);
 }
 
+void AnimatedModel::SetBoneCreationEnabled(bool enabled)
+{
+    boneCreationEnabled_ = enabled;
+}
+
 }

+ 5 - 0
Source/Atomic/Atomic3D/AnimatedModel.h

@@ -149,6 +149,9 @@ public:
     /// Return per-geometry skin matrices. If empty, uses global skinning
     const Vector<PODVector<Matrix3x4> >& GetGeometrySkinMatrices() const { return geometrySkinMatrices_; }
 
+    /// Globally enable/disable bone creation, useful for when in the editor
+    static void SetBoneCreationEnabled(bool enabled);
+
 protected:
     /// Handle node being assigned.
     virtual void OnNodeSet(Node* node);
@@ -237,6 +240,8 @@ private:
     bool loading_;
     /// Bone nodes assignment pending flag.
     bool assignBonesPending_;
+    /// Whether bone creation is enabled, globally
+    static bool boneCreationEnabled_;
 };
 
 }

+ 6 - 0
Source/AtomicEditorWork/Application/AEEditorApp.cpp

@@ -8,6 +8,7 @@
 #include <Atomic/Input/Input.h>
 #include <Atomic/Resource/ResourceCache.h>
 #include <Atomic/Graphics/Graphics.h>
+#include <Atomic/Atomic3D/AnimatedModel.h>
 
 #include <Atomic/UI/UI.h>
 
@@ -41,6 +42,11 @@ AEEditorApp::AEEditorApp(Context* context) :
 
 void AEEditorApp::Start()
 {
+
+    // Do not create bone structure by default when in the editor
+    // this can be toggled temporarily, for example to setup an animation preview
+    AnimatedModel::SetBoneCreationEnabled(false);
+
     Input* input = GetSubsystem<Input>();
     input->SetMouseVisible(true);
 

+ 5 - 2
Source/ToolCore/Import/OpenAssetImporter.cpp

@@ -235,9 +235,12 @@ void OpenAssetImporter::ExportModel(const String& outName, const String &animNam
     if (importNode_.Null())
         return;
 
-    ResourceCache* cache = GetSubsystem<ResourceCache>();
+    ResourceCache* cache = GetSubsystem<ResourceCache>();    
     Model* mdl = cache->GetResource<Model>( model.outName_);
 
+    // Force a reload, though file watchers will catch this delayed and load again
+    cache->ReloadResource(mdl);
+
     if (!mdl)
         return;
 
@@ -252,7 +255,7 @@ void OpenAssetImporter::ExportModel(const String& outName, const String &animNam
     {
         modelComponent = importNode_->CreateComponent<AnimatedModel>();
         importNode_->CreateComponent<AnimationController>();
-        ((AnimatedModel*)modelComponent)->SetModel(mdl, true);
+        ((AnimatedModel*)modelComponent)->SetModel(mdl, false);
     }
 
     if (!noMaterials_)