Summary:
- Removed ReadEntireFile - ZipWriter now writes directly to a file when possible - Added GetIndex to geometry - Moved Usd and Obj generators to different files - Removed unused procedures - Deduplicated obj generators - Updated tests for ZipWriter
This commit is contained in:
158
openVulkanoCpp/Scene/UsdEncoder.hpp
Normal file
158
openVulkanoCpp/Scene/UsdEncoder.hpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "Scene/Geometry.hpp"
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
std::string GetUsdContents(OpenVulkano::Scene::Geometry* geometry, const std::string texturePath = "")
|
||||
{
|
||||
std::ostringstream result;
|
||||
std::ostringstream points, normals, indices, texCoords, faceCounts;
|
||||
points << std::fixed << std::setprecision(6);
|
||||
normals << std::fixed << std::setprecision(6);
|
||||
|
||||
for (size_t i = 0; i < geometry->vertexCount; ++i)
|
||||
{
|
||||
const auto& v = geometry->vertices[i];
|
||||
points << "(" << v.position.x << ", " << v.position.y << ", " << v.position.z << ")";
|
||||
normals << "(" << v.normal.x << ", " << v.normal.y << ", " << v.normal.z << ")";
|
||||
if (i < geometry->vertexCount - 1)
|
||||
{
|
||||
points << ", ";
|
||||
normals << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < geometry->indexCount; ++i)
|
||||
{
|
||||
indices << geometry->GetIndex(i);
|
||||
if (i < geometry->indexCount - 1)
|
||||
{
|
||||
indices << ", ";
|
||||
}
|
||||
if ((i + 1) % 3 == 0)
|
||||
{
|
||||
faceCounts << "3";
|
||||
if (i < geometry->indexCount - 1)
|
||||
{
|
||||
faceCounts << ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
texCoords << std::fixed << std::setprecision(6);
|
||||
|
||||
for (size_t i = 0; i < geometry->indexCount; ++i)
|
||||
{
|
||||
const size_t vertexIndex = geometry->GetIndex(i);
|
||||
const auto& v = geometry->vertices[vertexIndex];
|
||||
texCoords << "(" << v.textureCoordinates.x << ", " << v.textureCoordinates.y << ")";
|
||||
if (i < geometry->indexCount - 1)
|
||||
{
|
||||
texCoords << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
result << R"(#usda 1.0
|
||||
(
|
||||
defaultPrim = "root"
|
||||
doc = "Exported from OpenVulkano"
|
||||
metersPerUnit = 1
|
||||
upAxis = "Y"
|
||||
)
|
||||
|
||||
def Xform "root" (
|
||||
customData = {
|
||||
dictionary Blender = {
|
||||
bool generated = 1
|
||||
}
|
||||
}
|
||||
)
|
||||
{
|
||||
def Xform "model"
|
||||
{
|
||||
custom string userProperties:blender:object_name = "model"
|
||||
float3 xformOp:rotateXYZ = (90, -0, 0)
|
||||
float3 xformOp:scale = (1, 1, 1)
|
||||
double3 xformOp:translate = (0, 0, 0)
|
||||
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:rotateXYZ", "xformOp:scale"]
|
||||
|
||||
def Mesh "model" (
|
||||
active = true
|
||||
prepend apiSchemas = ["MaterialBindingAPI"]
|
||||
)
|
||||
{
|
||||
uniform bool doubleSided = 1
|
||||
float3[] extent = [(-0.5, -0.5, 0), (0.5, 0.5, 0)]
|
||||
int[] faceVertexCounts = [)"
|
||||
<< faceCounts.str() << R"(]
|
||||
int[] faceVertexIndices = [)"
|
||||
<< indices.str() << R"(]
|
||||
rel material:binding = </root/_materials/Material0>
|
||||
normal3f[] normals = [)"
|
||||
<< normals.str() << R"(] (
|
||||
interpolation = "faceVarying"
|
||||
)
|
||||
point3f[] points = [)"
|
||||
<< points.str() << R"(]
|
||||
texCoord2f[] primvars:st = [)"
|
||||
<< texCoords.str() << R"(] (
|
||||
interpolation = "faceVarying"
|
||||
)
|
||||
uniform token subdivisionScheme = "none"
|
||||
custom string userProperties:blender:data_name = "model"
|
||||
}
|
||||
}
|
||||
|
||||
def Scope "_materials"
|
||||
{
|
||||
def Material "Material0"
|
||||
{
|
||||
token outputs:surface.connect = </root/_materials/Material0/Principled_BSDF.outputs:surface>
|
||||
custom string userProperties:blender:data_name = "Material0"
|
||||
|
||||
def Shader "Principled_BSDF"
|
||||
{
|
||||
uniform token info:id = "UsdPreviewSurface"
|
||||
float inputs:clearcoat = 0
|
||||
float inputs:clearcoatRoughness = 0.03
|
||||
color3f inputs:diffuseColor.connect = </root/_materials/Material0/Image_Texture.outputs:rgb>
|
||||
float inputs:ior = 1.5
|
||||
float inputs:metallic = 0
|
||||
float inputs:opacity = 1
|
||||
float inputs:roughness = 1
|
||||
float inputs:specular = 0
|
||||
token outputs:surface
|
||||
}
|
||||
|
||||
def Shader "Image_Texture"
|
||||
{
|
||||
uniform token info:id = "UsdUVTexture"
|
||||
asset inputs:file = @./texture.png@
|
||||
token inputs:sourceColorSpace = "sRGB"
|
||||
float2 inputs:st.connect = </root/_materials/Material0/uvmap.outputs:result>
|
||||
token inputs:wrapS = "repeat"
|
||||
token inputs:wrapT = "repeat"
|
||||
float3 outputs:rgb
|
||||
}
|
||||
|
||||
def Shader "uvmap"
|
||||
{
|
||||
uniform token info:id = "UsdPrimvarReader_float2"
|
||||
string inputs:varname = "st"
|
||||
float2 outputs:result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)";
|
||||
return result.str();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user