Beispiel #1
0
 public static void ModifyEffectTechniques(Model model, string techniqueName)
 {
     foreach (ModelMesh mesh in model.Mesh)
     {
         foreach (Effect effect in mesh.Effects)
         {
             effect.CurrentTechnique = effect.Techniques[techniqueName];
         }
     }
 }
Beispiel #2
0
        private void CreateObjects()
        {
            // Loads a textured model of a ship
            ModelLoader loader    = new ModelLoader();
            Model       shipModel = (Model)loader.Load("", "p1_wedge");

            // Create a geometry node of a loaded ship model
            GeometryNode shipNode = new GeometryNode("Ship");

            shipNode.Model = shipModel;
            // This ship model has material definitions in the model file, so instead
            // of creating a material node for this ship model, we simply use its internal materials
            ((Model)shipNode.Model).UseInternalMaterials = true;
            ((Model)shipNode.Model).ContainsTransparency = true;

            // Create a transform node to define the transformation for the ship
            TransformNode shipTransNode = new TransformNode();

            // shipTransNode.Translation = new Vector3(0, 5, -12);
            shipTransNode.Scale    = new Vector3(0.002f, 0.002f, 0.002f); // It's huge!
            shipTransNode.Rotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),
                                                                    MathHelper.ToRadians(-90));

            shipTransParentNode = new TransformNode();

            //Set our rotation animation to ease in initially
            animationRotation = new AnimationHelper(Easing.EaseIn);

            startPosition = new Vector3(-10, 0, -10);
            endPosition   = new Vector3(5, 2, -5);

            startRotationVector = new Vector3(0, 0, 0);
            endRotationVector   = new Vector3(MathHelper.ToRadians(0), MathHelper.ToRadians(180), MathHelper.ToRadians(180));

            //Set our translation animation to ease in initially
            animationTranslation = new AnimationHelper(Easing.EaseIn);

            //Define what kind of interpolation to use.
            animationTranslation.Animate(arrayOfTransitions[currentInterpolation], startPosition, endPosition, 2);
            // animationTranslation.SetLooping(true, 5); // Use if you want to loop through an animation.

            // Set an action to take place once the animation concludes.
            animationTranslation.SetEndAction(delegate()
            {
                animationRotation.Animate(arrayOfTransitions[currentInterpolation], startRotationVector, endRotationVector, 2.0);
            }); // Note: if you loop and set this animation, it'll occur after the end of the first loop, not after the end of all loops!

            textToPrint = "Linear interpolation";

            // Now add the above nodes to the scene graph in appropriate order
            scene.RootNode.AddChild(shipTransParentNode);
            shipTransParentNode.AddChild(shipTransNode);
            shipTransNode.AddChild(shipNode);
        }
Beispiel #3
0
        public override void ReRender(Model model, ref Matrix worldMatrix, Material material)
        {
            int count = 0;
            KeyValuePair <string, int> pair_techNvalue;

            do
            {
                pair_techNvalue  = toonPPShader.getDefaultTechniqueSettings(count++);
                defaultTechnique = pair_techNvalue.Key;

                model.RenderModel(ref worldMatrix, material);
            } while (pair_techNvalue.Value == 1);
        }
Beispiel #4
0
        public Item(string[] tokens)
        {
            Model m = (Model)loader.Load("", tokens[NAME]);

            m.CastShadows = true;
            Material defaultMaterial = new Material();

            defaultMaterial.Diffuse       = Color.White.ToVector4(); //new Vector4(0, 0.5f, 0, 1);
            defaultMaterial.Specular      = Color.White.ToVector4();
            defaultMaterial.SpecularPower = 10;

            build(m, tokens[NAME], defaultMaterial);
            this.Scale       = new Vector3(float.Parse(tokens[Item.SCALE]));
            this.savedTokens = tokens;
        }
Beispiel #5
0
        private void CreateObject()
        {
            // Loads a textured model of a ship
            ModelLoader loader    = new ModelLoader();
            Model       shipModel = (Model)loader.Load("", "p1_wedge");

            // Create a geometry node of a loaded ship model
            GeometryNode shipNode = new GeometryNode("Ship");

            shipNode.Model = shipModel;
            // This ship model has material definitions in the model file, so instead
            // of creating a material node for this ship model, we simply use its internal materials
            shipNode.Model.UseInternalMaterials = true;

            // Create a transform node to define the transformation for the ship
            shipTransNode             = new TransformNode();
            shipTransNode.Translation = new Vector3(0, 0, 0);
            shipTransNode.Scale       = new Vector3(0.002f, 0.002f, 0.002f); // It's huge!
            shipTransNode.Rotation    = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0),
                                                                       MathHelper.ToRadians(0));

            scene.RootNode.AddChild(shipTransNode);
            shipTransNode.AddChild(shipNode);
        }
