WIP: IO: Add file unit type selector to stl importer and exporter #128337
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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#128337
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "Bujus_Krachus/blender:main"
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?
As STL is a unitless format, most other programs assume it to be millimeters. Blender on the other hand uses meters. This means, that whatever size the object has (e.g. 2m) it will always be assumed as millimeters in other apps (in case of 2m that would be 2mm, as no unit is saved, only the numeric value). Changing the unit system inside blender only changes the UI display values, not however the actual data and fiddling with the scene scale or export scale values can be quite tedious (time consuming for often users, confusing for sporadic users).
To allow for CAD modelling and exporting to STL in real life measures (which is desirable as STLs are commonly used for 3d printing), this PR supplies the user with a dropdown allowing to choose the target unit type (m, dm, cm, mm, in) used by the application he wishes to export for, whilst leaving a custom option for user defined scale (otherwise the scale factor input field is disabled); the chosen unit will modify the scale factor value. Additionally a new option got added to scale the mesh according to the used scene unit (e.g. scene unit cm, which then also assumes the stl scale values to be cm).
The default unit stays meter (factor 1) to not introduce any breaking changes to existing workflows, whilst still allowing anyone to quickly change units without having to think about conversion factors too much.
This change is inspired by the upcoming release of the x3d extension with a similar (but not identical) choosing option:
7e0b0e903a
The current feature proposal looks like this:
meter selected (default):
dropdown options:
millimeter selected (1m in blender is now 1m for most other apps as well):
when using millimeter as preset value, a user can model in real life measures and export/import in the correct scale. For example: model is 10x10cm (blender internally this equals to 0.1x0.1(m), thus in other apps as 0.1x0.1(mm)), a scale factor of 1000 will be applied, which results in a final scale of 100x100(mm)=10x10(cm).
The proposal got implemented for the stl importer and exporter.
@ -0,0 +1,35 @@
/* SPDX-FileCopyrightText: 2023 Blender Authors
Today is
2024
/That's an interesting idea, but it makes me wonder: should some other formats that are "unit-less" (e.g. OBJ, PLY) also get the same feature?
Should? Idk, that's for the blender team to decide.
Could? Yes, absolutely; most of the code is located in io common, only embedding to the individual UI's would be needed. Adding that feature to the other file types (If it gets accepted ofc), would create a more generalized standard UI, which i already outlined here (due to many differences in the IO core addons): https://blender.community/c/rightclickselect/DY5B/ (still a decision has to be made what options to consider as general, and whether to adjust the IO core addons individually or to create a one-size-fits-all-solution).
Recommended? Maybe. It for sure would be a nice feature, as it simplifies the unit conversion process if needed and is transparent in it's making (the scale factor is exposed to the user in the UI).
However the use cases fully depend on the users, their modelling preferences (large (200m(blender)=200mm(extern)=20cm(extern)) or little scaling (200mm(blender)=200mm(extern)) with grid scale adjustments needed), the external software used, etc.
I remember back in school when i did some CAD models for 3D-printing in blender on a sporadic basis it was always headscratches which factor to use and why, as somehow all attempts were different size in the slicer program than i'd expect it to be from blender (i foolishly assumed cm to be cm).
@blender-bot build
@ -0,0 +35,4 @@
char scene_unit = scene->unit.length_unit;
if (scene->unit.system == USER_UNIT_METRIC) {
switch (scene_unit) {
case '\0': // kilometer
Not quite like hardcoding unit system indices in that way. As far as I can tell, these would only work as long as no one reorders to alters the unit systems arrays inside
unit.cc
. Would it be better to use something likeBKE_unit_base_scalar
to get the scaling factors instead?btw I'm not too familiar with the whole units system, perhaps @ideasman42 would have better opinions
Hi Aras, i didn't like the hardcoding either due to the reordering issue, usually try to avoid it.
In theory following code should work instead of hardcoding the bytes as type identifier and values as scalars
however
base
is always1
and thusbase_scalar
always1.0
no matter which scene unit is set for length in the blender scene properties. Even when changing thebase
here manually, only at int5
there is another value despite1.0
.I'll be honest, i have no idea how accessing the user defined scene unit works, thus the hardcoded approach.
The main issue is knowing which scene_unit is selected, only way i found until now is using
scene->unit.length_unit
and comparing it's byte values. I'd be glad to implement a proper idea over that if someone points me into the right direction.The second thing is the scalars values, these could be refactored to using
UN_SC_M
fromunit.cc
, as they're already defined there.little side note: only the dropdown entry
Scene unit length
of this PR is affected by this issue.IO: Add file unit type selector to stl importer and exporterto WIP: IO: Add file unit type selector to stl importer and exporterCheckout
From your project repository, check out a new branch and test the changes.