Clone() public method

Returns a deep copy of the effect where immutable types are shared and mutable data is duplicated.
See "Cloning an Effect" in MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/ff476138(v=vs.85).aspx
public Clone ( ) : Effect
return Effect
コード例 #1
0
        private void Initialize()
        {
            // create Camera
            _camera = new ArcBallCamera(MapData.GetWorldPosition(20, 20), 0, MathHelper.PiOver2 * 0.5f * 0.8f * 0.8f, 0, MathHelper.PiOver2, CameraDistance, 30, 100, Manager.GraphicsDevice);

            // zooming
            zooming = new Zooming("Middle", "VeryFar", 2f, "Far", 1.3f, "Middle", 1.0f, "Near", 0.7f, "VeryNear", 0.5f, "Detail", 0.2f);
            zooming.ZoomChanged += delegate(float zoom) { _camera.Distance = CameraDistance * zoom; };

            _effect = Manager.Content.Load<Effect>("Content/Effects/Series4Effects");

            Mouse.SetPosition(Manager.GraphicsDevice.Viewport.Width / 2, Manager.GraphicsDevice.Viewport.Height / 2);

            _skyDome = Manager.Content.Load<Model>("Content/Models/dome");
            _skyDome.Meshes[0].MeshParts[0].Effect = _effect.Clone();

            _cloudMap = Manager.Content.Load<Texture2D>("Content/Models/cloudMap");

            _mapRenderer.Initialize();
            _mapRenderer.LoadContent();

            // init complete view
            defaultViewport = new Viewport();
            defaultViewport.X = 0;
            defaultViewport.Y = 0;
            defaultViewport.Width = Manager.GraphicsDevice.Viewport.Width;
            defaultViewport.Height = Manager.GraphicsDevice.Viewport.Height;

            // init control view
            controlViewport = new Viewport();
            controlViewport.X = 4;
            controlViewport.Y = 27;
            controlViewport.Width = Manager.GraphicsDevice.Viewport.Width - 8;
            controlViewport.Height = Manager.GraphicsDevice.Viewport.Height - 32;
        }
コード例 #2
0
        public void SetModelEffect(Effect effect, bool CopyEffect)
        {
            foreach (ModelMesh mesh in Model.Meshes)
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    Effect toSet = effect;

                    // Copy the effect if necessary
                    if (CopyEffect)
                        toSet = effect.Clone();

                    MeshTag tag = ((MeshTag)part.Tag);

                    // If this ModelMeshPart has a texture, set it to the effect
                    if (tag.Texture != null)
                    {
                        setEffectParameter(toSet, "BasicTexture", tag.Texture);
                        setEffectParameter(toSet, "TextureEnabled", true);
                    }
                    else
                    {
                        setEffectParameter(toSet, "TextureEnabled", false);
                    }

                    // Set our remaining parameters to the effect
                    setEffectParameter(toSet, "DiffuseColor", tag.Color);
                    setEffectParameter(toSet, "SpecularPower", tag.SpecularPower);

                    part.Effect = toSet;
                }
        }
コード例 #3
0
ファイル: Materials.cs プロジェクト: sq/Fracture
        public Material(
            Effect effect, string techniqueName = null,
            Action<DeviceManager>[] beginHandlers = null,
            Action<DeviceManager>[] endHandlers = null
            )
            : this()
        {
            if (techniqueName != null) {
                Effect = effect.Clone();
                var technique = Effect.Techniques[techniqueName];

                if (technique != null)
                    Effect.CurrentTechnique = technique;
                else {
                    throw new ArgumentException("techniqueName");
                }
            } else {
                Effect = effect;
            }

            OwningThread = Thread.CurrentThread;

            // FIXME: This should probably never be null.
            if (Effect != null) {
                Parameters = new DefaultMaterialSetEffectParameters(Effect);
                _COMEffect = Effect.GetID3DXEffect();
            } else {
                _COMEffect = null;
            }

            BeginHandlers = beginHandlers;
            EndHandlers   = endHandlers;
        }
コード例 #4
0
 public override void LoadContent()
 {
     skyDome = game.Content.Load<Model>("Models\\dome");
     effect = game.Content.Load<Effect>("Series4Effects");
     skyDome.Meshes[0].MeshParts[0].Effect = effect.Clone();
     cloudMap = game.Content.Load<Texture2D>("Models\\cloudMap");
     base.LoadContent();
 }
