Skip to content

Commit

Permalink
improve-heatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouhang95 committed Dec 17, 2024
1 parent b518b64 commit 5cd56e4
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions zeno/src/nodes/mtl/ShaderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ struct SmartTexture2D : ShaderNodeClone<SmartTexture2D>
auto texId = em->tex2Ds.size();
auto tex = std::make_shared<zeno::Texture2DObject>();
auto texture_path = get_input2<std::string>("path");
if (has_input("heatmap")) {
if (texture_path.empty()) {
std::srand(std::time(0));
texture_path = std::filesystem::temp_directory_path().string() + '/' + "heatmap-" + std::to_string(std::rand()) + ".png";
}
auto heatmap = get_input<zeno::HeatmapObject>("heatmap");
std::vector<uint8_t> col;
int width = heatmap->colors.size();
int height = width;
col.reserve(width * height * 3);
for (auto i = 0; i < height; i++) {
for (auto & color : heatmap->colors) {
col.push_back(zeno::clamp(int(color[0] * 255.99), 0, 255));
col.push_back(zeno::clamp(int(color[1] * 255.99), 0, 255));
col.push_back(zeno::clamp(int(color[2] * 255.99), 0, 255));
}
}
stbi_flip_vertically_on_write(false);
stbi_write_png(texture_path.c_str(), width, height, 3, col.data(), 0);
}
if(!std::filesystem::exists(std::filesystem::u8path(texture_path))){
zeno::log_warn("texture file not found!");
auto type = get_input2<std::string>("type");
Expand Down Expand Up @@ -242,26 +262,6 @@ struct SmartTexture2D : ShaderNodeClone<SmartTexture2D>
}

tex->path = texture_path;
if (has_input("heatmap")) {
if (tex->path.empty()) {
std::srand(std::time(0));
tex->path = std::filesystem::temp_directory_path().string() + '/' + "heatmap-" + std::to_string(std::rand()) + ".png";
}
auto heatmap = get_input<zeno::HeatmapObject>("heatmap");
std::vector<uint8_t> col;
int width = heatmap->colors.size();
int height = width;
col.reserve(width * height * 3);
for (auto i = 0; i < height; i++) {
for (auto & color : heatmap->colors) {
col.push_back(zeno::clamp(int(color[0] * 255.99), 0, 255));
col.push_back(zeno::clamp(int(color[1] * 255.99), 0, 255));
col.push_back(zeno::clamp(int(color[2] * 255.99), 0, 255));
}
}
stbi_flip_vertically_on_write(false);
stbi_write_png(tex->path.c_str(), width, height, 3, col.data(), 0);
}
tex->blockCompression = get_input2<bool>("blockCompression");

#define SET_TEX_WRAP(TEX, WRAP) \
Expand Down

0 comments on commit 5cd56e4

Please sign in to comment.