UI: Import obj files by drag and drop #106871

Closed
Guillermo Venegas wants to merge 16 commits from guishe:drop-file-obj into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Contributor

The patch allows users to quickly import obj files by drag and drop. For
quick setup of the import, a popup dialog is displayed allowing the user
to configure the import or use a operator preset.

The patch allows users to quickly import obj files by drag and drop. For quick setup of the import, a popup dialog is displayed allowing the user to configure the import or use a operator preset.
Author
Contributor

Here is a video showing what the patch allows:

Here is a video showing what the patch allows:
Pablo Vazquez added this to the User Interface project 2023-04-12 19:05:24 +02:00
Pablo Vazquez added the
Module
User Interface
Interest
Pipeline, Assets & IO
labels 2023-04-12 19:05:42 +02:00
Guillermo Venegas reviewed 2023-04-12 19:21:32 +02:00
@ -485,0 +499,4 @@
/* To allow drag and drop obj files, the file path must be tagged as PROP_SKIP_SAVE, this is
* to be able to choose a operator preset without clearing the file path.
*/
RNA_def_property_flag(RNA_struct_type_find_property(ot->srna, "filepath"), PROP_SKIP_SAVE);
Author
Contributor

The filepath property is now not included in the import obj operator presets, however operator presets saved before the patch may overwrite the file path, to avoid this the presets must be overwritten.

The filepath property is now not included in the import obj operator presets, however operator presets saved before the patch may overwrite the file path, to avoid this the presets must be overwritten.
Member

Nice!

The changes in screen_ops.c should be within #ifdef WITH_IO_WAVEFRONT_OBJ directives to ensure that the code you need is compiled in.

Nice! The changes in `screen_ops.c` should be within `#ifdef WITH_IO_WAVEFRONT_OBJ` directives to ensure that the code you need is compiled in.
Guillermo Venegas force-pushed drop-file-obj from 3905d6c17d to da53519b42 2023-04-12 22:10:13 +02:00 Compare
Author
Contributor

Done!

Done!

Nice! I'm wondering though why only .OBJ and not all the formats that are native to blender (OBJ, USD, Alembic, Collada, PLY, STL)?

Nice! I'm wondering though why only .OBJ and not all the formats that are native to blender (OBJ, USD, Alembic, Collada, PLY, STL)?
Author
Contributor

I'll be uploading them soon!

I'll be uploading them soon!
Guillermo Venegas force-pushed drop-file-obj from da53519b42 to de5c021b75 2023-04-15 00:15:27 +02:00 Compare
Contributor

Looking forward to seeing this merged into master.

Looking forward to seeing this merged into master.
Member

Damn I love this. Please don't take any of the following as me asking you to change anything. Just talking out loud...

Thinking about how this would look with a half-dozen importers done the same way. Could we instead have screen_ops.c do a single WM_dropbox_add for a new operator defined in io_ops.c? Possibly just WM_OT_drop_import or similar. And that operator is what checks the file extensions and dispatches the specific importers? That would simplify screen_ops, you wouldn't need the defines there, and it would keep all the import-related stuff together.

Damn I love this. Please don't take any of the following as me asking you to change anything. Just talking out loud... Thinking about how this would look with a half-dozen importers done the same way. Could we instead have screen_ops.c do a single WM_dropbox_add for a new operator defined in io_ops.c? Possibly just WM_OT_drop_import or similar. And that operator is what checks the file extensions and dispatches the specific importers? That would simplify screen_ops, you wouldn't need the defines there, and it would keep all the import-related stuff together.
Author
Contributor

Maybe set each WM_dropbox_add on ED_operatortypes_io from the file io_ops.c

It's now like this

void ED_operatortypes_io(void)
{
...
#ifdef WITH_IO_WAVEFRONT_OBJ
  WM_operatortype_append(WM_OT_obj_export);
  WM_operatortype_append(WM_OT_obj_import);
#endif
...
}

Ending up being

void ED_operatortypes_io(void)
{
ListBase *lb = WM_dropboxmap_find("Window", 0, 0);
...

#ifdef WITH_IO_WAVEFRONT_OBJ
  WM_operatortype_append(WM_OT_obj_export);
  WM_operatortype_append(WM_OT_obj_import);
  WM_dropbox_add(lb, "WM_OT_obj_import", obj_file_drop_poll, file_drop_copy, NULL, NULL);
#endif
...
}

