55 vert_indices.
size() == normal_indices.
size());
59 const int n = vert_indices.
size();
62 for (
int j = 0; j < n; ++j) {
64 uv_indices[j] + uv_offset,
65 normal_indices[j] + normal_offset);
72 for (
int k = 0; k < n; ++k) {
73 int j = k == 0 ? 0 : n - k;
75 uv_indices[j] + uv_offset,
76 normal_indices[j] + normal_offset);
82 void OBJWriter::write_vert_normal_indices(FormatHandler<eFileType::OBJ> &fh,
83 const IndexOffsets &offsets,
90 const int vertex_offset = offsets.vertex_offset + 1;
91 const int normal_offset = offsets.normal_offset + 1;
92 const int n = vert_indices.
size();
95 for (
int j = 0; j < n; ++j) {
97 normal_indices[j] + normal_offset);
101 for (
int k = 0; k < n; ++k) {
102 int j = k == 0 ? 0 : n - k;
104 normal_indices[j] + normal_offset);
110 void OBJWriter::write_vert_uv_indices(FormatHandler<eFileType::OBJ> &fh,
111 const IndexOffsets &offsets,
112 Span<int> vert_indices,
113 Span<int> uv_indices,
117 BLI_assert(vert_indices.size() == uv_indices.size());
118 const int vertex_offset = offsets.vertex_offset + 1;
119 const int uv_offset = offsets.uv_vertex_offset + 1;
120 const int n = vert_indices.size();
123 for (
int j = 0; j < n; ++j) {
125 uv_indices[j] + uv_offset);
129 for (
int k = 0; k < n; ++k) {
130 int j = k == 0 ? 0 : n - k;
132 uv_indices[j] + uv_offset);
138 void OBJWriter::write_vert_indices(FormatHandler<eFileType::OBJ> &fh,
139 const IndexOffsets &offsets,
140 Span<int> vert_indices,
145 const int vertex_offset = offsets.vertex_offset + 1;
146 const int n = vert_indices.size();
149 for (
int j = 0; j < n; ++j) {
154 for (
int k = 0; k < n; ++k) {
155 int j = k == 0 ? 0 : n - k;
164 using namespace std::string_literals;
184 std::replace(r_name.begin(), r_name.end(),
' ',
'_');
188 const OBJMesh &obj_mesh_data)
const
215 template<
typename Function>
218 const Function &
function)
220 if (tot_count <= 0) {
227 if (chunk_count == 1) {
228 for (
int i = 0; i < tot_count; i++) {
234 std::vector<FormatHandler<eFileType::OBJ>> buffers(chunk_count);
236 for (
const int r : range) {
239 auto &buf = buffers[
r];
240 for (
int i = i_start; i < i_end; i++) {
246 for (
auto &buf : buffers) {
253 bool write_colors)
const
262 if (write_colors && (colors_layer !=
nullptr)) {
274 vertex[0], vertex[1], vertex[2], srgb[0], srgb[1], srgb[2]);
288 const int tot_count = uv_coords.
size();
290 const float2 &uv_vertex = uv_coords[i];
299 const int tot_count = normal_coords.
size();
306 OBJWriter::func_vert_uv_normal_indices OBJWriter::get_poly_element_writer(
307 const int total_uv_vertices)
const
310 if (export_params_.
export_uv && (total_uv_vertices > 0)) {
312 return &OBJWriter::write_vert_uv_normal_indices;
315 return &OBJWriter::write_vert_normal_indices;
318 if (export_params_.
export_uv && (total_uv_vertices > 0)) {
319 return &OBJWriter::write_vert_uv_indices;
322 return &OBJWriter::write_vert_indices;
331 if (
mesh.is_ith_poly_smooth(poly_idx)) {
340 std::function<
const char *(
int)> matname_fn)
342 const func_vert_uv_normal_indices poly_element_writer = get_poly_element_writer(
362 const int prev_group =
get_smooth_group(obj_mesh_data, export_params_, prev_i);
364 if (group != prev_group) {
372 local_weights.
resize(tot_deform_groups);
375 prev_i, local_weights);
377 if (group != prev_group) {
388 if (mat != prev_mat) {
393 const char *mat_name = matname_fn(mat);
408 (this->*poly_element_writer)(buf,
419 const OBJMesh &obj_mesh_data)
const
422 const int tot_edges = obj_mesh_data.
tot_edges();
423 for (
int edge_index = 0; edge_index < tot_edges; edge_index++) {
435 const OBJCurve &obj_nurbs_data)
const
438 for (
int spline_idx = 0; spline_idx < total_splines; spline_idx++) {
440 for (
int vertex_idx = 0; vertex_idx < total_vertices; vertex_idx++) {
461 for (
int i = 0; i < total_control_points; i++) {
478 for (
int i = 1; i <= total_control_points + 2; i++) {
479 float parm = 1.0f * i / (total_control_points + 2 + 1);
506 std::ostringstream r_string;
507 r_string << numbers[0] <<
" " << numbers[1] <<
" " << numbers[2];
508 return r_string.str();
513 mtl_filepath_ = obj_filepath;
516 throw std::system_error(ENAMETOOLONG, std::system_category(),
"");
518 outfile_ =
BLI_fopen(mtl_filepath_.c_str(),
"wb");
520 throw std::system_error(errno, std::system_category(),
"Cannot open file " + mtl_filepath_);
526 fmt_handler_.write_to_file(outfile_);
527 if (std::fclose(outfile_)) {
528 std::cerr <<
"Error: could not close the file '" << mtl_filepath_
529 <<
"' properly, it may be corrupted." << std::endl;
536 using namespace std::string_literals;
537 const char *blen_basename = (blen_filepath && blen_filepath[0] !=
'\0') ?
541 " MTL File: '" + blen_basename +
"'\n");
547 return mtl_filepath_;
550 void MTLWriter::write_bsdf_properties(
const MTLMaterial &mtl)
575 void MTLWriter::write_texture_map(
576 const MTLMaterial &mtl_material,
577 const Map<const eMTLSyntaxElement, tex_map_XX>::Item &texture_map,
578 const char *blen_filedir,
579 const char *dest_dir,
581 Set<std::pair<std::string, std::string>> ©_set)
585 if (texture_map.value.translation !=
float3{0.0f, 0.0f, 0.0f}) {
588 if (texture_map.value.scale !=
float3{1.0f, 1.0f, 1.0f}) {
596 texture_map.value.image_path.c_str(), blen_filedir, dest_dir, path_mode, ©_set);
598 std::replace(path.begin(), path.end(),
'\\',
'/');
600 #define SYNTAX_DISPATCH(eMTLSyntaxElement) \
601 if (texture_map.key == eMTLSyntaxElement) { \
602 fmt_handler_.write<eMTLSyntaxElement>(options, path.c_str()); \
613 #undef SYNTAX_DISPATCH
615 BLI_assert(!
"This map type was not written to the file.");
620 const char *dest_dir)
622 if (mtlmaterials_.size() == 0) {
638 write_bsdf_properties(mtlmat);
639 for (
const auto &
tex : mtlmat.texture_maps.items()) {
640 if (!
tex.value.is_valid()) {
643 write_texture_map(mtlmat,
tex, blen_filedir, dest_dir, path_mode, copy_set);
656 r_mtl_indices[i] = -1;
659 int mtlmat_index = material_map_.lookup_default(
material, -1);
660 if (mtlmat_index != -1) {
661 r_mtl_indices[i] = mtlmat_index;
665 r_mtl_indices[i] = mtlmaterials_.
size() - 1;
666 material_map_.add_new(
material, r_mtl_indices[i]);
669 return r_mtl_indices;
674 if (index < 0 || index >= mtlmaterials_.size()) {
677 return mtlmaterials_[index].name.c_str();
struct CustomDataLayer * BKE_id_attributes_active_color_get(const struct ID *id)
const char * BKE_blender_version_string(void)
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
MINLINE void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
void BLI_split_dir_part(const char *string, char *dir, size_t dirlen)
const char * BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
void BLI_split_dirfile(const char *string, char *dir, char *file, size_t dirlen, size_t filelen)
void BLI_path_normalize(const char *relabase, char *path) ATTR_NONNULL(2)
bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext) ATTR_NONNULL()
void BLI_path_slash_native(char *path) ATTR_NONNULL()
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color attribute
void sort(btMatrix3x3 &U, btVector3 &sigma, btMatrix3x3 &V, int t)
Helper function of 3X3 SVD for sorting singular values.
constexpr int64_t size() const
constexpr const char * data() const
void append(const T &value)
void resize(const int64_t new_size)
GVArray lookup_or_default(const AttributeIDRef &attribute_id, const eAttrDomain domain, const eCustomDataType data_type, const void *default_value=nullptr) const
MTLWriter(const char *obj_filepath) noexcept(false)
Vector< int > add_materials(const OBJMesh &mesh_to_export)
void write_header(const char *blen_filepath)
void write_materials(const char *blen_filepath, ePathReferenceMode path_mode, const char *dest_dir)
StringRefNull mtl_file_path() const
const char * mtlmaterial_name(int index)
int total_spline_vertices(int spline_index) const
int total_spline_control_points(int spline_index) const
short get_nurbs_flagu(int spline_index) const
int get_nurbs_degree(int spline_index) const
const char * get_curve_name() const
int total_splines() const
float3 vertex_coordinates(int spline_index, int vertex_index, float scaling_factor) const
const char * get_object_mesh_name() const
const char * get_object_name() const
const Vector< float2 > & get_uv_coords() const
int tot_deform_groups() const
int16_t tot_materials() const
Span< int > calc_poly_uv_indices(int poly_index) const
const char * get_poly_deform_group_name(int16_t def_group_index) const
bool is_mirrored_transform() const
float3 calc_vertex_coords(int vert_index, float scaling_factor) const
int tot_uv_vertices() const
const Material * get_object_material(int16_t mat_nr) const
int16_t get_poly_deform_group_index(int poly_index, MutableSpan< float > group_weights) const
int16_t ith_poly_matnr(int poly_index) const
const Vector< float3 > & get_normal_coords() const
int remap_poly_index(int i) const
Vector< int > calc_poly_vertex_indices(int poly_index) const
std::optional< std::array< int, 2 > > calc_loose_edge_vert_indices(int edge_index) const
Vector< int > calc_poly_normal_indices(int poly_index) const
void write_nurbs_curve(FormatHandler< eFileType::OBJ > &fh, const OBJCurve &obj_nurbs_data) const
void write_poly_elements(FormatHandler< eFileType::OBJ > &fh, const IndexOffsets &offsets, const OBJMesh &obj_mesh_data, std::function< const char *(int)> matname_fn)
void write_header() const
void write_mtllib_name(const StringRefNull mtl_filepath) const
void write_vertex_coords(FormatHandler< eFileType::OBJ > &fh, const OBJMesh &obj_mesh_data, bool write_colors) const
void write_uv_coords(FormatHandler< eFileType::OBJ > &fh, OBJMesh &obj_mesh_data) const
void write_edges_indices(FormatHandler< eFileType::OBJ > &fh, const IndexOffsets &offsets, const OBJMesh &obj_mesh_data) const
void write_object_name(FormatHandler< eFileType::OBJ > &fh, const OBJMesh &obj_mesh_data) const
void write_poly_normals(FormatHandler< eFileType::OBJ > &fh, OBJMesh &obj_mesh_data)
CCL_NAMESPACE_BEGIN struct Options options
IconTextureDrawCall normal
AttributeAccessor mesh_attributes(const Mesh &mesh)
static void spaces_to_underscores(std::string &r_name)
const int SMOOTH_GROUP_DEFAULT
static const char * MATERIAL_GROUP_DISABLED
MTLMaterial mtlmaterial_for_material(const Material *material)
const int SMOOTH_GROUP_DISABLED
@ vertex_uv_normal_indices
static std::string float3_to_string(const float3 &numbers)
static int get_smooth_group(const OBJMesh &mesh, const OBJExportParams ¶ms, int poly_idx)
static const int chunk_size
static int calc_chunk_count(int count)
void obj_parallel_chunked_output(FormatHandler< eFileType::OBJ > &fh, int tot_count, const Function &function)
static const char * DEFORM_GROUP_DISABLED
void path_reference_copy(const Set< std::pair< std::string, std::string >> ©_set)
std::string path_reference(StringRefNull filepath, StringRefNull base_src, StringRefNull base_dst, ePathReferenceMode mode, Set< std::pair< std::string, std::string >> *copy_set)
void parallel_for(IndexRange range, int64_t grain_size, const Function &function)
std::string to_string(const T &n)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
#define SYNTAX_DISPATCH(eMTLSyntaxElement)
bool export_material_groups
bool export_object_groups
bool export_vertex_groups
const tex_map_XX & tex_map_of_type(const eMTLSyntaxElement key) const