blender: Build with Draco support (#245535)

See https://github.com/NixOS/nixpkgs/issues/217921

Blender sets WITH_DRACO=OFF if WITH_PYTHON_INSTALL=OFF, however that’s
not totally necessary. Removing that forced-set then builds with
WITH_DRACO=ON, however Blender fails to launch because this creates
e.g. `share/blender/3.6/python`, and Blender then sets this as Python’s
home dir, so Python fails to init since it expects Python core to be
there (and it’s not). I couldn’t figure out how Blender sets Python’s
home dir, and explicitly setting PYTHONHOME in the env didn’t have any
effect. So instead just rename that dir to python-ext to avoid this
behavior. All that is left then is to adjust where Blender is looking
for the Draco lib.

This functionality may be verified by:

1. Visiting File → Export → glTF 2.0
2. In the right side panel (press the gear icon in top-right if not
visible), expanding “Data”
3. Enabling “Compression”
4. Press “Export glTF 2.0”
5. Verify:
- Blender stdout+stderr shows “Draco mesh compression is available”
- no error or warning message
- exported file exists

authored by

Andrew Marshall and committed by
GitHub
f1468a99 f2488b0f

+30 -1
+4 -1
pkgs/applications/misc/blender/default.nix
··· 35 35 hash = "sha256-SzdWyzdGhsaesv1VX5ZUfUnLHvRvW8buJTlOVxz6yOk="; 36 36 }; 37 37 38 - patches = lib.optional stdenv.isDarwin ./darwin.patch; 38 + patches = [ 39 + ./draco.patch 40 + ] ++ lib.optional stdenv.isDarwin ./darwin.patch; 39 41 40 42 nativeBuildInputs = 41 43 [ cmake makeWrapper python310Packages.wrapPython llvmPackages.llvm.dev ··· 165 167 mkdir $out/Applications 166 168 mv $out/Blender.app $out/Applications 167 169 '' + '' 170 + mv $out/share/blender/${lib.versions.majorMinor version}/python{,-ext} 168 171 buildPythonPath "$pythonPath" 169 172 wrapProgram $blenderExecutable \ 170 173 --prefix PATH : $program_PATH \
+26
pkgs/applications/misc/blender/draco.patch
··· 1 + --- a/CMakeLists.txt 2 + +++ b/CMakeLists.txt 3 + @@ -898,11 +898,6 @@ set_and_warn_dependency(WITH_PYTHON WITH_CYCLES OFF) 4 + set_and_warn_dependency(WITH_PYTHON WITH_DRACO OFF) 5 + set_and_warn_dependency(WITH_PYTHON WITH_MOD_FLUID OFF) 6 + 7 + -if(WITH_DRACO AND NOT WITH_PYTHON_INSTALL) 8 + - message(STATUS "WITH_DRACO requires WITH_PYTHON_INSTALL to be ON, disabling WITH_DRACO for now") 9 + - set(WITH_DRACO OFF) 10 + -endif() 11 + - 12 + # enable boost for cycles, audaspace or i18n 13 + # otherwise if the user disabled 14 + 15 + --- a/scripts/addons/io_scene_gltf2/io/com/gltf2_io_draco_compression_extension.py 16 + +++ b/scripts/addons/io_scene_gltf2/io/com/gltf2_io_draco_compression_extension.py 17 + @@ -17,7 +17,7 @@ def dll_path() -> Path: 18 + """ 19 + lib_name = 'extern_draco' 20 + - blender_root = Path(bpy.app.binary_path).parent 21 + + blender_root = Path(bpy.app.binary_path).parent.parent 22 + - python_lib = Path('{v[0]}.{v[1]}/python/lib'.format(v=bpy.app.version)) 23 + + python_lib = Path('share/blender/{v[0]}.{v[1]}/python-ext/lib'.format(v=bpy.app.version)) 24 + python_version = 'python{v[0]}.{v[1]}'.format(v=sys.version_info) 25 + 26 + path = os.environ.get('BLENDER_EXTERN_DRACO_LIBRARY_PATH')