NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.15k stars 14.17k forks source link

Package request: OpenUSD #250542

Closed ShaddyDC closed 11 months ago

ShaddyDC commented 1 year ago

Project description

Universal Scene Description (USD) is an efficient, scalable system for authoring, reading, and streaming time-sampled scene description for interchange between graphics applications.

OpenUSD is AFAIK the library to work with the USD format.

Metadata

ShaddyDC commented 1 year ago

I've got a working derivation, but I'm not sure if this is already in a state that is good enough for a PR. In particular, packaging the pyside tools properly didn't seem straightforward to me. AFAICT, it just copies some binaries from other QT parts and wraps them with extra arguments, so that's what I'm doing here.
While the python package seems to be working properly, I ran into an issue before when trying to include the headers into a C++ project, and I believe it failed to find some python headers? Maybe that needs some extra buildInput? I haven't investigated more. Locally, I've just been using a version compiled with "-DPXR_ENABLE_PYTHON_SUPPORT=OFF" for that.
The binaries, such as usdview, are working by my testing, besides requiring QT_QPA_PLATFORM=xcb on wayland.

{ buildPythonPackage
, fetchFromGitHub
, fetchpatch
, fetchurl
, pkgs
, lib
, cmake
, doxygen
, draco
, graphviz-nox
, ninja
, setuptools
, pyqt5
, pyopengl
, jinja2
, pyside6
, boost
, numpy
, git
, tbb
, opensubdiv
, openimageio
, opencolorio
, osl
, ptex
, embree
, openexr
, flex
, bison
, pysideApiextractor
, qt6
, python
, ...
}:
let
  pyside-tools-justcopied = pkgs.stdenv.mkDerivation rec {
    pname = "pyside-tools";
    version = "6.5.2";
    src = fetchurl {
      url = "https://download.qt.io/official_releases/QtForPython/pyside6/PySide6-${version}-src/pyside-setup-everywhere-src-${version}.tar.xz";
      sha256 = "sha256-kNvx0U/NQcmKfL6kS4pJUeENC3mOFUdJdW5JRmVNG6g=";
    };

    sourceRoot = "pyside-setup-everywhere-src-${version}/sources/${pname}";

    nativeBuildInputs = [ cmake ];
    buildInputs = [ qt6.qtbase ];

    dontWrapQtApps = true;
  };
  pyside-tools-uic = pkgs.writeShellScriptBin "pyside6-uic" ''
    exec ${pyside-tools-justcopied}/bin/uic -g python "$@"
  '';
in
buildPythonPackage rec {
  pname = "OpenUSD";
  version = "23.08";
  src = fetchFromGitHub {
    owner = "PixarAnimationStudios";
    repo = pname;
    rev = "v${version}";
    sha256 = "sha256-3wM6stJnpznTU7Lb0vAdeO0/cr8n9rhvPZgT7PGAe04=";
  };

  patches = [
    (fetchpatch {
      name = "fix-for-pyside-6.5.0-initialization-order.patch";
      url = "https://github.com/PixarAnimationStudios/OpenUSD/commit/78e66dee7dc448138687ce908ceeb2c4f54d83d9.patch";
      hash = "sha256-0IRmqZABvrzJ4cza3c2f3sOaMVEwaoms3Up5RsjOXFs=";
    })
    (fetchpatch {
      name = "fix-drawModeStandin-array.patch";
      url = "https://patch-diff.githubusercontent.com/raw/PixarAnimationStudios/OpenUSD/pull/2410.patch";
      hash = "sha256-WDLUqK6/gKHv7kj2ipHfav/Z64uAXQGr8152vRHj3b8=";
    })
  ];

  format = "other";

  propagatedBuildInputs = [
    setuptools
    pyqt5
    pyopengl
    jinja2
    pyside6
    pyside-tools-uic
    boost
    numpy
  ];

  cmakeFlags = [
    "-DPXR_BUILD_EXAMPLES=OFF"
    "-DPXR_BUILD_TUTORIALS=OFF"
    "-DPXR_BUILD_USD_TOOLS=ON"
    "-DPXR_BUILD_IMAGING=ON"
    "-DPXR_BUILD_USD_IMAGING=ON"
    "-DPXR_BUILD_USDVIEW=ON"
    "-DPXR_BUILD_DOCUMENTATION=ON"
    "-DPXR_BUILD_PYTHON_DOCUMENTATION=ON"
    "-DPXR_BUILD_EMBREE_PLUGIN=ON"
    "-DPXR_BUILD_ALEMBIC_PLUGIN=ON"
    # "-DPXR_ENABLE_MATERIALX_SUPPORT=ON"
    "-DPXR_ENABLE_OSL_SUPPORT=ON"
    "-DPXR_BUILD_DRACO_PLUGIN=ON"
  ];

  nativeBuildInputs = [
    cmake
    ninja
    git
    qt6.wrapQtAppsHook
    doxygen
    graphviz-nox
  ];
  buildInputs = [
    tbb
    opensubdiv
    openimageio
    opencolorio
    osl
    ptex
    embree
    pkgs.alembic.dev
    openexr
    flex
    bison
    boost
    draco

    pysideApiextractor
    qt6.qtbase
  ];

  pythonImportsCheck = [ "pxr" "pxr.Usd" ];

  postInstall = ''
    # Make python lib properly accessible
    mkdir -p $out/${python.sitePackages}
    cp -r $out/lib/python/* $out/${python.sitePackages}/
  '';

  meta = {
    description = "Universal Scene Description";
    longDescription = "Universal Scene Description (USD) is an efficient, scalable system for authoring, reading, and streaming time-sampled scene description for interchange between graphics applications.";
    homepage = "https://openusd.org/";
    license = lib.licenses.free;
    maintainers = [];
  };
}

I'd be happy to make a PR for this if this is a good-enough state.