obj_file_drop_poll would be defined on io_obj.c

Maybe set each `WM_dropbox_add` on `ED_operatortypes_io` from the file `io_ops.c` It's now like this ```C void ED_operatortypes_io(void) { ... #ifdef WITH_IO_WAVEFRONT_OBJ WM_operatortype_append(WM_OT_obj_export); WM_operatortype_append(WM_OT_obj_import); #endif ... } ``` Ending up being ```C void ED_operatortypes_io(void) { ListBase *lb = WM_dropboxmap_find("Window", 0, 0); ... #ifdef WITH_IO_WAVEFRONT_OBJ WM_operatortype_append(WM_OT_obj_export); WM_operatortype_append(WM_OT_obj_import); WM_dropbox_add(lb, "WM_OT_obj_import", obj_file_drop_poll, file_drop_copy, NULL, NULL); #endif ... } ``` obj_file_drop_poll would be defined on io_obj.c
Member

Maybe set each WM_dropbox_add on ED_operatortypes_io from the file io_ops.c

Yes, that sounds pretty nice. Haven't thought of any reasons why it wouldn't work well.

> Maybe set each `WM_dropbox_add` on `ED_operatortypes_io` from the file `io_ops.c` Yes, that sounds pretty nice. Haven't thought of any reasons why it wouldn't work well.
Guillermo Venegas force-pushed drop-file-obj from de5c021b75 to 0fd960bcc0 2023-04-19 06:25:46 +02:00 Compare
Guillermo Venegas force-pushed drop-file-obj from 0fd960bcc0 to 780bdaf45e 2023-04-19 06:33:21 +02:00 Compare
Author
Contributor

Just made the changes, most of the changes are now in the operator file.

Just made the changes, most of the changes are now in the operator file.

From the file explorer you can select multiple .obj files and drag them onto Blender, but it imports just the first one. This feels like a different functionality from the regular file import dialog, where you can select multiple .obj files and they get imported with the same settings.

From the file explorer you can select multiple .obj files and drag them onto Blender, but it imports just the first one. This feels like a different functionality from the regular file import dialog, where you can select multiple .obj files and they get imported with the same settings.
Guillermo Venegas force-pushed drop-file-obj from 780bdaf45e to 5b6378089f 2023-04-19 20:18:50 +02:00 Compare
Guillermo Venegas force-pushed drop-file-obj from 5b6378089f to 89f87984a9 2023-04-19 20:22:55 +02:00 Compare
Author
Contributor

I made changes to make it even easier to also apply the changes to the other formats

I made changes to make it even easier to also apply the changes to the other formats
Author
Contributor

From the file explorer you can select multiple .obj files and drag them onto Blender, but it imports just the first one. This feels like a different functionality from the regular file import dialog, where you can select multiple .obj files and they get imported with the same settings.

I'll work on it in another patch

> From the file explorer you can select multiple .obj files and drag them onto Blender, but it imports just the first one. This feels like a different functionality from the regular file import dialog, where you can select multiple .obj files and they get imported with the same settings. I'll work on it in another patch
Member

Still works like a magic trick.

The new files this adds would also need the same "SPDX-License-Identifier" header you find on other files nearby.

Not sure if better, but worth considering not having a separate WM_xxx_dropbox_add for each importer but create a shared function that takes just operator name and poll function as those would be the only things changing between them AFAICT.

Still works like a magic trick. The new files this adds would also need the same "SPDX-License-Identifier" header you find on other files nearby. Not sure if better, but worth _considering_ not having a separate `WM_xxx_dropbox_add` for each importer but create a shared function that takes just operator name and poll function as those would be the only things changing between them AFAICT.
Author
Contributor

Thinking about how this would look with a half-dozen importers done the same way. Could we instead have screen_ops.c do a single WM_dropbox_add for a new operator defined in io_ops.c? Possibly just WM_OT_drop_import or similar. And that operator is what checks the file extensions and dispatches the specific importers? That would simplify screen_ops, you wouldn't need the defines there, and it would keep all the import-related stuff together.

Just thought about this for a while, I don't know how easy it would be to invoke OP from another OP in C

