Server application for collaborative production of 3D assets and animations.
(define-module (vfx packages main)
  #:use-module (gnu packages)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages commencement)
  #:use-module (gnu packages boost)
  #:use-module (gnu packages tbb)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages xorg)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages sdl)
  #:use-module (gnu packages graphics)
  #:use-module (gnu packages image)
  #:use-module (gnu packages audio)
  #:use-module (gnu packages pulseaudio)
  #:use-module (gnu packages video)
  #:use-module (gnu packages algebra)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages multiprecision)
  #:use-module (gnu packages fonts)
  #:use-module (gnu packages fontutils)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages pdf)
  #:use-module (gnu packages pulseaudio)
  
  #:use-module (vfx packages base)
  #:use-module (vfx packages pixar)
   
  #:use-module (guix)
  #:use-module (guix git-download)
  #:use-module (guix build-system copy)
  #:use-module (guix build-system cmake)
  #:use-module ((guix licenses) #:prefix license:))

(define blender-translations-3.4
  ;; because translations are in a separate repo 
  ;; (will disappear in 3.5: moved to Blender repo)
  (package
    (name "blender-translations")
    (version "3.4.1")
    (source
         (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://projects.blender.org/blender/blender-translations")
		    ;; use the commit referenced by blender repo in v3.4.1
                    (commit "e398d3c4969a37ae2ecff388344dd780bc1cfe82")))
              (file-name (git-file-name name version))
              (sha256
               (base32
		"04f1vs4f592s9fxawb3fj8gnvhp2c759cgnm4cgn7mvmjg7fj8ly"))))
    (build-system copy-build-system)
    (home-page "https://blender.org/")
    (synopsis "All languages translation files for Blender")
    (description
     "Blender is a 3D graphics creation suite.  It supports the entirety of
the 3D pipeline—modeling, rigging, animation, simulation, rendering,
compositing and motion tracking, even video editing and game creation.  The
application can be customized via its API for Python scripting.")
    (license license:gpl2+)))    

(define blender-addons-3.4
  ;; because addons are in a separate repo 
  ;; (will disappear in 3.5: moved to Blender repo)
  (package
    (name "blender-addons")
    (version "3.4.1")
    (source
         (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://projects.blender.org/blender/blender-addons")
		    ;; use the commit referenced by blender repo in v3.4.1
                    (commit "7408fc7283fd98a88db1383f45f5d15680472a7f")))
              (file-name (git-file-name name version))
              (sha256
               (base32
		"0ss0w2jah25zv1xwd59nz9id4ppjms4vaxiqr774jvjx0jfk5x5d"))))
    (build-system copy-build-system)
    (home-page "https://blender.org/")
    (synopsis "All addon files for Blender")
    (description
     "Blender is a 3D graphics creation suite.  It supports the entirety of
the 3D pipeline—modeling, rigging, animation, simulation, rendering,
compositing and motion tracking, even video editing and game creation.  The
application can be customized via its API for Python scripting.")
    (license license:gpl2+)))    

(define blender-addons-contrib-3.4
  ;; because addons are in a separate repo 
  ;; (will disappear in 3.5: moved to Blender repo)
  (package
    (name "blender-addons-contrib")
    (version "3.4.1")
    (source
         (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://projects.blender.org/blender/blender-addons-contrib")
		    ;; use the commit referenced by blender repo in v3.4.1
                    (commit "886ea86bd9a0fd2761260a46356b728d51f2298a")))
              (file-name (git-file-name name version))
              (sha256
               (base32
		"17kwn8yczdzj5bxckar0qgpy66gv5my11zy00xnfkn67fsc8chan"))))
    (build-system copy-build-system)
    (home-page "https://blender.org/")
    (synopsis "Additional addon files for Blender")
    (description
     "Blender is a 3D graphics creation suite.  It supports the entirety of
the 3D pipeline—modeling, rigging, animation, simulation, rendering,
compositing and motion tracking, even video editing and game creation.  The
application can be customized via its API for Python scripting.")
    (license license:gpl2+)))    

