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.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

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 graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++17C++20Introduction to C++Learn C++

When Is The CMath Mathematical Special Functions Header Used in Modern C++?

C++C++17C++20Introduction to C++Learn C++

What Are The CMath Mathematical Special Functions in Modern C++?

C++C++17C++20Learn C++

What Are The New Rules For Auto Deduction In C++ 17?

C++C++14C++17Learn C++Syntax

What Are The New Overloads For Ranges In C++ 14?