Skip to content

Instantly share code, notes, and snippets.

View FantasyVR's full-sized avatar
🎯
Focusing

pengyu FantasyVR

🎯
Focusing
  • Taichi Graphics
  • Beijing
View GitHub Profile
# MPM-MLS in 88 lines of Taichi code, originally created by @yuanming-hu
# P2G is parallel in this script.
import taichi as ti
ti.init(arch=ti.gpu)
n_particles = 8192
n_grid = 128
dx = 1 / n_grid
dt = 2e-4
@FantasyVR
FantasyVR / vulkan_test.cpp
Created April 21, 2022 01:29
Create vulkan instance twice.
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <iostream>
#include <stdexcept>
#include <cstdlib>
#include <vector>
#include <string>
import taichi as ti
ti.init(arch=ti.cuda)
N = 5
NV = (N + 1)**2
NT = 2 * N**2
NE = 2 * N * (N + 1) + N**2
pos = ti.Vector.field(3, ti.f32, shape=NV)
tri = ti.field(ti.i32, shape=3 * NT)
edge = ti.Vector.field(2, ti.i32, shape=NE)
# https://www.cs.cmu.edu/~baraff/papers/sig98.pdf
import argparse
import numpy as np
import taichi as ti
@ti.data_oriented
class Cloth:
"""
Loop:
Press start button to start random selection
Press end to show the selected ID
"""
import taichi as ti
ti.init(arch=ti.cpu,cpu_max_num_threads=1)
n = 100
userId = ti.field(ti.i32, shape=n) # userId is an array of 0s
import taichi as ti
ti.init(arch=ti.cpu, packed=True)
a = ti.field(dtype=ti.i32)
ti.root.dense(ti.ij, (2, 3)).dense(ti.ij, (2,3)).place(a)
@ti.kernel
def fill():
for i, j in a:
@FantasyVR
FantasyVR / implicit_mass_spring.py
Last active October 9, 2021 06:44
Add diagnal edges
# https://www.cs.cmu.edu/~baraff/papers/sig98.pdf
import taichi as ti
import numpy as np
import argparse
@ti.data_oriented
class Cloth:
def __init__(self, N):
self.N = N
@FantasyVR
FantasyVR / stars.py
Last active September 26, 2021 02:25
import taichi as ti
from math import sin, cos, sqrt, pi
from random import random
@ti.data_oriented
class Star:
def __init__(self, position, velocity, mass) -> None:
assert len(position) == len(
velocity
import taichi as ti
ti.init(ti.gpu)
# global control
paused = ti.field(ti.i32, ())
# gravitational constant 6.67408e-11, using 1 for simplicity
G = 1
PI = 3.141592653
import taichi as ti
ti.init(arch=ti.gpu)
N = 3 #number of object
x = ti.Vector.field(2,ti.f32,shape=N)
v = ti.Vector.field(2,ti.f32,shape=N)
a = ti.Vector.field(2,ti.f32,shape=N)
f = ti.Vector.field(2,ti.f32,shape=N)
m = ti.field(ti.f32,shape=N)
color = ti.Vector.field(3, float, N)
@ti.kernel