port from perforce

This commit is contained in:
2026-04-18 22:31:51 +02:00
commit 8d0ab5b7cc
8409 changed files with 3972376 additions and 0 deletions

View File

@@ -0,0 +1,107 @@
#if _DEBUG
#include "ObjExporter.h"
#include <iostream>
#include <fstream>
void ObjExporter::Export(mt::Mesh* mesh, const std::string& filePath)
{
ObjExporter exporter(mesh);
exporter.Export(filePath);
}
ObjExporter::ObjExporter(mt::Mesh* mesh)
: mesh{mesh}
{
}
void ObjExporter::Export(const std::string& filePath)
{
std::ostringstream builder;
std::ostringstream mtlBuilder;
builder << "mtllib " + replace(filePath, ".obj", ".mtl") << std::endl;
WritePositions(builder);
WriteNormals(builder);
WriteUVs(builder);
WriteFaceGroups(builder, mtlBuilder);
std::ofstream objFile(filePath);
objFile << builder.str();
objFile.close();
std::ofstream mtlFile(replace(filePath, ".obj", ".mtl"));
mtlFile << mtlBuilder.str();
mtlFile.close();
}
void ObjExporter::WriteFaceGroups(std::ostringstream& builder, std::ostringstream& mtlBuilder)
{
auto groups = mesh->GetSubMeshs();
for(const auto& group : groups)
{
auto materialId = group->Key;
builder << "usemtl " << materialId << std::endl;
builder << "g " << materialId << std::endl;
WriteFaces(builder, group->Value);
mtlBuilder << "newmtl " << materialId << std::endl;
mtlBuilder << "Ka 0.0 0.0 0.0" << std::endl;
mtlBuilder << "Kd 1.0 1.0 1.0" << std::endl;
mtlBuilder << "Ks 1.0 1.0 1.0" << std::endl;
mtlBuilder << "Ns 16.0" << std::endl;
mtlBuilder << "illum 0" << std::endl;
mtlBuilder << "map_Kd " << materialId << ".png" << std::endl;
}
}
void ObjExporter::WriteFaces(std::ostringstream& builder, const mt::FaceList& faces)
{
for (auto face : faces)
{
auto indices = face->GetIndices(true);
builder << "f";
for (int i = 0; i < indices.Count(); ++i)
{
builder << " ";
auto index = indices[i] + 1;
builder << index << "/" << index << "/" << index;
}
builder << std::endl;
}
}
void ObjExporter::WritePositions(std::ostringstream& builder)
{
for (const auto& v : mesh->GetVertices())
{
builder << "v " << v->Position.x << " " << v->Position.y << " " << v->Position.z << std::endl;
}
}
void ObjExporter::WriteNormals(std::ostringstream& builder)
{
for (const auto& v : mesh->GetVertices())
{
auto normal = v->GetNormal();
builder << "vn " << normal.x << " " << normal.y << " " << normal.z << std::endl;
}
}
void ObjExporter::WriteUVs(std::ostringstream& builder)
{
for (const auto& v : mesh->GetVertices())
{
builder << "vt " << v->UV[0] << " " << v->UV[1] << std::endl;
}
}
#endif

View File

@@ -0,0 +1,44 @@
#pragma once
#if _DEBUG
#include "../src/Lib/mt/mt.h"
#include <sstream>
#include <string>
class Mesh;
class ObjExporter
{
public:
static void Export(mt::Mesh* mesh, const std::string& filePath);
ObjExporter(mt::Mesh* mesh);
void Export(const std::string& filePath);
void WriteFaceGroups(std::ostringstream& builder, std::ostringstream& mtlBuilder);
void WriteFaces(std::ostringstream& builder, const mt::FaceList& faces);
void WritePositions(std::ostringstream& builder);
void WriteNormals(std::ostringstream& builder);
void WriteUVs(std::ostringstream& builder);
private:
std::string replace(const std::string &input, const std::string &search, const std::string &replace)
{
auto s = input;
for (size_t pos = 0;; pos += replace.length())
{
// Locate the substring to replace
pos = s.find(search, pos);
if (pos == std::string::npos) break;
// Replace by erasing and inserting
s.erase(pos, search.length());
s.insert(pos, replace);
}
return s;
}
private:
mt::Mesh* mesh;
};
#endif

View File

@@ -0,0 +1,40 @@
========================================================================
CONSOLE APPLICATION : TestApp Project Overview
========================================================================
AppWizard has created this TestApp application for you.
This file contains a summary of what you will find in each of the files that
make up your TestApp application.
TestApp.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.
TestApp.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).
TestApp.cpp
This is the main application source file.
/////////////////////////////////////////////////////////////////////////////
Other standard files:
StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named TestApp.pch and a precompiled types file named StdAfx.obj.
/////////////////////////////////////////////////////////////////////////////
Other notes:
AppWizard uses "TODO:" comments to indicate parts of the source code you
should add to or customize.
/////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,161 @@
// 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;
}

View File

@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{0E9C6FB6-B6ED-407B-A868-3157BC58EC02}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>TestApp</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(IncludePath)</IncludePath>
<LibraryPath>D:\Repositories\blu-flame.org\meshToolsV5\lib\Debug;$(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86);$(NETFXKitsDir)Lib\um\x86</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>Lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ObjExporter.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ObjExporter.cpp" />
<ClCompile Include="stdafx.cpp" />
<ClCompile Include="TestApp.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ObjExporter.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="TestApp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ObjExporter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// TestApp.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

View File

@@ -0,0 +1,15 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here

View File

@@ -0,0 +1,8 @@
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>