67 std::cerr << ex.code().category().name() <<
": " << ex.what() <<
": " << ex.code().message()
100 switch (object->type) {
105 r_exportable_meshes.
append(std::make_unique<OBJMesh>(
depsgraph, export_params,
object));
113 r_exportable_nurbs.
append(
114 std::make_unique<OBJCurve>(
depsgraph, export_params,
object));
120 r_exportable_nurbs.
append(std::make_unique<OBJCurve>(
depsgraph, export_params,
object));
124 r_exportable_meshes.
append(std::make_unique<OBJMesh>(
depsgraph, export_params,
object));
134 return {std::move(r_exportable_meshes), std::move(r_exportable_nurbs)};
145 size_t count = exportable_as_mesh.size();
146 std::vector<FormatHandler<eFileType::OBJ>> buffers(
count);
154 for (
auto &obj_mesh : exportable_as_mesh) {
167 for (
const int i : range) {
168 OBJMesh &obj = *exportable_as_mesh[i];
170 obj.store_normal_coords_and_indices();
173 obj.store_uv_coords_and_indices();
183 for (
auto &obj_mesh : exportable_as_mesh) {
185 index_offsets.append(offsets);
193 for (
const int i : range) {
194 OBJMesh &obj = *exportable_as_mesh[i];
195 auto &fh = buffers[i];
201 if (export_params.export_smooth_groups) {
202 obj.calc_smooth_groups(export_params.smooth_groups_bitflags);
205 obj.calc_poly_order();
208 obj_writer.write_poly_normals(fh, obj);
211 obj_writer.write_uv_coords(fh, obj);
215 const auto *obj_mtlindices = mtlindices.
is_empty() ?
nullptr : &mtlindices[i];
216 std::function<
const char *(
int)> matname_fn = [&](
int s) ->
const char * {
217 if (!obj_mtlindices || s < 0 || s >= obj_mtlindices->size()) {
233 FILE *f = obj_writer.get_outfile();
234 for (
auto &
b : buffers) {
248 for (
const std::unique_ptr<OBJCurve> &obj_curve : exportable_as_nurbs) {
256 std::unique_ptr<OBJWriter> frame_writer =
nullptr;
258 frame_writer = std::make_unique<OBJWriter>(filepath, export_params);
260 catch (
const std::system_error &ex) {
265 BLI_assert(!
"File should be writable by now.");
268 std::unique_ptr<MTLWriter> mtl_writer =
nullptr;
271 mtl_writer = std::make_unique<MTLWriter>(filepath);
273 catch (
const std::system_error &ex) {
278 frame_writer->write_header();
284 std::move(exportable_as_mesh), *frame_writer, mtl_writer.get(), export_params);
315 const char *filepath = export_params.
filepath;
319 fprintf(stderr,
"Writing to %s\n", filepath);
324 char filepath_with_frames[
FILE_MAX];
331 fprintf(stderr,
"Error: File Path too long.\n%s\n", filepath_with_frames);
337 fprintf(stderr,
"Writing to %s\n", filepath_with_frames);
338 export_frame(obj_depsgraph.
get(), export_params, filepath_with_frames);
struct Scene * CTX_data_scene(const bContext *C)
struct ViewLayer * CTX_data_view_layer(const bContext *C)
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
struct Main * CTX_data_main(const bContext *C)
void BKE_scene_graph_update_for_newframe(struct Depsgraph *depsgraph)
void BKE_scene_graph_evaluated_ensure(struct Depsgraph *depsgraph, struct Main *bmain)
MINLINE int integer_digits_i(int i)
void BLI_split_dir_part(const char *string, char *dir, size_t dirlen)
bool BLI_path_frame(char *path, int frame, int digits) ATTR_NONNULL()
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()
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Depsgraph * DEG_graph_new(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, eEvaluationMode mode)
struct Depsgraph Depsgraph
void DEG_graph_free(Depsgraph *graph)
void DEG_graph_build_for_all_objects(struct Depsgraph *graph)
struct Scene * DEG_get_input_scene(const Depsgraph *graph)
#define DEG_OBJECT_ITER_END
#define DEG_OBJECT_ITER_BEGIN(graph_, instance_, flag_)
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
@ DEG_ITER_OBJECT_FLAG_VISIBLE
@ DEG_ITER_OBJECT_FLAG_DUPLI
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
bool ED_object_mode_set(struct bContext *C, eObjectMode mode)
void append(const T &value)
void reserve(const int64_t min_capacity)
Vector< int > add_materials(const OBJMesh &mesh_to_export)
StringRefNull mtl_file_path() const
const char * mtlmaterial_name(int index)
void update_for_newframe()
OBJDepsgraph(const bContext *C, eEvaluationMode eval_mode)
int tot_normal_indices() const
int tot_uv_vertices() const
void ensure_mesh_normals() const
void ensure_mesh_edges() 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_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_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
FILE * get_outfile() const
const Depsgraph * depsgraph
static void print_exception_error(const std::system_error &ex)
static void write_mesh_objects(Vector< std::unique_ptr< OBJMesh >> exportable_as_mesh, OBJWriter &obj_writer, MTLWriter *mtl_writer, const OBJExportParams &export_params)
static bool is_curve_nurbs_compatible(const Nurb *nurb)
bool append_frame_to_filename(const char *filepath, const int frame, char *r_filepath_with_frames)
std::pair< Vector< std::unique_ptr< OBJMesh > >, Vector< std::unique_ptr< OBJCurve > > > filter_supported_objects(Depsgraph *depsgraph, const OBJExportParams &export_params)
void exporter_main(bContext *C, const OBJExportParams &export_params)
void export_frame(Depsgraph *depsgraph, const OBJExportParams &export_params, const char *filepath)
static void write_nurbs_curve_objects(const Vector< std::unique_ptr< OBJCurve >> &exportable_as_nurbs, const OBJWriter &obj_writer)
void parallel_for(IndexRange range, int64_t grain_size, const Function &function)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
eEvaluationMode export_eval_mode
bool export_curves_as_nurbs
const char * blen_filepath
bool export_selected_objects
char file_base_for_tests[FILE_MAX]
ePathReferenceMode path_mode