Skip to content

Instantly share code, notes, and snippets.

@Utsira
Utsira / DisintegrationShader.lua
Last active May 2, 2019 20:23
Disintegration Shader
--# Main
-- Disintegration Shader
supportedOrientations(LANDSCAPE_ANY)
function setup()
-- parameter.watch("grav")
-- parameter.watch("gravBack") --for bug-checking the get local point function
print ("tilt to spin the sphere \ntap the screen to explode / unexplode the mesh")
aerial = color(28, 27, 54, 255)
verts = Isosphere(5)
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
guard let plane = anchor as? ARPlaneAnchor,
let device = renderer.device,
let geometry = ARSCNPlaneGeometry(device: device)
else { return nil }
geometry.update(from: plane.geometry)
let maskMaterial = SCNMaterial()
maskMaterial.colorBufferWriteMask = []
geometry.materials = [maskMaterial]
let node = SCNNode(geometry: geometry)
private func planeBoundary(extent: float3) -> (min: SCNVector3, max: SCNVector3) {
let radius = extent * 0.5
return (min: SCNVector3(-radius), max: SCNVector3(radius))
}
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
guard let plane = anchor as? ARPlaneAnchor,
let geometry = node.geometry as? ARSCNPlaneGeometry
else { return }
geometry.update(from: plane.geometry)
node.boundingBox = planeBoundary(extent: plane.extent)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
startTracking()
}
private func startTracking() {
sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = [.vertical, .horizontal]
sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
@Utsira
Utsira / example_augmentedOffice_didUpdateNode.swift
Created June 9, 2018 14:11
Examples for augmented office blog post
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
guard let plane = anchor as? ARPlaneAnchor,
let geometry = node.geometry as? ARSCNPlaneGeometry
else { return }
geometry.update(from: plane.geometry)
node.boundingBox = planeBoundary(extent: plane.extent)
}
@Utsira
Utsira / MarkdownCodeaParaStitch
Created July 12, 2015 15:41
Markdown Codea with paragraph stitching
--# Main
-- Markdown Codea
-- paragraph-stitching version
-- by Yojimbo2000
displayMode(OVERLAY)
displayMode(FULLSCREEN)
function setup()
state = Stitch
state.init()
@Utsira
Utsira / Component system
Last active April 15, 2016 14:30
Component System using Mix-ins for Codea / Lua
--# Main
-- Component System by Utsira. uses runtime mix-ins to add component's methods to entities (ie not a pure entity - component - system model).
-- TO USE:
-- Entity is a superclass that adds the method :add, for adding (including) components to game objects(entities).
-- Components are tables, but use : to name their methods.
-- If component has an iterator table then it is a system. Iterate will run through every entity that is part of that system
-- If component has an :init function, this will not be added to the entity, but will instead be run when the component is added
-- Use this function to perform your initial setup
function setup()
@Utsira
Utsira / MarkdownCodea
Last active January 9, 2016 13:37
Markdown-like text formatting in Codea
--# Main
-- Markdown Codea
-- by Yojimbo2000
displayMode(FULLSCREEN)
function setup()
setText()
y,vel = 0,0
scrollY={} --store deltas for smooth scrolling upon finger release
end
@Utsira
Utsira / InstancingOBJtest.lua
Created October 30, 2015 23:05
Profiling instancing of obj models in Codea
--# Main
--Simple Blender .obj loader
--assumes each object has only one texture image
--currently only supports one object per file
--todo: remote images
local touches, tArray, lastPinchDist = {}, {}