Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AnimScript.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Runtime.Remoting.Contexts;
5 using System.Threading.Tasks;
6 
7 using SiliconStudio.Paradox;
8 using SiliconStudio.Paradox.DataModel;
9 using SiliconStudio.Paradox.Effects;
10 using SiliconStudio.Paradox.Effects.Modules;
11 using SiliconStudio.Paradox.Engine;
12 using SiliconStudio.Paradox.EntityModel;
13 using SiliconStudio.Paradox.Games;
14 using SiliconStudio.Paradox.Graphics;
15 using SiliconStudio.Paradox.Graphics.Data;
16 using SiliconStudio.Paradox.Games.Mathematics;
17 using SiliconStudio.Paradox.Games.MicroThreading;
18 using SiliconStudio.Paradox.Games.Serialization;
19 using SiliconStudio.Paradox.Games.Serialization.Contents;
20 using SiliconStudio.Paradox.Games.IO;
21 using SiliconStudio.Paradox.Prefabs;
22 using SiliconStudio.Paradox.Games.Serialization.Serializers;
23 
24 namespace ScriptTest2
25 {
26  [ContentSerializer(typeof(EntityComponentContentSerializer<ModelConverterComponent>))]
28  {
29  public static PropertyKey<ModelConverterComponent> Key = new PropertyKey<ModelConverterComponent>("Key", typeof(ModelConverterComponent));
30 
31  [DataMemberConvert]
32  public string Model { get; set; }
33  public EffectOld Effect { get; set; }
34  }
35 
36  public class ModelConverterProcessor : EntityProcessor<ModelConverterComponent>
37  {
38  private EngineContext engineContext;
39 
40  public ModelConverterProcessor(EngineContext engineContext)
41  : base(new PropertyKey[] { ModelConverterComponent.Key })
42  {
43  this.engineContext = engineContext;
44  }
45 
47  {
48  return entity.Get(ModelConverterComponent.Key);
49  }
50  }
51 
52  [ParadoxScript]
53  public class AnimScript
54  {
55  private static EffectOld effect;
56 
57  public static async Task<Entity> LoadFBXModel(EngineContext engineContext, string url)
58  {
59  var characterEntityPrefab = await engineContext.AssetManager.LoadAsync<Entity>(url);
60  // Prefabs
61  var characterEntity = Prefab.Clone(characterEntityPrefab);
62 
63  //characterEntity.Set(TransformationComponent.Key, new TransformationTRSComponent());
64  await engineContext.EntityManager.AddEntityAsync(characterEntity);
65 
66  return characterEntity;
67  }
68 
69  public static async Task AnimateFBXModel(EngineContext engineContext, Entity characterEntity, float endAnimTime = 0.0f, float loopTime = 0.0f)
70  {
71  var animationComponent = characterEntity.GetOrCreate(AnimationComponent.Key);
72  while (true)
73  {
74  await Scheduler.Current.NextFrame();
75  if (engineContext.EntityManager.State != GameState.Saving)
76  {
77  if (loopTime == 0.0f)
78  {
79  loopTime = endAnimTime;
80  }
81 
82  var endTick = endAnimTime == 0.0f ? animationComponent.AnimationData.Duration.Ticks : (long)((double)endAnimTime * TimeSpan.TicksPerSecond);
83  var resetTick = (long)((double)loopTime * TimeSpan.TicksPerSecond);
84  animationComponent.CurrentTime = new TimeSpan(Math.Min(endTick, (engineContext.CurrentTime.Ticks % resetTick)));
85  }
86  else
87  {
88  animationComponent.CurrentTime = new TimeSpan(0);
89  }
90  }
91  }
92  }
93 }
Game entity. It usually aggregates multiple EntityComponent
Definition: Entity.cs:28
static async Task AnimateFBXModel(EngineContext engineContext, Entity characterEntity, float endAnimTime=0.0f, float loopTime=0.0f)
Definition: AnimScript.cs:69
static PropertyKey< ModelConverterComponent > Key
Definition: AnimScript.cs:29
ModelConverterProcessor(EngineContext engineContext)
Definition: AnimScript.cs:40
override ModelConverterComponent GenerateAssociatedData(Entity entity)
Definition: AnimScript.cs:46
Entity processor, triggered on various EntitySystem events such as Entity and Component additions and...
static async Task< Entity > LoadFBXModel(EngineContext engineContext, string url)
Definition: AnimScript.cs:57
Collection of Mesh, each one usually being a different LOD of the same Model. The effect system will ...
Definition: Model.cs:23