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

Generate the surface figure that consists of spheres

// Generate the surface figure that consists of spheres
#include <CoreAPI.h>
//@config: Debug
class SpheresPrim:public BaseClass {
public:
SpheresPrim() {
BaseRadius = 100;
SubDivisions = 1;
Rings = 12;
Slices = 24;
}
float BaseRadius;
int SubDivisions;
int Rings;
int Slices;
// this is class registration, look dialogs example
SERIALIZE() {
Enumerator* E = ENUM.Get("DIVMODE");
if (E->GetAmount() == 0) {
E->Add("triangle");
E->Add("meridian");
E->Add("cube");
}
REG_DROPLIST(DivMode,"DivMode","DIVMODE");
FSLIDER(BaseRadius, "BaseRadius", 50, 200, 1, false);
SLIDER(Slices, "Slices", 8, 60);
SLIDER(Rings, "Rings", 6, 60);
}
else if (DivMode == coat::sphere::DivisionMode::DIV_CUBE) {
SLIDER(SubDivisions, "SubDivisions", 2, 20);
}
else {
SLIDER(SubDivisions,"SubDivisions", 1, 10);
}
}
void build() {
auto current = coat::Scene::sculptRoot().addChild("Spheres"+coat::str::ToString(voxId));
auto volume = current.Volume();
volume.toSurface();
coat::sphere sphere;
sphere.radius(BaseRadius).sub_div_mode(DivMode).sub_division(SubDivisions).rings(Rings).slices(Slices).add(volume);
sphere.radius(BaseRadius/2).translate(coat::vec3(0,0,1.5*BaseRadius)).add(volume);
sphere.radius(BaseRadius/2).translate(coat::vec3(0,0,-1.5*BaseRadius)).add(volume);
}
};
EXPORT
int main() {
// get to sculpt room
coat::ui::toRoom("Sculpt");
SpheresPrim spheres;
// load generator settings if exist
spheres.ReadFromFile("data/Temp/SpheresPrim.json");
if(dlg.ok().cancel().params(&spheres).show() == 1) {// ok pressed, buttons start from 1
// save settings
spheres.WriteToFile("data/Temp/SpheresPrim.json");
// build the figure
spheres.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
int childCount() const
returns the child elements count
SceneElement addChild(const char *name) const
add the child element of the same nature
static SceneElement sculptRoot()
get the root of all sculpt objects
the rich dialog. You may customize it, show your custom parameters and custom buttons.
Definition CoreAPI.h:3593
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 & translate(const vec3 &_pos)
Set the primitive translation.
void add(Volume &v)
add the prim into scene
The sphere.
Definition CorePrimAPI.h:620
sphere & sub_division(const int subdiv)
set the degree for subdivision in the mesh.
DivisionMode
division modes
Definition CorePrimAPI.h:625
@ DIV_TRIANGLE
triangle mode
Definition CorePrimAPI.h:627
@ DIV_CUBE
cube projection mode
Definition CorePrimAPI.h:631
@ DIV_MERIDIAN
meridian mode
Definition CorePrimAPI.h:629
sphere & radius(const float &r)
set the radius of the sphere.
sphere & slices(const int &_slices)
set the number of slices in the mesh.
sphere & sub_div_mode(const sphere::DivisionMode &divmode)
set the division mode for the mesh.
sphere & rings(const int &_rings)
set the number of rings in the mesh.
static void toRoom(const char *name)
switch to the room
comms::cVec3 vec3
3D - float vector, see the cVec3
Definition CoreAPI.h:50