コード例 #5
0
ファイル: SkyDome.cs プロジェクト: MenosGrandes/mrowisko-pbl
        public SkyDome(GraphicsDevice device, ContentManager Content)
        {
            this.device = device;
            this.effect = Content.Load<Effect>("Effects/TexturedEffect");
            skyDome = Content.Load<Model>("Models/SkyDome/dome");

            cloudMap = Content.Load<Texture2D>("Models/SkyDome/cloudMap");
               skyDome.Meshes[0].MeshParts[0].Effect = effect.Clone();
        }
コード例 #6
0
ファイル: Enemy.cs プロジェクト: silenthunter/MPG4803
 public Enemy(Game game, Effect effect)
     : base(game)
 {
     mechEffect = effect;
     mech = game.Content.Load<Model>("mech8");
     texCube = game.Content.Load<TextureCube>("CubeMap");
     effect.Parameters["cubetex"].SetValue(texCube);
     foreach(ModelMesh mesh in mech.Meshes)
         foreach (ModelMeshPart meshPart in mesh.MeshParts)
             meshPart.Effect = mechEffect.Clone();
 }
コード例 #7
0
        public override void load(ContentManager content, Effect effect)
        {
            mModel = content.Load<Model>("dome");
            cloudMap = content.Load<Texture2D>("cloud_texture");

            foreach (ModelMesh mesh in mModel.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    meshPart.Effect = effect.Clone();
                }
            }
        }
コード例 #8
0
        public Terrain(float CellSize, float Height, float TextureTiling, int size, Vector3 Position,
                        Effect effect, Texture2D BaseTexture, Type type = Type.Flat, int depth = 0,
                        Texture2D RedTexture = null, Texture2D GreenTexture = null, Texture2D WeightTexture = null)
        {
            this.type = type;
            this.Size = size;
            this.depth = depth;
            this.CellSize = CellSize;
            this.Height = Height;
            this.Position = Position;
            this.baseTexture = BaseTexture;
            this.redTexture = RedTexture;
            this.greenTexture = GreenTexture;
            this.weightTexture = WeightTexture;
            this.TextureTiling = TextureTiling;
            this.PersistantRot = Matrix.Identity;
            this.waterSphere = new BoundingSphere(Vector3.Zero, PlanetRadius + Planet.HeightMag);
            this.MyRawHeightBorders = new List<float>[4];
            this.OtherRawHeightBorders = new List<float>[4];
            this.MyHeightBorders = new List<float>[4];
            this.nVertices = Size * Size;
            this.vertices = new VertexPositionNormalTexture[nVertices];

            //2 tris per cell, 3 indices per tris
            nIndices = (Size - 1) * (Size - 1) * 6;

            this.effect = effect.Clone();
            this.cachedEffect = effect.Clone();

            this.effect.Parameters["DiffuseColor"].SetValue(new Vector3(1));
            this.cachedEffect.Parameters["DiffuseColor"].SetValue(new Vector3(1));

            this.effect.Parameters["AmbientColor"].SetValue(new Vector3(0.75f));
            this.cachedEffect.Parameters["AmbientColor"].SetValue(new Vector3(0.75f));

            this.effect.Parameters["BasicTexture"].SetValue(baseTexture);
            this.cachedEffect.Parameters["BasicTexture"].SetValue(baseTexture);
        }
コード例 #9
0
ファイル: BaseMaterial.cs プロジェクト: konlil/pipe
        public BaseMaterial(PipeEngine engine, Effect eff)
        {
            this.engine = engine;
            if(eff == null)
            {
                throw new ArgumentException("effect");
            }

            this.effect = eff.Clone(engine.GraphicsDevice);
            this.effect.CurrentTechnique = this.effect.Techniques[0];

            g_world = this.effect.Parameters["gWorld"];
            g_view = this.effect.Parameters["gView"];
        }
コード例 #10
0
        public override void load(ContentManager content, Effect effect)
        {
            mModel = content.Load<Model>("xwing");

            mNoiseArray = loadPerlinNoiseFromFile();

            foreach (ModelMesh mesh in mModel.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    meshPart.Effect = effect.Clone();
                }
            }
        }
