Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
openroomxyz / run.py
Created April 16, 2020 11:12
Blender Python : How to get Boolean Union of two objects?
import bpy
def Union(name_a, name_b, new_one_name):
# Create a boolean modifier named 'my_bool_mod' for the cube.
mod_bool = bpy.data.objects[name_a].modifiers.new('my_bool_mod', 'BOOLEAN')
# Set the mode of the modifier to DIFFERENCE.
mod_bool.operation = 'UNION' #'DIFFERENCE'
# Set the object to be used by the modifier.
mod_bool.object = bpy.data.objects[name_b]
bpy.context.view_layer.objects.active = bpy.data.objects[name_a]
@openroomxyz
openroomxyz / BlenderHowToCreateACube.py
Created April 16, 2020 11:07
Blender Python : How to create a cube at position rotation scale?
import bpy
def create_a_cube(name, position, set_rotation, scale):
# Create a simple cube.
bpy.ops.mesh.primitive_cube_add()
# Get the cube object and rename it.
cube = bpy.context.object
cube.name = name
cube.rotation_euler = set_rotation
@openroomxyz
openroomxyz / CropFolderOfPhotos.py
Created April 14, 2020 09:44
Python : How can i crop folder of photos?
from PIL import Image
import os
def get_list_of_files_only_in_folder(folder_path):
return [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
def get_extension(name):
return name.split('.')[-1]
def crop(path_input, path_output, left, top, right, bottom):
@openroomxyz
openroomxyz / CropSingleImage.py
Created April 14, 2020 09:27
Python : How can i crop single image?
from PIL import Image
def crop(path_input, path_output, left, top, right, bottom):
im = Image.open(path_input)
im1 = im.crop((left, top, right, bottom)) # new cropped image
im1.show() #Display the image if you wan't to
im1 = im1.save(path_output)
name = "somename"
path_in = "C:\\Users\x\\x\\x\\"+name+".png"
@openroomxyz
openroomxyz / RenameAllFilesInFolderToBeNumerical.py
Created April 13, 2020 18:05
Python : How to rename all files in a folder so that their names are ordered numbers?
import os
def get_list_of_files_only_in_folder(folder_path):
return [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
def get_extension(name):
return name.split('.')[-1]
def rename_files_in_folder_to_numerical_order(path, start_index = 0):
n = start_index;
@openroomxyz
openroomxyz / ConvertAllFilesInFolderFromOggToMp3.py
Last active April 13, 2020 17:48
Python : How can i convert all files in folder from ogg to mp3?
import os
from pydub import AudioSegment
def get_list_of_files_only_in_folder(folder_path):
return [f for f in os.listdir(folder_path) if os.path.isfile(os.path.join(folder_path, f))]
def convert_from_ogg_to_mp3(path_file_input, path_file_output):
ogg_version = AudioSegment.from_ogg(path_file_input)
ogg_version.export(path_file_output, format="mp3")
@openroomxyz
openroomxyz / ConvertOggToMp3.py
Created April 13, 2020 14:49
Python : How can i convert from ogg to mp3?
#you need to have installed pydub and conda
#conda install -c conda-forge ffmpeg
#conda install -c conda-forge pydub
from pydub import AudioSegment
path_file_input = "C://Users//X//Downloads//t_voice5812054872861705901.ogg"
path_file_output = "C://Users//X//Desktop//bip//audioX.mp3"
ogg_version = AudioSegment.from_ogg(path_file_input)
ogg_version.export(path_file_output, format="mp3")
@openroomxyz
openroomxyz / HowToSetRenderTextureAsTextureProgramaticallyUnderClassirRenderPipeline.cs
Created April 11, 2020 21:09
Unity : How to set render texture as texture pragmatically (classic render pipeline ) ?
//Make sure to enable the Keywords (You may not need todo this in a loop)
rend.material.EnableKeyword("_NORMALMAP");
rend.material.EnableKeyword("_METALLICGLOSSMAP");
//After that you can use this
rend.material.SetTexture("_MainTex", result_render_texture);
@openroomxyz
openroomxyz / HowToSetRenderTextureAsTextureProgramaticallyUnderHDRP.cs
Created April 11, 2020 21:04
Unity : How to set render texture as texture pragmatically under HDRP?
public static void SetBaseColorMap(ref Renderer renderer, in RenderTexture render_texture)
{
renderer.material.SetTexture("_BaseColorMap", render_texture);
}
@openroomxyz
openroomxyz / GetPartsOfPath.py
Created April 11, 2020 10:06
Python : How to get parts of file path ( folder path, filename with extension, without , only extension ) ?
import os
def getPartsOfPath(path):
path_to_folder = os.path.dirname(path)
file_name_with_extension = os.path.basename(path)
file_name_without_extension, extension = os.path.splitext(file_name_with_extension)
return (path_to_folder, file_name_with_extension, file_name_without_extension, extension)
getPartsOfPath("C:\\Users\\C\\Desktop\\Cosmos\\test.png")