WIP: IO: C++ STL exporter #105598
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#105598
Loading…
Reference in New Issue
No description provided.
Delete Branch "(deleted):io-cpp-stl-exporter"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
A C++ .stl mesh file exporter for faster exports (especially with large meshes or large number of objects)
@ -0,0 +72,4 @@
bm_convert_params.calc_face_normal = true;
bm_convert_params.calc_vert_normal = false;
BMesh *bmesh = BKE_mesh_to_bmesh_ex(mesh, &bm_create_params, &bm_convert_params);
What do you think about using the
Mesh
triangulation instead of converting to BMesh and triangulating there? That can be accessed withMesh.looptris()
Oh awesome, I will use it then
1a5f97220d
tod0543ca26e
d0543ca26e
to23c164317a
38a896dba0
to7bc454f7c0
7bc454f7c0
to4d03220e6b
WIP: IO: C++ STL exporterto IO: C++ STL exporterNice! Added some comments wrt non-ASCII file paths on windows, and naming of some paramters for the Python API.
@ -25,0 +47,4 @@
export_params.forward_axis = RNA_enum_get(op->ptr, "forward_axis");
export_params.up_axis = RNA_enum_get(op->ptr, "up_axis");
export_params.global_scale = RNA_float_get(op->ptr, "global_scale");
export_params.use_apply_modifiers = RNA_boolean_get(op->ptr, "use_apply_modifiers");
Maybe instead of
use_apply_modifiers
this could beapply_modifiers
? That way it would be consistent with OBJ, PLY, Collada APIs.@ -25,0 +48,4 @@
export_params.up_axis = RNA_enum_get(op->ptr, "up_axis");
export_params.global_scale = RNA_float_get(op->ptr, "global_scale");
export_params.use_apply_modifiers = RNA_boolean_get(op->ptr, "use_apply_modifiers");
export_params.use_selection_only = RNA_boolean_get(op->ptr, "use_selection_only");
Similar, maybe instead of
use_selection_only
it should follow some existing export APIs. The trouble is... there's no consistency for that name. Alembic and Collada useselected
, USD usesselected_objects_only
, OBJ and PLY useexport_selected_objects
. But at least picking one of those is better than introducing yet another new name :)@ -25,0 +49,4 @@
export_params.global_scale = RNA_float_get(op->ptr, "global_scale");
export_params.use_apply_modifiers = RNA_boolean_get(op->ptr, "use_apply_modifiers");
export_params.use_selection_only = RNA_boolean_get(op->ptr, "use_selection_only");
export_params.use_ascii = RNA_boolean_get(op->ptr, "use_ascii");
PLY export uses
ascii_format
name for the same argument, so maybe follow that.@ -28,0 +35,4 @@
bool use_apply_modifiers;
bool use_ascii;
bool use_batch;
float global_scale;
Suuuper minor: I'd put the float member before the bool ones. Right now it wastes 3 bytes of padding between the last bool and the float, in order to align the float to 4-byte boundary. This does not really matter all that much for this struct, but as a general guidance it's a good one to learn.
@ -0,0 +21,4 @@
class ASCIIFileWriter : public FileWriter, NonCopyable {
private:
std::ofstream file_;
std::ofstream
will fail writing a file on Windows if path contains non-ASCII characters. Useblender::fstream
fromBLI_fileops.hh
instead.@ -0,0 +42,4 @@
BinaryFileWriter::BinaryFileWriter(const char *filepath)
{
file_ = fopen(filepath, "wb");
Similar to ASCII writer:
fopen
will fail correctly writing to a non-ASCII path on Windows. UseBLI_fopen
fromBLI_fileops.h
instead.Would also be good if this exporter handles "collection instances" properly. There's an open patch for the python one: blender/blender-addons#104460
I found a much bigger problem, exporting two selected cubes only exports one cube, does not matter if selection only is enabled or not, trying to fix it,
Update 1: I think the problem is unapplied object transform is not taken into account somehow, so both cube end up in the same place, not sure if PLY exporter suffers same, CC: @aras_p
Update 2: I think PLY does not suffer, because it includes the object to world matrix for each object, I just need to do same
IO: C++ STL exporterto WIP: IO: C++ STL exporterIt's nice that there really isn't much code here, a pretty simple change!
Would it be worth adding multithreading in this first commit? That could be done by just gathering a list of objects and making the file large enough in the first depsgraph loop, then writing all the data in parallel after. It's okay to do that later too.
Does the PR have a "WIP:" prefix for a specific reason at this point? If it's considered ready for review, probably best to remove it.
@ -14,14 +14,162 @@
# include "DNA_space_types.h"
Best to add this new file as a C++ file, that's the direction Blender is moving in generally.
@ -0,0 +85,4 @@
}
float scale_vec[3] = {global_scale, global_scale, global_scale};
float obmat3x3[3][3];
unit_m3(obmat3x3);
It would be best to try looking into using the new matrix types recently added in https://archive.blender.org/developer/D16625. Should be a nice cleanup here too!
@ -0,0 +95,4 @@
rescale_m4(obmat4x4, scale_vec);
/* Write triangles. */
auto loops = mesh->loops();
In similar Blender code,
auto
isn't generally used in this context. The type information gives helpful context to the reader. Same forauto
in the loop below.@ -0,0 +99,4 @@
for (const auto &loop_tri : mesh->looptris()) {
Triangle t{};
for (int i = 0; i < 3; i++) {
auto co = mesh->vert_positions()[loops[loop_tri.tri[i]].v];
I expect that these
vert_positions()
calls would show up in a profile. Each one does a string lookup in all vertex custom data layers. It would be better to retrieve the span once below.@ -0,0 +20,4 @@
#pragma pack(push, 1)
struct STLBinaryTriangle {
float normal[3]{};
Use the
float3
type here instead@ -0,0 +22,4 @@
struct STLBinaryTriangle {
float normal[3]{};
float vertices[3][3]{};
uint16_t attribute_byte_count{};
The defaults with
{}
shouldn't be necessary here@ -0,0 +18,4 @@
if (type == FileWriter::Type::ASCII) {
return std::make_unique<ASCIIFileWriter>(filepath);
}
else if (type == FileWriter::Type::BINARY) {
else after return is redundant and can be removed here
Yep added WIP back because of this: #105598 (comment)
f2abaac62b
to9d00506ae7
@ -0,0 +96,4 @@
rescale_m4(obmat4x4, scale_vec);
/* Write triangles. */
const Span<float3> vertices = mesh->vert_positions();
The typical name for this
vert_positions
span ispositions
rather thanvertices
. Vertices might refer to any/all vertex-domain attributes.5cedc71ba2
tof973604fe6
To be clear, I probably won't do more review here as long as the patch is marked as WIP. If you have questions though, feel free to ask here or in chat.
Implemented as part of #114862
Pull request closed