WPF FAQ - 3D Graphics

Find answers for the most frequently asked questions
Expand All Collapse All

Lights are similar to lights in real life. Light objects are used to illuminate a part of a scene. Lights can be used to create shadow effects. In a 3D scene at least one light has to be added to make the scene visible. WPF has four different types of lights with unique functionalities.

The following are the types of light available in WPF.

  • AmbientLight – provides uniform lighting to all the objects in a 3D scene.
  • DirectionalLight – It is like a distant light source. It does not have a location but has a direction.
  • PointLight – It illuminates like a nearby light source. It has a location and provides light effect from the location and objects in the scene are illuminated based on the location and position of the point light.
  • SpotLight – It is similar to a pointlight. It provides illumination in a cone shape. The ‘InnerConeAngle’ and ‘OuterConeAngle’ properties determine the illumination of the objects in the 3D scene.
  • Permalink

    The value of the property on which the animation is applied is overwritten to ’To’ value of the animation because the animation has higher precedence but this can be prevented using the ‘FillBehavior’ property of the animation. By default, FillBehavior has a value ’HoldEnd’ which causes the value of the property to be overwritten to the value when the animation completes. By setting the FillBehavior value to ’Stop’ will prevent overwriting the property value.

    Permalink

    Each model has a particular location in the scene. In order to move the model around the scene, rotate the model or to change it’s size, it is not practical to change the vertices of a model like the 2D objects. Instead 3D models have the ‘Transform’ property with which you can move the models, change their sizes or rotate them.

    Permalink

    The scenario is such that the animations in the page will continue to play until it is garbage collected, even when the page is navigated away to another page holding the memory and system resources for animation. There will be severe drop in performance when more animations are running in a page. To overcome this issue, ‘Unloaded’ event of the page can be used to remove the animations from the page such that the animations don’t consume memory and system resources.

    Permalink

    Animations can be applied without using the StoryBoard. BeginAnimation() method can be used to apply animations instead of StoryBoard. This method can be used when simple animations are applied to a property of a control.

    The following code snippet animates the width of the TextBlock using the ’BeginAnimation’ method.

    [C#]
    
    DoubleAnimation Dblanimation = new DoubleAnimation();
    Dblanimation.From = 25;
    Dblanimation.To = 50;
    Dblanimation.Duration = new Duration(TimeSpan.FromSeconds(3));
    tb.BeginAnimation(TextBlock.WidthProperty, Dblanimation);
    
    Permalink

    Share with

    Couldn't find the FAQs you're looking for?

    Please submit your question and answer.