This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
class MyCustomMaterial extends THREE.ShaderMaterial { | |
// constructor takes appropriate parameters. | |
// Default values using object destructuring (ES6) | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring | |
constructor({ | |
color = 0xffffff, | |
emissive = 0x000000, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Noodle() { | |
const { viewport, camera } = useThree() | |
const { nodes } = useGLTF('/worms-transformed.glb') | |
const [geometry] = useState(() => nodes[`noodle_${Math.ceil(Math.random() * 4)}`].geometry) | |
const [speed] = useState(() => 0.1 + Math.random() / 10) | |
const position = useMemo(() => { | |
const z = Math.random() * -30 | |
const bounds = viewport.getCurrentViewport(camera, [0, 0, z]) | |
return [THREE.MathUtils.randFloatSpread(bounds.width), THREE.MathUtils.randFloatSpread(bounds.height * 0.75), z] | |
}, [viewport]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FontLoader } from 'three-stdlib'; | |
import { useLoader } from '@react-three/fiber'; | |
export const useFont = (src) => { | |
return useLoader(FontLoader, src); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @file useIsoLayoutEffect.js | |
* Hook to suppress useLayoutEffect error on SSR. | |
*/ | |
import { useLayoutEffect, useEffect } from 'react'; | |
const useIsoLayoutEffect = | |
typeof window !== 'undefined' ? useLayoutEffect : useEffect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as THREE from 'three'; | |
(function () { | |
'use strict'; | |
var root = this; | |
var has_require = typeof require !== 'undefined'; | |
// var THREE = root.THREE || (has_require && require('three')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
AdditiveBlending, | |
Color, | |
LinearFilter, | |
MeshBasicMaterial, | |
RGBAFormat, | |
ShaderMaterial, | |
Texture, | |
UniformsUtils, | |
Vector2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precision highp float; | |
precision highp int; | |
#define SHADER_NAME ShaderMaterial | |
#define GAMMA_FACTOR 2 | |
#define DOUBLE_SIDED | |
#define NUM_CLIPPING_PLANES 0 | |
uniform mat4 viewMatrix; | |
uniform vec3 cameraPosition; | |
#define TONE_MAPPING | |
#define saturate(a) clamp( a, 0.0, 1.0 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Rotations | |
const step = 'q1'; | |
const cameraRotations = { | |
q1: { | |
x: 0.75, | |
y: 0, | |
z: 0, | |
}, | |
q2A: { | |
x: -0, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const [sound, setSound] = useState() | |
const [listener, setListener] = useState() | |
const [analyser, setAnalyser] = useState() | |
const [data, setData] = useState(1) | |
// load a sound and set it as the Audio object's buffer | |
useEffect(() => { | |
const listener = new THREE.AudioListener() | |
setListener(listener) | |
const sound = new THREE.PositionalAudio(listener) | |
setSound(sound) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Description : Array and textureless GLSL 2D/3D/4D simplex | |
// noise functions. | |
// Author : Ian McEwan, Ashima Arts. | |
// Maintainer : stegu | |
// Lastmod : 20110822 (ijm) | |
// License : Copyright (C) 2011 Ashima Arts. All rights reserved. | |
// Distributed under the MIT License. See LICENSE file. | |
// https://github.com/ashima/webgl-noise | |
// https://github.com/stegu/webgl-noise |
NewerOlder