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);
        }
Ejemplo n.º 2
0
        void RestartJacks()
        {
            var ll = new Vector <Node>();  //get rid of some old objects

            scene.GetChildrenWithName(ll, "Sphere", true);
            for (int ii = 0; ii < ll.Size; ii++)
            {
                ll[ii].Remove();
            }

            var nn = new Vector <Node>();

            scene.GetChildrenWithName(nn, "Stuffing", true);
            for (int ii = 0; ii < nn.Size; ii++)
            {
                nn[ii].Remove();
            }

            var mm = new Vector <Node>();

            scene.GetChildrenWithName(mm, "Jack", true);
            for (int ii = 0; ii < mm.Size; ii++)
            {
                mm[ii].Remove();
            }

            // Create animated models, you dont know ... jack
            var cache = GetSubsystem <ResourceCache>();

            for (int z = -1; z <= 1; ++z)
            {
                for (int x = -4; x <= 4; ++x)
                {
                    Node modelNode = scene.CreateChild("Jack");
                    modelNode.Position = new Vector3(x * 5.0f, 0.0f, z * 5.0f);
                    modelNode.Rotation = new Quaternion(0.0f, 180.0f, 0.0f);
                    AnimatedModel modelObject = modelNode.CreateComponent <AnimatedModel>();
                    modelObject.Model = cache.Get <Model>("Models/Jack.mdl");
                    modelObject.SetMaterial(cache.Get <Material>("Materials/Jack.xml"));
                    modelObject.CastShadows = true;
                    // Set the model to also update when invisible to avoid staying invisible when the model should come into
                    // view, but does not as the bounding box is not updated
                    modelObject.UpdateInvisible = true;

                    // Create a rigid body and a collision shape. These will act as a trigger for transforming the
                    // model into a ragdoll when hit by a moving object
                    RigidBody body = modelNode.CreateComponent <RigidBody>();
                    // The Trigger mode makes the rigid body only detect collisions, but impart no forces on the
                    // colliding objects
                    body.Trigger = true;
                    CollisionShape shape = modelNode.CreateComponent <CollisionShape>();
                    // Create the capsule shape with an offset so that it is correctly aligned with the model, which
                    // has its origin at the feet
                    shape.SetCapsule(0.7f, 2.0f, new Vector3(0.0f, 1.0f, 0.0f), Quaternion.Identity);

                    // Create a custom component that reacts to collisions and creates the ragdoll
                    modelNode.AddComponent(new Ragdoll());
                }
            }
        }
Ejemplo n.º 3
0
        protected override void Start()
        {
            base.Start();

            // Create Scene and stuff
            Scene  scene  = new Scene();
            Octree octree = scene.CreateComponent <Octree>();
            Zone   zone   = scene.CreateComponent <Zone>();

            zone.AmbientColor = new Color(0.75f, 0.75f, 0.75f);

            // Create the root note
            Node rootNode = scene.CreateChild();

            rootNode.Position = new Vector3(0, 0, 0);

            // Create a light node
            Node  lightNode = rootNode.CreateChild();
            Light light     = lightNode.CreateComponent <Light>();

            light.Color     = new Color(0.75f, 0.75f, 0.75f);
            light.LightType = LightType.Directional;
            lightNode.SetDirection(new Vector3(2, -3, -1));

            // Create the camera
            cameraNode = scene.CreateChild();
            Camera camera = cameraNode.CreateComponent <Camera>();

            // Set camera Position and Direction above the monkey pointing down
            cameraNode.Position = new Vector3(0, 12, 0);
            cameraNode.SetDirection(new Vector3(0, 0, 0) - cameraNode.Position);

            // Save the camera transform resulting from that configuration
            cameraTransform = From3x4(cameraNode.Transform);

            monkeyNode = rootNode.CreateChild("monkeyNode");
            AnimatedModel monkey = monkeyNode.CreateComponent <AnimatedModel>();

            // Xamarin monkey model created by Vic Wang at http://vidavic.weebly.com
            monkey.Model = ResourceCache.GetModel("monkey1.mdl");
            monkey.SetMaterial(ResourceCache.GetMaterial("Materials/phong1.xml"));

            // Move the monkey down a bit so it's centered on the origin
            monkeyNode.Translate(new Vector3(0, -3, 0));

            // Get the initial rotations of the arm bones
            rightArmRotationBase = monkeyNode.GetChild("arm2", true).Rotation;
            leftArmRotationBase  = monkeyNode.GetChild("arm6", true).Rotation;

            // And the leg bones
            rightLegRotationBase = monkeyNode.GetChild("leg1", true).Rotation;
            leftLegRotationBase  = monkeyNode.GetChild("leg5", true).Rotation;

            // Set up the Viewport
            Viewport viewport = new Viewport(Context, scene, camera, null);

            Renderer.SetViewport(0, viewport);
            viewport.SetClearColor(new Color(0.88f, 0.88f, 0.88f));
        }