Beispiel #6
0
        private void CreateObject()
        {
            // Loads a textured model of a ship
            ModelLoader loader    = new ModelLoader();
            Model       shipModel = (Model)loader.Load("", "Ship");

            // Create a geometry node of a loaded ship model
            shipNode = new GeometryNode("Ship");

            shipNode.Model        = shipModel;
            shipNode.Model.Shader = toonImplClass_obj.toonShader;

            ((Model)shipNode.Model).UseNonPhotoRealisticRendering = true;
            ((Model)shipNode.Model).ReRenderModel        = true;
            ((Model)shipNode.Model).PostProcessShader    = toonImplClass_obj.toonPostProcessShader;
            ((Model)shipNode.Model).UseInternalMaterials = true;


            // Create a transform node to define the transformation for the ship
            TransformNode shipTransNode = new TransformNode();

            shipTransNode.Translation = new Vector3(0, 5, -12);
            shipTransNode.Scale       = new Vector3(0.02f, 0.02f, 0.02f); // It's huge!
            shipTransNode.Rotation    = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),
                                                                       MathHelper.ToRadians(90));
            shipTransNode.Name = "shipTransNode";

            shipTransParentNode             = new TransformNode();
            shipTransParentNode.Translation = Vector3.Zero;
            shipTransParentNode.Name        = "shipTransParentNode";

            // Now add the above nodes to the scene graph in appropriate order
            scene.RootNode.AddChild(shipTransParentNode);
            shipTransParentNode.AddChild(shipTransNode);
            shipTransNode.AddChild(shipNode);
        }
Beispiel #7
0
        /// <summary>
        /// Alters a model so it will draw using a custom effect, while preserving
        /// whatever textures were set on it as part of the original effects.
        /// </summary>
        public static void ReplaceModelEffect(Model model, Effect replacementEffect,
                                              String alpha, String diffuseColor, String emissiveColor, String specularColor,
                                              String specularPower, String texture, String textureEnabled)
        {
            // Table mapping the original effects to our replacement versions.
            Dictionary <Effect, Effect> effectMapping = new Dictionary <Effect, Effect>();

            foreach (ModelMesh mesh in model.Mesh)
            {
                // Scan over all the effects currently on the mesh.
                foreach (BasicEffect oldEffect in mesh.Effects)
                {
                    // If we haven't already seen this effect...
                    if (!effectMapping.ContainsKey(oldEffect))
                    {
                        // Make a clone of our replacement effect. We can't just use
                        // it directly, because the same effect might need to be
                        // applied several times to different parts of the model using
                        // a different texture each time, so we need a fresh copy each
                        // time we want to set a different texture into it.
                        Effect newEffect = replacementEffect.Clone();

                        try
                        {
                            if (alpha.Length > 0)
                            {
                                newEffect.Parameters[alpha].SetValue(oldEffect.Alpha);
                            }
                            if (diffuseColor.Length > 0)
                            {
                                newEffect.Parameters[diffuseColor].SetValue(
                                    new Vector4(oldEffect.DiffuseColor, oldEffect.Alpha));
                            }
                            if (emissiveColor.Length > 0)
                            {
                                newEffect.Parameters[emissiveColor].SetValue(new Vector4(oldEffect.EmissiveColor, 1));
                            }
                            if (specularColor.Length > 0)
                            {
                                newEffect.Parameters[specularColor].SetValue(new Vector4(oldEffect.SpecularColor, 1));
                            }
                            if (specularPower.Length > 0)
                            {
                                newEffect.Parameters[specularPower].SetValue(oldEffect.SpecularPower);
                            }
                            if (texture.Length > 0)
                            {
                                newEffect.Parameters[texture].SetValue(oldEffect.Texture);
                            }
                            if (textureEnabled.Length > 0)
                            {
                                newEffect.Parameters[textureEnabled].SetValue(oldEffect.TextureEnabled);
                            }
                        }
                        catch (Exception)
                        {
                            throw new GoblinException("One of the parameter name does not exist " +
                                                      "in your replacement effect");
                        }

                        effectMapping.Add(oldEffect, newEffect);
                    }
                }

                // Now that we've found all the effects in use on this mesh,
                // update it to use our new replacement versions.
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    meshPart.Effect = effectMapping[meshPart.Effect];
                }
            }
        }
