Syntax changes, removed rotation in usd file format
This commit is contained in:
@@ -22,7 +22,7 @@ namespace OpenVulkano::Scene
|
|||||||
{
|
{
|
||||||
std::ofstream file(filePath);
|
std::ofstream file(filePath);
|
||||||
|
|
||||||
if (!file.is_open())
|
if (!file.is_open()) [[unlikely]]
|
||||||
throw std::runtime_error("Failed to open file '" + filePath + "' for writing!");
|
throw std::runtime_error("Failed to open file '" + filePath + "' for writing!");
|
||||||
|
|
||||||
WriteObjContents(geometry, "", file);
|
WriteObjContents(geometry, "", file);
|
||||||
@@ -32,7 +32,7 @@ namespace OpenVulkano::Scene
|
|||||||
void MeshWriter::WriteAsUSD(Geometry* geometry, const std::string& filePath)
|
void MeshWriter::WriteAsUSD(Geometry* geometry, const std::string& filePath)
|
||||||
{
|
{
|
||||||
std::ofstream file(filePath);
|
std::ofstream file(filePath);
|
||||||
if (!file.is_open())
|
if (!file.is_open()) [[unlikely]]
|
||||||
throw std::runtime_error("Failed to open file '" + filePath + "' for writing!");
|
throw std::runtime_error("Failed to open file '" + filePath + "' for writing!");
|
||||||
WriteUsdContents(file, geometry);
|
WriteUsdContents(file, geometry);
|
||||||
file.close();
|
file.close();
|
||||||
@@ -45,20 +45,19 @@ namespace OpenVulkano::Scene
|
|||||||
{
|
{
|
||||||
std::stringstream objContents;
|
std::stringstream objContents;
|
||||||
WriteObjContents(geometry, DEFAULT_OBJ_MATERIAL_NAME, objContents);
|
WriteObjContents(geometry, DEFAULT_OBJ_MATERIAL_NAME, objContents);
|
||||||
auto objContentsStr = objContents.str();
|
std::string objContentsStr = objContents.str();
|
||||||
auto objDesc = OpenVulkano::FileDescription::MakeDescriptionForFile("model.obj", objContentsStr.size());
|
FileDescription objDesc = FileDescription::MakeDescriptionForFile("model.obj", objContentsStr.size());
|
||||||
zipWriter.AddFile(objDesc, objContentsStr.data());
|
zipWriter.AddFile(objDesc, objContentsStr.data());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto mtlContentsStr = DEFAULT_OBJ_MATERIAL_CONTENTS;
|
FileDescription mtlDesc = FileDescription::MakeDescriptionForFile("material.mtl", DEFAULT_OBJ_MATERIAL_CONTENTS.size());
|
||||||
auto mtlDesc = OpenVulkano::FileDescription::MakeDescriptionForFile("material.mtl", mtlContentsStr.size());
|
zipWriter.AddFile(mtlDesc, DEFAULT_OBJ_MATERIAL_CONTENTS.data());
|
||||||
zipWriter.AddFile(mtlDesc, mtlContentsStr.data());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!texturePath.empty() && std::filesystem::exists(texturePath))
|
if (!texturePath.empty() && std::filesystem::exists(texturePath))
|
||||||
{
|
{
|
||||||
auto textureFile = MemMappedFile(texturePath);
|
MemMappedFile textureFile(texturePath);
|
||||||
auto texDesc = OpenVulkano::FileDescription::MakeDescriptionForFile("texture.png", textureFile.Size());
|
FileDescription texDesc = FileDescription::MakeDescriptionForFile("texture.png", textureFile.Size());
|
||||||
zipWriter.AddFile(texDesc, textureFile.Data());
|
zipWriter.AddFile(texDesc, textureFile.Data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,15 +69,15 @@ namespace OpenVulkano::Scene
|
|||||||
{
|
{
|
||||||
std::stringstream usdFile;
|
std::stringstream usdFile;
|
||||||
WriteUsdContents(usdFile, geometry);
|
WriteUsdContents(usdFile, geometry);
|
||||||
auto usdFileStr = usdFile.str();
|
std::string usdFileStr = usdFile.str();
|
||||||
auto usdDesc = OpenVulkano::FileDescription::MakeDescriptionForFile("geometry.usda", usdFileStr.size());
|
FileDescription usdDesc = FileDescription::MakeDescriptionForFile("geometry.usda", usdFileStr.size());
|
||||||
zipWriter.AddFile(usdDesc, usdFileStr.data());
|
zipWriter.AddFile(usdDesc, usdFileStr.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!texturePath.empty() && std::filesystem::exists(texturePath))
|
if (!texturePath.empty() && std::filesystem::exists(texturePath))
|
||||||
{
|
{
|
||||||
auto textureFile = MemMappedFile(texturePath);
|
MemMappedFile textureFile(texturePath);
|
||||||
auto texDesc = OpenVulkano::FileDescription::MakeDescriptionForFile("texture.png", textureFile.Size());
|
FileDescription texDesc = FileDescription::MakeDescriptionForFile("texture.png", textureFile.Size());
|
||||||
zipWriter.AddFile(texDesc, textureFile.Data());
|
zipWriter.AddFile(texDesc, textureFile.Data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,31 +29,41 @@ map_Kd texture.png
|
|||||||
|
|
||||||
if (materialName.size() != 0)
|
if (materialName.size() != 0)
|
||||||
{
|
{
|
||||||
objContent << "mtllib material.mtl\n";
|
std::string_view content = "mtllib material.mtl\n";
|
||||||
objContent << "usemtl " << materialName << "\n";
|
objContent.write(content.data(), content.size());
|
||||||
|
|
||||||
|
content = "usemtl ";
|
||||||
|
objContent.write(content.data(), content.size());
|
||||||
|
|
||||||
|
objContent.write(materialName.data(), materialName.size());
|
||||||
|
objContent.write("\n", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < geometry->vertexCount; ++i)
|
for (int i = 0; i < geometry->vertexCount; ++i)
|
||||||
{
|
{
|
||||||
const auto& v = geometry->vertices[i];
|
const auto& v = geometry->vertices[i];
|
||||||
objContent << fmt::format("v {} {} {}\n", v.position.x, v.position.y, v.position.z);
|
const std::string content = fmt::format("v {} {} {}\n", v.position.x, v.position.y, v.position.z);
|
||||||
|
objContent.write(content.data(), content.size());
|
||||||
}
|
}
|
||||||
for (int i = 0; i < geometry->vertexCount; ++i)
|
for (int i = 0; i < geometry->vertexCount; ++i)
|
||||||
{
|
{
|
||||||
const auto& v = geometry->vertices[i];
|
const auto& v = geometry->vertices[i];
|
||||||
objContent << fmt::format("vn {} {} {}\n", v.normal.x, v.normal.y, v.normal.z);
|
const std::string content = fmt::format("vn {} {} {}\n", v.normal.x, v.normal.y, v.normal.z);
|
||||||
|
objContent.write(content.data(), content.size());
|
||||||
}
|
}
|
||||||
for (int i = 0; i < geometry->vertexCount; ++i)
|
for (int i = 0; i < geometry->vertexCount; ++i)
|
||||||
{
|
{
|
||||||
const auto& v = geometry->vertices[i];
|
const auto& v = geometry->vertices[i];
|
||||||
objContent << fmt::format("vt {} {}\n", v.textureCoordinates.x, v.textureCoordinates.y);
|
const std::string content = fmt::format("vt {} {}\n", v.textureCoordinates.x, v.textureCoordinates.y);
|
||||||
|
objContent.write(content.data(), content.size());
|
||||||
}
|
}
|
||||||
for (int i = 0; i < geometry->indexCount; i += 3)
|
for (int i = 0; i < geometry->indexCount; i += 3)
|
||||||
{
|
{
|
||||||
uint32_t i0 = geometry->GetIndex(i + 0) + 1;
|
uint32_t i0 = geometry->GetIndex(i + 0) + 1;
|
||||||
uint32_t i1 = geometry->GetIndex(i + 1) + 1;
|
uint32_t i1 = geometry->GetIndex(i + 1) + 1;
|
||||||
uint32_t i2 = geometry->GetIndex(i + 2) + 1;
|
uint32_t i2 = geometry->GetIndex(i + 2) + 1;
|
||||||
objContent << fmt::format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", i0, i1, i2);
|
const std::string content = fmt::format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", i0, i1, i2);
|
||||||
|
objContent.write(content.data(), content.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ def Xform "root" (
|
|||||||
def Xform "model"
|
def Xform "model"
|
||||||
{
|
{
|
||||||
custom string userProperties:blender:object_name = "model"
|
custom string userProperties:blender:object_name = "model"
|
||||||
float3 xformOp:rotateXYZ = (90, -0, 0)
|
float3 xformOp:rotateXYZ = (0, -0, 0)
|
||||||
float3 xformOp:scale = (1, 1, 1)
|
float3 xformOp:scale = (1, 1, 1)
|
||||||
double3 xformOp:translate = (0, 0, 0)
|
double3 xformOp:translate = (0, 0, 0)
|
||||||
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale"]
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale"]
|
||||||
|
|||||||
Reference in New Issue
Block a user