protected override void OnShow(Node node, Asset asset) { node.CreateComponent <WirePlane>(); //Here we should find a model to apply ANI //TODO: ask user if not sure var modelName = Directory.GetFiles(Path.GetDirectoryName(asset.FullPathToAsset), "*.mdl") .Select(Path.GetFileNameWithoutExtension) .FirstOrDefault(f => asset.AssetFileName.StartsWith(f)); if (string.IsNullOrEmpty(modelName)) { throw new Exception("Can't find a model to apply selected animation."); } model = node.CreateComponent <AnimatedModel>(); model.Model = ResourceCache.GetModel(Path.Combine(Path.GetDirectoryName(asset.RelativePathToAsset), modelName + ".mdl")); model.SetMaterial(CreateDefaultMaterial()); var walkAnimation = ResourceCache.GetAnimation(asset.RelativePathToAsset); var state = model.AddAnimationState(walkAnimation); if (state != null) { state.Weight = 1; state.Looped = true; } node.SetScaleBasedOnBoundingBox(60); }
/// <summary> /// Onde eu crio o maluco que fica andando pelo mapa, animado por uma aniamação esqueletal /// </summary> /// <param name="scene"></param> private Node CreateDude(Scene scene) { var cache = this.ResourceCache; var modelNode = scene.CreateChild("Jack"); modelNode.Position = new Vector3(0, 0, 0); modelNode.Rotation = new Quaternion(0, 0, 0); //var modelObject = modelNode.CreateComponent<AnimatedModel>(); var modelObject = new AnimatedModel(); modelNode.AddComponent(modelObject); modelObject.Model = cache.GetModel("Models/Jack.mdl"); //modelObject.Material = cache.GetMaterial("Materials/Jack.xml"); modelObject.CastShadows = true; // Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the // animation, The alternative would be to use an AnimationController component which updates the animation automatically, // but we need to update the model's position manually in any case var walkAnimation = cache.GetAnimation("Models/Jack_Walk.ani"); var state = modelObject.AddAnimationState(walkAnimation); // The state would fail to create (return null) if the animation was not found if (state != null) { // Enable full blending weight and looping state.Weight = 1; state.Looped = true; } // Create our custom Mover component that will move & animate the model during each frame's update var mover = new Mover(ModelMoveSpeed, ModelRotationSpeed, Bounds); modelNode.AddComponent(mover); return(modelNode); }
public Urho_AnimateChar(Scene scene, ResourceCache cache) { // Create animated models const int numModels = 100; const float modelMoveSpeed = 2.0f; const float modelRotateSpeed = 100.0f; var bounds = new BoundingBox(new Vector3(-47.0f, 0.0f, -47.0f), new Vector3(47.0f, 0.0f, 47.0f)); for (var i = 0; i < numModels; ++i) { var modelNode = scene.CreateChild("Jack"); modelNode.Position = new Vector3(Randoms.Next(-45, 45), 0.0f, Randoms.Next(-45, 45)); modelNode.Rotation = new Quaternion(0, Randoms.Next(0, 360), 0); //var modelObject = modelNode.CreateComponent<AnimatedModel>(); var modelObject = new AnimatedModel(); modelNode.AddComponent(modelObject); modelObject.Model = cache.GetModel("Models/Jack.mdl"); //modelObject.Material = cache.GetMaterial("Materials/Jack.xml"); modelObject.CastShadows = true; // Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the // animation, The alternative would be to use an AnimationController component which updates the animation automatically, // but we need to update the model's position manually in any case var walkAnimation = cache.GetAnimation("Models/Jack_Walk.ani"); var state = modelObject.AddAnimationState(walkAnimation); // The state would fail to create (return null) if the animation was not found if (state != null) { // Enable full blending weight and looping state.Weight = 1; state.Looped = true; } // Create our custom Mover component that will move & animate the model during each frame's update var mover = new Mover(modelMoveSpeed, modelRotateSpeed, bounds); modelNode.AddComponent(mover); } }
void CreateScene() { var cache = ResourceCache; scene = new Scene(); // Create the Octree component to the scene so that drawable objects can be rendered. Use default volume // (-1000, -1000, -1000) to (1000, 1000, 1000) scene.CreateComponent <Octree>(); scene.CreateComponent <DebugRenderer>(); // Create scene node & StaticModel component for showing a static plane var planeNode = scene.CreateChild("Plane"); planeNode.Scale = new Vector3(100, 1, 100); var planeObject = planeNode.CreateComponent <StaticModel>(); planeObject.Model = cache.GetModel("Models/Plane.mdl"); planeObject.SetMaterial(cache.GetMaterial("Materials/StoneTiled.xml")); // Create a Zone component for ambient lighting & fog control var zoneNode = scene.CreateChild("Zone"); var zone = zoneNode.CreateComponent <Zone>(); // Set same volume as the Octree, set a close bluish fog and some ambient light zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f)); zone.AmbientColor = new Color(0.15f, 0.15f, 0.15f); zone.FogColor = new Color(0.5f, 0.5f, 0.7f); zone.FogStart = 100; zone.FogEnd = 300; // Create a directional light to the world. Enable cascaded shadows on it var lightNode = scene.CreateChild("DirectionalLight"); lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f)); var light = lightNode.CreateComponent <Light>(); light.LightType = LightType.Directional; light.CastShadows = true; light.ShadowBias = new BiasParameters(0.00025f, 0.5f); // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance light.ShadowCascade = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f); // Create animated models const int numModels = 100; const float modelMoveSpeed = 2.0f; const float modelRotateSpeed = 100.0f; var bounds = new BoundingBox(new Vector3(-47.0f, 0.0f, -47.0f), new Vector3(47.0f, 0.0f, 47.0f)); for (var i = 0; i < numModels; ++i) { var modelNode = scene.CreateChild("Jack"); modelNode.Position = new Vector3(NextRandom(-45, 45), 0.0f, NextRandom(-45, 45)); modelNode.Rotation = new Quaternion(0, NextRandom(0, 360), 0); //var modelObject = modelNode.CreateComponent<AnimatedModel>(); var modelObject = new AnimatedModel(); modelNode.AddComponent(modelObject); modelObject.Model = cache.GetModel("Models/Jack.mdl"); //modelObject.Material = cache.GetMaterial("Materials/Jack.xml"); modelObject.CastShadows = true; // Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the // animation, The alternative would be to use an AnimationController component which updates the animation automatically, // but we need to update the model's position manually in any case var walkAnimation = cache.GetAnimation("Models/Jack_Walk.ani"); var state = modelObject.AddAnimationState(walkAnimation); // The state would fail to create (return null) if the animation was not found if (state != null) { // Enable full blending weight and looping state.Weight = 1; state.Looped = true; } // Create our custom Mover component that will move & animate the model during each frame's update var mover = new Mover(modelMoveSpeed, modelRotateSpeed, bounds); modelNode.AddComponent(mover); } // Create the camera. Limit far clip distance to match the fog CameraNode = scene.CreateChild("Camera"); camera = CameraNode.CreateComponent <Camera>(); camera.FarClip = 300; // Set an initial position for the camera scene node above the plane CameraNode.Position = new Vector3(0.0f, 5.0f, 0.0f); }
void CreateScene () { var cache = ResourceCache; scene = new Scene (); // Create the Octree component to the scene so that drawable objects can be rendered. Use default volume // (-1000, -1000, -1000) to (1000, 1000, 1000) scene.CreateComponent<Octree> (); scene.CreateComponent<DebugRenderer>(); // Create scene node & StaticModel component for showing a static plane var planeNode = scene.CreateChild("Plane"); planeNode.Scale = new Vector3 (100, 1, 100); var planeObject = planeNode.CreateComponent<StaticModel> (); planeObject.Model = cache.GetModel ("Models/Plane.mdl"); planeObject.SetMaterial (cache.GetMaterial ("Materials/StoneTiled.xml")); // Create a Zone component for ambient lighting & fog control var zoneNode = scene.CreateChild("Zone"); var zone = zoneNode.CreateComponent<Zone>(); // Set same volume as the Octree, set a close bluish fog and some ambient light zone.SetBoundingBox (new BoundingBox(-1000.0f, 1000.0f)); zone.AmbientColor = new Color (0.15f, 0.15f, 0.15f); zone.FogColor = new Color (0.5f, 0.5f, 0.7f); zone.FogStart = 100; zone.FogEnd = 300; // Create a directional light to the world. Enable cascaded shadows on it var lightNode = scene.CreateChild("DirectionalLight"); lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f)); var light = lightNode.CreateComponent<Light>(); light.LightType = LightType.Directional; light.CastShadows = true; light.ShadowBias = new BiasParameters(0.00025f, 0.5f); // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance light.ShadowCascade = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f); // Create animated models const int numModels = 100; const float modelMoveSpeed = 2.0f; const float modelRotateSpeed = 100.0f; var bounds = new BoundingBox (new Vector3(-47.0f, 0.0f, -47.0f), new Vector3(47.0f, 0.0f, 47.0f)); for (var i = 0; i < numModels; ++i) { var modelNode = scene.CreateChild("Jack"); modelNode.Position = new Vector3(NextRandom(-45,45), 0.0f, NextRandom (-45, 45)); modelNode.Rotation = new Quaternion (0, NextRandom(0, 360), 0); //var modelObject = modelNode.CreateComponent<AnimatedModel>(); var modelObject = new AnimatedModel (); modelNode.AddComponent (modelObject); modelObject.Model = cache.GetModel("Models/Jack.mdl"); //modelObject.Material = cache.GetMaterial("Materials/Jack.xml"); modelObject.CastShadows = true; // Create an AnimationState for a walk animation. Its time position will need to be manually updated to advance the // animation, The alternative would be to use an AnimationController component which updates the animation automatically, // but we need to update the model's position manually in any case var walkAnimation = cache.GetAnimation("Models/Jack_Walk.ani"); var state = modelObject.AddAnimationState(walkAnimation); // The state would fail to create (return null) if the animation was not found if (state != null) { // Enable full blending weight and looping state.Weight = 1; state.Looped = true; } // Create our custom Mover component that will move & animate the model during each frame's update var mover = new Mover (modelMoveSpeed, modelRotateSpeed, bounds); modelNode.AddComponent (mover); } // Create the camera. Limit far clip distance to match the fog CameraNode = scene.CreateChild("Camera"); camera = CameraNode.CreateComponent<Camera>(); camera.FarClip = 300; // Set an initial position for the camera scene node above the plane CameraNode.Position = new Vector3(0.0f, 5.0f, 0.0f); }