Beispiel #8
0
 /// <summary>
 /// Replaces
 /// </summary>
 /// <param name="model"></param>
 /// <param name="replacementEffect"></param>
 /// <param name="texture"></param>
 /// <param name="textureEnabled"></param>
 public static void ReplaceModelEffect(Model model, Effect replacementEffect,
                                       String texture, String textureEnabled)
 {
     ReplaceModelEffect(model, replacementEffect, "", "", "", "", "", texture,
                        textureEnabled);
 }
Beispiel #9
0
        /// <summary>
        /// Create the different types of ships available in the game
        /// </summary>
        private void CreateShips()
        {
            AvailableShips = new List<Ship>();

            Ship sailBoat = new Ship();
            sailBoat.Ammo = 0;
            sailBoat.Armour = 0;
            sailBoat.Boat_Name = "Fighter";
            sailBoat.Health = 100;
            sailBoat.Speed = 0;
            sailBoat.Position = Vector3.Zero;

            ModelLoader loader = new ModelLoader();
            sailBoat.Player_Ship_Model = (Model)loader.Load("Models//", "fighter");
            missileModel = (Model)loader.Load("Models//", "missile");

            AvailableShips.Add(sailBoat);
        }
Beispiel #10
0
        private void CreateObject()
        {
            // Loads a textured model of a ship
            ModelLoader loader    = new ModelLoader();
            Model       shipModel = (Model)loader.Load("", "p1_wedge");

            // Create a geometry node of a loaded ship model
            GeometryNode shipNode = new GeometryNode("Ship");

            shipNode.Model = shipModel;
            ((Model)shipNode.Model).UseInternalMaterials = true;

            // Create a transform node to define the transformation for the ship
            TransformNode shipTransNode = new TransformNode();

            shipTransNode.Translation = new Vector3(0, 0, -50);
            shipTransNode.Scale       = new Vector3(0.01f, 0.01f, 0.01f); // It's huge!
            shipTransNode.Rotation    = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),
                                                                       MathHelper.ToRadians(90));

            shipTransParentNode             = new TransformNode();
            shipTransParentNode.Translation = Vector3.Zero;

            // Create a geometry node with model of a torus
            GeometryNode torusNode = new GeometryNode("Torus");

            torusNode.Model = new Torus(12f, 15.5f, 20, 20);

            TransformNode torusTransNode = new TransformNode();

            torusTransNode.Translation = new Vector3(-50, 0, 0);
            torusTransNode.Rotation    = Quaternion.CreateFromAxisAngle(Vector3.UnitX,
                                                                        MathHelper.ToRadians(90));

            // Create a material node for this torus model
            Material torusMaterial = new Material();

            torusMaterial.Diffuse       = Color.DarkGoldenrod.ToVector4();
            torusMaterial.Specular      = Color.White.ToVector4();
            torusMaterial.SpecularPower = 5;

            torusNode.Material = torusMaterial;

            // Now add the above nodes to the scene graph in appropriate order
            scene.RootNode.AddChild(shipTransParentNode);
            shipTransParentNode.AddChild(shipTransNode);
            shipTransNode.AddChild(shipNode);

            scene.RootNode.AddChild(torusTransNode);
            torusTransNode.AddChild(torusNode);

            // Now create couple of particle effects to attach to the models

            // Create a smoke particle effect and fire particle effect to simulate a
            // ring of fire around the torus model
#if WINDOWS_PHONE
            SmokePlumeParticleEffect smokeParticles = new SmokePlumeParticleEffect(20);
            FireParticleEffect       fireParticles  = new FireParticleEffect(40);
#else
            SmokePlumeParticleEffect smokeParticles = new SmokePlumeParticleEffect();
            FireParticleEffect       fireParticles  = new FireParticleEffect();
            // The order defines which particle effect to render first. Since we want
            // to show the fire particles in front of the smoke particles, we make
            // the smoke particles to be rendered first, and then fire particles
            smokeParticles.DrawOrder = 200;
            fireParticles.DrawOrder  = 300;