コード例 #11
0
        public static Model LoadModel(string assetName, out Texture2D[] textures, ContentManager content, Effect effect)
        {
            Model newModel = content.Load<Model>(assetName);
            textures = new Texture2D[newModel.Meshes.Count];
            int i = 0;
            foreach (ModelMesh mesh in newModel.Meshes)
                foreach (BasicEffect currentEffect in mesh.Effects)
                    textures[i++] = currentEffect.Texture;

            foreach (ModelMesh mesh in newModel.Meshes)
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    meshPart.Effect = effect.Clone();

            return newModel;
        }
コード例 #12
0
ファイル: Material.cs プロジェクト: JamesPersaud/GOOS
        public Material(ContentManager contentManager, GraphicsDevice graphicsDevice,
            Effect baseEffect)
        {
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("graphicsDevice");
            }
            device = graphicsDevice;

            if (contentManager == null)
            {
                throw new ArgumentNullException("contentManager");
            }
            content = contentManager;

            if (baseEffect == null)
            {
                throw new ArgumentNullException("baseEffect");
            }

            //////////////////////////////////////////////////////////////
            // Example 2.1                                              //
            //                                                          //
            // There are many ways to store and organize the constants  //
            // used for a material.  For this example, an entiire       //
            // Effect instance is cloned from the basic material shader //
            // and the material parameters are bound to that instance.  //
            // The result is a vastly simplified way of rendering a     //
            // material by simply setting the appropriate shader and    //
            // starting to draw.  This is also a very efficient         //
            // technique on the XBox 360, but typically less so on a    //
            // PC.                                                      //
            //////////////////////////////////////////////////////////////
            effectInstance = baseEffect.Clone(device);
            effectInstance.CurrentTechnique =
                effectInstance.Techniques[0];
            device = graphicsDevice;

            // Set the defaults for the effect
            effectInstance.Parameters["specularPower"].SetValue(specularPowerValue);
            effectInstance.Parameters["specularIntensity"].SetValue(
                specularIntensityValue);
            effectInstance.Parameters["materialColor"].SetValue(colorValue.ToVector4());
            effectInstance.Parameters["textureUReps"].SetValue(textureURepsValue);
            effectInstance.Parameters["textureVReps"].SetValue(textureVRepsValue);
        }
コード例 #13
0
        public SkyRenderer(ContentManager contentManager, Camera camera)
            : base(contentManager)
        {
            this.camera = camera;
             skyDome = Content.Load<Model>("sky_dome");
             effect = Content.Load<Effect>("sky");
             skyDome.Meshes[0].MeshParts[0].Effect = effect.Clone(Device);
             projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Device.Viewport.AspectRatio,
            Config.Instance.Rendering.NearClippingDistance, Config.Instance.Rendering.FarClippingDistance);

             var pp = Device.PresentationParameters;
             cloudsRenderTarget = new RenderTarget2D(Device, pp.BackBufferWidth, pp.BackBufferHeight, 1, Device.DisplayMode.Format);
             cloudStaticMap = CreateStaticMap(32);

             fullScreenVertexDeclaration = new VertexDeclaration(Device, VertexPositionTexture.VertexElements);
             fullScreenVertices = SetUpFullscreenVertices();
        }
コード例 #14
0
ファイル: Water.cs プロジェクト: patrykos91/Laikos
        public Water(GraphicsDevice device, ContentManager content, Effect GBuffer)
        {
            this.GBuffer = GBuffer;
            this.device = device;
            int backbufferWidth = device.PresentationParameters.BackBufferWidth;
            int backbufferHeight = device.PresentationParameters.BackBufferHeight;

            refractionRenderTarget = new RenderTarget2D(device, backbufferWidth, backbufferHeight, false, device.DisplayMode.Format, DepthFormat.Depth24Stencil8, 1, RenderTargetUsage.DiscardContents);
            reflectionRenderTarget = new RenderTarget2D(device, backbufferWidth, backbufferHeight, false, device.DisplayMode.Format, DepthFormat.Depth24Stencil8, 1, RenderTargetUsage.DiscardContents);

            skyDome = content.Load<Model>("Models/SkyDome/dome");
            skyDome.Meshes[0].MeshParts[0].Effect = GBuffer.Clone();
            cloudMap = content.Load<Texture2D>("Models/SkyDome/cloudMap");
            waterEffect = content.Load<Effect>("Effects/Water");
            waterBump = content.Load<Texture2D>("waterbump");
            SetUpWaterVertices();
            waterVertexDeclaration = VertexPositionTexture.VertexDeclaration;
        }
