Browse Source

initial commit

master
Victor Giers 1 year ago
commit
0be7fe4eb6

+ 8
- 0
Blender Launcher.desktop View File

@@ -0,0 +1,8 @@
[Desktop Entry]
Name=Blender Launcher
Exec=/home/giers/.local/bin/blender-launcher.sh %f
Comment=Blender Launcher
Terminal=false
Icon=/home/giers/.local/share/blender/blender.svg
Type=Application
Name[de_DE]=Blender Launcher

+ 56
- 0
README.md View File

@@ -0,0 +1,56 @@
# Double-click any 3D file to open it in Blender 2.8

You can run `blender-launcher.sh` like you can run the `blender` binary.
I'm using `/home/giers/.local/bin/blender-launcher.sh %f` as launcher command for Blender 2.81a in Linux Mint 19.3. Note that `~` won't work in a .desktop file. Put the .desktop file in `~/.local/share/applications` if it didn't go there automatically after creating it.
Put `blender-launcher.sh` and `blender_2.8_import_3dobjects.py` in `~/.local/bin`. Blender is expected to be in `~/.local/share/blender`, you can change that path in the .sh.

## How to set MIME-Types and respective icons in Linux Mint 19.3
Probably also works in other versions of Mint and maybe in Ubuntu as well.

In order to run Blender with the launcher when double clicking on a 3D-model file and for them to have Blenders icon, do the following:

Create a new mime-type in `/etc/mime.types` file. I called mine model/model which counts for all kinds of 3d models.
Create a .xml file in `/usr/share/mime/*` (one respective folder with arbitrary name) - with arbitrary name. I made mine be `/usr/share/mime/model/3d-models.xml` and for safety measures put a copy in `/usr/share/mime/packages/overrides.xml` because I saw that on StackOverflow .. ! One of them should be enough though.
This is the content:
```
<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="model/model">
<comment>3D model or scene</comment>
<comment xml:lang="de">3D Model oder Szene</comment>
<generic-icon name="model-model"/>
<glob pattern="*.dae"/>
<glob pattern="*.stl"/>
<glob pattern="*.obj"/>
<glob pattern="*.fbx"/>
<glob pattern="*.ply"/>
<glob pattern="*.gltf"/>
<glob pattern="*.glb"/>
<glob pattern="*.mdl"/>
<glob pattern="*.3ds"/>
<glob pattern="*.abc"/>
<glob pattern="*.x3d"/>
<glob pattern="*.wrl"/>
<glob pattern="*.bvh"/>
</mime-type>
</mime-info>
```
Run
```
sudo grep -R "\.dae" *
```
in `/usr/share/mime` for each filetype (not only dae) to see if one of the file types is associated with another mime type already.
If so, delete these entries from all the files that do not say that they're automatically generated in their first lines. I found intervening entries in the files in the `model` folder and in the following files: `freedesktop.org.xml` `types` and `subclasses` - so I removed them.
Now renew and overwrite the automatically generate files with the new mime-info file by running
```
sudo update-mime-database /usr/share/mime/
```
Reload Cinnamon with `Alt+F2` and running the command `r` and pressing F5 in the folder containing example files. Check if your files mimetypes have been updated by either looking at their properties ("Type" is shown right underneath the "Name" in Nemo). Running `file -i <filename>` didn't give me the actual updated results right away, strangely.
If the new mimetypes have been set successfully it's now time to change the files icons.
Put the icon .pngs with their respective sizes in `/usr/share/icons/Mint-Y-Dark/*` (or your respective themes relative folders)
If your file types mimetype is `model/model`, they have to be called `model-model` (replace / with -).
Run the following command to update the icon cache.
```
sudo update-icon-caches /usr/share/icons/*
```
If the icons don't show up make sure you're not checking on empty files and reload Cinnamon by pressing `Alt+F2` and running the command `r` and press F5, just like when refreshing the mimetypes.

BIN
blender-icons/128/model-model.png View File


BIN
blender-icons/16/model-model.png View File


BIN
blender-icons/24/model-model.png View File


BIN
blender-icons/32/model-model.png View File


BIN
blender-icons/48/model-model.png View File


BIN
blender-icons/64/model-model.png View File


+ 13
- 0
blender-launcher.sh View File

@@ -0,0 +1,13 @@
#!/bin/bash
if [[ -f $1 ]]; then
echo "$1 is a file"
filename=$(basename -- "$1")
extension="${filename##*.}"
if [[ $extension == *"blend"* ]]; then
exec ~/.local/share/blender/blender "$@"
else
exec ~/.local/share/blender/blender --python ~/.local/bin/blender_2.8_import_3dobjects.py -- "$1"
fi
else
exec ~/.local/share/blender/blender "$@"
fi

+ 57
- 0
blender_2.8_import_3dobjects.py View File

@@ -0,0 +1,57 @@
#!/usr/bin/env python
import os
import sys
import bpy

file_loc = sys.argv[4] #0: blender 1: --python 2: path to script 3: -- 4: actual filepath
print("Path: ", file_loc)
for o in bpy.data.objects:
if o.type == 'MESH':
o.select_set(True)
else:
o.select_set(False)
# call the operator only one initial time
bpy.ops.object.delete()

#check for filetype
extension = file_loc.split(".")[-1]
# BLENDER 2.8 3DS IMPORT NOT YET AVAILABLE
#if(extension == "3ds" or extension == "3DS"):
# imported_object = bpy.ops.import_scene.autodesk_3ds(filepath=file_loc)
if(extension == "obj" or extension == "OBJ"):
imported_object = bpy.ops.import_scene.obj(filepath=file_loc)
if(extension == "fbx" or extension == "FBX"):
imported_object = bpy.ops.import_scene.fbx(filepath=file_loc)
if(extension == "gltf" or extension == "GLTF" or extension == "glb" or extension == "GLB"):
imported_object = bpy.ops.import_scene.gltf(filepath=file_loc)
if(extension == "ply" or extension == "PLY"):
imported_object = bpy.ops.import_mesh.ply(filepath=file_loc)
if(extension == "stl" or extension == "STL"):
imported_object = bpy.ops.import_mesh.stl(filepath=file_loc)
if(extension == "abc" or extension == "ABC"):
imported_object = bpy.ops.wm.alembic_import(filepath=file_loc, as_background_job=False)
if(extension == "dae" or extension == "DAE"):
imported_object = bpy.ops.wm.collada_import(filepath=file_loc)
if(extension == "x3d" or extension == "X3D" or extension == "wrl" or extension == "WRL"):
imported_object = bpy.ops.import_scene.x3d(filepath=file_loc)
if(extension == "bvh" or extension == "BVH"):
imported_object = bpy.ops.import_anim.bvh(filepath=file_loc)
if(extension == "mdl" or extension == "MDL"):
file_name = os.path.basename(file_loc)
imported_object = bpy.ops.import_mesh.mdl(filepath=file_loc, files=[{"name":file_name}])

#zoom to object
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for region in area.regions:
if region.type == 'WINDOW':
override = {'area': area, 'region': region, 'edit_object': bpy.context.edit_object}
bpy.ops.view3d.view_selected(override)

#change view: zoom to object & hide overlays
area = next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D')
if(extension != "bvh" and extension != "BVH"):
area.spaces[0].overlay.show_overlays = False
area.spaces[0].shading.type = 'MATERIAL'
#bpy.ops.view3d.camera_to_view_selected()
#area.spaces[0].region_3d.view_perspective = 'CAMERA'

Loading…
Cancel
Save