Skip to content

Instantly share code, notes, and snippets.

@pofulu
pofulu / Rotation.js
Last active February 27, 2019 08:23
Rotation utilities for Spark AR Studio
function Rotation(value) {
return Remap(value, -180, 180, Math.PI * -1, Math.PI);
}
function Remap(value, low1, high1, low2, high2) {
return low2 + (value - low1) * (high2 - low2) / (high1 - low1)
}
function RotationSignal(signal) {
return RemapSignal(signal, Reactive.val(-180), Reactive.val(180), Reactive.val(Math.PI * -1), Reactive.val(Math.PI));
}
function RemapSignal(value, low1, high1, low2, high2) {
return low2.add(value.sub(low1).mul(high2.sub(low2)).div(high1.sub(low1)));
}
@pofulu
pofulu / Dragable.js
Created March 7, 2019 07:48
Script for Spark AR, make SceneObject dragable with TouchGestures.
// const Scene = require('Scene');
// new Dragable(Scene.root.find('plane0'));
function Dragable(object) {
const CameraInfo = require('CameraInfo');
const TouchGestures = require('TouchGestures');
const width = CameraInfo.previewSize.width;
const height = CameraInfo.previewSize.height;
@pofulu
pofulu / Audio to Spark AR
Last active August 14, 2020 21:01
Convert any sound to the format acceptable to Spark AR Studio with FFmpeg.
ffmpeg -i audio.wav -ar 44100 -ac 1 output.m4a
@pofulu
pofulu / BrownianMotion.js
Last active March 8, 2019 10:14
Rewrite keijiro's BrownianMotion to ReactiveStyle for Spark AR.
// C# version source by keijiro: https://github.com/keijiro/Klak/blob/master/Assets/Klak/Motion/Runtime/BrownianMotion.cs
const Scene = require('Scene');
BrownianMotion(Scene.root.find('bubble'),
{
enablePositionNoise: true,
enableRotationNoise: false,
enableScaleNoise: false,
positionAmplitude: 10
});
@pofulu
pofulu / Vector3.js
Created March 7, 2019 08:02
Vector3 function in reactive style for Spark AR.
function Vector3(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
this.mul = function (multiplier) {
return new Vector3(this.x.mul(multiplier), this.y.mul(multiplier), this.z.mul(multiplier));
};
this.scale = function (anotherVector3) {
return new Vector3(this.x.mul(anotherVector3.x), this.y.mul(anotherVector3.y), this.z.mul(anotherVector3.z));
@pofulu
pofulu / TRSModel.js
Last active March 7, 2019 08:09
Script for Spark AR. Transform, Rotation, Scale model by TouchGestures. The script can avoid moving the model when rotating and scaling.
/* How to use
const Scene = require('Scene');
const planeTracker = Scene.root.find('planeTracker');
const model = Scene.root.find('model');
const trs = new TouchTRS(planeTracker);
trs.AddModel(model);
*/
function TouchTRS(planeTracker) {
@pofulu
pofulu / CrossFade.shader
Last active March 26, 2019 10:37
A simple crossfade unlit shader for Unity
// Origin: http://guidohenkel.com/2013/04/a-simple-cross-fade-shader-for-unity/
Shader "CrossFade"
{
Properties
{
_Blend("Blend", Range(0, 1)) = 0.5
_Color("Main Color", Color) = (1, 1, 1, 1)
_MainTex("Texture 1", 2D) = "white" {}
_Texture2("Texture 2", 2D) = ""
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class RenderSource
{
public Camera targetCamera;
public RenderTexture targetTexture;
@pofulu
pofulu / filename.applescript
Created April 9, 2019 15:00 — forked from lg0/filename.applescript
applescript:get selected filename and extension
tell application "Finder" to set theFile to POSIX path of (selection as alias)
tell application "Finder" to set fileExtension to name extension of (selection as alias)