Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
openroomxyz / CreatingPNG.cs
Created April 21, 2020 13:50
Unity Editor : How to create in code Texture2D and save as file an PNG image lunch from menu?
sing System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEditor;
public class CreatingPNG : MonoBehaviour
{
public static Texture2D CreateTexture()
{
int width = 100;
@openroomxyz
openroomxyz / shader.cg
Created April 21, 2020 13:45
Unity : Can i see an Unlit shader example ?
0 : Shader "Unlit/MyUnlitShader"
1 : {
2 : Properties
3 : {
4 : _MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
@openroomxyz
openroomxyz / deleteAllObjects.py
Created April 21, 2020 12:47
Blender Python : How to delete all object in scene?
import bpy
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False, confirm=False)
@openroomxyz
openroomxyz / make_a_parent.py
Created April 21, 2020 12:46
Blender Python : How do i make one object child of some other object?
def make_a_parent(parent, child):
objects = bpy.data.objects
a = objects[parent]
b = objects[child]
b.parent = a
@openroomxyz
openroomxyz / GiveItName.py
Created April 21, 2020 12:45
Blender Python : How do we give created object a name?
bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0))
bpy.context.object.name = "Generated"
@openroomxyz
openroomxyz / DuplicateLinkedAndGiveItAName.py
Created April 21, 2020 12:44
Blender Python : How to duplicate linked object and give it a name?
import bpy
def making_object_active(name):
obj_to_make_active = bpy.data.objects[name]
bpy.context.view_layer.objects.active = obj_to_make_active
def duplicating_linked_object_with_name(name, new_object_name):
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_pattern(pattern=name)
bpy.ops.object.duplicate_move_linked(OBJECT_OT_duplicate={"linked":True})
@openroomxyz
openroomxyz / SetLocationRotationScaleToAnObjectWithAName.py
Created April 21, 2020 12:42
Blender Python : How to set location, rotation, scale of object with name?
import bpy
def set_location(name, xyz):
bpy.data.objects[name].location = xyz
def set_euler_rotation(name, xyz):
bpy.data.objects[name].rotation_euler = xyz
def set_scale(name, xyz):
bpy.data.objects[name].scale = xyz
@openroomxyz
openroomxyz / DeselectAllAndSelectOnlyWithName.py
Created April 21, 2020 12:40
Blender Python : How to deselect all object and select only the object with name?
import bpy
bpy.ops.object.select_all(action='DESELECT')
bpy.data.objects["PEPE"].select_set(state=True)
@openroomxyz
openroomxyz / DoesObjectWithNameExist.py
Created April 21, 2020 12:38
Blender Python : Does object with name exist?
import bpy
def does_object_with_name_exist(name):
if name in bpy.data.objects:
return True
return False
if not does_object_with_name_exist("Generated"):
bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0))
bpy.context.object.name = "Generated"
@openroomxyz
openroomxyz / HowToMoveAnObjectFromOnColletionToAnother.py
Created April 21, 2020 12:36
Python : How to move an object from once collection to another, if collection does not exist create it?
import bpy
import uuid
##
def find_collection(context, item):
collections = item.users_collection
if len(collections) > 0:
return collections[0]
return context.scene.collection