> Thinking about how this would look with a half-dozen importers done the same way. Could we instead have screen_ops.c do a single WM_dropbox_add for a new operator defined in io_ops.c? Possibly just WM_OT_drop_import or similar. And that operator is what checks the file extensions and dispatches the specific importers? That would simplify screen_ops, you wouldn't need the defines there, and it would keep all the import-related stuff together. Just thought about this for a while, I don't know how easy it would be to invoke OP from another OP in C
Member

Just thought about this for a while, I don't know how easy it would be to invoke OP from another OP in C

It's actually pretty easy, but I like your current plan much better anyway.

But if you ever want to invoke an operator, even from within another operator, it is like this:

WmOperatorType *ot = WM_operatortype_find("OperatorName", true);
// set some properties...
PointerRNA op_props;
WM_operator_properties_create_ptr(&op_props, ot);
RNA_string_set(&op_props, "propertyname", value);
return WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &op_props, NULL);
> Just thought about this for a while, I don't know how easy it would be to invoke OP from another OP in C It's actually pretty easy, **but I like your current plan much better** anyway. But if you ever want to invoke an operator, even from within another operator, it is like this: ``` WmOperatorType *ot = WM_operatortype_find("OperatorName", true); // set some properties... PointerRNA op_props; WM_operator_properties_create_ptr(&op_props, ot); RNA_string_set(&op_props, "propertyname", value); return WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &op_props, NULL); ```
Guillermo Venegas force-pushed drop-file-obj from 89f87984a9 to d9ff390ee1 2023-04-21 00:31:07 +02:00 Compare
Guillermo Venegas changed title from UI: Import obj files by drag and drop to UI: Import aea, dae, obj and usd files by drag and drop 2023-04-21 00:34:10 +02:00
Guillermo Venegas force-pushed drop-file-obj from d9ff390ee1 to eee5ecb715 2023-04-21 00:51:17 +02:00 Compare
Guillermo Venegas force-pushed drop-file-obj from eee5ecb715 to 31f262ee4a 2023-04-21 00:53:52 +02:00 Compare
Guillermo Venegas force-pushed drop-file-obj from 31f262ee4a to 36ab0382f7 2023-04-21 21:02:13 +02:00 Compare
Guillermo Venegas force-pushed drop-file-obj from 36ab0382f7 to 9eca2b93fc 2023-04-21 21:05:11 +02:00 Compare
Guillermo Venegas force-pushed drop-file-obj from 9eca2b93fc to 10933d0d27 2023-04-21 21:06:29 +02:00 Compare
Guillermo Venegas changed title from UI: Import aea, dae, obj and usd files by drag and drop to UI: Import obj files by drag and drop 2023-04-21 21:06:35 +02:00
First-time contributor

Do you plan to have this in 3.6 LTS?

Do you plan to have this in 3.6 LTS?
Guillermo Venegas force-pushed drop-file-obj from 10933d0d27 to 642d39a5ba 2023-05-29 22:45:46 +02:00 Compare
Guillermo Venegas requested review from Campbell Barton 2023-05-29 22:51:13 +02:00
Guillermo Venegas requested review from Julian Eisel 2023-05-29 22:51:13 +02:00
Author
Contributor

Cleaner version created, waiting for #108477 to be merged on main to upload improvements

Cleaner version created, waiting for https://projects.blender.org/blender/blender/pulls/108477 to be merged on main to upload improvements
Guillermo Venegas changed title from UI: Import obj files by drag and drop to WIP: UI: Import obj files by drag and drop 2023-06-02 23:15:18 +02:00
Guillermo Venegas force-pushed drop-file-obj from 642d39a5ba to 0b2aef0052 2023-06-02 23:37:04 +02:00 Compare
Guillermo Venegas added 1 commit 2023-06-03 00:41:37 +02:00
Author
Contributor

with the current state now to add others dropbox is just as seen in the image, PD: I could leave this set and the drop will work, ones will open import window an other will just import

image

However changes are still required to show the pop-up dialog, and to skip save the file paths in the prefabs, as i did in the obj file

image

