Jump to content
  • Advertisement
Sign in to follow this  
EvilWeebl

ModelMesh effect.DiffuseColor

This topic is 2480 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, a simple question I'm sure but...

I'm rendering my object as standard but when I select an object I would like to change its diffuse colour to red or something to show that its selected. The thing is that even though I use an if statement to set the diffuse to red only if its selected it always remains red even after I stop selecting it, also its not like I can do an else statement to say to render the model the colour it was loaded because it doesn't remember what colour as it has been overridden as red.

For example this is what I currently have...


// Draw scene.
foreach (SceneObject sceneObject in Scene.ObjectList)
{
boneTransforms = new Matrix[sceneObject.Model.Bones.Count];
sceneObject.Model.CopyAbsoluteBoneTransformsTo(boneTransforms);

foreach (ModelMesh mesh in sceneObject.Model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
if (Scene.SelectedObjects.Contains(sceneObject))
{
effect.DiffuseColor = new Vector3(1, 0, 0);
}
else
{
//???
}
effect.World = boneTransforms[mesh.ParentBone.Index] * sceneObject.World;
effect.View = GetViewMatrix();
effect.Projection = GetProjectionMatrix();
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
effect.SpecularPower = 16;
}

mesh.Draw();
}
}

Any help much appreciated

Share this post


Link to post
Share on other sites
Advertisement
I'm a bit confused to as why you're saying you can't revert the color back...you can certainly save it in some sort of structure (e.g. use ModelMesh's tag property, or write a wrapper that encapsulates your model and contains the necessary information). If you're not setting the old color back (or any other color) when the mesh is no longer selected, of course it's going to remain the color you set when it is selected. Think of it as a state machine, the system will keep using the last state you set (in this case, a color) until you set a different state.

Another way of showing a selection is not to change the diffuse color, but to change the ambient light color (I assume your models are lit?) or the emissive color property. That way you don't worry about having to save the diffuse color, or otherwise changing the appearance of the selection so dramatically. Instead, have a standard ambient color (like (.5, .5, .5)) for all non-selected objects, then for selected objects set it to (1, 0, 0). That will give the selected objects a reddish hue that should be enough to indicate they're selected, while preserving the object's diffuse color/texture information.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!