The basic generator example, just to demonstrate the principles of generators, look the TreesGenerator.cpp for the more sophisticated example.
#include <CoreAPI.h>
const char* file_for_settings = "data/Temp/SimpleGenerator.json";
class SimpleGenerator : public SculptGenerator{
public:
SimpleGenerator() {
numSpheres = 200;
FigureRadius = 30;
FigureRadiusVariation = 0.1;
SpheresRadius = 10;
SpheresRadiusVariation = 0.5;
m.
Read(
"data/Samples/Sphere.obj");
}
virtual const char* GetID() {
return "SimpleGenerator";
}
virtual const char* getDefaultObjectName() {
return "Spheres";
}
int numSpheres;
float FigureRadius;
float FigureRadiusVariation;
float SpheresRadius;
float SpheresRadiusVariation;
SERIALIZE() {
FUNCTION_CALL(CreateNewObject,"CreateNewObject");
if (getObject()) {
SLIDER(numSpheres, "numSpheres", 1, 1000);
FSLIDER(FigureRadius, "FigureRadius", 1, 100, 1, false);
FSLIDER(FigureRadiusVariation, "FigureRadiusVariation", 0, 1, 100, false);
FSLIDER(SpheresRadius, "SpheresRadius", 1, 100, 1, false);
FSLIDER(SpheresRadiusVariation, "SpheresRadiusVariation", 0, 1, 100, false);
REG_AUTO(TransformObject);
if(TransformObject) {
NOHASH{
REG_AUTO(Transform);
}
}
}
}
float random(float value, float variation) {
return value * (1.0f + variation * rand() / 32768.0f);
}
for (int i = 0; i < numSpheres; i++) {
coat::mat4 transform = coat::mat4::Scaling(random(SpheresRadius, SpheresRadiusVariation));
transform *= coat::mat4::Translation(coat::vec3::RandNormal() * random(FigureRadius, FigureRadiusVariation));
}
WriteToFile(file_for_settings);
}
virtual void GeneratePreview() override {
generate(t.Volume());
};
virtual void GenerateFinalObject() override {
GeneratePreview();
}
};
EXPORT_EXTENSION(SimpleGenerator) {
SimpleGenerator* tg = new SimpleGenerator;
tg->ReadFromFile(file_for_settings);
VoxelExtension::Register(tg);
ui::toRoom("Sculpt");
tg->Activate();
}
The mesh reference.
Definition CoreAPI.h:412
void addTransformed(const Mesh &m, const mat4 &t)
concatenate the transformed mesh with the current one
bool Read(const char *name)
Load the mesh from the file.
The scene element, like sculpt object or curve.
Definition CoreAPI.h:1632
void selectOne() const
unselect all similar elements and select this one
mat4 getTransform() const
get the scene element transform
void removeSubtree() const
remove the whole subtree
const SceneElement & setTransform(const mat4 &Transform) const
Set the transform matrix.
SceneElement addChild(const char *name) const
add the child element of the same nature
The class allows to operate over voxels/surface on the relatively low-level.
Definition CoreAPI.h:1947
void mergeMesh(Mesh &mesh, const mat4 &transform=mat4::Identity, BoolOpType op=BOOL_MERGE)
merge the mesh into scene
void toSurface()
turn to surface mode, the triangles will be tangentially relaxed
The coat namespace used for most 3DCoat API calls except low-level internal structures.
Definition CoreAPI.h:43
@ BOOL_MERGE
just merge, no booleans, it may be used only in surface mode
Definition CoreAPI.h:89
comms::cMat4 mat4
4x4 float matrix, see the cMat4
Definition CoreAPI.h:59