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)
}
@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) {
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 / 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 / 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)
@pofulu
pofulu / RandomNext.js
Created April 22, 2019 09:57
隨機從陣列中選取一個元素
function RandomNext(array) {
return array[Math.random() * array.length | 0];
}
@pofulu
pofulu / Open Unity 16-9.scpt
Created April 30, 2019 03:07 — forked from walterpalladino/Open Unity 16-9.scpt
How to Open the Unity Window on Mac OS X on a 16:9 relationship (1280x720)
tell application "Unity" to activate -- needs to be in front
tell application "System Events" to tell application process "Unity"
try
get properties of window 1
set size of window 1 to {1280, 720}
on error errmess
log errmess
-- no window open
end try
end tell