Lights, Camera, Model!

These are three main components of a WPF 3D scene. In fact, it should be more like “Lights, Camera, GeometryModel3D”, but “GeometryModel3D” looks ugly and messes up the rhythm of the title.

All 3D objects in WPF live inside a Viewport3D object. This is a two-dimensional window (typically, a rectangle, but it can be made to take any shape) that shows 3D stuff inside itself.

Each viewport has a camera. This defines a point (and angle, etc.) from which we look at things. There is only one camera per viewport – you cannot look at things from different points of view simultaneously. Besides the camera, viewport may contain one or more ModelVisual3D objects. Each ModelVisual3D has a Content property that is of type Model3D.

Model3D is a base class in a typical composite pattern. It may be a light, a “body” (GeometryModel3D), or a group of lights and bodies (Model3dGroup).

wpf_3dmodel

Now, each body (GeometryModel3D) further needs a mesh (MeshGeometry3D), i.e. a list of vertices, and material that defines what the body is made of and what color it has.

These are the basic elements of a 3D world setup, and unfortunately they are all required. Without a camera you cannot see, without bodies there is nothing to see, and without light everything is pitch black. Without mesh or material, bodies are invisible. But if you set it all up, a new brave 3D world suddenly jumps into action.

Posted in

Leave a Reply

Your email address will not be published. Required fields are marked *