(define-public blender-3.4
  (package
    (name "blender")
    (version "3.4.1")
    (source (origin
              (method url-fetch)
              (uri (string-append "https://projects.blender.org/blender/blender"
                                  "/archive/v" version ".tar.gz"))
              (sha256
               (base32
		"06pw0g55j6y5q7qk81qbzkwdkj7rmiq8jii3p8zzy2ql91c5p0s1"))
              (patches
               (search-patches
		;; make python3.9 work until Guix has python3.10
		"vfx/patches/blender-allow-python-3.9.patch"
		;; fix Python includes and unresolved symbols
		"vfx/patches/blender-fix-cmake-for-python.patch"))))
    (build-system cmake-build-system)
    (arguments
      (let ((python-version (version-major+minor (package-version python))))
       `(#:tests? #f
         #:configure-flags
         (list "-DWITH_CYCLES_OSL=OFF"
               "-DWITH_DOC_MANPAGE=ON"
               "-DWITH_INSTALL_PORTABLE=OFF" ; no FHS installation (use CMAKE_INSTALL_PREFIX)

	       (string-append "-DUSD_LIBRARY=" (assoc-ref %build-inputs "usd") "/lib/libusd_ms.so")

	       "-DWITH_PYTHON_INSTALL=OFF" ; don't copy system python into the blender install folder
	       "-DWITH_DRACO=OFF" ; can't enable Draco without copying system python into the blender install folder

               (string-append "-DPYTHON_LIBRARY=python" ,python-version)
               (string-append "-DPYTHON_LIBPATH="
			      (assoc-ref %build-inputs "python")
                              "/lib")
               (string-append "-DPYTHON_INCLUDE_DIR="
			      (assoc-ref %build-inputs "python")
                              "/include/python" ,python-version)
               (string-append "-DPYTHON_VERSION=" ,python-version)
               (string-append "-DPYTHON_NUMPY_INCLUDE_DIRS="
                              (assoc-ref %build-inputs "python-numpy")
                              "/lib/python" ,python-version "/site-packages/numpy/core/include/")
               (string-append "-DPYTHON_NUMPY_PATH="
                              (assoc-ref %build-inputs "python-numpy")
                              "/lib/python" ,python-version "/site-packages/"))
         #:phases
         (modify-phases %standard-phases
	  (add-after 'configure 'link-translations
	   ;; integrate external repo files into the sources
           (lambda* (#:key inputs #:allow-other-keys)
		    (let ((translations   (assoc-ref inputs "blender-translations"))
			  (addons         (assoc-ref inputs "blender-addons"))
			  (addons-contrib (assoc-ref inputs "blender-addons-contrib"))
			  (translations-folder   "../blender/release/datafiles/locale")
			  (addons-folder         "../blender/release/scripts/addons")
		          (addons-contrib-folder "../blender/release/scripts/addons_contrib"))
		      (rmdir translations-folder)
                      (symlink translations translations-folder)
		      (copy-recursively addons addons-folder)
		      (copy-recursively addons-contrib addons-contrib-folder)
		      #t)))))))
    (native-inputs
     (list pkg-config
           blender-translations-3.4
           ld-gold-wrapper))
    (inputs
     `(("blender-addons" ,blender-addons-3.4)
       ("blender-addons-contrib" ,blender-addons-contrib-3.4)
       ("jemalloc" ,jemalloc-5.3)
       ("boost" ,boost)
       ("tbb" ,tbb-2020)
       ("libx11" ,libx11)
       ("libxi" ,libxi)
       ("libxrender" ,libxrender)
       ("font-dejavu" ,font-dejavu)
       ("sdl2" ,sdl2)
       ("freetype" ,freetype-2.13)
       ("glew" ,glew)
       ;("wayland" ,wayland)
       ;("libxkbcommon" ,libxkbcommon)
       ("libepoxy" ,libepoxy)
       ("python-wrapper" ,python-wrapper)
       ("python-numpy" ,python-numpy)
       ("openvdb" ,openvdb-10.0)
       ("opencolorio" ,opencolorio-2.2)
       ("openimageio" ,openimageio-2.4)
       ("openexr" ,openexr)
       ("imath" ,imath)
       ("opensubdiv" ,opensubdiv-3.5)
       ;("openshadinglanguage" ,openshadinglanguage-1.12)
       ("alembic" ,alembic)
       ("usd" ,usd)
       ("embree" ,embree)
       ("c-blosc" ,c-blosc)
       ("openjpeg" ,openjpeg)
       ("libjpeg-turbo" ,libjpeg-turbo)
       ("libpng" ,libpng)
       ("libtiff" ,libtiff)
       ("ffmpeg" ,ffmpeg)
       ("libwebp" ,libwebp)
       ("potrace" ,potrace)
       ("libharu" ,libharu)
       ("fftw" ,fftw)
       ("gmp" ,gmp)
       ("jack" ,jack-1)
       ("pulseaudio" ,pulseaudio)
       ("libsndfile" ,libsndfile)
       ("openal" ,openal)
       ("pugixml" ,pugixml)
       ("zlib" ,zlib)
       ("zstd" ,zstd "lib")))
    (home-page "https://blender.org/")
    (synopsis "3D graphics creation suite")
    (description
     "Blender is a 3D graphics creation suite.  It supports the entirety of
the 3D pipeline—modeling, rigging, animation, simulation, rendering,
compositing and motion tracking, even video editing and game creation.  The
application can be customized via its API for Python scripting.")
    (license license:gpl2+)))