3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
thread.cpp

This example generates the surface figure that consists of thread

// This example generates the surface figure that consists of thread
#include <CoreAPI.h>
//@config: Debug
using namespace coat;
class ThreadPrim:public BaseClass {
public:
ThreadPrim() {
Diameter = 50;
Step = 10;
Turns = 10;
Profile = ThreadProfile::ThreadTriangle;
Clockwise = true;
}
float Diameter;
float Step;
int Turns;
bool Clockwise;
ThreadProfile Profile;
// this is class registration, look dialogs example
SERIALIZE() {
FSLIDER(Diameter, "%Diameter", 10, 100, 50, false);
FSLIDER(Step, "%Step", 0.2, 20, 10, false);
SLIDER(Turns, "%Turns", 3, 20);
REG_AUTO(Clockwise,"%ClockWise");
Enumerator* E = ENUM.Get("PROFILE");
if (E->GetAmount() == 0) {
E->Add("triangle");
E->Add("trapeze");
E->Add("Rectangular");
E->Add("Round");
E->Add("Persistent");
}
REG_DROPLIST(Profile,"Profile","PROFILE");
}
void build() {
auto voxId = Scene::sculptRoot().childCount();
auto current = Scene::sculptRoot().addChild("Thread" + str::ToString(voxId));
auto volume = current.Volume();
volume.toSurface();
thread().diameter(Diameter).pitch(Step).turns(Turns).clockwise(Clockwise).profile(Profile).details(0.2).add(volume);
}
};
EXPORT
int main() {
// get to sculpt room
ui::toRoom("Sculpt");
ThreadPrim threadPrim;
dialog dlg;
// load settings if exist
threadPrim.ReadFromFile("data/Temp/thread.json");
if(dlg.ok().cancel().params(&threadPrim).show() == 1) {// ok pressed, buttons start from 1
// save settings
threadPrim.WriteToFile("data/Temp/thread.json");
// build the figure
threadPrim.build();
};
return 0;
}
Use this class for build a class for UI or serialization. see class_reg.h for details about the class...
Definition BaseClass.h:91
the rich dialog. You may customize it, show your custom parameters and custom buttons.
Definition CoreAPI.h:3388
dialog & params(BaseClass *params)
The important core feature. BaseClass allows to create the custom controls in the dialog....
dialog & ok()
add Ok button
dialog & cancel()
add Cancel button
int show()
pass the function/lambda that will be called when the button will be pressed. The button index (start...
prim & details(const float det_level)
set the detail level
void add(Volume &v)
add the prim into scene
thread primitive
Definition CorePrimAPI.h:2101
thread & diameter(const float d)
set the diameter of the thread.
thread & pitch(const float p)
set the pitch of the thread.
thread & turns(const int &n)
set the number of the thread turns.
thread & clockwise(const bool &cw)
set the clockwise flag of the thread.
thread & profile(const ThreadProfile &prf)
set the thread profile type.
The coat namespace used for most 3DCoat API calls except low-level internal structures.
Definition CoreAPI.h:43
ThreadProfile
thread profile types
Definition CorePrimAPI.h:2089