Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Urho;
- namespace AppUrhoGame1
- {
- public class CAnimatedModel_OLD : Component
- {
- Node node;
- AnimatedModel model;
- /**
- lataa animoidun modelin ja materiaalin
- name : modelin nimi
- materialName : materiaalin nimi
- jos ei anneta materialNamea, luetaan fileName.txt:stä materiaalin nimi ja käytetään sitä.
- */
- public static CAnimatedModel_OLD Load(Scene scene, string name, string materialName = "")
- {
- CAnimatedModel_OLD m = new CAnimatedModel_OLD();
- m._Load(scene, name, materialName);
- return m;
- }
- void _Load(Scene scene, string name, string materialName)
- {
- // luo node ja sille model
- node = scene.CreateChild();
- model = node.CreateComponent<AnimatedModel>();
- // lataa model
- var cache = Globals.ResourceCache;
- model.Model = cache.GetModel("Models/" + name);
- // jos materialName ei ole "", ladataan materialName.xml (muuten name.txt:stä löytyvä materiaali)
- if (materialName != "")
- {
- model.SetMaterial(cache.GetMaterial("Materials/" + materialName));
- }
- else
- {
- string txtPath = "Models/" + name.Substring(0, name.LastIndexOf(".")) + ".txt";
- model.SetMaterial(cache.GetMaterial(Globals.ReadTxt(txtPath)));
- }
- node.AddComponent(new AnimationController());
- model.CastShadows = Globals.CastShadows;
- }
- public void Clear()
- {
- if (node != null)
- {
- node.Remove();
- node = null;
- }
- if (model != null)
- {
- model.Remove();
- model = null;
- }
- }
- public Node GetNode()
- {
- return node;
- }
- public void LoadAnimation(string name, float weight)
- {
- var cache = Globals.ResourceCache;
- Animation animation = cache.GetAnimation("Models/" + name);
- AnimationState state = model.AddAnimationState(animation);
- // The state would fail to create (return null) if the animation was not found
- if (state != null)
- {
- state.Weight = weight;
- state.Looped = true;
- }
- }
- public void SetWeight(uint animNum, float weight)
- {
- AnimationState state = model.GetAnimationState(animNum);
- if (state != null)
- {
- state.Weight = weight;
- }
- }
- public void AddWeight(uint animNum, float weight)
- {
- AnimationState state = model.GetAnimationState(animNum);
- if (state != null)
- {
- float w = state.Weight + weight;
- if (w < 0) w = 0;
- if (w > 1) w = 1;
- state.Weight = w;
- }
- }
- int lastAnim = -1;
- public void Update(uint animNum, float timeStep)
- {
- AnimationState state = model.GetAnimationState(animNum);
- if (state != null)
- {
- if (lastAnim != animNum)
- {
- //state.Time = 0;
- lastAnim = (int)animNum;
- }
- state.AddTime(timeStep);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement