Added function to generated diamond shaped model
This commit is contained in:
parent
93db27f40c
commit
c4ec355f41
2 changed files with 53 additions and 0 deletions
|
@ -597,5 +597,53 @@ GLModel::InitializationData straight_arrow(float tip_width, float tip_height, fl
|
|||
return data;
|
||||
}
|
||||
|
||||
GLModel::InitializationData diamond(int resolution)
|
||||
{
|
||||
resolution = std::max(4, resolution);
|
||||
|
||||
GLModel::InitializationData data;
|
||||
GLModel::InitializationData::Entity entity;
|
||||
entity.type = GLModel::PrimitiveType::Triangles;
|
||||
|
||||
const float step = 2.0f * float(PI) / float(resolution);
|
||||
|
||||
// positions
|
||||
for (int i = 0; i < resolution; ++i) {
|
||||
float ii = float(i) * step;
|
||||
entity.positions.emplace_back(0.5f * ::cos(ii), 0.5f * ::sin(ii), 0.0f);
|
||||
}
|
||||
entity.positions.emplace_back(0.0f, 0.0f, 0.5f);
|
||||
entity.positions.emplace_back(0.0f, 0.0f, -0.5f);
|
||||
|
||||
// normals
|
||||
for (const Vec3f& v : entity.positions) {
|
||||
entity.normals.emplace_back(v.normalized());
|
||||
}
|
||||
|
||||
// triangles
|
||||
// top
|
||||
for (int i = 0; i < resolution; ++i) {
|
||||
entity.indices.push_back(i + 0);
|
||||
entity.indices.push_back(i + 1);
|
||||
entity.indices.push_back(resolution);
|
||||
}
|
||||
entity.indices.push_back(resolution - 1);
|
||||
entity.indices.push_back(0);
|
||||
entity.indices.push_back(resolution);
|
||||
|
||||
// bottom
|
||||
for (int i = 0; i < resolution; ++i) {
|
||||
entity.indices.push_back(i + 0);
|
||||
entity.indices.push_back(resolution + 1);
|
||||
entity.indices.push_back(i + 1);
|
||||
}
|
||||
entity.indices.push_back(resolution - 1);
|
||||
entity.indices.push_back(resolution + 1);
|
||||
entity.indices.push_back(0);
|
||||
|
||||
data.entities.emplace_back(entity);
|
||||
return data;
|
||||
}
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
|
|
@ -100,6 +100,11 @@ namespace GUI {
|
|||
// used to render sidebar hints for position and scale
|
||||
GLModel::InitializationData straight_arrow(float tip_width, float tip_height, float stem_width, float stem_height, float thickness);
|
||||
|
||||
// create a diamond with the given resolution
|
||||
// the origin of the diamond is in its center
|
||||
// the diamond is contained into a box with size [1, 1, 1]
|
||||
GLModel::InitializationData diamond(int resolution);
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
|
|
Loading…
Reference in a new issue