Skip to content

Instantly share code, notes, and snippets.

@ewmb7701
ewmb7701 / web-dev-server.config.mjs
Created February 15, 2026 20:57
web-dev-server.config.mjs for bevy app website in workspace
import { resolve } from "node:path";
import serve from "koa-static";
import mount from "koa-mount";
const ROOT_DIR = resolve(import.meta.dirname, "./code");
const ASSETS_DIR = resolve(import.meta.dirname, "../../assets");
const APPS_DIR = resolve(
import.meta.dirname,
"../../build/wasm32-unknown-unknown/debug",
);
import { glob } from "glob";
import { mkdir, copyFile } from "node:fs/promises";
import { dirname } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { Module, ModuleEmitter, ModuleResolver, type API } from "swooce";
/**
* Module without any content.
*
* Useful for eg,
type HTMLElementAttributes<THTMLElement extends keyof HTMLElementTagNameMap> = {
[K in keyof HTMLElementTagNameMap[THTMLElement]]?: HTMLElementTagNameMap[THTMLElement][K] extends DOMTokenList
? string | HTMLElementTagNameMap[THTMLElement][K]
: HTMLElementTagNameMap[THTMLElement][K];
};
/**
* Append a single Node or string as a text node to a parent element.
*/
function appendChild(parent: HTMLElement, child: Node | string) {
// /// Casts a moving ball against a static triangle and returns the first time of impact, if any.
// ///
// /// Checks all triangle features (face, edge, vertex) manually.
// pub fn cast_ball_triangle(
// pos12: &Isometry<f32>,
// vel12: &Vector<f32>,
// g1: &Triangle,
// g2: &Ball,
// options: ShapeCastOptions,
// ) -> Option<(ShapeCastHit, FeatureId)> {
@ewmb7701
ewmb7701 / input.rs
Created November 25, 2024 22:12
pole-based character controller in Bevy
use bevy::{
log::debug,
math::{Dir3, Vec3},
};
fn map_range(from_range: (f32, f32), to_range: (f32, f32), s: f32) -> f32 {
to_range.0
+ (s - from_range.0) * (to_range.1 - to_range.0)
/ (from_range.1 - from_range.0)
}
@ewmb7701
ewmb7701 / utils.rs
Created November 23, 2024 22:13
bevy_rapier3d character controller heel surface
pub fn determine_next_heel_stage_surface(
rapier_context: &Res<RapierContext>,
root_position: Vec3,
root_rotation: Quat,
cast_origin_forward: f32,
cast_origin_down: f32,
cast_distance: f32,
cast_max_angle: f32,
) -> Option<StageSurfaceData> {
@ewmb7701
ewmb7701 / bevy_rapier_3d_character_controller.rs
Created November 23, 2024 20:13
step down character controller
/// Determine the next "step down" stage surface for a character.
///
/// # Parameters
pub fn get_step_down_floor(
rapier_context: &RapierContext,
query_filter: QueryFilter,
root_source_translation: Vec3,
root_source_rotation: Quat,
wall_cast_origin_local_neg_y: f32,
wall_cast_distance: f32,
@ewmb7701
ewmb7701 / character_contorller_utils_.rs
Last active November 23, 2024 03:36
Bevy character controller rotate body around root
/// translate and rotate a point around anhter
pub fn rotate_point_around_pivot(
point: Vec3,
pivot: Vec3,
rotation: Quat,
) -> Vec3 {
// Translate the point to the origin
let translated_point = point - pivot;
// Apply the rotation
@ewmb7701
ewmb7701 / character_controller_3d.rs
Created November 16, 2024 14:55
3D character controller in Bevy with Avian3D
/// determine next linear velocity for a character.
/// "with body" means veloicity is applied to the body.
// TODO move to avian3d_lib
pub fn determine_next_step_linear_velocity_for_rigidbody_with_body(
spatial_query: &SpatialQuery,
query_filter: SpatialQueryFilter,
start_root_global_translation: Vec3,
start_root_global_rotation: Quat,
body_shape: SharedShape,
body_local_translation: Vec3,
@ewmb7701
ewmb7701 / index.ts
Created December 21, 2023 16:29
fiddle-typescript-type-maps
import { ValueOf } from 'type-fest';
/**
* a "type map" is a map of type tag/ discriminator to type.
* https://javascript.plainenglish.io/tagged-union-types-in-typescript-leveraging-type-safety-and-flexibility-be0e60145815
*
* type maps are useful for creating event maps or action maps.
*
* Actions as in Redux action: https://redux.js.org/tutorials/fundamentals/part-2-concepts-data-flow#actions
*/