Skip to content

Instantly share code, notes, and snippets.

@aobond2
aobond2 / ObjectShader
Last active October 1, 2021 18:10
Cube shader
Shader "Custom/ObjectDiffuseStencil" {
Properties {
_Color("Color", Color) = (1,1,1,1)
_myDiffuse ("Diffuse Texture", 2D) = "white" {}
_myBump ("Bump Texture", 2D) = "bump" {}
_mySlider ("Bump Amount", Range(0,10)) = 1
_SRef("Stencil Ref", Float) = 1
[Enum(UnityEngine.Rendering.CompareFunction)] _SComp("Stencil Comp", Float) = 8
[Enum(UnityEngine.Rendering.StencilOp)] _SOp("Stencil Op", Float) = 2
from math import pi
from random import random
import bpy
def delete_object(name):
if name in bpy.data.objects:
obj = bpy.data.objects[name]
obj.select_set(True)
bpy.ops.object.delete(use_global=False)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class GIDisabler : EditorWindow
{
try (closeRolloutFloater MainFloater) catch()
rollout LODCheck "LOD Checker"
(
spinner lodNumberSpinner "Max LOD number" type:#integer range:[0,5,3] align:#left
spinner reductionSpinner "Reduction percentage" type:#integer range:[0,100,50] align:#left
global nodeArray = #()
global reductionPercentage = 50
global maxLOD = 3
label menuLabel "Select an object/layer from layer explorer" align:#left
@aobond2
aobond2 / change.py
Created November 17, 2022 11:05
Blender material change test
import bpy
def replace_material(obj, obj_data, mat_src, mat_dst):
"""
replace a material in blender.
"""
print("ob is", obj)
for i in range(len(obj_data.materials)):
# test if the old material is in the slot and replace it
def repositionChildrenToPivot():
coll = bpy.context.collection
# Iterate on all object, separate into list of objects, pivot, shadow catcher
objectList = []
pivot = None
shadowCatcher = None
for c in coll.all_objects:
if ("Pivot" in c.name):
pivot = c
continue
def renameCollection_2():
categoryColl = bpy.context.collection
categoryName = categoryColl.name
pivotObject = None
shadowCatcherObject = None
prefix = "Prefix_"
if (checkCollectionNaming(categoryColl.name) == True):
# Set naming for collection
for childColl in categoryColl.children:
objectName = None
def matchPlaceholderName():
# Function to rename placeholder to match the category name
# Select props collection
placeholderString = "Placeholder"
propsColl = bpy.context.collection
categoryArray = []
placeholderArray = []
placeholderCollection = bpy.data.collections[placeholderString]
if (propsColl.name == "Props"):
# Fill both array
Shader "UI/Procedural UI Image 2"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_Fade ("Fade", Float) = 1
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
@aobond2
aobond2 / VertexColorToMaterial.py
Created July 31, 2023 14:46
Vertex color to material blender
import bpy
def create_material(color_name, color):
# Create a new material with the given color
mat = bpy.data.materials.new(name=color_name)
mat.use_nodes = True
nodes = mat.node_tree.nodes
principled_bsdf = nodes.get("Principled BSDF")
if principled_bsdf is not None: