Skip to content

Instantly share code, notes, and snippets.

const q = this._hoverEffect.$viewManager.active._components.lights._directionalLight.shadow.camera.quaternion
const v = vector3.set(0, 0, -1).applyQuaternion(q)
this.helper.setDirection(v)
this._mesh.material.uniforms.uLightDirection.value.copy(v)
// Implementation from https://gist.github.com/TimSC/8c25ca941d614bf48ebba6b473747d72
vec3 projectToGround(vec3 planeNormal, vec3 planePoint, vec3 rayDirection, vec3 rayPoint ) {
float epsilon=0.000001;
import * as THREE from 'three'
const vertexShader = `
varying vec2 vUv;
void main() {
gl_Position = vec4(position.xy * 2., 1.0, 1.0);
vUv = uv;
}
`
@mixin delay($delayOffset, $type, $baseDelay: 0ms, $childNumber: 5) {
@for $i from 1 through $childNumber {
&:nth-child(#{$i}) {
$finalDelay: $baseDelay + $delayOffset * (1 - $i);
@if $type == "both" {
animation-delay: $finalDelay;
transition-delay: $finalDelay;
} @else {
#{$type}-delay: $finalDelay;
}
// ------------
// --- MATH ---
// ------------
float remap(float value, float start1, float stop1, float start2, float stop2) {
return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
}
float cremap(float value, float start1, float stop1, float start2, float stop2) {
float r = remap(value, start1, stop1, start2, stop2);
declare module 'virtual-scroll' {
export type VirtualScrollEvent = {
x: number // total distance scrolled on the x axis
y: number // total distance scrolled on the y axis
deltaX: number // distance scrolled since the last event on the x axis
deltaY: number // distance scrolled since the last event on the y axis
originalEvent: Event // the native event triggered by the pointer device or keyboard
}
export type VirtualScrollCallback = (e: VirtualScrollEvent) => void
import * as THREE from 'three'
/**
* Utility class for gpgpu
*
*
* Receives initTexture and shaderMaterial.
*
*
* Each tick renders the material with the previous state as input.
const randomVectorInCone = (theta: number, target: THREE.Vector3) => {
const z = remap(Math.random(), [0, 1], [Math.cos(theta), 1])
const phi = remap(Math.random(), [0, 1], [0, 2 * Math.PI])
target.set(
Math.sqrt(1 - z * z) * Math.cos(phi),
Math.sqrt(1 - z * z) * Math.sin(phi),
z
)
target.normalize()
@LeonBaudouin
LeonBaudouin / observableState.ts
Last active October 19, 2021 21:10
Observable state with proxy in Typescript
type Callback<T, K extends keyof T> = (prop: T[K], prevProp: T[K] | null) => void
type OnChange<T> = <K extends keyof T>(propName: K, cb: Callback<T, K>, triggerOnBind?: boolean) => () => void
type Trigger<T> = <K extends keyof T>(propName: K) => void
export type ObservableState<T> = {
__onChange: OnChange<T>
__trigger: Trigger<T>
} & T