Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Code/BuildInfo.hpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#pragma once
#define SM_CONVERTER_BUILD_VERSION 2662
#define SM_CONVERTER_BUILD_VERSION 2682
35 changes: 27 additions & 8 deletions Code/Converter/BlueprintConverter/BlueprintConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@

SM_UNMANAGED_CODE

void BlueprintConv::WriteToFileInternal(SMBlueprint* pBlueprint, const std::wstring& bp_name, ConvertError& error)
void BlueprintConv::WriteToFileInternal(SMBlueprint* pBlueprint, const std::wstring& blueprintName, ConvertError& error)
{
if (error) return;

const std::wstring v_bp_out_dir(DatabaseConfig::BlueprintOutputFolder);
if (!File::CreateDirectorySafe(v_bp_out_dir))
const std::wstring v_bpOutDir(DatabaseConfig::BlueprintOutputFolder);
if (!File::CreateDirectorySafe(v_bpOutDir))
{
error.setError(1, "Couldn't create the main output directory");
return;
}

const std::wstring v_bp_dir_path = v_bp_out_dir + L"/" + bp_name;
if (!File::CreateDirectorySafe(v_bp_dir_path))
const std::wstring v_bpDirPath = v_bpOutDir + L"/" + blueprintName;
if (!File::CreateDirectorySafe(v_bpDirPath))
{
error.setError(1, "Couldn't create the blueprint output directory");
return;
}

const std::wstring v_bp_output_path = v_bp_dir_path + L"/" + bp_name;
const std::wstring v_bpOutputPath = v_bpDirPath + L"/" + blueprintName;

#if 0 // OBJ implementation
{
//Write object file
std::ofstream v_obj_writer(v_bp_output_path + L".obj");
std::ofstream v_obj_writer(v_bpOutputPath + L".obj");
if (!v_obj_writer.is_open())
{
error.setError(1, "Couldn't create an object file");
Expand Down Expand Up @@ -70,8 +71,26 @@ void BlueprintConv::WriteToFileInternal(SMBlueprint* pBlueprint, const std::wstr
ProgCounter::ProgressMax = v_textureMap.size();
}

MtlFileWriter::Write(v_bp_output_path + L".mtl", v_textureMap);
MtlFileWriter::Write(v_bpOutputPath + L".mtl", v_textureMap);
}
#else
ProgCounter::SetState(ProgState::WritingObjects, pBlueprint->GetAmountOfObjects());

const std::wstring v_bpBinaryPath = v_bpDirPath + L"/mesh_data.bin";
GltfWriterContext v_writerContext(v_bpBinaryPath);

if (!v_writerContext.m_outFile.is_open())
{
error.setError(1, "Couldn't create an object file");
return;
}

v_writerContext.getOrCreateNewGroup(L"Main");
pBlueprint->WriteObjectToFileGltf(v_writerContext, glm::mat4(1.0f));

ProgCounter::SetState(ProgState::WritingMtlFile, 0);
v_writerContext.writeGltfToFile(v_bpOutputPath + L".gltf");
#endif
}

SMBody* BlueprintConv::CreateCollection(
Expand Down
2 changes: 1 addition & 1 deletion Code/Converter/BlueprintConverter/BlueprintConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum : std::uint8_t

class BlueprintConv
{
static void WriteToFileInternal(SMBlueprint* pBlueprint, const std::wstring& bp_name, ConvertError& error);
static void WriteToFileInternal(SMBlueprint* pBlueprint, const std::wstring& blueprintName, ConvertError& error);

static SMBody* CreateCollection(SMBlueprint* self, const std::string_view& name);

Expand Down
8 changes: 4 additions & 4 deletions Code/Converter/Entity/Asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ char* SMAsset::GetMtlNameCStr(
pCString = m_uuid.toCString(pCString);
*pCString++ = ' ';

const SMTextureList* v_tex_list = m_parent->m_textures->getTexList(material, idx);
if (v_tex_list)
const SMTextureList* v_pTexList = m_parent->m_textures->getTexList(material, idx);
if (v_pTexList)
{
pCString = this->GetColor(v_tex_list->m_defColorIdx).StringHexCStr(pCString);
pCString = this->GetColor(v_pTexList->m_defColorIdx).StringHexCStr(pCString);
*pCString++ = ' ';
pCString = String::FromInteger<std::size_t>(idx + 1, pCString);
*pCString++ = ' ';
return MaterialManager::GetMaterialACStr(v_tex_list->m_material, pCString);
return MaterialManager::GetMaterialACStr(v_pTexList->m_material, pCString);
}

pCString = SMColor::WriteEmptyHex(pCString);
Expand Down
1 change: 0 additions & 1 deletion Code/Converter/Entity/Asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "Utils/clr_include.hpp"
#include "Utils/Hashing.hpp"
#include "Utils/Color.hpp"
#include "Utils/Uuid.hpp"

SM_UNMANAGED_CODE

Expand Down
128 changes: 122 additions & 6 deletions Code/Converter/Entity/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,39 @@ char* SMBlock::GetMtlNameCStr(
return MaterialManager::GetMaterialACStr(m_parent->m_textures.m_material, pCString);
}

void SMBlock::GetMtlNameString(
std::string& outString,
const std::string_view& material,
const std::size_t idx) const
{
m_uuid.appendToString(outString);
outString.append(1, ' ');
m_color.appendStringHex(outString);
outString.append(1, ' ');
String::AppendIntegerToString(outString, idx + 1);
MaterialManager::AppendMaterialIdx(outString, m_parent->m_textures.m_material);
}

std::size_t SMBlock::GetGltfMaterialEntry(
GltfWriterContext& context,
const std::string_view& material,
const std::size_t idx) const
{
std::string v_matName;
GetMtlNameString(v_matName, material, idx);

std::size_t v_matIdx;
if (context.getOrCreateMaterial(v_matName, v_matIdx))
{
GltfMaterial& v_curMaterial = context.m_vecMaterials[v_matIdx];

v_curMaterial.m_color = m_color;
v_curMaterial.m_pTextures = &m_parent->m_textures;
}

return v_matIdx;
}

std::string SMBlock::GetMtlName(const std::size_t idx) const
{
std::string v_mtlName(m_uuid.toString());
Expand Down Expand Up @@ -96,14 +129,33 @@ static void GenerateUVs(Model& model, const glm::vec3& bounds, const glm::vec3&
{
model.m_uvs.resize(24);

const static glm::vec4 v_blockTextureNormals[6] =
const static glm::vec4 v_blockUvNormal1( 0.0f, 0.0f, 1.0f, 1.0f);
const static glm::vec4 v_blockUvNormal2( 1.0f, 1.0f, 0.0f, 0.0f);
const static glm::vec4 v_blockUvNormal3( 0.0f, 0.0f, 1.0f, -1.0f);
const static glm::vec4 v_blockUvNormal4( 1.0f, 1.0f, 0.0f, 0.0f);
const static glm::vec4 v_blockUvNormal5( 1.0f, 0.0f, 0.0f, -1.0f);
const static glm::vec4 v_blockUvNormal6(-1.0f, 0.0f, 0.0f, -1.0f);

/*const static glm::vec4 v_blockTextureNormals[6] =
{
{ 0.0f, 0.0f, 1.0f, 1.0f },
{ 1.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f, -1.0f },
{ 1.0f, 1.0f, 0.0f, 0.0f },
{ 1.0f, 0.0f, 0.0f, -1.0f },
{ -1.0f, 0.0f, 0.0f, -1.0f }
};*/

const static glm::vec4 v_blockTextureNormals[24] =
{
v_blockUvNormal1, v_blockUvNormal2, v_blockUvNormal3,
v_blockUvNormal1, v_blockUvNormal4, v_blockUvNormal3,
v_blockUvNormal5, v_blockUvNormal2, v_blockUvNormal3,
v_blockUvNormal5, v_blockUvNormal4, v_blockUvNormal3,
v_blockUvNormal1, v_blockUvNormal2, v_blockUvNormal6,
v_blockUvNormal1, v_blockUvNormal4, v_blockUvNormal6,
v_blockUvNormal5, v_blockUvNormal2, v_blockUvNormal6,
v_blockUvNormal5, v_blockUvNormal4, v_blockUvNormal6
};

const float v_tilingAdj = 1.0f / (float)tiling;
Expand All @@ -130,6 +182,32 @@ static void FillCustomCube(Model& model, const glm::vec3& bounds, const glm::vec
{
model.m_vertices =
{
{ bounds.x, bounds.y, -bounds.z },
{ bounds.x, bounds.y, -bounds.z },
{ bounds.x, bounds.y, -bounds.z },
{ bounds.x, -bounds.y, -bounds.z },
{ bounds.x, -bounds.y, -bounds.z },
{ bounds.x, -bounds.y, -bounds.z },
{ bounds.x, bounds.y, bounds.z },
{ bounds.x, bounds.y, bounds.z },
{ bounds.x, bounds.y, bounds.z },
{ bounds.x, -bounds.y, bounds.z },
{ bounds.x, -bounds.y, bounds.z },
{ bounds.x, -bounds.y, bounds.z },
{ -bounds.x, bounds.y, -bounds.z },
{ -bounds.x, bounds.y, -bounds.z },
{ -bounds.x, bounds.y, -bounds.z },
{ -bounds.x, -bounds.y, -bounds.z },
{ -bounds.x, -bounds.y, -bounds.z },
{ -bounds.x, -bounds.y, -bounds.z },
{ -bounds.x, bounds.y, bounds.z },
{ -bounds.x, bounds.y, bounds.z },
{ -bounds.x, bounds.y, bounds.z },
{ -bounds.x, -bounds.y, bounds.z },
{ -bounds.x, -bounds.y, bounds.z },
{ -bounds.x, -bounds.y, bounds.z }

/*
{ -bounds.x, bounds.y, bounds.z },
{ -bounds.x, -bounds.y, -bounds.z },
{ -bounds.x, -bounds.y, bounds.z },
Expand All @@ -138,15 +216,28 @@ static void FillCustomCube(Model& model, const glm::vec3& bounds, const glm::vec
{ bounds.x, bounds.y, -bounds.z },
{ bounds.x, -bounds.y, bounds.z },
{ bounds.x, bounds.y, bounds.z }
*/
};

if (SharedConverterSettings::ExportNormals)
{
model.m_normals =
{
{ -1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, -1.0f },
{ 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f },
{ 0.0f, -1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }
{ 0.0f, 0.0f, -1.0f }, { 0.0f, 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f }, { 0.0f, -1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f }, { 0.0f, -1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f }, { 0.0f, 1.0f, 0.0f }, { -1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f }, { 0.0f, -1.0f, 0.0f }, { -1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f }, { 0.0f, 1.0f, 0.0f }, { -1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f }, { 0.0f, -1.0f, 0.0f }, { -1.0f, 0.0f, 0.0f }

/*{ -1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, -1.0f },
{ 1.0f, 0.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f },
{ 0.0f, -1.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f }*/
};
}

Expand All @@ -155,7 +246,19 @@ static void FillCustomCube(Model& model, const glm::vec3& bounds, const glm::vec
SharedConverterSettings::ExportNormals,
SharedConverterSettings::ExportUvs,
std::initializer_list<std::initializer_list<VertexData>>{
{ { 0, 0 , 0 }, { 1, 1 , 0 }, { 2, 2 , 0 } },
{ { 13, 13, 13 }, { 7, 7, 7 }, { 1, 1, 1 } },
{ { 6, 6, 6 }, { 21, 21, 21 }, { 9, 9, 9 } },
{ { 20, 20, 20 }, { 17, 17, 17 }, { 23, 23, 23 } },
{ { 4, 4, 4 }, { 22, 22, 22 }, { 16, 16, 16 } },
{ { 2, 2, 2 }, { 11, 11, 11 }, { 5, 5, 5 } },
{ { 12, 12, 12 }, { 3, 3, 3 }, { 15, 15, 15 } },
{ { 13, 13, 13 }, { 19, 19, 19 }, { 7, 7, 7 } },
{ { 6, 6, 6 }, { 18, 18, 18 }, { 21, 21, 21 } },
{ { 20, 20, 20 }, { 14, 14, 14 }, { 17, 17, 17 } },
{ { 4, 4, 4 }, { 10, 10, 10 }, { 22, 22, 22 } },
{ { 2, 2, 2 }, { 8, 8, 8 }, { 11, 11, 11 } },
{ { 12, 12, 12 }, { 0, 0, 0 }, { 3, 3, 3 } }
/*{ { 0, 0 , 0 }, { 1, 1 , 0 }, { 2, 2 , 0 } },
{ { 3, 3 , 1 }, { 4, 4 , 1 }, { 1, 5 , 1 } },
{ { 5, 6 , 2 }, { 6, 7 , 2 }, { 4, 8 , 2 } },
{ { 7, 9 , 3 }, { 2, 10, 3 }, { 6, 11, 3 } },
Expand All @@ -166,7 +269,7 @@ static void FillCustomCube(Model& model, const glm::vec3& bounds, const glm::vec
{ { 5, 6 , 2 }, { 7, 20, 2 }, { 6, 7 , 2 } },
{ { 7, 9 , 3 }, { 0, 21, 3 }, { 2, 10, 3 } },
{ { 4, 12, 4 }, { 6, 22, 4 }, { 2, 13, 4 } },
{ { 3, 15, 5 }, { 0, 23, 5 }, { 7, 16, 5 } }
{ { 3, 15, 5 }, { 0, 23, 5 }, { 7, 16, 5 } }*/
}
);

Expand All @@ -188,6 +291,19 @@ void SMBlock::WriteObjectToFile(
ProgCounter::ProgressValue++;
}

void SMBlock::WriteObjectToFileGltf(
GltfWriterContext& context,
const glm::mat4& transform) const
{
Model v_blockModel;
FillCustomCube(v_blockModel, m_size / 2.0f, m_position, m_parent->m_tiling);

const glm::mat4 v_blockTransform = transform * this->GetTransformMatrix();
v_blockModel.WriteToFileGltf(context, v_blockTransform, this);

ProgCounter::ProgressValue++;
}

glm::mat4 SMBlock::GetTransformMatrix() const
{
const glm::mat4 v_blockRotation = Rotations::GetRotationMatrix(m_xzRotation);
Expand Down
3 changes: 3 additions & 0 deletions Code/Converter/Entity/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ class SMBlock final : public SMEntityWithUuid
SMColor GetColor() const override;
EntityType Type() const override;
char* GetMtlNameCStr(const std::string_view& material, const std::size_t idx, char* pCString) const override;
void GetMtlNameString(std::string& outString, const std::string_view& material, const std::size_t idx) const override;
std::size_t GetGltfMaterialEntry(GltfWriterContext& context, const std::string_view& material, const std::size_t idx) const override;
std::string GetMtlName(const std::size_t idx) const override;
void FillTextureMap(EntityTextureMap& textureMap) const override;
void WriteObjectToFile(std::ofstream& file, WriterOffsetData& offset, const glm::mat4& transform) const override;
void WriteObjectToFileGltf(GltfWriterContext& context, const glm::mat4& transform) const override;
glm::mat4 GetTransformMatrix() const override;

private:
Expand Down
10 changes: 10 additions & 0 deletions Code/Converter/Entity/Blueprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ void SMBlueprint::WriteObjectToFile(
v_pCurEntity->WriteObjectToFile(file, offset, v_blueprintTransform);
}

void SMBlueprint::WriteObjectToFileGltf(
GltfWriterContext& context,
const glm::mat4& transform) const
{
const glm::mat4 v_blueprintTransform = transform * this->GetTransformMatrix();

for (const SMEntity* v_pCurEntity : m_objects)
v_pCurEntity->WriteObjectToFileGltf(context, v_blueprintTransform);
}

std::size_t SMBlueprint::GetAmountOfObjects() const
{
std::size_t v_output = 0;
Expand Down
1 change: 1 addition & 0 deletions Code/Converter/Entity/Blueprint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SMBlueprint final : public SMEntity
EntityType Type() const override;
void FillTextureMap(EntityTextureMap& textureMap) const override;
void WriteObjectToFile(std::ofstream& file, WriterOffsetData& offset, const glm::mat4& transform) const override;
void WriteObjectToFileGltf(GltfWriterContext& context, const glm::mat4& transform) const override;
std::size_t GetAmountOfObjects() const override;
void CalculateCenterPoint(glm::vec3& outInput) const override;

Expand Down
32 changes: 30 additions & 2 deletions Code/Converter/Entity/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ char* SMEntity::GetMtlNameCStr(
return pCString;
}

void SMEntity::GetMtlNameString(
std::string& outString,
const std::string_view& material,
const std::size_t idx) const
{}

std::size_t SMEntity::GetGltfMaterialEntry(
GltfWriterContext& context,
const std::string_view& material,
const std::size_t idx) const
{
return std::size_t(-1);
}

std::string SMEntity::GetMtlName(const std::size_t idx) const
{
return "";
Expand All @@ -127,6 +141,11 @@ void SMEntity::WriteObjectToFile(
const glm::mat4& transform) const
{}

void SMEntity::WriteObjectToFileGltf(
GltfWriterContext& context,
const glm::mat4& transform) const
{}

void SMEntity::CalculateCenterPoint(glm::vec3& outInput) const
{
outInput += m_position;
Expand Down Expand Up @@ -219,9 +238,18 @@ void SMEntityWithModel::WriteObjectToFile(
WriterOffsetData& offset,
const glm::mat4& transform) const
{
const glm::mat4 model_matrix = transform * this->GetTransformMatrix();
const glm::mat4 v_modelMatrix = transform * this->GetTransformMatrix();
m_model->WriteToFile(v_modelMatrix, offset, file, this);

m_model->WriteToFile(model_matrix, offset, file, this);
ProgCounter::ProgressValue++;
}

void SMEntityWithModel::WriteObjectToFileGltf(
GltfWriterContext& context,
const glm::mat4& transform) const
{
const glm::mat4 v_modelMatrix = transform * this->GetTransformMatrix();
m_model->WriteToFileGltf(context, v_modelMatrix, this);

ProgCounter::ProgressValue++;
}
Expand Down
Loading