with the current state now to add others dropbox is just as seen in the image, PD: I could leave this set and the drop will work, ones will open import window an other will just import ![image](/attachments/6c17da6f-0b1f-44aa-ba27-e75b44ac1e39) However changes are still required to show the pop-up dialog, and to skip save the file paths in the prefabs, as i did in the obj file ![image](/attachments/91df0180-4201-4ba5-9945-a83e498c4825)
122 KiB
121 KiB
Guillermo Venegas added 1 commit 2023-06-03 04:14:08 +02:00
Guillermo Venegas added 1 commit 2023-06-03 04:30:44 +02:00
Guillermo Venegas added 1 commit 2023-06-03 04:32:54 +02:00
Guillermo Venegas added 1 commit 2023-06-03 04:33:07 +02:00
Guillermo Venegas changed title from WIP: UI: Import obj files by drag and drop to UI: Import obj files by drag and drop 2023-06-07 03:29:24 +02:00
Guillermo Venegas added 1 commit 2023-06-07 03:34:21 +02:00
Guillermo Venegas added 1 commit 2023-06-07 03:35:35 +02:00
Guillermo Venegas added 1 commit 2023-06-07 03:36:31 +02:00
Guillermo Venegas added 1 commit 2023-06-07 03:37:24 +02:00
Guillermo Venegas added 1 commit 2023-06-07 03:53:30 +02:00
Guillermo Venegas added 1 commit 2023-06-07 03:59:47 +02:00
Guillermo Venegas added 1 commit 2023-06-07 21:26:51 +02:00
Guillermo Venegas added 1 commit 2023-06-07 21:27:14 +02:00
Author
Contributor

With this patch and together with this other one #107230, importing multiple files would be ready

Here a video

It would only be necessary to adapt in this patch files_drop_copy to copy all file paths

With this patch and together with this other one #107230, importing multiple files would be ready Here a [video ](https://projects.blender.org/attachments/02969f77-8900-46a2-88ab-da26428251c9) It would only be necessary to adapt in this patch `files_drop_copy` to copy all file paths
Guillermo Venegas added 1 commit 2023-06-08 05:37:45 +02:00
Member

Hey @guishe ! Just a quick note to tell you that this PR isn't being ignored, but that review could take longer than you might hope.

This type of interaction has obviously been requested by users for quite a long time. But we have also had implementations submitted over the years that have worked similarly but we couldn't accept back then because they caused issues that frankly I can't remember. But... most importantly... those were before Julian completely overhauled the drag and drop code. Your PR is using the new drag and drop code and seems to work wonderfully.

So basically this new (wonderful) functionality has some history that will cause a bit of thought for the review process. But I have great hope that this can be a Blender 4.0 feature.

Hey @guishe ! Just a quick note to tell you that this PR isn't being ignored, but that review could take longer than you might hope. This type of interaction has obviously been requested by users for quite a long time. But we have also had implementations submitted over the years that have worked similarly but we couldn't accept back then because they caused issues that frankly I can't remember. But... most importantly... those were before Julian completely overhauled the drag and drop code. Your PR is using the new drag and drop code and seems to work wonderfully. So basically this new (wonderful) functionality has some history that will cause a bit of thought for the review process. But I have great hope that this can be a Blender 4.0 feature.
Author
Contributor

Thank you, I know that the release of 3.6 is coming up right now, and although I wanted it to come out for 3.6, I understand that there are other issues that need to be resolved in advance.

I'm still looking forward to seeing this included for 4.0 as well.

Thank you, I know that the release of 3.6 is coming up right now, and although I wanted it to come out for 3.6, I understand that there are other issues that need to be resolved in advance. I'm still looking forward to seeing this included for 4.0 as well.
First-time contributor

Hey! I might be misunderstanding the code here, but is there any chance to put the file extension to operator mapping into Python? That way the code would be extendable for authors of addons that introduce new file formats or for pipeline TDs who want to overwrite on existing file formats which operator with which settings gets executed/exposed to the users.

Hey! I might be misunderstanding the code here, but is there any chance to put the file extension to operator mapping into Python? That way the code would be extendable for authors of addons that introduce new file formats or for pipeline TDs who want to overwrite on existing file formats which operator with which settings gets executed/exposed to the users.
Author
Contributor
@Frieder see https://projects.blender.org/blender/blender/pulls/111242
Member

Okay, let's close this patch and focus on the new one. I think there's agreement there that the other has the better design. Thanks!

Okay, let's close this patch and focus on the new one. I think there's agreement there that the other has the better design. Thanks!
Hans Goudey closed this pull request 2023-09-13 17:41:00 +02:00
Guillermo Venegas deleted branch drop-file-obj 2023-09-13 17:42:14 +02:00

Pull request closed

Sign in to join this conversation.
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
7 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#106871
No description provided.