3DCoat Core API
The 3DCoat API documentation.
|
The Core API is a powerful method to extend 3DCoat's functionality. You can automate the job or add principally new tools. This is not just the scripting, the code you write runs at full speed of compiled C++. We use Microsoft Visual Studio for the compiling. But the whole process is entirely transparent for you. You don't need to configure anything or manage complex project configurations. 3DCoat will lead you through the whole process with a simple wizard.
The core API requires Visual Studio 2022 Community with the C++ features installed. If you have not installed the Visual Studio, 3DCoat will help to install it with correct options.
The start is quite easy. Just use Scripts->Create new Core API script
Choose the template and path for your project. Then 3DCoat will assist you in installing the Visual Studio if needed.
Each example is well documented and uses relatively simple syntax, so it is easy to understand from basic to complex.
There are several important notes you need to know:
1) Always start your project from one of the examples. Even if you want to make everything from scratch, use Scripts->Create new Core API script->Minimal c++ program as your starting point. Don't create the project manually!
2) Use Debugging; it is very convenient; all 3DCoat native data types are shown in a user-friendly interface.
3) Always follow the Visual Studio linter hints to write the correct code. Hover the data types and function names to access the documentation on-the-fly.
4) Don't read the full documentation. It is impossible to remember. Follow the Examples first. And then look at the documentation if you need some details.
5) Look the C++ syntax, but don't read the whole manual, take the basics first - https://beginnersbook.com/2017/08/c-plus-plus-tutorial-for-beginners/
6) Click on the item in the Script menu to execute. Use RMB click to get the useful set of commends - edit, build, rebuild. Yoy may also create distributive of your script to share with oher users.
Pay attention. The API uses the same set of classes as 3DCoat. For the uniform look of the code, some types referred to in this document were renamed. For example, coat::vec3 is the same as cVec3. Please, use notation like coat::vec3 instead of cVec3 for 3d vectors (and similar for other vectors and matrices).
General I/O: coat::io
Dialog management: coat::dialog
Mesh operations: coat::Mesh
Scene roots: coat::Scene
Scene element: coat::SceneElement
Volume management: coat::Volume
UI management: coat::ui
2D-vectors math: coat::vec2, look the cVec2 for details.
3D-vectors math: coat::vec3, look the cVec3 for details.
4D-vectors math: coat::vec4, look the cVec4 for details.
3D-matrix math: coat::mat3, look the cMat3 for details.
4D-matrix math: coat::mat4, look the cMat4 for details.
Symmetry management: coat::symm
array: coat::list, look the cList and 3DCoat arrays for details.
Class registration rules and principles: ClassEngine introduction
Vector operations: 3DCoat math/vectors operations
Primitives: Construct scene using primitives, coat::box, coat::sphere, coat::ellipse, coat::gear, coat::cylinder, coat::ngon, coat::tube, coat::spiral, coat::torus.
3DCoat generates cmake Visual Studio project to simplify the coding. If the free Visual Studio Express 2022 installed, the project will open automatically after the Script->Create Core API script. Of course, you should select the CPP file in the Solution Explorer to edit the code. We generate the project only to be able to edit with auto-complete and see the correct hints in the editor. Anyway, you can use Build->Build All in the Visual Studio to check for the syntax errors.
Use Visual Studio for the debugging. Use Debug->Attach to process, 3DCoatGL64.exe, then open your script in Visual Studio, and set the breakpoint. Attach:
Select process:
Set breakpoint:
As soon as the script is executed, the VS stops at the breakpoint. Ensure that there is the 3dcoat.natvis file in the project folder. In this case, all the native 3DCoat types are shown correctly.
!!! Pay attention that if you ended the debug session and want to change the source file, you need to activate Debug->Detach All, otherwise 3DCoat will not be able to compile the project because the .pdb file is locked by the Visual Studio. Detach, then change sources, then attach again, and run the project using the Scripts->click on the project filename.
Looking the The Core API examples is the best way to understand the API. Use Scripts->Create new Core API script to experiment with that examples.