Skip to content

Instantly share code, notes, and snippets.

@GOFAI
Last active May 4, 2021 23:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GOFAI/d52e83784bbffdbac2a89699a27e62dd to your computer and use it in GitHub Desktop.
Save GOFAI/d52e83784bbffdbac2a89699a27e62dd to your computer and use it in GitHub Desktop.
Basic SceneKit demo in Common Lisp using CCL's ObjC bridge
(objc:load-framework "SceneKit" :scenekit)
(defpackage :scenekit-demo)
(in-package :scenekit-demo)
(defun make-scenekit-view (window)
(let* ((view (#/alloc ns:s-c-n-view))
(scene (#/scene ns:s-c-n-scene))
;;; for some reason #/rootNode is unbound, but this works:
(root (objc:send scene 'root-node))
(box (#/boxWithWidth:height:length:chamferRadius:
ns:s-c-n-box 1.0d0 1.0d0 1.0d0 0.0d0))
(box-node (#/nodeWithGeometry: ns:s-c-n-node box)))
(#/initWithFrame:options: view (#/frame window) gui::+null-ptr+)
(#/setScene: view scene)
;;; Add automatic lights
(#/setAutoenablesDefaultLighting: view t)
;;; Turn on automatic camera control
(#/setAllowsCameraControl: view t)
(#/addChildNode: root box-node)
(#/setBackgroundColor: view (#/blackColor ns:ns-color))
(values view scene root)))
(defclass scenekit-window (ns:ns-window)
()
(:metaclass ns:+ns-object))
(defun scenekit-demo ()
(objc:with-autorelease-pool
(multiple-value-bind (w v)
(gui::execute-in-gui
#'(lambda () (let* ((win (gui::new-cocoa-window :class (find-class 'scenekit-window)
:title "SceneKit Demo"
:height 600
:width 800
:expandable t))
(vi (make-scenekit-view win)))
(#/setContentView: win vi)
(values win vi))))
(list w v))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment