Skip to content

Instantly share code, notes, and snippets.

View cart's full-sized avatar

Carter Anderson cart

View GitHub Profile
@cart
cart / example.rs
Created October 31, 2023 21:41
An example of using GpuArrayBuffer to support platforms without storage buffers (ex: WebGL2)
#[derive(Clone, ShaderType)]
struct MyType {
x: f32,
}
// Create a GPU array buffer
let mut buffer = GpuArrayBuffer::<MyType>::new(&render_device.limits());
// Push some items into it
for i in 0..N {
use bevy::prelude::*;
struct Player {
velocity: Vec3,
}
fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_startup_system(spawn_player.system())
// Anchors
.spawn(ButtonComponents {
node: Node::with_size(Anchors::CENTER, Size {
Dimension::Points(150.0),
Dimension::Points(70.0)
}),
material: button_materials.normal,
..Default::default()
})
.with_children(|parent| {
use bevy_ecs::{Changed, Entity, Query, Res, ResMut, With, Without};
use bevy_math::Vec2;
use bevy_render::renderer::RenderResources;
use bevy_transform::prelude::{Children, Parent, Transform};
use bevy_window::Windows;
use std::collections::HashMap;
use stretch::{number::Number, result::Layout, style::Style, Stretch};
#[derive(Debug, Clone, Default, RenderResources)]
pub struct Node {
@cart
cart / tracker.rs
Created July 18, 2020 04:08
tracker
use std::{fmt::Debug, ops::{Deref, DerefMut}};
pub struct Track<T> {
modified: bool,
value: T,
}
pub trait Tracker {
fn is_modified(&self) -> bool;
fn reset(&mut self);
Entity [
MyComponent,
Scale { x: 2.0, y: 2.0, z: 2.0 },
PropDemo {
value: "hello",
sequence: [0,1,2],
map: {field: 1.0, hello: "hi"},
nested: {field: [{test: 1.0}]}
},
// Children entities are nested
PipelineLayout {
bind_groups: [
BindGroupDescriptor {
index: 0,
bindings: [
BindingDescriptor {
name: "Camera2d",
index: 0,
bind_type: Uniform {
dynamic: false,
@cart
cart / FXAA.tscn
Last active January 30, 2024 18:17
Godot Nvidia FXAA 3.11 Port
[gd_scene load_steps=3 format=2]
[sub_resource type="Shader" id=1]
code = "shader_type canvas_item;
// Godot Nvidia FXAA 3.11 Port
// Usage: Drop this in to any 3D scene for FXAA! This is a port of the \"PC High Quality Preset 39\". However the medium quality
// parameters are also included. For medium quality, just comment out sections \"PS 6\" and above and uncomment the \"med 13\" variables.
@cart
cart / gist:cc095f4950c40c1fe25169be5ee78247
Created February 1, 2018 06:34
A collection of C# Math extensions for Godot
using Godot;
namespace HighHat.MathHelpers
{
public static class MathExtensions
{
// TODO: expose Godot's Transform::interpolate_with to scripting. This is just a C# port
public static Transform InterpolateWith(this Transform transform, Transform targetTransform, float percent, bool includeScale = true)
{
var rotation = transform.basis.Orthonormalized().ToQuat();
@cart
cart / NodeExtensions.cs
Created February 1, 2018 06:31
A collection of C# Node extensions for Godot
using Godot;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace HighHat.Scene.Nodes
{
public static class NodeExtensions
{
private static Regex _nameRegex = new Regex("@*(?<Name>[\\w|\\d]+)@*.*");