Ejemplo n.º 4
0
        void CreateCharacter()
        {
            var cache = ResourceCache;

            Node objectNode = scene.CreateChild("Jack");

            objectNode.Position = (new Vector3(0.0f, 1.0f, 0.0f));

            // spin node
            Node adjustNode = objectNode.CreateChild("AdjNode");

            adjustNode.Rotation = (new  Quaternion(0, 180, 0));

            // Create the rendering component + animation controller
            AnimatedModel obj = adjustNode.CreateComponent <AnimatedModel>();

            obj.Model = cache.GetModel("Models/Mutant/Mutant.mdl");
            obj.SetMaterial(cache.GetMaterial("Models/Mutant/Materials/mutant_M.xml"));
            obj.CastShadows = true;
            adjustNode.CreateComponent <AnimationController>();

            // Set the head bone for manual control
            obj.Skeleton.GetBoneSafe("Mutant:Head").Animated = false;

            // Create rigidbody, and set non-zero mass so that the body becomes dynamic
            RigidBody body = objectNode.CreateComponent <RigidBody>();

            body.CollisionLayer = 1;
            body.Mass           = 1.0f;

            // Set zero angular factor so that physics doesn't turn the character on its own.
            // Instead we will control the character yaw manually
            body.SetAngularFactor(Vector3.Zero);

            // Set the rigidbody to signal collision also when in rest, so that we get ground collisions properly
            body.CollisionEventMode = CollisionEventMode.Always;

            // Set a capsule shape for collision
            CollisionShape shape = objectNode.CreateComponent <CollisionShape>();

            shape.SetCapsule(0.7f, 1.8f, new Vector3(0.0f, 0.9f, 0.0f), Quaternion.Identity);

            // Create the character logic component, which takes care of steering the rigidbody
            // Remember it so that we can set the controls. Use a WeakPtr because the scene hierarchy already owns it
            // and keeps it alive as long as it's not removed from the hierarchy
            character = new Character();
            objectNode.AddComponent(character);
        }
Ejemplo n.º 5
0
        void SpawnJack(Vector3 pos, Node jackGroup)
        {
            Node jackNode = jackGroup.CreateChild("Jack");

            jackNode.Position = pos;
            AnimatedModel modelObject = jackNode.CreateComponent <AnimatedModel>();

            modelObject.Model = (ResourceCache.GetModel("Models/Jack.mdl"));
            modelObject.SetMaterial(ResourceCache.GetMaterial("Materials/Jack.xml"));
            modelObject.CastShadows = true;
            jackNode.CreateComponent <AnimationController>();

            // Create the CrowdAgent
            var agent = jackNode.CreateComponent <CrowdAgent>();

            agent.Height   = 2.0f;
            agent.MaxSpeed = 3.0f;
            agent.MaxAccel = 3.0f;
        }