#endif

            // Create a particle node to hold these two particle effects
            ParticleNode fireRingEffectNode = new ParticleNode();
            fireRingEffectNode.ParticleEffects.Add(smokeParticles);
            fireRingEffectNode.ParticleEffects.Add(fireParticles);

            // Implement an update handler for each of the particle effects which will be called
            // every "Update" call
            fireRingEffectNode.UpdateHandler += new ParticleUpdateHandler(UpdateRingOfFire);

            torusNode.AddChild(fireRingEffectNode);

            // Create another set of fire and smoke particle effects to simulate the fire
            // the ship catches when the ship passes the ring of fire
#if WINDOWS_PHONE
            FireParticleEffect       shipFireEffect  = new FireParticleEffect(150);
            SmokePlumeParticleEffect shipSmokeEffect = new SmokePlumeParticleEffect(80);
            shipFireEffect.MinScale *= 1.5f;
            shipFireEffect.MaxScale *= 1.5f;
#else
            FireParticleEffect       shipFireEffect  = new FireParticleEffect();
            SmokePlumeParticleEffect shipSmokeEffect = new SmokePlumeParticleEffect();
            shipSmokeEffect.DrawOrder = 400;
            shipFireEffect.DrawOrder  = 500;
#endif

            ParticleNode shipFireNode = new ParticleNode();
            shipFireNode.ParticleEffects.Add(shipFireEffect);
            shipFireNode.ParticleEffects.Add(shipSmokeEffect);

            shipFireNode.UpdateHandler += new ParticleUpdateHandler(UpdateShipFire);

            shipNode.AddChild(shipFireNode);
        }
Beispiel #11
0
        private void CreateObjects()
        {
            // Loads a textured model of a ship
            ModelLoader loader    = new ModelLoader();
            Model       shipModel = (Model)loader.Load("", "p1_wedge");

            // Create a geometry node of a loaded ship model
            GeometryNode shipNode = new GeometryNode("Ship");

            shipNode.Model = shipModel;
            // This ship model has material definitions in the model file, so instead
            // of creating a material node for this ship model, we simply use its internal materials
            ((Model)shipNode.Model).UseInternalMaterials = true;

            // Create a transform node to define the transformation for the ship
            TransformNode shipTransNode = new TransformNode();

            shipTransNode.Translation = new Vector3(0, 5, -12);
            shipTransNode.Scale       = new Vector3(0.002f, 0.002f, 0.002f); // It's huge!
            shipTransNode.Rotation    = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0),
                                                                       MathHelper.ToRadians(90));

            shipTransParentNode             = new TransformNode();
            shipTransParentNode.Translation = Vector3.Zero;

            // Create a torus model and assign it to two geometry nodes
            Model torusModel = (Model)loader.Load("", "torus");// new Torus(2.2f, 3.5f, 30, 30);

            GeometryNode torusNode1 = new GeometryNode("Torus1");

            torusNode1.Model = torusModel;

            GeometryNode torusNode2 = new GeometryNode("Torus2");

            torusNode2.Model = torusModel;

            // Create transform node for these two torus models
            TransformNode torusTransNode1 = new TransformNode();

            torusTransNode1.Translation = new Vector3(5, 0, -12);

            TransformNode torusTransNode2 = new TransformNode();

            torusTransNode2.Translation = new Vector3(-5, 0, -12);

            torusTransParentNode             = new TransformNode();
            torusTransParentNode.Translation = Vector3.Zero;

            // Create a material node for these two torus models
            Material torusMaterial = new Material();

            torusMaterial.Diffuse       = Color.DarkGoldenrod.ToVector4();
            torusMaterial.Specular      = Color.White.ToVector4();
            torusMaterial.SpecularPower = 5;

            // Now apply this material to these two torus models
            torusNode1.Material = torusMaterial;
            torusNode2.Material = torusMaterial;

            // Now add the above nodes to the scene graph in appropriate order
            scene.RootNode.AddChild(shipTransParentNode);
            shipTransParentNode.AddChild(shipTransNode);
            shipTransNode.AddChild(shipNode);

            scene.RootNode.AddChild(torusTransParentNode);
            torusTransParentNode.AddChild(torusTransNode1);
            torusTransParentNode.AddChild(torusTransNode2);
            torusTransNode1.AddChild(torusNode1);
            torusTransNode2.AddChild(torusNode2);
        }