Skip to content

Instantly share code, notes, and snippets.

View oslavdev's full-sized avatar
👽
-__-

Jaroslaw oslavdev

👽
-__-
View GitHub Profile
@oslavdev
oslavdev / gist:d8fa1ecc3858c52947acb14cc9c621ad
Last active February 18, 2026 10:07
Get project folder structure
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const IGNORE = ['node_modules', 'dist', '.git', 'coverage', '.next', '.cache', '.turbo'];
const MAX_DEPTH = 5;
function walk(dir, depth = 0, prefix = '') {
@oslavdev
oslavdev / .js
Created April 11, 2025 09:22
Output folder structure
import fs from 'fs'
import path from 'path'
const IGNORE_DIRS = ['node_modules', '.git', 'dist', 'build', '.next']
const OUTPUT_FILE = 'structure.md'
function getTree(dir, prefix = '') {
const items = fs.readdirSync(dir, { withFileTypes: true })
const tree = []
@oslavdev
oslavdev / Animation.js
Last active November 15, 2021 19:22
Animate character
/**
*
* Crossfade action allows us
* smoothly switch between animations
*
*
*/
function crossfadeAnimation(newAction){
newAction.reset()
@oslavdev
oslavdev / lerpToPosition.js
Last active November 15, 2021 19:32
Lerp objects to position, to follow character
/**
* Smoothly move character position Vector3 to actiual character position
*
*/
character_position.lerp(character.position, 0.4);
/**
* Set default camera position Vector3 to the follower
*/
camera_position.copy(follower.position);
@oslavdev
oslavdev / characterMove.js
Created November 14, 2021 10:38
Move character
//** Tick function to update */
const tick = () =>
{
const elapsedTime = clock.getElapsedTime()
const deltaTime = elapsedTime - previousTime
previousTime = elapsedTime
// Model animation
if(mixer)
@oslavdev
oslavdev / chacterLoad.js
Last active November 15, 2021 20:20
Load character with animations
/**
* Loading model
*/
const dracoLoader = new DRACOLoader()
dracoLoader.setDecoderPath('/draco/')
const gltfLoader = new GLTFLoader()
gltfLoader.setDRACOLoader(dracoLoader)
@oslavdev
oslavdev / helpers.js
Last active November 15, 2021 19:24
Helper objects for smooth camera movements
const character_position = new THREE.Vector3;
const camera_position = new THREE.Vector3;
const tail_position = new THREE.Vector3;
const camera_offset = new THREE.Vector3;
const distance = 4;
let velocity = 0.0; // velocity provides smooth speed gain
let speed = 0.0; // default idle speed
// Helper objects to provide camera movements
@oslavdev
oslavdev / lights.js
Created December 9, 2020 18:54
Lights in Three.js for article on medium
import React from "react";
const Lights = () => {
return (
<>
<ambientLight intensity={0.1} />
<directionalLight position={[40, 10, 5]} intensity={0.2} />
<directionalLight
castShadow
position={[10, 420, 100]}
@oslavdev
oslavdev / model.ts
Last active December 9, 2020 18:53
Simple model loading in Next.js with GLTF loader
import React, { useEffect, useState, useRef } from "react";
import { useFrame } from "react-three-fiber";
import * as THREE from "three";
import { Html } from "drei";
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
const Model = () => {
const ref = useRef();
const [model, setModel] = useState(null);
/* Load model */
@oslavdev
oslavdev / next-loader-webpack.js
Created December 9, 2020 18:32
Next webpack configuration for Three.js
const withTM = require("next-transpile-modules")([
"three",
"react-three-fiber",
"drei",
]);
module.exports = withTM({
webpack(config, options) {
config.module.rules.push({
test: /\.(glb|gltf)$/,