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

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He was born in 1974, Eskisehir-Turkey, started coding in college and graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. He worked as a research assistant at the same university for more than 10 years. He received his MSc and PhD degrees from the same department at the same university. Since 2012, he is the founder and CEO of Esenja LLC Company. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Learn C++Syntax

What Is A Forced (Default) Copy Assignment Operator In Modern C++

C++C++11C++14C++17C++20Learn C++Syntax

What is Implicitly-declared Copy Assignment Operator In C++?

C++C++11C++14C++17C++20Learn C++Syntax

What is Avoiding Implicit Copy Assignment In C++?

C++C++11C++14C++17C++20Learn C++

Typical Declaration Of A Copy Assignment Operator Without std::swap