Search code examples
wpf3dcube

Programmatically creating a WPF 3D cube


What is the simplest way to programmatically create a GeometryModel3D cube in wpf?


Solution

  • The simplest method? It all depends on your point of view.

    I'd say this kind of thing is pretty "simple":

    return new GeometryModel3D
    {
      Material = ...,
      Geometry = new Geometry
      {
        Points = new Point3DCollection
        {
          new Point3D(0,0,0),
          ...
        },
        TriangleIndices = new Int32Collection
        {
          ...
        },
        ...
      },
      ...
    };
    

    But others might consider a single call to XamlReader.Parse("...put your xaml here...") as more simple.

    It's a judgement call.