C++C++11C++14C++17Language FeatureLearn C++

Learn To Quickly Create Specific 3D Objects In Modern C++ Applications For Windows

3D Objects are like wrapped papers in 3D form. They consists points and each of 4 points that shape a polygon. Our 3D objects are stored with these points, data that which points are shaping polygons. In modern application development most of these objects are generated by a 3D Designer Software with their own 3d Object standards and these are displayed or animated in mechanics by a 3D Engine.

In C++ Builder you can directly create your own 3D objects, you can animate them on runtime. Viewport3D (TViewportd3D) component in C++ Builder FireMonkey projects is good to display many basic 3D Objects like Plane, Cube, Sphere, Cone, Plane, Ellipse3D etc. You can also easily load your 3D objects into Viewport3D by using Model3D (TModel3D).

To create a 3D object to be used in Viewport3D we need to use TMesh classes.  TMesh is a custom 3D shape that can be customized by drawing 3D shapes.  It is a class publishes a set of properties from its ancestor, TCustomMesh, in order to let you design new 3D shapes at design time from within the IDE, through the Object Inspector. Use the Data property to specify the points, normals and textures for each point, and the order in which the resulting triangles are drawn. The designed shape is filled with the material specified through MaterialSource property. If no material is specified, then the shape is filled with red color.

1.Create a new Multi-Device C++ Builder Firemonkey project, Save all unit and project files into a folder.

2. Drag a Viewport3D from Tool Palette on to Form. We will use this to display our 3D Mesh object. Add Light, Dummy Object, Color Material.

3. Add a Button to generate mesh when button is pressed.

3. Go to Unit1.h, lets define our TMesh pointer in public section of Form as below;

4. Back to Form design, and double click to Button1, add these variables.

5. And add these lines (Step 5,6,7) to setup our new mesh. Note that Parent object must be defined to be displayed. Here our parent object will be Dummy1. You can set to ViewPort3D1 too.

6. Now let’s add our Points and Polygons to Mesh Data

7. Finally let’s setup our mesh Material and some other specifics.

8. Don’t forget to free mesh from the memory when user close your application.

close

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++Introduction to C++Language FeatureLearn C++

How To Use The Comprehensive Form Properties In C++ VCL Apps

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Add Characters to Wide Strings in Modern C++

C++ComponentsLanguage FeatureLearn C++

How To Create Gorgeous Transparent App Windows With C++

C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Get A Substring of a Wide String in C++

en_USEnglish