Beispiel #1
0
        private void CreateToaster()
        {
            var toaster = new Entity("toaster")
                          .AddComponent(new SkinnedModel("Assets/Animation/toaster_template_animation_uv_fbx.wpk"))
                          .AddComponent(new MaterialsMap(new BasicMaterial("Assets/Textures/toaster_red.wpk")
            {
                LightingEnabled = true,
            }))
                          .AddComponent(new Transform3D()
            {
                Scale = new Vector3(1.5f, 1, 0.67f),
            })
                          .AddComponent(new Animation3D("Assets/Animation/toaster_template_animation_uv_fbx_animation.wpk"))
                          .AddComponent(new SkinnedModelRenderer())
                          .AddComponent(new ToasterBehavior())
                          .AddComponent(new Transform2D())
                          .AddComponent(new RectangleCollider())
                          .AddComponent(new TouchGestures());

            toaster.FindComponent <TouchGestures>().TouchPressed += new EventHandler <GestureEventArgs>(StartGame);

            EntityManager.Add(toaster);

            Animation3D anim = toaster.FindComponent <Animation3D>();

            anim.PlayAnimation("StartRoast", true);
        }
Beispiel #2
0
        /// <summary>
        /// Instantiate model hierarchy
        /// </summary>
        /// <param name="entityName">The entity name</param>
        /// <param name="setMaterials">Set the materials to entities</param>
        /// <returns>The entity hierarchy</returns>
        public Entity InstantiateModelHierarchy(string entityName, bool setMaterials)
        {
            var nodeEntities = new Entity[this.Nodes.Length];

            for (int i = 0; i < this.Nodes.Length; i++)
            {
                nodeEntities[i] = this.CreateNodeEntity(this.Nodes[i]);
            }

            Material material = new StandardMaterial();

            Entity rootEntity = null;

            if (this.RootNodes.Length == 1)
            {
                var rootNodeIx = this.RootNodes[0];
                rootEntity = nodeEntities[rootNodeIx];
                this.GenerateModelsHierarchy(nodeEntities, rootNodeIx, material, null);
            }
            else
            {
                rootEntity = new Entity()
                             .AddComponent(new Transform3D());

                for (int i = 0; i < this.RootNodes.Length; i++)
                {
                    this.GenerateModelsHierarchy(nodeEntities, this.RootNodes[i], material, rootEntity);
                }
            }

            for (int i = 0; i < this.Nodes.Length; i++)
            {
                this.FillNode(i, nodeEntities, setMaterials);
            }

            if (this.Animations.Count > 0)
            {
                var animation = new Animation3D()
                {
                    ModelPath = this.AssetPath
                };

                rootEntity.AddComponent(animation);
            }

            if (string.IsNullOrEmpty(entityName))
            {
                rootEntity.Name = Entity.NextDefaultName();
            }
            else
            {
                rootEntity.Name = entityName;
            }

            return(rootEntity);
        }
Beispiel #3
0
        protected override void CreateScene()
        {
            ViewCamera camera = new ViewCamera("MainCamera", new Vector3(2, 1, 2), new Vector3(0, 1, 0));

            camera.BackgroundColor = Color.CornflowerBlue;
            EntityManager.Add(camera.Entity);

            Entity animatedModel = new Entity("Isis")
                                   .AddComponent(new Transform3D())
                                   .AddComponent(new BoxCollider())
                                   .AddComponent(new SkinnedModel("Content/isis.wpk"))
                                   .AddComponent(new MaterialsMap(new BasicMaterial("Content/isis-difuse.wpk")))
                                   .AddComponent(new Animation3D("Content/isis-animations.wpk"))
                                   .AddComponent(new SkinnedModelRenderer());

            anim = animatedModel.FindComponent <Animation3D>();
            EntityManager.Add(animatedModel);
        }
Beispiel #4
0
        protected override void CreateScene()
        {
            #region Scene creation
            // Create the camera
            ViewCamera camera = new ViewCamera("MainCamera", new Vector3(2, 1, 2), new Vector3(0, 1, 0));
            EntityManager.Add(camera.Entity);

            RenderManager.SetActiveCamera(camera.Entity);

            // Create the model. Note of we add the Animation3D component.
            Entity animatedModel = new Entity("Isis")
                                   .AddComponent(new Transform3D())
                                   .AddComponent(new BoxCollider())
                                   .AddComponent(new SkinnedModel("Content/isis.wpk"))
                                   .AddComponent(new MaterialsMap(new BasicMaterial("Content/isis-difuse.wpk")))
                                   .AddComponent(new Animation3D("Content/isis-animations.wpk"))
                                   .AddComponent(new SkinnedModelRenderer())
                                   .AddComponent(new IsisBehavior());

            // Create the sound bank
            SoundBank spankerSlamSounds = new SoundBank();
            spankerSlamSounds.Add(SoundsManager.FootStep1);
            spankerSlamSounds.Add(SoundsManager.FootStep2);
            WaveServices.SoundPlayer.RegisterSoundBank(spankerSlamSounds);

            RenderManager.BackgroundColor = Color.CornflowerBlue;
            #endregion

            #region Key Events
            // Add the key frames. The first parameter is the name of the animation, the second the number of frames and the third the name of the event. As you can see, we raise two events when
            // the animation is "Attack" ( see the Animation3D example for further information ). The first event is raised on frame 10 and the second on frame 25. See the SpankerBehavior class
            animation = animatedModel.FindComponent <Animation3D>()
                        .AddKeyFrameEvent("Jog", 1, "DoFootstep")
                        .AddKeyFrameEvent("Jog", 14, "DoFootstep")
                        .AddKeyFrameEvent("Jog", 26, "DoFootstep")
                        .AddKeyFrameEvent("Jog", 39, "DoFootstep");
            EntityManager.Add(animatedModel);
            #endregion
        }