Skip to content

Instantly share code, notes, and snippets.

View kamend's full-sized avatar

Kamen Dimitrov kamend

View GitHub Profile
@kamend
kamend / AssetPathAttribute.cs
Created November 3, 2015 08:28
A custom attribute to easily link prefab's paths instead of linking directly the prefab itself, especially useful inside scriptable objects and if you don't want Unity to load all the prefabs' resources as soon as the Scriptable Object loads.
using UnityEngine;
using System;
using System.Collections;
public class AssetPathAttribute : PropertyAttribute {
System.Type type;
string label;
public bool isResource;
public AssetPathAttribute(string l, System.Type t, bool isR) {
@kamend
kamend / FlatSubdivide.js
Created July 23, 2016 14:54
THREE.js Flat Triangle Subdivide
// Triangle Subdivision based on http://wiki.unity3d.com/index.php?title=MeshHelper
// There is not smoothing of any sort, it will just divide the triangles
// hence the FlatSubdivide name
THREE.FlatSubdivide = function () {
};
// Applies the "modify" pattern
@kamend
kamend / WorldToCanvasPosition.cs
Created March 10, 2017 14:34
Position a UI element based on a World Position
Vector2 screenPos = camera.WorldToViewportPoint( worldPosition );
screenPos.x *= guiCanvas.rect.width;
screenPos.y *= guiCanvas.rect.height;
// the element should be anchored bottom/left
uiElement.anchoredPosition = screenPos;
// How to load in modules
const FaceTracking = require('FaceTracking');
const D = require('Diagnostics');
const Scene = require('Scene');
const TouchGestures = require('TouchGestures');
const object = Scene.root.find("object");
face.mouth.openness.monitor().subscribe(function(event) {
if(event.newValue > 0) {
object.transform.x = FaceTracking.face(0).cameraTransform.applyTo(FaceTracking.face(0).mouth.center).x;
const Diagnostics = require('Diagnostics');
const Scene = require('Scene');
const Shaders = require('Shaders');
const Materials = require("Materials");
const R = require("Reactive");
const CameraInfo = require('CameraInfo');
const Textures = require('Textures');
const mat = Materials.get("material0");
const cameraTexture = Textures.get("cameraTexture0");
const Diagnostics = require('Diagnostics');
const Scene = require('Scene');
const Shaders = require('Shaders');
const Materials = require("Materials");
const R = require("Reactive");
const CameraInfo = require('CameraInfo');
const Textures = require('Textures');
const Time = require('Time');
const mat = Materials.get("material0");
const cameraTexture = Textures.get("cameraTexture0");
const D = require('Diagnostics');
const Scene = require('Scene');
const Patches = require('Patches');
const FaceTracking = require('FaceTracking');
const Shaders = require('Shaders');
const R = require('Reactive');
const Patchers = require('Patches');
const face = FaceTracking.face(0);
const rect = Scene.root.find("rectangle0");
const cam = Scene.root.find("Camera");
@kamend
kamend / convert-audio.sh
Created November 20, 2019 08:53 — forked from positlabs/spark-convert-audio.sh
FFMPEG audio conversion for Spark AR
#! /bin/bash
# This command converts audio according to the specifications listed in the Spark docs:
# https://sparkar.facebook.com/ar-studio/learn/documentation/docs/audio
# mono m4a, 44.1kHz sample rate, 16-bit-depth resolution
# Usage:
# convert-audio.sh myaudio.mp3 converted.m4a
# Notes:
# Always use m4a for output file type
# Change "64k" to a higher value to improve bitrate/quality. e.g. 96k 128k 192k
@kamend
kamend / CustomPlacementInteractable.cs
Last active December 16, 2022 13:23
XR Interaction Toolkit: Custom ARPlacementInteractable to place object with the left mouse button when in the Editor
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit.AR;
public class CustomPlacementInteractable : ARPlacementInteractable
{
ARObjectPlacementEventArgs m_ObjectPlacementEventArgs = new ARObjectPlacementEventArgs();
void Update()
@kamend
kamend / gist:ddf30de73ae17017d3b85c0f984cc0a1
Created August 9, 2023 07:57
Holding unstructured data in a Dictionary
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DictExperiments
{
public static class DictExt
{
public class SceneObjectParser : IDisposable