Skip to content

Instantly share code, notes, and snippets.

View bartteunis's full-sized avatar

bartteunis

View GitHub Profile
@bartteunis
bartteunis / path_utilities.gml
Last active June 6, 2022 15:12
Path utilities
/// Path functions and escalator functions
/// @func path_points(path, radius)
/// @desc Create two arrays with the points of the inner and outer casing around a path
function path_points(path, radius) {
// Make sure we use the smallest possible increase in t
var e = math_get_epsilon();
var precision = 240;
var t = 0;
@bartteunis
bartteunis / VertexFormat.gml
Last active December 27, 2021 10:39
Very unfinished idea for a vertex format wrapper struct
///
#macro POSITION_2D vertex_format_add_position
#macro POSITION_3D vertex_format_add_position_3d
#macro COLOR vertex_format_add_color
#macro UV vertex_format_add_texcoord
#macro NORMAL vertex_format_add_normal
/*
vertex_format_add_position_3d();
/// @description Load WAV file
function wav(path) constructor {
read_chunk_id_size = function(buffer) {
var _id = "";
repeat(4) { _id += chr(buffer_read(buffer, buffer_u8)); }
var _size = buffer_read(buffer, buffer_u32);
return [_id, _size];
}
@bartteunis
bartteunis / update_spheres.gml
Last active January 27, 2021 16:26
Update code for sphere collision calculations
function update_spheres() {
// Copy initial state
ds_grid_copy(grd_calc_spheres, grd_spheres);
var y_max = no_spheres-1;
// Do point_distance_3d (squared)
ds_grid_add_region(grd_calc_spheres, 0, 0, 0, y_max, -x); // x[i] -= x
ds_grid_add_region(grd_calc_spheres, 1, 0, 1, y_max, -y); // y[i] -= y
ds_grid_add_region(grd_calc_spheres, 2, 0, 2, y_max, -z); // z[i] -= z
@bartteunis
bartteunis / Q_rsqrt
Created November 4, 2020 18:13
The fast inverse square root algorithm using buffers in GameMaker:Studio
function Q_rsqrt(number) {
gml_pragma("forceinline");
#macro threehalfs 1.5
static buf_var = buffer_create(4, buffer_fixed, 4);
var x2 = number * .5, _y = number;
buffer_poke(buf_var, 0, buffer_f32, _y);
var i = buffer_peek(buf_var, 0, buffer_s32);
buffer_poke(buf_var, 0, buffer_s32, 0x5f3759df - ( i >> 1 ));
_y = buffer_peek(buf_var, 0, buffer_f32);
@bartteunis
bartteunis / attributes279.py
Last active June 7, 2020 14:11
Short example of how to fix attribute assignment order causing errors when working with Blender operator presets
import bpy
# ExportHelper is a helper class, defines filename and
# invoke() function which calls the file selector.
from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, BoolProperty, IntProperty, EnumProperty, CollectionProperty
from bpy.types import Operator, PropertyGroup
def items_callback(self, context):
@bartteunis
bartteunis / render_topdown.py
Last active December 23, 2019 12:44
Render topdown image of 3D model
import bpy
C = bpy.context
D = bpy.data
fname = 'C:/Users/Dev/Desktop/test.png'
# This'll be our object
obj = C.object
obj_cam = C.scene.camera
@bartteunis
bartteunis / blender_data_paths
Last active November 5, 2019 09:08
Paths to all kinds of data in Blender 2.79
### Paths to all kinds of model data in bpy ###
## Textures, UVs ##
C.object.material_slots[0].material.texture_slots[0].texture_coords # Type of coords
C.object.material_slots[0].material.texture_slots[0].uv_layer # UV layer if type uv
C.object.material_slots[0].material.texture_slots[0].texture # Ref to texture
## Shape keys (Morph targets) ##
C.object.data.shape_keys # Entry point
C.object.data.shape_keys.key_blocks[0].vertex_group # Affected vertex group
@bartteunis
bartteunis / blender_interleaved_attributes
Last active October 24, 2018 18:13
Blender data traversal using new export format
import bpy
from struct import pack, calcsize
# First define what we want
attribs = [
(bpy.types.MeshVertex,'co',0),
(bpy.types.MeshVertex,'co',1),
(bpy.types.MeshVertex,'normal',0)
]