コード例 #15
0
        public SpatialHash4(GraphicsDevice device,
            Effect effect,
            int width, int height, int particleNumber,
            Vector2 spatialHashTextureSize,
            Vector3 buckets,
            Vector3 bucketSpacePosition, Vector3 bucketSpaceDimensions)
        {
            state1.DepthBufferEnable = true;
            state1.DepthBufferWriteEnable = true;
            state1.DepthBufferFunction = CompareFunction.Greater;

            state2.DepthBufferEnable = true;
            state2.DepthBufferFunction = CompareFunction.Less;
            state2.StencilEnable = true;
            state2.StencilFunction = CompareFunction.Greater;
            state2.ReferenceStencil = 1;
            state2.StencilPass = StencilOperation.Increment;

            this.effect = effect;
            this.effect2 = effect.Clone();
            Device = device;

            this.pwidth = width;
            this.pheight = height;

            Buckets = buckets;
            BucketSpacePosition = bucketSpacePosition;
            BucketSpaceDimensions = bucketSpaceDimensions;

            SpatialHashTextureSize = spatialHashTextureSize;

            createParticles();

            ParticleNumber = particleNumber;

            loadContent();
        }
コード例 #16
0
ファイル: SkyBox.cs プロジェクト: zpconn/TerrainExplorer
        /// <summary>
        /// This loads the model and texture data needed to render the skybox.
        /// </summary>
        public SkyBox(Game game, ContentManager content, Camera camera)
        {
            this.game = game;
            this.camera = camera;

            GraphicsDevice graphicsDevice = game.GraphicsDevice;

            model = content.Load<Model>("Content\\Models\\Skybox");
            textures = new Texture2D[model.Meshes.Count];

            // Initialize the effect.

            effect = content.Load<Effect>("Content\\Shaders\\Skybox");

            // Save the textures in the mesh to the textures array.

            int textureCount = 0;

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect meshEffect in mesh.Effects)
                {
                    textures[textureCount] = meshEffect.Texture;
                    ++textureCount;
                }
            }

            // We need to pass our effect down to the child mesh parts.

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    part.Effect = effect.Clone(graphicsDevice);
                }
            }
        }
コード例 #17
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>
        static void ChangeEffectUsedByModel(Model model, Effect replacementEffect)
        {
            // Table mapping the original effects to our replacement versions.
            Dictionary<Effect, Effect> effectMapping = new Dictionary<Effect, Effect>();

            foreach (ModelMesh mesh in model.Meshes)
            {
                if (mesh.Effects[0].GetType() == typeof(BasicEffect))
                {
                    // 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();

                            // Copy across the texture from the original effect.
                            newEffect.Parameters["Texture"].SetValue(oldEffect.Texture);
                            newEffect.Parameters["TextureEnabled"].SetValue(oldEffect.TextureEnabled);

                            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];
                    }
                }
            }
        }
コード例 #18
0
        public virtual void SetModelEffect(Effect effect, bool copyEffect)
        {
            CacheEffect();

            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    Effect toBeSet = effect;

                    if (copyEffect)
                    {
                        toBeSet = effect.Clone();
                    }

                    var tag = (part.Tag as MeshTag);

                    if (tag.Texture!=null)
                    {
                        SetEffectParameter(toBeSet, "Texture", tag.Texture);
                        SetEffectParameter(toBeSet, "TextureEnabled", true);
                    }
                    else
                    {
                        SetEffectParameter(toBeSet, "TextureEnabled", false);
                    }

                    SetEffectParameter(toBeSet, "DiffuseColor", tag.Color);
                    SetEffectParameter(toBeSet, "SpecularPower", tag.SpecularPower);

                    part.Effect = toBeSet;
                }
            }
        }
コード例 #19
0
ファイル: Planet.cs プロジェクト: pentiumx/HLSLTest
        public override void SetModelEffect(Effect effect, bool CopyEffect)
        {
            foreach (ModelMesh mesh in Model.Meshes)
                foreach (ModelMeshPart part in mesh.MeshParts) {
                    Effect toSet = effect;
                    // Copy the effect if necessary
                    if (CopyEffect)
                        toSet = effect.Clone();
                    MeshTag tag = ((MeshTag)part.Tag);

                    if (DrawingDepthNormalPass) {
                        SetEffectParameter(toSet, "BumpMap", normalmap);// hennkou
                    }
                    SetEffectParameter(toSet, "BasicTexture", Mercator);// hennkou
                    SetEffectParameter(toSet, "TextureEnabled", true);

                    // Set our remaining parameters to the effect
                    SetEffectParameter(toSet, "DiffuseColor", tag.Color);
                    SetEffectParameter(toSet, "SpecularPower", tag.SpecularPower);
                    part.Effect = toSet;
                }
        }
