41 float scene_unit_scale,
44 std::unique_ptr<FileWriter> writer;
51 catch (
const std::runtime_error &ex) {
52 fprintf(stderr,
"%s\n", ex.what());
55 "STL Export: Cannot open file '%s'",
79 char object_name[
sizeof(
object->id.name) - 2];
80 STRNCPY(object_name, object->id.name + 2);
92 if (basename !=
nullptr &&
BLI_strcasecmp(basename,
".stl") == 0) {
93 *
const_cast<char *
>(basename) =
'\0';
103 writer = std::make_unique<FileWriter>(filepath, export_params.
ascii_format);
105 catch (
const std::runtime_error &ex) {
106 fprintf(stderr,
"%s\n", ex.what());
108 export_params.
reports,
RPT_ERROR,
"STL Export: Cannot open file '%s'", filepath);
121 float global_scale = export_params.
global_scale * scene_unit_scale;
122 float axes_transform[3][3];
128 mul_m4_m3m4(xform, axes_transform, obj_eval->object_to_world().ptr());
130 mul_v3_m3v3(xform[3], axes_transform, obj_eval->object_to_world().location());
131 xform[3][3] = obj_eval->object_to_world()[3][3];
137 const Span<int> corner_verts = mesh->corner_verts();
138 for (
const int3 &tri : mesh->corner_tris()) {
140 for (
int i = 0; i < 3; i++) {
142 int idx = mirrored ? 2 - i : i;
143 float3 pos = positions[corner_verts[tri[idx]]];
146 data.vertices[i] =
pos;
148 data.normal =
math::normal_tri(data.vertices[0], data.vertices[1], data.vertices[2]);
149 writer->write_triangle(data);
158 bool needs_free =
false;
168 "STL Export: Unable to find collection '%s'",
184 float scene_unit_scale = 1.0f;
186 scene_unit_scale = scene->unit.scale_length;
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
ID * BKE_libblock_find_name(Main *bmain, short type, const char *name, const std::optional< Library * > lib=std::nullopt) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BKE_mesh_wrapper_ensure_mdata(Mesh *mesh)
General operations, lookup, etc. for blender objects.
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Mesh * BKE_object_get_pre_modified_mesh(const Object *object)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
void unit_m3(float m[3][3])
void mul_m4_v3(const float M[4][4], float r[3])
bool is_negative_m4(const float mat[4][4])
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
void mul_m4_m3m4(float R[4][4], const float A[3][3], const float B[4][4])
bool mat3_from_axis_conversion(int src_forward, int src_up, int dst_forward, int dst_up, float r_mat[3][3])
bool bool BLI_path_suffix(char *path, size_t path_maxncpy, const char *suffix, const char *sep) ATTR_NONNULL(1
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
bool BLI_path_make_safe_filename(char *filename) ATTR_NONNULL(1)
#define STRNCPY(dst, src)
int char char int BLI_strcasecmp(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1)
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
void DEG_graph_free(Depsgraph *graph)
void DEG_graph_build_from_collection(Depsgraph *graph, Collection *collection)
#define DEG_OBJECT_ITER_BEGIN(settings_, instance_)
#define DEG_OBJECT_ITER_END
Object * DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
@ DEG_ITER_OBJECT_FLAG_VISIBLE
@ DEG_ITER_OBJECT_FLAG_DUPLI
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
#define BASE_SELECTED(v3d, base)
const Depsgraph * depsgraph
void export_frame(Depsgraph *depsgraph, float scene_unit_scale, const STLExportParams &export_params)
void exporter_main(const bContext *C, const STLExportParams &export_params)
VecBase< T, 3 > normal_tri(const VecBase< T, 3 > &v1, const VecBase< T, 3 > &v2, const VecBase< T, 3 > &v3)
bool export_selected_objects
char collection[MAX_IDPROP_NAME]