41 "array size mismatch");
48 const char *identifier,
60 switch (property_type) {
65 r_property[0] = socket_def_value->
value;
95 const char *dest_socket_id,
98 r_linked_sockets.
clear();
105 for (
const bNodeSocket *curr_socket : dest_inputs) {
106 if (
STREQ(curr_socket->identifier, dest_socket_id)) {
107 dest_socket = curr_socket;
113 r_linked_sockets.
resize(linked_sockets.
size());
114 r_linked_sockets = linked_sockets;
124 const bNode &parent_node = socket->owner_node();
125 if (parent_node.
typeinfo->type_legacy == node_type) {
141 Image *tex_image =
reinterpret_cast<Image *
>(tex_node->
id);
150 "Packed image found:'%s'. Unpack and place the image in the same "
151 "directory as the .MTL file.",
180 for (
const bNode *node : nodetree->nodes_by_type(
"ShaderNodeOutputMaterial")) {
181 const bNodeSocket &node_input_socket0 = node->input_socket(0);
182 for (
const bNodeSocket *out_sock : node_input_socket0.directly_linked_sockets()) {
183 const bNode &in_node = out_sock->owner_node();
204 float spec_exponent = (1.0f - roughness);
205 spec_exponent *= spec_exponent * 1000.0f;
207 float specular = material->
spec;
212 float metallic = material->
metallic;
217 float refraction_index = 1.0f;
222 float alpha = material->
a;
226 const bool transparent = alpha != 1.0f;
228 float3 diffuse_col = {material->
r, material->
g, material->
b};
233 float3 emission_col{0.0f};
234 float emission_strength = 0.0f;
239 mul_v3_fl(emission_col, emission_strength);
243 float coat_roughness = -1.0f;
245 float aniso_rot = -1.0f;
246 float transmission = -1.0f;
262 if (specular == 0.0f) {
266 else if (metallic > 0.0f) {
277 else if (transparent) {
282 if (metallic != 0.0f) {
288 r_mtl_mat.
color = diffuse_col;
289 r_mtl_mat.
spec_color = {specular, specular, specular};
291 r_mtl_mat.
ior = refraction_index;
292 r_mtl_mat.
alpha = alpha;
299 r_mtl_mat.
aniso = aniso;
301 r_mtl_mat.
transmit_color = {transmission, transmission, transmission};
312 if (!material || !node_tree || !bsdf_node) {
325 const bNode *normal_map_node{
nullptr};
339 float emission_strength = 0.0f;
341 SOCK_FLOAT, bsdf_node,
"Emission Strength", {&emission_strength, 1});
342 if (emission_strength == 0.0f) {
357 if (tex_image_filepath.empty()) {
365 if (normal_map_node) {
382 mtlmat.
name = std::string(material->
id.
name + 2);
383 std::replace(mtlmat.
name.begin(), mtlmat.
name.end(),
' ',
'_');
385 if (nodetree !=
nullptr) {
386 nodetree->ensure_topology_cache();
bool BKE_image_has_filepath(const Image *ima)
bool BKE_image_has_packedfile(const Image *image)
#define SH_NODE_TEX_IMAGE
#define SH_NODE_BSDF_PRINCIPLED
#define SH_NODE_NORMAL_MAP
#define BLI_STATIC_ASSERT(a, msg)
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
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)
char * STRNCPY(char(&dst)[N], const char *src)
#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, StringRef identifier)
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)
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)
VecBase< float, 3 > float3
closure color sheen(normal N, float roughness) BUILTIN
struct bNodeTree * nodetree
bNodeTypeHandle * typeinfo
MTLTexMap texture_maps[int(MTLTexMapType::Count)]