Ejemplo n.º 6
0
        void CreateScene()
        {
            var cache = GetSubsystem <ResourceCache>();

            scene = new Scene();

            // Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
            // Also create a DebugRenderer component so that we can draw debug geometry
            scene.CreateComponent <Octree>();
            scene.CreateComponent <DebugRenderer>();

            // Create scene node & StaticModel component for showing a static plane
            Node planeNode = scene.CreateChild("Plane");

            planeNode.Scale = new Vector3(100.0f, 1.0f, 100.0f);
            StaticModel planeObject = planeNode.CreateComponent <StaticModel>();

            planeObject.Model = cache.Get <Model>("Models/Plane.mdl");
            planeObject.SetMaterial(cache.Get <Material>("Materials/StoneTiled.xml"));

            // Create a Zone component for ambient lighting & fog control
            Node zoneNode = scene.CreateChild("Zone");
            Zone zone     = zoneNode.CreateComponent <Zone>();

            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.0f;
            zone.FogEnd       = 300.0f;

            // Create a directional light to the world. Enable cascaded shadows on it
            Node lightNode = scene.CreateChild("DirectionalLight");

            lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f));
            Light light = lightNode.CreateComponent <Light>();

            light.LightType   = LightType.LIGHT_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 some mushrooms
            const uint numMushrooms = 100;

            for (uint i = 0; i < numMushrooms; ++i)
            {
                CreateMushroom(new Vector3(NextRandom(90.0f) - 45.0f, 0.0f, NextRandom(90.0f) - 45.0f));
            }

            // Create randomly sized boxes. If boxes are big enough, make them occluders
            const uint numBoxes = 20;

            for (uint i = 0; i < numBoxes; ++i)
            {
                Node  boxNode = scene.CreateChild("Box");
                float size    = 1.0f + NextRandom(10.0f);
                boxNode.Position = new Vector3(NextRandom(80.0f) - 40.0f, size * 0.5f, NextRandom(80.0f) - 40.0f);
                boxNode.SetScale(size);
                StaticModel boxObject = boxNode.CreateComponent <StaticModel>();
                boxObject.Model = cache.Get <Model>("Models/Box.mdl");
                boxObject.SetMaterial(cache.Get <Material>("Materials/Stone.xml"));
                boxObject.CastShadows = true;
                if (size >= 3.0f)
                {
                    boxObject.Occluder = true;
                }
            }

            // Create Jack node that will follow the path
            jackNode          = scene.CreateChild("Jack");
            jackNode.Position = new Vector3(-5.0f, 0.0f, 20.0f);
            AnimatedModel modelObject = jackNode.CreateComponent <AnimatedModel>();

            modelObject.Model = cache.Get <Model>("Models/Jack.mdl");
            modelObject.SetMaterial(cache.Get <Material>("Materials/Jack.xml"));
            modelObject.CastShadows = true;

            // Create a NavigationMesh component to the scene root
            NavigationMesh navMesh = scene.CreateComponent <NavigationMesh>();

            // Create a Navigable component to the scene root. This tags all of the geometry in the scene as being part of the
            // navigation mesh. By default this is recursive, but the recursion could be turned off from Navigable
            scene.CreateComponent <Navigable>();
            // Add padding to the navigation mesh in Y-direction so that we can add objects on top of the tallest boxes
            // in the scene and still update the mesh correctly
            navMesh.Padding = new Vector3(0.0f, 10.0f, 0.0f);
            // Now build the navigation geometry. This will take some time. Note that the navigation mesh will prefer to use
            // physics geometry from the scene nodes, as it often is simpler, but if it can not find any (like in this example)
            // it will use renderable geometry instead
            navMesh.Build();

            // Create the camera. Limit far clip distance to match the fog
            CameraNode = scene.CreateChild("Camera");
            Camera camera = CameraNode.CreateComponent <Camera>();

            camera.FarClip = 300.0f;

            // Set an initial position for the camera scene node above the plane
            CameraNode.Position = new Vector3(0.0f, 5.0f, 0.0f);
        }
Ejemplo n.º 7
0
        private void CreateScene()
        {
            var cache = ResourceCache;

            BrickScene = new Scene();

            BrickScene.CreateComponent <Octree>();
            BrickScene.CreateComponent <DebugRenderer>();

            scene1 = new Scene1();
            scene1.CreateListOfBlocks(BrickScene);

            // Create a Zone component for ambient lighting & fog control
            var zoneNode = BrickScene.CreateChild("Zone");
            var zone     = zoneNode.CreateComponent <Zone>();

            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.0f;
            zone.FogEnd       = 300.0f;

            // Create a directional light to the world. Enable cascaded shadows on it
            var lightNode = BrickScene.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 Jack node that will follow the path
            jackNode          = BrickScene.CreateChild("Jack");
            jackNode.Position = new Vector3(15.0f, 15.0f, 20.0f);
            AnimatedModel modelObject = jackNode.CreateComponent <AnimatedModel>();

            //modelObject.Model = cache.GetModel("Models/Jack.mdl");
            modelObject.SetMaterial(cache.GetMaterial("Materials/Moon.xml"));
            modelObject.CastShadows = true;

            // Create a NavigationMesh component to the scene root
            NavigationMesh navMesh = BrickScene.CreateComponent <NavigationMesh>();

            // Create a Navigable component to the scene root. This tags all of the geometry in the scene as being part of the
            // navigation mesh. By default this is recursive, but the recursion could be turned off from Navigable
            BrickScene.CreateComponent <Navigable>();
            // Add padding to the navigation mesh in Y-direction so that we can add objects on top of the tallest boxes
            // in the scene and still update the mesh correctly
            navMesh.Padding = new Vector3(0.0f, 10.0f, 0.0f);

            // Create the camera. Limit far clip distance to match the fog
            CameraNode = BrickScene.CreateChild("Camera");
            Camera camera = CameraNode.CreateComponent <Camera>();

            camera.FarClip = 300.0f;

            // Set an initial position for the camera scene node above the plane
            CameraNode.Position = new Vector3(57.48847f, 60.82811f, -60.87394f); //
            CameraNode.Rotation = new Quaternion(29.3f, 1.1f, 0.0f);

            var n = BrickScene.CreateChild("gui");

            var b = new Urho.Gui.Button();
            //b.
            ///var b = new UrhoSharp.Gu
            ///
            var bnNode = BrickScene.CreateChild("button");
            var btn    = new Button();

            btn.CreateButton("newBtn");
            btn.SetSize(500, 500);

            // bnNode.AddChild(btn);
        }
