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 2679
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
95 changes: 89 additions & 6 deletions Code/Converter/Entity/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,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 +149,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 +183,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 +213,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 +236,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 +258,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
1 change: 1 addition & 0 deletions Code/Converter/Entity/Block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SMBlock final : public SMEntityWithUuid
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
18 changes: 16 additions & 2 deletions Code/Converter/Entity/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,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 +224,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);

ProgCounter::ProgressValue++;
}

m_model->WriteToFile(model_matrix, offset, file, this);
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
4 changes: 4 additions & 0 deletions Code/Converter/Entity/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class SMC_NOVTABLE SMEntity
virtual std::string GetMtlName(const std::size_t idx) const;
virtual void FillTextureMap(EntityTextureMap& textureMap) const = 0;
virtual void WriteObjectToFile(std::ofstream& file, WriterOffsetData& offset, const glm::mat4& transform) const;
virtual void WriteObjectToFileGltf(GltfWriterContext& context, const glm::mat4& transform) const;
virtual void CalculateCenterPoint(glm::vec3& outInput) const;
virtual std::size_t GetAmountOfObjects() const;
virtual SMColor GetColor() const;
Expand Down Expand Up @@ -139,6 +140,9 @@ class SMC_NOVTABLE SMEntityWithModel : public SMEntity
std::ofstream& file,
WriterOffsetData& offset,
const glm::mat4& transform) const override;
void WriteObjectToFileGltf(
GltfWriterContext& context,
const glm::mat4& transform) const override;

protected:
Model* m_model;
Expand Down
Loading