Переглянути джерело

08_Decals sample: add animated models

1vanK 3 роки тому
батько
коміт
2184afd996
2 змінених файлів з 36 додано та 0 видалено
  1. 19 0
      Source/Samples/08_Decals/Decals.cpp
  2. 17 0
      bin/Data/Scripts/08_Decals.as

+ 19 - 0
Source/Samples/08_Decals/Decals.cpp

@@ -3,6 +3,8 @@
 
 
 #include <Urho3D/Core/CoreEvents.h>
 #include <Urho3D/Core/CoreEvents.h>
 #include <Urho3D/Engine/Engine.h>
 #include <Urho3D/Engine/Engine.h>
+#include <Urho3D/Graphics/AnimatedModel.h>
+#include <Urho3D/Graphics/AnimationController.h>
 #include <Urho3D/Graphics/Camera.h>
 #include <Urho3D/Graphics/Camera.h>
 #include <Urho3D/Graphics/DebugRenderer.h>
 #include <Urho3D/Graphics/DebugRenderer.h>
 #include <Urho3D/Graphics/DecalSet.h>
 #include <Urho3D/Graphics/DecalSet.h>
@@ -122,6 +124,23 @@ void Decals::CreateScene()
             boxObject->SetOccluder(true);
             boxObject->SetOccluder(true);
     }
     }
 
 
+    // Create some animated models
+    const i32 NUM_MUTANTS = 20;
+    for (i32 i = 0; i < NUM_MUTANTS; ++i)
+    {
+        Node* mutantNode = scene_->CreateChild("Mutant");
+        mutantNode->SetPosition(Vector3(Random(90.0f) - 45.0f, 0.0f, Random(90.0f) - 45.0f));
+        mutantNode->SetRotation(Quaternion(0.0f, Random(360.0f), 0.0f));
+        mutantNode->SetScale(0.5f + Random(2.0f));
+        AnimatedModel* mutantObject = mutantNode->CreateComponent<AnimatedModel>();
+        mutantObject->SetModel(cache->GetResource<Model>("Models/Mutant/Mutant.mdl"));
+        mutantObject->SetMaterial(cache->GetResource<Material>("Models/Mutant/Materials/mutant_M.xml"));
+        mutantObject->SetCastShadows(true);
+        AnimationController* animCtrl = mutantNode->CreateComponent<AnimationController>();
+        animCtrl->PlayExclusive("Models/Mutant/Mutant_Idle0.ani", 0, true, 0.f);
+        animCtrl->SetTime("Models/Mutant/Mutant_Idle0.ani", Random(animCtrl->GetLength("Models/Mutant/Mutant_Idle0.ani")));
+    }
+
     // Create the camera. Limit far clip distance to match the fog
     // Create the camera. Limit far clip distance to match the fog
     cameraNode_ = scene_->CreateChild("Camera");
     cameraNode_ = scene_->CreateChild("Camera");
     auto* camera = cameraNode_->CreateComponent<Camera>();
     auto* camera = cameraNode_->CreateComponent<Camera>();

+ 17 - 0
bin/Data/Scripts/08_Decals.as

@@ -94,6 +94,23 @@ void CreateScene()
             boxObject.occluder = true;
             boxObject.occluder = true;
     }
     }
 
 
+    // Create some animated models
+    const int NUM_MUTANTS = 20;
+    for (int i = 0; i < NUM_MUTANTS; ++i)
+    {
+        Node@ mutantNode = scene_.CreateChild("Mutant");
+        mutantNode.position = Vector3(Random(90.0f) - 45.0f, 0.0f, Random(90.0f) - 45.0f);
+        mutantNode.rotation = Quaternion(0.0f, Random(360.0f), 0.0f);
+        mutantNode.SetScale(0.5f + Random(2.0f));
+        AnimatedModel@ mutantObject = mutantNode.CreateComponent("AnimatedModel");
+        mutantObject.model = cache.GetResource("Model", "Models/Mutant/Mutant.mdl");
+        mutantObject.material = cache.GetResource("Material", "Models/Mutant/Materials/mutant_M.xml");
+        mutantObject.castShadows = true;
+        AnimationController@ animCtrl = mutantNode.CreateComponent("AnimationController");
+        animCtrl.PlayExclusive("Models/Mutant/Mutant_Idle0.ani", 0, true, 0.f);
+        animCtrl.SetTime("Models/Mutant/Mutant_Idle0.ani", Random(animCtrl.GetLength("Models/Mutant/Mutant_Idle0.ani")));
+    }
+
     // Create the camera. Limit far clip distance to match the fog
     // Create the camera. Limit far clip distance to match the fog
     cameraNode = scene_.CreateChild("Camera");
     cameraNode = scene_.CreateChild("Camera");
     Camera@ camera = cameraNode.CreateComponent("Camera");
     Camera@ camera = cameraNode.CreateComponent("Camera");