コード例 #20
0
        protected override void LoadContent()
        {
            device = graphics.GraphicsDevice;
            screenWidth = device.Viewport.Width;
            screenHeight = device.Viewport.Height;
            camFeed = new Texture2D(device, 1, 1);
            motionDetector = new MotionDetector(screenHeight, screenWidth);
            camAvailable = motionDetector.isCameraAvailable();
            if (camAvailable){
            currentCameraName= motionDetector.ConnectToFeed();
            }

            optConPos = new Vector2((float)200 / 800 * screenWidth, (float)190 / 640 * screenHeight);
            optCamPos = new Vector2((float)200 / 800 * screenWidth, (float)220 / 640 * screenHeight);
            optMinColRPos = new Vector2((float)150 / 800 * screenWidth, (float)360 / 640 * screenHeight);
            optMinColGPos = new Vector2((float)150 / 800 * screenWidth, (float)390 / 640 * screenHeight);
            optMinColBPos = new Vector2((float)150 / 800 * screenWidth, (float)420 / 640 * screenHeight);
            optMaxColRPos = new Vector2((float)350 / 800 * screenWidth, (float)360 / 640 * screenHeight);
            optMaxColGPos = new Vector2((float)350 / 800 * screenWidth, (float)390 / 640 * screenHeight);
            optMaxColBPos = new Vector2((float)350 / 800 * screenWidth, (float)420 / 640 * screenHeight);
            optCamPrvPos = new Vector2((float)530 / 800 * screenWidth, (float)200 / 640 * screenHeight);

            sceneryTexture = Content.Load<Texture2D>("Textures/texturemap");
            grassTexture = Content.Load<Texture2D>("Textures/grass");
            sandTexture = Content.Load<Texture2D>("Textures/sand");
            rockTexture = Content.Load<Texture2D>("Textures/rock");
            mainMenuBG = Content.Load<Texture2D>("Textures/menuBack");
            aboutMenuBG = Content.Load<Texture2D>("Textures/aboutMenuBack");
            optionsMenuBG = Content.Load<Texture2D>("Textures/optionsMenuBack");
            helpBG = Content.Load<Texture2D>("Textures/helpMenuBack");
            cloudMap = Content.Load<Texture2D>("Textures/cloudMap");
            waterBumpMap = Content.Load<Texture2D>("Textures/waterbump");
            optSelectedBack = Content.Load<Texture2D>("Textures/optionsSelected");
            //maxColTex = new Texture2D(GraphicsDevice, 1, 1);
            ColTex = new Texture2D(GraphicsDevice, 1, 1);
            //maxColTex.SetData(new Color[] { new Color(new Vector3(motionDetector.getRMax(), motionDetector.getGMax(), motionDetector.getBMax())) });
            ColTex.SetData(new Color[] { new Color(new Vector3(motionDetector.getRMax(), motionDetector.getGMax(), motionDetector.getBMax())) });

            SetUpBuildingVertices();
            basicEffect = new BasicEffect(device, null);
            customEffect = Content.Load<Effect>("effects");
            tEffect = Content.Load<Effect>("tEffects");
            shipModel = Content.Load<Model>("Models/jet2");
            //car = Content.Load<Model>("Models/car");
            //textModel=Content.Load<Model>("Models/moratext");
            itemModel = BasicLoadModel("Models/bonus1");
            treeModel = BasicLoadModel("Models/tree2");
            //skyboxModel = LoadModel("Models/skybox2", out skyboxTextures);
            skyDome = Content.Load<Model>("Models/dome");
            skyDome.Meshes[0].MeshParts[0].Effect = tEffect.Clone(device);
            //boundingSphereRenderer = new BoundingSphereRenderer(this);
            //boundingSphereRenderer.OnCreateDevice();

            //camPreviewBorder = new Texture2D(device, 1, 1, 0, TextureUsage.Tiled, SurfaceFormat.Color);
            //Int32[] pixel = { 0xFFFFFF }; // White. 0xFF is Red, 0xFF0000 is Blue
            //camPreviewBorder.SetData(pixel,0,1,SetDataOptions.None);//, 0, camPreviewBorder.Width * camPreviewBorder.Height);

            PresentationParameters pp = device.PresentationParameters;
            refractionRenderTarget = new RenderTarget2D(device, pp.BackBufferWidth, pp.BackBufferHeight, 1, device.DisplayMode.Format);
            reflectionRenderTarget = new RenderTarget2D(device, pp.BackBufferWidth, pp.BackBufferHeight, 1, device.DisplayMode.Format);
            cloudsRenderTarget = new RenderTarget2D(device, pp.BackBufferWidth, pp.BackBufferHeight, 1, device.DisplayMode.Format);
            cloudStaticMap = CreateStaticMap(16);

            timeS = Content.Load<SoundEffect>("Sounds/timeS");
            timeE = Content.Load<SoundEffect>("Sounds/timeE");
            select = Content.Load<SoundEffect>("Sounds/select");
            explode = Content.Load<SoundEffect>("Sounds/explode");
            item = Content.Load<SoundEffect>("Sounds/item");
            shoot = Content.Load<SoundEffect>("Sounds/shoot");
            go = Content.Load<SoundEffect>("Sounds/go");
            warning = Content.Load<SoundEffect>("Sounds/warning");
            warningInstance = warning.CreateInstance();
            goInstance = go.CreateInstance();
            timeSInstance = timeS.CreateInstance();

            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            gameFont = Content.Load<SpriteFont>("gameFont");
            menuFont = Content.Load<SpriteFont>("menuFont");
            optionsMenuFont = Content.Load<SpriteFont>("optionsFont");
            LoadTerrainVertices();
            //MediaPlayer.Volume = 0.6f;
            setupMenu();
        }
