Skip to content

Commit

Permalink
Refactor. Rename variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Apr 27, 2024
1 parent 2140153 commit f0ceaa7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
22 changes: 11 additions & 11 deletions src/tydra/obj-export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ bool export_to_obj(const RenderScene &scene, const int mesh_id,
// Emit PBR material: https://github.com/tinyobjloader/tinyobjloader/blob/release/pbr-mtl.md

if (scene.materials[mat_id].surfaceShader.diffuseColor.is_texture()) {
int32_t texId = scene.materials[mat_id].surfaceShader.diffuseColor.textureId;
int32_t texId = scene.materials[mat_id].surfaceShader.diffuseColor.texture_id;
if ((texId < 0) || (texId >= int(scene.textures.size()))) {
PUSH_ERROR_AND_RETURN(fmt::format("Invalid texture id {}. scene.textures.size = {}", texId, scene.textures.size()));
}
Expand All @@ -235,7 +235,7 @@ bool export_to_obj(const RenderScene &scene, const int mesh_id,

if (scene.materials[mat_id].surfaceShader.useSpecularWorkFlow) {
if (scene.materials[mat_id].surfaceShader.specularColor.is_texture()) {
int32_t texId = scene.materials[mat_id].surfaceShader.specularColor.textureId;
int32_t texId = scene.materials[mat_id].surfaceShader.specularColor.texture_id;
if ((texId < 0) || (texId >= int(scene.textures.size()))) {
PUSH_ERROR_AND_RETURN(fmt::format("Invalid texture id {}. scene.textures.size = {}", texId, scene.textures.size()));
}
Expand All @@ -257,7 +257,7 @@ bool export_to_obj(const RenderScene &scene, const int mesh_id,
} else {

if (scene.materials[mat_id].surfaceShader.metallic.is_texture()) {
int32_t texId = scene.materials[mat_id].surfaceShader.metallic.textureId;
int32_t texId = scene.materials[mat_id].surfaceShader.metallic.texture_id;
if ((texId < 0) || (texId >= int(scene.textures.size()))) {
PUSH_ERROR_AND_RETURN(fmt::format("Invalid texture id {}. scene.textures.size = {}", texId, scene.textures.size()));
}
Expand All @@ -279,7 +279,7 @@ bool export_to_obj(const RenderScene &scene, const int mesh_id,
}

if (scene.materials[mat_id].surfaceShader.roughness.is_texture()) {
int32_t texId = scene.materials[mat_id].surfaceShader.roughness.textureId;
int32_t texId = scene.materials[mat_id].surfaceShader.roughness.texture_id;
if ((texId < 0) || (texId >= int(scene.textures.size()))) {
PUSH_ERROR_AND_RETURN(fmt::format("Invalid texture id {}. scene.textures.size = {}", texId, scene.textures.size()));
}
Expand All @@ -300,7 +300,7 @@ bool export_to_obj(const RenderScene &scene, const int mesh_id,
}

if (scene.materials[mat_id].surfaceShader.emissiveColor.is_texture()) {
int32_t texId = scene.materials[mat_id].surfaceShader.emissiveColor.textureId;
int32_t texId = scene.materials[mat_id].surfaceShader.emissiveColor.texture_id;
if ((texId < 0) || (texId >= int(scene.textures.size()))) {
PUSH_ERROR_AND_RETURN(fmt::format("Invalid texture id {}. scene.textures.size = {}", texId, scene.textures.size()));
}
Expand All @@ -322,7 +322,7 @@ bool export_to_obj(const RenderScene &scene, const int mesh_id,


if (scene.materials[mat_id].surfaceShader.opacity.is_texture()) {
int32_t texId = scene.materials[mat_id].surfaceShader.opacity.textureId;
int32_t texId = scene.materials[mat_id].surfaceShader.opacity.texture_id;
if ((texId < 0) || (texId >= int(scene.textures.size()))) {
PUSH_ERROR_AND_RETURN(fmt::format("Invalid texture id {}. scene.textures.size = {}", texId, scene.textures.size()));
}
Expand All @@ -344,7 +344,7 @@ bool export_to_obj(const RenderScene &scene, const int mesh_id,

// emit as cleacoat thickness
if (scene.materials[mat_id].surfaceShader.clearcoat.is_texture()) {
int32_t texId = scene.materials[mat_id].surfaceShader.clearcoat.textureId;
int32_t texId = scene.materials[mat_id].surfaceShader.clearcoat.texture_id;
if ((texId < 0) || (texId >= int(scene.textures.size()))) {
PUSH_ERROR_AND_RETURN(fmt::format("Invalid texture id {}. scene.textures.size = {}", texId, scene.textures.size()));
}
Expand All @@ -365,7 +365,7 @@ bool export_to_obj(const RenderScene &scene, const int mesh_id,
}

if (scene.materials[mat_id].surfaceShader.clearcoatRoughness.is_texture()) {
int32_t texId = scene.materials[mat_id].surfaceShader.clearcoatRoughness.textureId;
int32_t texId = scene.materials[mat_id].surfaceShader.clearcoatRoughness.texture_id;
if ((texId < 0) || (texId >= int(scene.textures.size()))) {
PUSH_ERROR_AND_RETURN(fmt::format("Invalid texture id {}. scene.textures.size = {}", texId, scene.textures.size()));
}
Expand All @@ -386,7 +386,7 @@ bool export_to_obj(const RenderScene &scene, const int mesh_id,
}

if (scene.materials[mat_id].surfaceShader.ior.is_texture()) {
int32_t texId = scene.materials[mat_id].surfaceShader.ior.textureId;
int32_t texId = scene.materials[mat_id].surfaceShader.ior.texture_id;
if ((texId < 0) || (texId >= int(scene.textures.size()))) {
PUSH_ERROR_AND_RETURN(fmt::format("Invalid texture id {}. scene.textures.size = {}", texId, scene.textures.size()));
}
Expand All @@ -408,7 +408,7 @@ bool export_to_obj(const RenderScene &scene, const int mesh_id,
}

if (scene.materials[mat_id].surfaceShader.occlusion.is_texture()) {
int32_t texId = scene.materials[mat_id].surfaceShader.occlusion.textureId;
int32_t texId = scene.materials[mat_id].surfaceShader.occlusion.texture_id;
if ((texId < 0) || (texId >= int(scene.textures.size()))) {
PUSH_ERROR_AND_RETURN(fmt::format("Invalid texture id {}. scene.textures.size = {}", texId, scene.textures.size()));
}
Expand All @@ -430,7 +430,7 @@ bool export_to_obj(const RenderScene &scene, const int mesh_id,
}

if (scene.materials[mat_id].surfaceShader.ior.is_texture()) {
int32_t texId = scene.materials[mat_id].surfaceShader.ior.textureId;
int32_t texId = scene.materials[mat_id].surfaceShader.ior.texture_id;
if ((texId < 0) || (texId >= int(scene.textures.size()))) {
PUSH_ERROR_AND_RETURN(fmt::format("Invalid texture id {}. scene.textures.size = {}", texId, scene.textures.size()));
}
Expand Down
28 changes: 14 additions & 14 deletions src/tydra/render-data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,7 @@ bool ListUVNames(const RenderMaterial &material,
StringAndIdMap &si_map) {
// TODO: Use auto
auto fun_vec3 = [&](const ShaderParam<vec3> &param) {
int32_t texId = param.textureId;
int32_t texId = param.texture_id;
if ((texId >= 0) && (size_t(texId) < textures.size())) {
const UVTexture &tex = textures[size_t(texId)];
if (tex.varname_uv.size()) {
Expand All @@ -2310,7 +2310,7 @@ bool ListUVNames(const RenderMaterial &material,
};

auto fun_float = [&](const ShaderParam<float> &param) {
int32_t texId = param.textureId;
int32_t texId = param.texture_id;
if ((texId >= 0) && (size_t(texId) < textures.size())) {
const UVTexture &tex = textures[size_t(texId)];
if (tex.varname_uv.size()) {
Expand Down Expand Up @@ -4711,7 +4711,7 @@ bool RenderSceneConverter::ConvertPreviewSurfaceShaderParam(
DCOUT(fmt::format("TexId {} = {}",
shader_abs_path.prim_part() + ".diffuseColor", texId));

dst_param.textureId = int32_t(texId);
dst_param.texture_id = int32_t(texId);

return true;
} else {
Expand Down Expand Up @@ -6742,87 +6742,87 @@ std::string DumpPreviewSurface(const PreviewSurfaceShader &shader,

ss << pprint::Indent(indent + 1) << "diffuseColor = ";
if (shader.diffuseColor.is_texture()) {
ss << "textureId[" << shader.diffuseColor.textureId << "]";
ss << "texture_id[" << shader.diffuseColor.texture_id << "]";
} else {
ss << shader.diffuseColor.value;
}
ss << "\n";

ss << pprint::Indent(indent + 1) << "metallic = ";
if (shader.metallic.is_texture()) {
ss << "textureId[" << shader.metallic.textureId << "]";
ss << "texture_id[" << shader.metallic.texture_id << "]";
} else {
ss << shader.metallic.value;
}
ss << "\n";

ss << pprint::Indent(indent + 1) << "roughness = ";
if (shader.roughness.is_texture()) {
ss << "textureId[" << shader.roughness.textureId << "]";
ss << "texture_id[" << shader.roughness.texture_id << "]";
} else {
ss << shader.roughness.value;
}
ss << "\n";

ss << pprint::Indent(indent + 1) << "ior = ";
if (shader.ior.is_texture()) {
ss << "textureId[" << shader.ior.textureId << "]";
ss << "texture_id[" << shader.ior.texture_id << "]";
} else {
ss << shader.ior.value;
}
ss << "\n";

ss << pprint::Indent(indent + 1) << "clearcoat = ";
if (shader.clearcoat.is_texture()) {
ss << "textureId[" << shader.clearcoat.textureId << "]";
ss << "texture_id[" << shader.clearcoat.texture_id << "]";
} else {
ss << shader.clearcoat.value;
}
ss << "\n";

ss << pprint::Indent(indent + 1) << "clearcoatRoughness = ";
if (shader.clearcoatRoughness.is_texture()) {
ss << "textureId[" << shader.clearcoatRoughness.textureId << "]";
ss << "texture_id[" << shader.clearcoatRoughness.texture_id << "]";
} else {
ss << shader.clearcoatRoughness.value;
}
ss << "\n";

ss << pprint::Indent(indent + 1) << "opacity = ";
if (shader.opacity.is_texture()) {
ss << "textureId[" << shader.opacity.textureId << "]";
ss << "texture_id[" << shader.opacity.texture_id << "]";
} else {
ss << shader.opacity.value;
}
ss << "\n";

ss << pprint::Indent(indent + 1) << "opacityThreshold = ";
if (shader.opacityThreshold.is_texture()) {
ss << "textureId[" << shader.opacityThreshold.textureId << "]";
ss << "texture_id[" << shader.opacityThreshold.texture_id << "]";
} else {
ss << shader.opacityThreshold.value;
}
ss << "\n";

ss << pprint::Indent(indent + 1) << "normal = ";
if (shader.normal.is_texture()) {
ss << "textureId[" << shader.normal.textureId << "]";
ss << "texture_id[" << shader.normal.texture_id << "]";
} else {
ss << shader.normal.value;
}
ss << "\n";

ss << pprint::Indent(indent + 1) << "displacement = ";
if (shader.displacement.is_texture()) {
ss << "textureId[" << shader.displacement.textureId << "]";
ss << "texture_id[" << shader.displacement.texture_id << "]";
} else {
ss << shader.displacement.value;
}
ss << "\n";

ss << pprint::Indent(indent + 1) << "occlusion = ";
if (shader.occlusion.is_texture()) {
ss << "textureId[" << shader.occlusion.textureId << "]";
ss << "texture_id[" << shader.occlusion.texture_id << "]";
} else {
ss << shader.occlusion.value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/tydra/render-data.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ template <typename T>
struct ShaderParam {
ShaderParam(const T &t) { value = t; }

bool is_texture() const { return textureId >= 0; }
bool is_texture() const { return texture_id >= 0; }

template <typename STy>
void set_value(const STy &val) {
Expand All @@ -1075,7 +1075,7 @@ struct ShaderParam {
}

T value;
int32_t textureId{-1}; // negative = invalid
int32_t texture_id{-1}; // negative = invalid
};

// UsdPreviewSurface
Expand Down
Loading

0 comments on commit f0ceaa7

Please sign in to comment.