From f1468a99463b4e94ff049263e3fda6efd10fe21d Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sat, 29 Jul 2023 01:34:33 -0400 Subject: [PATCH] blender: Build with Draco support (#245535) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- pkgs/applications/misc/blender/default.nix | 5 ++++- pkgs/applications/misc/blender/draco.patch | 26 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 pkgs/applications/misc/blender/draco.patch diff --git a/pkgs/applications/misc/blender/default.nix b/pkgs/applications/misc/blender/default.nix index f6f5edc84ef8..58cdf9592cdc 100644 --- a/pkgs/applications/misc/blender/default.nix +++ b/pkgs/applications/misc/blender/default.nix @@ -35,7 +35,9 @@ stdenv.mkDerivation rec { hash = "sha256-SzdWyzdGhsaesv1VX5ZUfUnLHvRvW8buJTlOVxz6yOk="; }; - patches = lib.optional stdenv.isDarwin ./darwin.patch; + patches = [ + ./draco.patch + ] ++ lib.optional stdenv.isDarwin ./darwin.patch; nativeBuildInputs = [ cmake makeWrapper python310Packages.wrapPython llvmPackages.llvm.dev @@ -165,6 +167,7 @@ stdenv.mkDerivation rec { mkdir $out/Applications mv $out/Blender.app $out/Applications '' + '' + mv $out/share/blender/${lib.versions.majorMinor version}/python{,-ext} buildPythonPath "$pythonPath" wrapProgram $blenderExecutable \ --prefix PATH : $program_PATH \ diff --git a/pkgs/applications/misc/blender/draco.patch b/pkgs/applications/misc/blender/draco.patch new file mode 100644 index 000000000000..2a856a0638ae --- /dev/null +++ b/pkgs/applications/misc/blender/draco.patch @@ -0,0 +1,26 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -898,11 +898,6 @@ set_and_warn_dependency(WITH_PYTHON WITH_CYCLES OFF) + set_and_warn_dependency(WITH_PYTHON WITH_DRACO OFF) + set_and_warn_dependency(WITH_PYTHON WITH_MOD_FLUID OFF) + +-if(WITH_DRACO AND NOT WITH_PYTHON_INSTALL) +- message(STATUS "WITH_DRACO requires WITH_PYTHON_INSTALL to be ON, disabling WITH_DRACO for now") +- set(WITH_DRACO OFF) +-endif() +- + # enable boost for cycles, audaspace or i18n + # otherwise if the user disabled + +--- a/scripts/addons/io_scene_gltf2/io/com/gltf2_io_draco_compression_extension.py ++++ b/scripts/addons/io_scene_gltf2/io/com/gltf2_io_draco_compression_extension.py +@@ -17,7 +17,7 @@ def dll_path() -> Path: + """ + lib_name = 'extern_draco' +- blender_root = Path(bpy.app.binary_path).parent ++ blender_root = Path(bpy.app.binary_path).parent.parent +- python_lib = Path('{v[0]}.{v[1]}/python/lib'.format(v=bpy.app.version)) ++ python_lib = Path('share/blender/{v[0]}.{v[1]}/python-ext/lib'.format(v=bpy.app.version)) + python_version = 'python{v[0]}.{v[1]}'.format(v=sys.version_info) + + path = os.environ.get('BLENDER_EXTERN_DRACO_LIBRARY_PATH')