コード例 #21
0
ファイル: ModelInstance.cs プロジェクト: BaronVonTeapot/Basic
        /// <summary>
        /// Applies an effect to a mesh.
        /// </summary>
        /// <param name="inMeshName">Name of the mesh to apply to.</param>
        /// <param name="inEffect">Effect to apply.</param>
        /// <param name="inCopyEffect">If true, cache the effect.</param>
        protected virtual void SetMeshEffect(string inMeshName, Effect inEffect, bool inCopyEffect)
        {
            foreach (ModelMesh modelMesh in this.Model.Meshes)
            {
                if (modelMesh.Name != inMeshName) { continue; }

                foreach (ModelMeshPart meshPart in modelMesh.MeshParts)
                {
                    Effect effectToSet = inEffect;

                    if (inCopyEffect) { effectToSet = inEffect.Clone(); }
                    MeshTag tag = (MeshTag)meshPart.Tag;

                    if (tag.Texture != null)
                    {
                        SetEffectParameter(effectToSet, "t_Basic", tag.Texture);
                        SetEffectParameter(effectToSet, "TextureEnabled", true);
                    }
                    else
                    {
                        SetEffectParameter(effectToSet, "TextureEnabled", false);
                    }

                    SetEffectParameter(effectToSet, "DiffuseColor", tag.Color);
                    SetEffectParameter(effectToSet, "SpecularColor", tag.SpecularPower);

                    meshPart.Effect = effectToSet;
                }
            }
        }
コード例 #22
0
ファイル: Actor.cs プロジェクト: pgonzbecer/apis-bundle
 // Adds the given effect onto the actor
 public virtual void setEffect(Effect pmEffect)
 {
     foreach(ModelMesh mesh in model.Meshes)
     {
         foreach(ModelMeshPart part in mesh.MeshParts)
             part.Effect=	pmEffect.Clone();
     }
 }
コード例 #23
0
ファイル: Game1.cs プロジェクト: SobczakMalgorzata/GK3D
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            //spriteBatch = new SpriteBatch(GraphicsDevice);

            //Models
            myBenchModel = Content.Load<Model>("bench");
            myLaternModel = Content.Load<Model>("latern1");
            //myTreeModel = Content.Load<Model>("Alan Tree");

            //Textures
            //treeTexture = Content.Load<Texture2D>("");
            grassTexture = Content.Load<Texture2D>("GrassTry");
            benchTexture = Content.Load<Texture2D>("GrassTry");
            laternTexture = Content.Load<Texture2D>("GrassTry");

            //Effect loading
            if (basic)
            {
            }
            else
            {
                myEffect = Content.Load<Effect>("shaderPointLight");
                foreach (ModelMesh mesh in myBenchModel.Meshes)
                    foreach (ModelMeshPart meshPart in mesh.MeshParts)
                        meshPart.Effect = myEffect.Clone();
                foreach (ModelMesh mesh in myLaternModel.Meshes)
                    foreach (ModelMeshPart meshPart in mesh.MeshParts)
                        meshPart.Effect = myEffect.Clone();
                /*foreach (ModelMesh mesh in myTreeModel.Meshes)
                    foreach (ModelMeshPart meshPart in mesh.MeshParts)
                        meshPart.Effect = myEffect.Clone();*/
            }
            aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
            // TODO: use this.Content to load your game content here
        }
