Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.56 KB | None | 0 0
  1. /*
  2. Animation blending  testaus (OLD)
  3.  
  4.  * aseta idle weight 1.0,  walk 0.0
  5.    
  6.   * kun painetaan up/down, lisää walk weightiä  deltalla
  7.   * jos ei paineta up/down, vähennä walk weight  deltalla
  8.  
  9.  * ja walk pitää olla  idlen JÄLKEEN eli mitä aikasempi  animaatio,
  10.    sitä vähemmäl se jää kun toiset animaatiot saa weightii   (vissiin)
  11.  
  12.  
  13. Lataa ja käytä    test_stickman.fbx_UkkoArmature*    niin toimii oikein
  14. (test_stickman.fbx_Walk.ani:ssa animaatiossa ukko nytkähtää animaation lopussa, en tiedä miksi)
  15.  
  16.  
  17.  */
  18.  
  19. using Urho;
  20. using Urho.Samples;
  21.  
  22. namespace AppUrhoGame1
  23. {
  24.     public class Test_AnimationBlending_OLD : Sample
  25.     {
  26.         public Test_AnimationBlending_OLD(ApplicationOptions options = null) : base(options) { }
  27.         bool drawDebug = false;
  28.  
  29.         Camera camera;
  30.         Scene scene;
  31.         CModel wall, floor;
  32.         CAnimatedModel_OLD man;
  33.  
  34.         protected override void Start()
  35.         {
  36.             base.Start();
  37.  
  38.             CreateScene();
  39.         }
  40.  
  41.         void CreateScene()
  42.         {
  43.             Globals.ResourceCache = ResourceCache;
  44.             Globals.Graphics = Graphics;
  45.             Globals.Input = Input;
  46.  
  47.             // 3D scene with Octree
  48.             scene = new Scene(Context);
  49.             scene.CreateComponent<Octree>();
  50.             scene.CreateComponent<DebugRenderer>();
  51.  
  52.             // Create a directional light to the world. Enable cascaded shadows on it
  53.             var lightNode = scene.CreateChild("DirectionalLight");
  54.             lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f)); // The direction vector does not need to be normalized
  55.             var light = lightNode.CreateComponent<Light>();
  56.             light.LightType = LightType.Directional;
  57.             light.CastShadows = true;
  58.             light.ShadowBias = new BiasParameters(0.00025f, 0.5f);
  59.             // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance
  60.             light.ShadowCascade = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f);
  61.  
  62.  
  63.             // Create the camera. Limit far clip distance to match the fog
  64.             CameraNode = scene.CreateChild("Camera");
  65.             camera = CameraNode.CreateComponent<Camera>();
  66.             camera.FarClip = 1000;
  67.             CameraNode.Position = new Vector3(0.0f, 10.0f, -50.0f);
  68.  
  69.             Renderer.SetViewport(0, new Viewport(Context, scene, camera, null));
  70.  
  71.             //wall = CModel.Load(scene, "wall.fbx.mdl");
  72.             //floor = CModel.Load(scene, "floor.fbx.mdl");
  73.             //wall = CModel.Load(scene, "wall.fbx.mdl", "Material_001.xml");
  74.             //floor = CModel.Load(scene, "floor.fbx.mdl", "Material.001.xml");
  75.  
  76.             const float SCALE = 20;
  77.             for (int x = 0; x < 10; x++)
  78.             {
  79.                 floor = CModel.Load(scene, "floor.fbx.mdl");
  80.                 floor.GetNode().SetTransform(new Vector3(x * SCALE, 0, 0), Quaternion.Identity, 1);
  81.  
  82.  
  83.                 wall = CModel.Load(scene, "wall.fbx.mdl");
  84.                 wall.GetNode().SetTransform(new Vector3(x * SCALE, 0, 0), Quaternion.Identity, 1);
  85.             }
  86.  
  87.             man = CAnimatedModel_OLD.Load(scene, "test_stickman.fbx.mdl");
  88.             man.LoadAnimation("test_stickman.fbx_UkkoArmatureIdle.ani", 1); // lataa ekana että walk weight muutos hävittää tämän
  89.             man.LoadAnimation("test_stickman.fbx_UkkoArmatureWalk.ani", 0);
  90.  
  91.         }
  92.  
  93.         bool walk = false;
  94.         protected override void OnUpdate(float timeStep)
  95.         {
  96.             base.OnUpdate(timeStep);
  97.             SimpleMoveCamera3D(timeStep, 50);
  98.  
  99.             if (Input.GetKeyDown(Key.Tab))
  100.             {
  101.                 drawDebug = !drawDebug;
  102.                 if (drawDebug) Renderer.DrawDebugGeometry(false);
  103.             }
  104.  
  105.             walk = false;
  106.             if (Input.GetKeyDown(Key.Up))
  107.             {
  108.                 walk = true;
  109.                 man.GetNode().Translate(Vector3.Forward * timeStep * 5);
  110.             }
  111.             if (Input.GetKeyDown(Key.Down))
  112.             {
  113.                 walk = true;
  114.                 man.GetNode().Translate(Vector3.Back * timeStep * 5);
  115.             }
  116.  
  117.             if (Input.GetKeyDown(Key.Left))
  118.             {
  119.                 man.GetNode().Rotate(new Quaternion(0, -timeStep * 200, 0), TransformSpace.Local);
  120.             }
  121.             if (Input.GetKeyDown(Key.Right))
  122.             {
  123.                 man.GetNode().Rotate(new Quaternion(0, timeStep * 200, 0), TransformSpace.Local);
  124.             }
  125.  
  126.             if (walk)
  127.             {
  128.                 man.Update(1, timeStep);
  129.                 man.AddWeight(1, timeStep * 2.0f); // blendaa kävelyyn (muuta WALK animaation blendausta)
  130.             }
  131.             else
  132.             {
  133.                 man.Update(0, timeStep * 0.2f); // idle
  134.                 man.AddWeight(1, -timeStep * 4.0f); // blendaa idleen (muuta WALK animaation blendausta)
  135.             }
  136.  
  137.  
  138.             /*
  139. // AMPUU KATSOMISSUUNTAAN:  
  140.   (aikash HACK, ei järkee laittaa dir varriin suuntaa, vaa laittais sen suoraan shootDir:iin)
  141.  
  142.         if (input->GetMouseButtonPress(MOUSEB_LEFT))
  143.         {
  144.             Vector3 dir = cameraNode_->GetRotation() * Vector3(0.0f, 0, 1.0f);
  145.             obj->GetNode()->SetVar("dir", dir);
  146.             obj->GetNode()->SetPosition(cameraNode_->GetPosition());
  147.         }
  148.  
  149.         if (obj->GetNode()->GetVar("dir")!=0)
  150.         {
  151.             obj->GetNode()->Translate(obj->GetNode()->GetVar("dir").GetVector3() * 100 * timeStep);
  152.         }
  153.              *
  154.              *
  155.              * */
  156.  
  157.         }
  158.  
  159.  
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement