Skip to content

Instantly share code, notes, and snippets.

@erwincoumans
erwincoumans / cube.py
Created October 11, 2022 01:01
Create 120k cubes in Blender 3.4 alpha: selection is broken (b key and select some region of cubes) and deletion (select all 'a', delete 'x') takes very long.
#See Aras' post, https://twitter.com/aras_p/status/1579383862165405696
import time
import bpy
print("hello world")
mesh = bpy.data.meshes['Cube']
start = time.time()
for z in range (0,7,3):
for x in range(-9,10):
for y in range(-9,10):
ob = bpy.data.objects.new("Gen", object_data=mesh)
@erwincoumans
erwincoumans / render_tiled_cuda_torch_interop.py
Created August 25, 2022 21:40
opengl3 tiled rendering output to cuda / pytorch interop example
#pycuda cuda interop inspired by
#https://gist.github.com/victor-shepardson/5b3d3087dc2b4817b9bffdb8e87a57c4
#and https://discuss.pytorch.org/t/create-edit-pytorch-tensor-using-opengl/42111/5
#pip install pytinydiffsim, pycuda, numpy, matplotlib, PyQt5
#visit https://pytorch.org/get-started/locally to install cuda-enabled pytorch
#git clone https://github.com/erwincoumans/tiny-differentiable-simulator.git
#cd tiny-differentiable-simulator/python/examples
import pytinydiffsim as tds
@erwincoumans
erwincoumans / BasicDemo.cpp
Created October 21, 2020 23:13
Kinematic btRigidBody example
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2015 Google Inc. http://bulletphysics.org
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
@erwincoumans
erwincoumans / read_scales.py
Created March 29, 2019 15:53
DYMO usb scale reading (multiple scales)
import sys
import usb.core
VENDOR_ID = 0x0922
PRODUCT_ID = 0x8003
# find USB devices
devices = list(usb.core.find(find_all=True, idVendor=VENDOR_ID,
idProduct=PRODUCT_ID))
import pybullet as p
import time
usePhysX = True
if usePhysX:
p.connect(p.PhysX)
p.loadPlugin("eglRendererPlugin")
else:
p.connect(p.GUI)
@erwincoumans
erwincoumans / minitaur_gym_env.py
Created October 29, 2017 02:58
minitaur gym environment with bunny on its back
"""This file implements the gym environment of minitaur.
"""
import os, inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(os.path.dirname(currentdir))
os.sys.path.insert(0,parentdir)
@erwincoumans
erwincoumans / ground.urdf
Created October 28, 2017 02:09
pybullet URDF example of a static concave triangle mesh (non-moving)
<?xml version="1.0" ?>
<robot name="ground">
<link name="ground">
<visual>
<geometry>
<mesh filename="ground.obj" scale="2 2 0.1" />
</geometry>
<material name="white">
<color rgba="1 1 1 1"/>
</material>
@erwincoumans
erwincoumans / test.py
Created October 28, 2017 02:08
pybullet concave collision test
import pybullet as p
import time
p.connect(p.GUI)
#disable rendering during loading speeds it up
p.configureDebugVisualizer(p.COV_ENABLE_RENDERING,0)
p.configureDebugVisualizer(p.COV_ENABLE_TINY_RENDERER,0)
p.loadURDF("ground.urdf",useMaximalCoordinates=True)
for i in range (10):
for j in range (10):
@erwincoumans
erwincoumans / dobot.ino
Created March 17, 2016 17:20
Dobot control using RAMPS 1.4 shield with Arduino Mega
//This is taken from https://www.reddit.com/r/Dobot/comments/45ilan/controlling_dobot_with_ramps_14
#include <AccelStepper.h>
#define X_STEP_PIN 54
#define X_DIR_PIN 55
#define X_ENABLE_PIN 38
#define X_MIN_PIN 3
#define X_MAX_PIN 2
@erwincoumans
erwincoumans / gist:6666160
Last active January 7, 2024 10:28
Example how to create the A matrix and b vector and solve the LCP using Projected Gauss Seidel for Bullet 2.x. Requires Eigen lib and Bullet 2.82. Note that one of the differences between plain projected Gauss Seidel and the Bullet iterative solver is that the friction limits are computed at each iterations, from the related normal force. (This …
//#include "Eigen/Dense"
#include "Eigen/Sparse"
static Eigen::VectorXf Solve_GaussSeidel (Eigen::MatrixXf & A, Eigen::VectorXf & b, Eigen::VectorXf & lo,Eigen::VectorXf & hi,int kMax = 5)
{
//A is a m-n matrix, m rows, n columns
if (A.rows() != b.rows())
return b;
int i, j, n = A.rows();