Ejemplo n.º 8
0
        void CreateScene()
        {
            var cache = GetSubsystem <ResourceCache>();

            scene = new Scene();

            // Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
            // Create a physics simulation world with default parameters, which will update at 60fps. Like the Octree must
            // exist before creating drawable components, the PhysicsWorld must exist before creating physics components.
            // Finally, create a DebugRenderer component so that we can draw physics debug geometry
            scene.CreateComponent <Octree>();
            scene.CreateComponent <PhysicsWorld>();
            scene.CreateComponent <DebugRenderer>();

            // Create a Zone component for ambient lighting & fog control
            Node zoneNode = scene.CreateChild("Zone");
            Zone zone     = zoneNode.CreateComponent <Zone>();

            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.0f;
            zone.FogEnd       = 300.0f;

            // Create a directional light to the world. Enable cascaded shadows on it
            Node lightNode = scene.CreateChild("DirectionalLight");

            lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f));
            Light light = lightNode.CreateComponent <Light>();

            light.LightType   = LightType.LIGHT_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 a floor object, 500 x 500 world units. Adjust position so that the ground is at zero Y
                Node floorNode = scene.CreateChild("Floor");
                floorNode.Position = new Vector3(0.0f, -0.5f, 0.0f);
                floorNode.Scale    = new Vector3(500.0f, 1.0f, 500.0f);
                StaticModel floorObject = floorNode.CreateComponent <StaticModel>();
                floorObject.Model = cache.Get <Model>("Models/Box.mdl");
                floorObject.SetMaterial(cache.Get <Material>("Materials/StoneTiled.xml"));

                // Make the floor physical by adding RigidBody and CollisionShape components
                RigidBody body = floorNode.CreateComponent <RigidBody>();
                // We will be spawning spherical objects in this sample. The ground also needs non-zero rolling friction so that
                // the spheres will eventually come to rest
                body.RollingFriction = 0.15f;
                CollisionShape shape = floorNode.CreateComponent <CollisionShape>();
                // Set a box shape of size 1 x 1 x 1 for collision. The shape will be scaled with the scene node scale, so the
                // rendering and physics representation sizes should match (the box model is also 1 x 1 x 1.)
                shape.SetBox(Vector3.One, Vector3.Zero, Quaternion.Identity);
            }

            // Create animated models
            for (int z = -1; z <= 1; ++z)
            {
                for (int x = -4; x <= 4; ++x)
                {
                    Node modelNode = scene.CreateChild("Jack");
                    modelNode.Position = new Vector3(x * 5.0f, 0.0f, z * 5.0f);
                    modelNode.Rotation = new Quaternion(0.0f, 180.0f, 0.0f);
                    AnimatedModel modelObject = modelNode.CreateComponent <AnimatedModel>();
                    modelObject.Model = cache.Get <Model>("Models/Jack.mdl");
                    modelObject.SetMaterial(cache.Get <Material>("Materials/Jack.xml"));
                    modelObject.CastShadows = true;
                    // Set the model to also update when invisible to avoid staying invisible when the model should come into
                    // view, but does not as the bounding box is not updated
                    modelObject.UpdateInvisible = true;

                    // Create a rigid body and a collision shape. These will act as a trigger for transforming the
                    // model into a ragdoll when hit by a moving object
                    RigidBody body = modelNode.CreateComponent <RigidBody>();
                    // The Trigger mode makes the rigid body only detect collisions, but impart no forces on the
                    // colliding objects
                    body.Trigger = true;
                    CollisionShape shape = modelNode.CreateComponent <CollisionShape>();
                    // Create the capsule shape with an offset so that it is correctly aligned with the model, which
                    // has its origin at the feet
                    shape.SetCapsule(0.7f, 2.0f, new Vector3(0.0f, 1.0f, 0.0f), Quaternion.Identity);

                    // Create a custom component that reacts to collisions and creates the ragdoll
                    modelNode.AddComponent(new Ragdoll());
                }
            }

            // Create the camera. Limit far clip distance to match the fog
            CameraNode     = new Node();
            camera         = CameraNode.CreateComponent <Camera>();
            camera.FarClip = 300.0f;
            // Set an initial position for the camera scene node above the plane
            CameraNode.Position = new Vector3(0.0f, 3.0f, -20.0f);
        }