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

This example generates the freeform primitive (cylinder)

// This example generates the freeform primitive (cylinder)
#include <CoreAPI.h>
using namespace coat;
class ffCylinder:public BaseClass {
public:
ffCylinder() {
ff.ffname("Cylinder");
ffSubNames = ff.ffSubNamesList();
RadiusVariation = 30;
SubIndex = 0;
}
float RadiusVariation;
list<str>* ffSubNames;
int SubIndex;
// this is class registration, look dialogs example
SERIALIZE() {
Enumerator* E = ENUM.Get("SubIndex");
if (E->GetAmount() == 0) {
if (ffSubNames){
for(int i = 0; i < ffSubNames->Count(); i++){
E->Add((*ffSubNames)[i]);
}
}
}
REG_DROPLIST(SubIndex,"Sub Index","SubIndex");
FSLIDER(RadiusVariation, "%RadiusVariation", 1, 100, 30, false);
}
// generate random value with variation
float random(float variation) {
return (1.0f + variation * comms::cMath::Rand(1, 100) / 100.0f);
}
void generate() {
auto current = coat::Scene::sculptRoot().addChild("Cylinder"+coat::str::ToString(voxId));
auto volume = current.Volume();
// turn to surface
volume.toSurface();
// create the free form sub object
ff.ffsubname((*ffSubNames)[SubIndex]);
// get the control poinst
freeform::Points3D points = ff.ffControlPoints();
// modify the point's
int N = ff.CountPoints();
for(int i = 0; i < N; i++){
vec3 P = points[i];
vec3 VN = P;
VN.Normalize();
vec3 P1 = P + VN * random(RadiusVariation);
ff.SetPoint(i,P1);
}
ff.details(0.5).add(volume);
}
};
EXPORT
int main() {
// get to sculpt room
coat::ui::toRoom("Sculpt");
// create the generator object
ffCylinder fg;
// load generator settings if exist
fg.ReadFromFile("data/Temp/ffCylinder.json");
if(dlg.caption("Free Cylinder").ok().cancel().params(&fg).show() == 1) {// ok pressed, buttons start from 1
// save settings
fg.WriteToFile("data/Temp/ffCylinder.json");
// generate the ffcube
fg.generate();
};
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:3732
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()
Show the dialog. This is usually the last command in the chain.
dialog & caption(const char *id)
pass the caption of the dialog
freeform primitive
Definition CorePrimAPI.h:3880
freeform & ffsubname(const char *name)
set the free form sub name.
Points3D & ffControlPoints()
get the knot(control) points of the primitive.
freeform & SetPoint(int i, const vec3 &point)
set the knot point of the primitive.
int CountPoints() const
get the account of the knot points
prim & details(const float det_level)
set the detail level
void add(Volume &v)
add the prim into scene
static void toRoom(const char *name, bool Force=false)
switch to the room
The coat namespace used for most 3DCoat API calls except low-level internal structures.
Definition CoreAPI.h:43
comms::cVec3 vec3
3D - float vector, see the cVec3
Definition CoreAPI.h:50
comms::cList< X > list
the array template, see cList
Definition CoreAPI.h:70