コード例 #24
0
        private static void ChangeEffectUsedByModel(Model model, Effect replacementEffect)
        {
            Dictionary<Effect, Effect> effectMapping = new Dictionary<Effect, Effect>();

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect oldEffect in mesh.Effects)
                {
                    if (!effectMapping.ContainsKey(oldEffect))
                    {
                        Effect newEffect = replacementEffect.Clone();
                        newEffect.Parameters["Texture"].SetValue(oldEffect.Texture);
                        newEffect.Parameters["TextureEnabled"].SetValue(oldEffect.TextureEnabled);
                        effectMapping.Add(oldEffect, newEffect);
                    }
                }
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    meshPart.Effect = effectMapping[meshPart.Effect];
                }
            }
        }
コード例 #25
0
ファイル: ObjectMesh.cs プロジェクト: Andrusza/PiratesArr
 private Model LoadModel(string assetName, Effect technique)
 {
     Model newModel = ContentLoader.Load<Model>(ContentType.FBX, assetName);
     foreach (ModelMesh mesh in newModel.Meshes)
     {
         foreach (ModelMeshPart meshPart in mesh.MeshParts)
         {
             meshPart.Effect = technique.Clone();
         }
     }
     return newModel;
 }
コード例 #26
0
        public void SetModelEffect(Effect effect, bool CopyEffect)
        {
            foreach (ModelMesh mesh in Model.Meshes)
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    Effect toSet = effect;

                    //copy effect if necessary
                    if (CopyEffect)
                        toSet = effect.Clone();

                    MeshTag tag = ((MeshTag)part.Tag);

                    //set texture
                    if (tag.Texture != null)
                    {
                        setEffectParameter(toSet, "BasicTexture", tag.Texture);
                        setEffectParameter(toSet, "TextureEnabled", true);
                    }
                    else
                        setEffectParameter(toSet, "TextureEnabled", false);

                    //set other params
                    setEffectParameter(toSet, "DiffuseColor", tag.Color);
                    setEffectParameter(toSet, "SpecularPower", tag.SpecularPower);

                    part.Effect = toSet;
                }
        }
コード例 #27
0
ファイル: Map.cs プロジェクト: Koura/eternia
        private void LoadMap(String map)
        {
            effect = game.Content.Load<Effect>("EterniaEffects");
            skyDome = game.Content.Load<Model>("models/dome"); skyDome.Meshes[0].MeshParts[0].Effect = effect.Clone();

            LoadVertices(map);
            LoadTextures();
        }
コード例 #28
0
ファイル: ModelManager.cs プロジェクト: CS583/3D-Game
        protected override void LoadContent()
        {
            //Load explosion texture and effects
            explosionTexture = Game.Content.Load<Texture2D>(@"Textures\Particle");
            explosionColorsTexture = Game.Content.Load<Texture2D>(@"Textures\ParticleColors");
            explosionEffect = Game.Content.Load<Effect>(@"effects\particle");

            //set effect parameters that don't change per particle
            explosionEffect.CurrentTechnique = explosionEffect.Techniques["Technique1"];
            explosionEffect.Parameters["theTexture"].SetValue(explosionTexture);

            //Load the stars
            starTexture = Game.Content.Load<Texture2D>(@"textures\stars");
            starEffect = explosionEffect.Clone();
            starEffect.CurrentTechnique = starEffect.Techniques["Technique1"];
            starEffect.Parameters["theTexture"].SetValue(explosionTexture);

            //Initialize particle star sheet
            stars = new ParticleStarSheet(GraphicsDevice,
                new Vector3(2000,2000,-1900),
                1500, starTexture,
                particleSettings,
                starEffect);

            base.LoadContent();
        }
