This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reading from render result without heavy workarounds | |
# Supports 2.93 | |
# Author Iyad Ahmed (Twitter: @cgonfire, email: iyadahmed@cgonfire.com) | |
# Licensed under GPL-3 | |
import bgl | |
import bpy | |
import gpu | |
import numpy as np |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
from timeit import default_timer as timer | |
import bmesh | |
import bpy | |
import numpy as np | |
from mathutils import Matrix | |
DEBUG = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
from mathutils.bvhtree import BVHTree | |
C = bpy.context | |
# Build BVH once | |
bvh = BVHTree.FromObject(C.object, C.evaluated_depsgraph_get()) | |
for i in range(999999): | |
# Slower, this possibly builds BVH everytime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Iyad Ahmed | |
import bpy | |
# importing numpy is slow for first time | |
import numpy as np | |
prev_mode = bpy.context.object.mode | |
bpy.ops.object.mode_set(mode="OBJECT") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constexpr size_t N = 900; | |
Eigen::Matrix<uint8_t, -1, -1> output(N, N); | |
output.fill(255); | |
std::ofstream ofs("output.pgm", std::ofstream::binary); | |
ofs << "P5\n" | |
<< N << ' ' << N << "\n255\n"; | |
// Otherwise the image will be flipped due to how PGM file format is layed out | |
output.rowwise().reverseInPlace(); | |
ofs.write(reinterpret_cast<char *>(output.data()), N * N * sizeof(uint8_t)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(MSVC) | |
target_compile_options(eigen_vis_cpp PRIVATE $<$<CONFIG:RelWithDebInfo,Debug>:/fsanitize=address>) | |
elseif() | |
target_compile_options(eigen_vis_cpp PRIVATE $<$<CONFIG:RelWithDebInfo,Debug>:-fsanitize=address -fno-omit-frame-pointer>) | |
target_link_options(eigen_vis_cpp PRIVATE $<$<CONFIG:RelWithDebInfo,Debug>-fsanitize=address>) | |
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void skip_line(std::ifstream &ifs) | |
{ | |
// Thanks to Eljay and CPPReference | |
// https://stackoverflow.com/questions/53693218/how-to-skip-a-line-of-standard-input#comment94242047_53693218 | |
// https://en.cppreference.com/w/cpp/string/basic_string/getline#Notes | |
// ifs.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); | |
// also thanks to https://stackoverflow.com/a/72365435/8094047 | |
// and https://jdhao.github.io/2018/12/08/newline_vim_python_sublime_notepad/ | |
// Skip all characters until newline or carriage return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GPLv3 iyadahmed430@gmail.com (Iyad Ahmed) | |
#pragma once | |
#include <chrono> | |
#include <functional> | |
void time_function(const char *message, std::function<void()> function) | |
{ | |
auto start = std::chrono::high_resolution_clock::now(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import ctypes | |
def fast_foreach_set_vertices(mesh: bpy.types.Mesh, array: NDArray): | |
# Ultra fast vertices setting | |
# Thanks a ton!: https://blender.stackexchange.com/a/298488/53664 | |
# beware all things could go wrong here! | |
assert array.dtype == np.float32 | |
assert len(array.shape) == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// License Public Domain | |
// These constants are arbitrary but make sure they do not accidentally collide with other things | |
const animationAttributeName = 'animation__onkeydown_space'; | |
const animationStartEvent = 'onkeydown_space'; | |
AFRAME.registerComponent('simple-jump', { | |
schema: {}, | |
init: function () { | |
var el = this.el; | |
// Thank you!!!: https://stackoverflow.com/a/47019444/8094047 | |
// https://stackoverflow.com/a/51050251/8094047 |
NewerOlder