Files
bluflame/meshToolsV5/TestApp/TestApp.cpp
2026-04-18 22:31:51 +02:00

162 lines
4.6 KiB
C++

// TestApp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "../src/Lib/mt/mt.h"
#include "ObjExporter.h"
int main()
{
auto mesh = mt::CreateSphere(2);
const int FFD_X = 2;
const int FFD_Y = 5;
const int FFD_Z = 5;
auto ffd = new mt::FFD(mesh->GetFaces(), FFD_X, FFD_Y, FFD_Z, mt::FFD::FFDControlPointMode::Surface);
// Bring the skull shape in form for the top view [DONE]
auto selection = ffd->SelectPoints(0, FFD_X, 0, FFD_Y, 0, FFD_Z); // Select all FFD Points
for (const auto& v : selection)
{
v->x *= 1 + (0.3f * (v->z + 0.5f));
v->z *= 1.5f;
}
// Shape the back view [DONE]
selection = ffd->SelectPoints(0, FFD_X, 0, 0, 0, FFD_Z); // Select all bottom Points
for (const auto& v : selection)
{
v->x *= 1.75f;
}
// Shape the side view (Cheek) [DONE]
selection = ffd->SelectPoints(0, FFD_X, 0, 2, 2, 2);
for (const auto& v : selection)
{
v->y = v->y * 0.5f + 0.5f;
}
// Shape the side view (Nose) [Done]
selection = ffd->SelectPoints(1, 1, 0, 2, 0, 0);
//selection.Add(&ffd->ControlPoints[1][0][1]);
for (const auto& v : selection)
{
v->y -= 0.75f;
}
// Generell vertical upscale
selection = ffd->SelectPoints(0, FFD_X, 0, FFD_Y, 0, FFD_Z);
for (const auto& v : selection)
{
v->y *= 1.25f;
}
// Fix the back part of the head which is really high above [Done]
selection = ffd->SelectPoints(0, FFD_X, 5, 5, FFD_Z, FFD_Z);
for (const auto& v : selection)
{
v->y += 0.4f;
v->z += 0.4f;
}
// Descale the length of the head [Done]
selection = ffd->SelectPoints(0, FFD_X, 0, FFD_Y, 0, 2);
for (const auto& v : selection)
{
v->z *= 0.9f;
}
//ffd->DrawFFDGrid(mesh, 0.025f, &selection);
//ffd->DumpFFDGridPositions();
ffd->Apply();
// Despike the chin [Done]
auto chinVertex = mesh->GetVertices()[38];
// chinVertex->Position.y += 0.1f;
// Dechamfer chin
int chinIndices[] = { 51, 53, 55 }; // 3
auto chinVertices = mesh->GetVertices().GetSubset(chinIndices, 3);
/*auto chinVertices = mt::GetVerticesOnPositivePlane(mesh->GetVertices(), mt::Plane(mt::vec3::back, mt::vec3::zero));
chinVertices = mt::GetVerticesOnPositivePlane(chinVertices, mt::Plane(mt::vec3::forward, mt::vec3::back * 0.25f));
chinVertices = mt::GetVerticesOnPositivePlane(chinVertices, mt::Plane(mt::vec3::down, mt::vec3::down * 0.2f));
mt::DumpIndicies(chinVertices, mesh->GetVertices());
mt::DisplayVertices(chinVertices, 0.1f, mesh);*/
for (const auto& v : chinVertices)
v->Position.z -= 0.05f;
auto faceSelection = mt::GetFacesOnPositivePlane(mesh->GetFaces(), { mt::vec3::down, mt::vec3::zero });
faceSelection = mt::GetFacesOnPositivePlane(faceSelection, { mt::vec3::forward, mt::vec3::back * 0.25f });
//faceSelection = mt::GetFacesOnPositivePlane(faceSelection, { mt::vec3::back, mt::vec3::forward * 0.25f });
ffd = new mt::FFD(faceSelection, 1, 1, 1, mt::FFD::FFDControlPointMode::Surface);
selection = ffd->SelectPoints(0, 1, 0, 0, 0, 0);
for (const auto& v : selection)
{
v->x *= 0.5f;
}
//ffd->DrawFFDGrid(mesh, 0.025f, &selection);
//ffd->DumpFFDGridPositions();
ffd->Apply();
faceSelection = mt::GetFacesOnPositivePlane(mesh->GetFaces(), { mt::vec3::left, mt::vec3::zero });
mt::Delete(faceSelection);
//faceSelection.Clear();
//faceSelection.Add(mesh->GetFaces()[2]);
//faceSelection.Add(mesh->GetFaces()[6]);
//mt::Split(faceSelection, {mt::vec3::up, mt::vec3::zero});
// Dat eye socket
mt::vec3 eyeCenter = { 0.22f, -0.05f, -0.5f };
auto eyeBall = mt::CreateSphere(1, eyeCenter, 0.35f);
mt::Scale(eyeBall->GetVertices(), { 1, 0.7f, 2.0f });
mt::Rotate(eyeBall->GetVertices(), eyeCenter, mt::vec3::forward, -0.3f);
// De noze
mt::vec3 nostrilCenter = { 0.2f, -0.25f, -0.5f };
auto nostril = mt::CreateSphere(1, nostrilCenter, 0.45f);
ffd = new mt::FFD(nostril->GetFaces(), 1, 1, 1, mt::FFD::FFDControlPointMode::Surface);
selection = ffd->SelectPoints(0, 1, 1, 1, 0, 1);
for (const auto& v : selection)
{
v->x *= 0.8f;
}
selection = ffd->SelectPoints(0, 1, 0, 1, 0, 1);
for (const auto& v : selection)
{
v->x = v->x * 0.5f - 0.1f;
v->y *= 0.65f;
}
selection = ffd->SelectPoints(1, 1, 0, 0, 0, 1);
for (const auto& v : selection)
{
v->y -= 0.05f;
}
ffd->Apply();
for (const auto& v : nostril->GetVertices())
v->Position.x = v->Position.x < 0.004f ? 0.004f : v->Position.x;
mt::CloneToMesh(nostril->GetFaces(), eyeBall);
mesh = mt::CsgSubtract(mesh->GetFaces(), eyeBall->GetFaces());
auto vertices = mesh->GetVertices();
mt::Weld(vertices);
faceSelection = mt::Clone(mesh->GetFaces());
mt::Mirror(faceSelection, { mt::vec3::right, mt::vec3::zero });
//mt::Subdivide(mesh->GetFaces(), true);
ObjExporter::Export(mesh, "mesh.obj");
return 0;
}