コード例 #29
0
        public GameModel SetEffect(Effect effect, 
            bool clone = true, 
            bool allowSpecular = true)
        {
            foreach (var mesh in Model.Meshes)
                foreach (var part in mesh.MeshParts)
                {
                    var to = (clone ? effect.Clone() : effect);
                    var tag = (MeshTag)part.Tag;

                    if (tag.Texture != null)
                    {
                        if (to.Parameters["BasicTexture"] != null)
                            to.Parameters["BasicTexture"].SetValue(tag.Texture);
                        if (to.Parameters["TextureEnabled"] != null)
                            to.Parameters["TextureEnabled"].SetValue(true);
                    }
                    else
                    {
                        if (to.Parameters["TextureEnabled"] != null)
                            to.Parameters["TextureEnabled"].SetValue(false);
                    }

                    if (to.Parameters["DiffuseColor"] != null)
                        to.Parameters["DiffuseColor"].SetValue(tag.Color);

                    if (to.Parameters["SpecularPower"] != null)
                        to.Parameters["SpecularPower"].SetValue(tag.SpecularPower);

                    if (to.Parameters["SpecularEnabled"] != null)
                        to.Parameters["SpecularEnabled"].SetValue(allowSpecular);

                    part.Effect = to;
                }
            return this;
        }
コード例 #30
0
ファイル: TankOnAHeightmap.cs プロジェクト: ravduke/Tank-Wars
        /// <summary>
        /// Load your graphics content.
        /// </summary>
        protected override void LoadContent()
        {
            ///
            /// Physics Load Content
            ///

            Cannon.fire = Content.Load<SoundEffect>("Sound/fire");
            EnemyCannon.fire = Content.Load<SoundEffect>("Sound/fire");

            CannonBall.blast = Content.Load<SoundEffect>("Sound/blast");
            EnemyCannonBall.blast = Content.Load<SoundEffect>("Sound/blast");

            Physic.LoadContent();

            // Terrain material
            TerrainMaterial material = new TerrainMaterial();
            material.DiffuseTexture1 = LoadTextureMaterial("Terrain1", new Vector2(50, 50));
            material.DiffuseTexture2 = LoadTextureMaterial("Terrain2", new Vector2(50, 50));
            material.DiffuseTexture3 = LoadTextureMaterial("Terrain3", new Vector2(30, 30));
            material.DiffuseTexture4 = LoadTextureMaterial("Terrain4", Vector2.One);
            material.AlphaMapTexture = LoadTextureMaterial("AlphaMap", Vector2.One);
            material.NormalMapTexture = LoadTextureMaterial("Rockbump", new Vector2(196, 196));
            material.LightMaterial = new LightMaterial(new Vector3(0.8f), new Vector3(0.3f), 32);
            terrain.Material = material;


            //Load Sky Content
            effect = Content.Load<Effect>(GameAssetsPath.EFFECTS_PATH + "Series4Effects");
            skyDome = Content.Load<Model>("dome");
            skyDome.Meshes[0].MeshParts[0].Effect = effect.Clone();

            cloudMap = Content.Load<Texture2D>("cloudMap");

            skybox = new Skybox(GameAssetsPath.TEXTURES_PATH + "t", Content);
            /*
            //skysphere
           // Load the effect, the texture it uses, and 
           // the model used for drawing it
           SkySphereEffect = Content.Load<Effect>(GameAssetsPath.EFFECTS_PATH +"SkySphere");
           TextureCube SkyboxTexture =
               Content.Load<TextureCube>(GameAssetsPath.TEXTURES_PATH + "t");
           SkySphere = Content.Load<Model>(GameAssetsPath.MODELS_PATH + "SphereHighPoly");

           // Set the parameters of the effect
           SkySphereEffect.Parameters["ViewMatrix"].SetValue(
               camera.View);
           SkySphereEffect.Parameters["ProjectionMatrix"].SetValue(
               camera.Projection);
           SkySphereEffect.Parameters["SkyboxTexture"].SetValue(
               SkyboxTexture);
           // Set the Skysphere Effect to each part of the Skysphere model
           foreach (ModelMesh mesh in SkySphere.Meshes)
           {
               foreach (ModelMeshPart part in mesh.MeshParts)
               {
                   part.Effect = SkySphereEffect;
               }
           }*/

            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(music);
            MediaPlayer.Volume = 0.5f;
        }