44 "array size mismatch");
51 const char *identifier,
63 switch (property_type) {
68 r_property[0] = socket_def_value->
value;
98 const char *dest_socket_id,
101 r_linked_sockets.
clear();
108 for (
const bNodeSocket *curr_socket : dest_inputs) {
109 if (
STREQ(curr_socket->identifier, dest_socket_id)) {
110 dest_socket = curr_socket;
116 r_linked_sockets.
resize(linked_sockets.
size());
117 r_linked_sockets = linked_sockets;
127 const bNode &parent_node = socket->owner_node();
144 Image *tex_image =
reinterpret_cast<Image *
>(tex_node->
id);
153 "Packed image found:'%s'. Unpack and place the image in the same "
154 "directory as the .MTL file.",
160 STRNCPY(filepath, tex_image->filepath);
183 for (
const bNode *
node : nodetree->nodes_by_type(
"ShaderNodeOutputMaterial"_ustr)) {
185 for (
const bNodeSocket *out_sock : node_input_socket0.directly_linked_sockets()) {
186 const bNode &in_node = out_sock->owner_node();
202 float roughness = material->roughness;
207 float spec_exponent = (1.0f - roughness);
208 spec_exponent *= spec_exponent * 1000.0f;
210 float specular = material->spec;
215 float metallic = material->metallic;
220 float refraction_index = 1.0f;
225 float alpha = material->a;
229 const bool transparent = alpha != 1.0f;
231 float3 diffuse_col = {material->r, material->g, material->b};
236 float3 emission_col{0.0f};
237 float emission_strength = 0.0f;
242 mul_v3_fl(emission_col, emission_strength);
246 float coat_roughness = -1.0f;
248 float aniso_rot = -1.0f;
249 float transmission = -1.0f;
265 if (specular == 0.0f) {
269 else if (metallic > 0.0f) {
280 else if (transparent) {
285 if (metallic != 0.0f) {
291 r_mtl_mat.
color = diffuse_col;
292 r_mtl_mat.
spec_color = {specular, specular, specular};
294 r_mtl_mat.
ior = refraction_index;
295 r_mtl_mat.
alpha = alpha;
302 r_mtl_mat.
aniso = aniso;
304 r_mtl_mat.
transmit_color = {transmission, transmission, transmission};
315 if (!material || !node_tree || !bsdf_node) {
328 const bNode *normal_map_node{
nullptr};
342 float emission_strength = 0.0f;
344 SOCK_FLOAT, bsdf_node,
"Emission Strength", {&emission_strength, 1});
345 if (emission_strength == 0.0f) {
360 if (tex_image_filepath.empty()) {
368 if (normal_map_node) {
385 mtlmat.
name = std::string(material->id.name + 2);
386 std::replace(mtlmat.
name.begin(), mtlmat.
name.end(),
' ',
'_');
387 const bNodeTree *nodetree = material->nodetree;
388 if (nodetree !=
nullptr) {
389 nodetree->ensure_topology_cache();
#define SH_NODE_TEX_IMAGE
#define SH_NODE_BSDF_PRINCIPLED
#define SH_NODE_NORMAL_MAP
#define CLOG_INFO(clg_ref,...)
constexpr int64_t size() const
constexpr T * data() const
constexpr const T & first() const
constexpr int64_t size() const
void resize(const int64_t new_size)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
std::string filename(const std::string_view &str, size_t pos)
const char * tex_map_type_to_socket_id[]
static const bNode * get_node_of_type(Span< const bNodeSocket * > sockets_list, const int node_type)
static std::string get_image_filepath(const bNode *tex_node)
static const bNode * find_bsdf_node(const bNodeTree *nodetree)
static void store_bsdf_properties(const bNode *bsdf_node, const Material *material, MTLMaterial &r_mtl_mat)
MTLMaterial mtlmaterial_for_material(const Material *material)
BLI_STATIC_ASSERT(ARRAY_SIZE(tex_map_type_to_string)==int(MTLTexMapType::Count), "array size mismatch")
static void copy_property_from_node(const eNodeSocketDatatype property_type, const bNode *node, const char *identifier, MutableSpan< float > r_property)
static void store_image_textures(const bNode *bsdf_node, const bNodeTree *node_tree, const Material *material, MTLMaterial &r_mtl_mat)
static void linked_sockets_to_dest_id(const bNode *dest_node, const bNodeTree &node_tree, const char *dest_socket_id, Vector< const bNodeSocket * > &r_linked_sockets)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
char * STRNCPY(char(&dst)[N], const char *src)
MINLINE void copy_v3_v3(float r[3], const float a[3])
bool BKE_image_has_filepath(const Image *ima)
MINLINE void mul_v3_fl(float r[3], float f)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
int BLI_path_sequence_decode(const char *path, char *head, size_t head_maxncpy, char *tail, size_t tail_maxncpy, unsigned short *r_digits_len)
void BLI_path_sequence_encode(char *path, size_t path_maxncpy, const char *head, const char *tail, unsigned short numlen, int pic)
VecBase< float, 3 > float3
bool BKE_image_has_packedfile(const Image *image)
closure color sheen(normal N, float roughness)
bke::bNodeType * typeinfo
MTLTexMap texture_maps[int(MTLTexMapType::Count)]