Mesh: Replace auto smooth with node group #108014
|
@ -218,9 +218,10 @@ void AssetList::ensurePreviewsJob(const bContext *C)
|
|||
int numfiles = filelist_files_ensure(files);
|
||||
|
||||
filelist_cache_previews_set(files, true);
|
||||
filelist_file_cache_slidingwindow_set(files, 128);
|
||||
/* TODO fetch all previews for now. */
|
||||
filelist_file_cache_block(files, numfiles / 2);
|
||||
/* Add one extra entry to ensure nothing is lost because of integer division. */
|
||||
filelist_file_cache_slidingwindow_set(files, numfiles / 2 + 1);
|
||||
filelist_file_cache_block(files, 0);
|
||||
filelist_cache_previews_update(files);
|
||||
|
||||
{
|
||||
|
|
|
@ -84,6 +84,29 @@ static const char *temp_textures_dir()
|
|||
return temp_dir;
|
||||
}
|
||||
|
||||
using blender::io::usd::ShaderToNodeMap;
|
||||
|
||||
/* Returns the Blender node previously cached for
|
||||
* the given USD shader in the given map. Returns
|
||||
* null if no cached shader was found. */
|
||||
static bNode *get_cached_node(const ShaderToNodeMap &node_cache,
|
||||
const pxr::UsdShadeShader &usd_shader)
|
||||
{
|
||||
if (bNode *const *node_ptr = node_cache.lookup_ptr(usd_shader.GetPath().GetAsString())) {
|
||||
return *node_ptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Cache the Blender node translated from the given USD shader
|
||||
* in the given map. */
|
||||
static void cache_node(ShaderToNodeMap &node_cache,
|
||||
const pxr::UsdShadeShader &usd_shader,
|
||||
bNode *node)
|
||||
{
|
||||
node_cache.add(usd_shader.GetPath().GetAsString(), node);
|
||||
}
|
||||
|
||||
/* Add a node of the given type at the given location coordinates. */
|
||||
static bNode *add_node(
|
||||
const bContext *C, bNodeTree *ntree, const int type, const float locx, const float locy)
|
||||
|
@ -627,12 +650,15 @@ void USDMaterialReader::convert_usd_uv_texture(const pxr::UsdShadeShader &usd_sh
|
|||
return;
|
||||
}
|
||||
|
||||
bNode *tex_image = get_cached_node(r_ctx->node_cache, usd_shader);
|
||||
|
||||
if (tex_image == nullptr) {
|
||||
float locx = 0.0f;
|
||||
float locy = 0.0f;
|
||||
compute_node_loc(column, &locx, &locy, r_ctx);
|
||||
|
||||
/* Create the Texture Image node. */
|
||||
bNode *tex_image = add_node(nullptr, ntree, SH_NODE_TEX_IMAGE, locx, locy);
|
||||
tex_image = add_node(nullptr, ntree, SH_NODE_TEX_IMAGE, locx, locy);
|
||||
|
||||
if (!tex_image) {
|
||||
std::cerr << "ERROR: Couldn't create SH_NODE_TEX_IMAGE for node input " << dest_socket_name
|
||||
|
@ -640,8 +666,12 @@ void USDMaterialReader::convert_usd_uv_texture(const pxr::UsdShadeShader &usd_sh
|
|||
return;
|
||||
}
|
||||
|
||||
/* Cache newly created node. */
|
||||
cache_node(r_ctx->node_cache, usd_shader, tex_image);
|
||||
|
||||
/* Load the texture image. */
|
||||
load_tex_image(usd_shader, tex_image);
|
||||
}
|
||||
|
||||
/* Connect to destination node input. */
|
||||
|
||||
|
@ -779,12 +809,15 @@ void USDMaterialReader::convert_usd_primvar_reader_float2(
|
|||
return;
|
||||
}
|
||||
|
||||
bNode *uv_map = get_cached_node(r_ctx->node_cache, usd_shader);
|
||||
|
||||
if (uv_map == nullptr) {
|
||||
float locx = 0.0f;
|
||||
float locy = 0.0f;
|
||||
compute_node_loc(column, &locx, &locy, r_ctx);
|
||||
|
||||
/* Create the UV Map node. */
|
||||
bNode *uv_map = add_node(nullptr, ntree, SH_NODE_UVMAP, locx, locy);
|
||||
uv_map = add_node(nullptr, ntree, SH_NODE_UVMAP, locx, locy);
|
||||
|
||||
if (!uv_map) {
|
||||
std::cerr << "ERROR: Couldn't create SH_NODE_UVMAP for node input " << dest_socket_name
|
||||
|
@ -792,6 +825,9 @@ void USDMaterialReader::convert_usd_primvar_reader_float2(
|
|||
return;
|
||||
}
|
||||
|
||||
/* Cache newly created node. */
|
||||
cache_node(r_ctx->node_cache, usd_shader, uv_map);
|
||||
|
||||
/* Set the texmap name. */
|
||||
pxr::UsdShadeInput varname_input = usd_shader.GetInput(usdtokens::varname);
|
||||
|
||||
|
@ -821,6 +857,7 @@ void USDMaterialReader::convert_usd_primvar_reader_float2(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Connect to destination node input. */
|
||||
link_nodes(ntree, uv_map, "UV", dest_node, dest_socket_name);
|
||||
|
|
|
@ -4,9 +4,11 @@
|
|||
|
||||
#include "usd.h"
|
||||
|
||||
#include "BLI_map.hh"
|
||||
|
||||
#include <pxr/usd/usdShade/material.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
struct Main;
|
||||
struct Material;
|
||||
|
@ -15,6 +17,8 @@ struct bNodeTree;
|
|||
|
||||
namespace blender::io::usd {
|
||||
|
||||
using ShaderToNodeMap = blender::Map<std::string, bNode *>;
|
||||
|
||||
/* Helper struct used when arranging nodes in columns, keeping track the
|
||||
* occupancy information for a given column. I.e., for column n,
|
||||
* column_offsets[n] is the y-offset (from top to bottom) of the occupied
|
||||
|
@ -26,6 +30,12 @@ struct NodePlacementContext {
|
|||
const float horizontal_step;
|
||||
const float vertical_step;
|
||||
|
||||
/* Map a USD shader prim path to the Blender node converted
|
||||
* from that shader. This map is updated during shader
|
||||
* conversion and is used to avoid creating duplicate nodes
|
||||
* for a given shader. */
|
||||
ShaderToNodeMap node_cache;
|
||||
|
||||
NodePlacementContext(float in_origx,
|
||||
float in_origy,
|
||||
float in_horizontal_step = 300.0f,
|
||||
|
|
Loading…
Reference in New Issue