This file contains hidden or 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
public static void TakeSnapshot(Camera cam, int resolution, string filename) | |
{ | |
if (cam.targetTexture == null) | |
{ | |
cam.targetTexture = new RenderTexture(resolution, resolution, 24); | |
} | |
Texture2D snapshoot = new Texture2D(resolution, resolution, TextureFormat.RGB24, false); | |
cam.Render(); |
This file contains hidden or 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
public static bool isEqual(float a, float b) | |
{ | |
if (a >= b - Mathf.Epsilon && a <= b + Mathf.Epsilon) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} |
This file contains hidden or 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
public static bool isOrtagonal(Vector4 a, Vector4 b) | |
{ | |
return isEqual(Vector3.Dot(a, b), 0.0f); | |
} | |
public static bool isOrtagonal(Vector3 a, Vector3 b) | |
{ | |
return isEqual(Vector3.Dot(a, b), 0.0f); | |
} | |
public static bool isOrtagonal(Vector2 a, Vector2 b) | |
{ |
This file contains hidden or 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
public static bool isOrtagonal(Vector4 a, Vector4 b) | |
{ | |
return isEqual(Vector3.Dot(a, b), 0.0f); | |
} | |
public static bool isOrtagonal(Vector3 a, Vector3 b) | |
{ | |
return isEqual(Vector3.Dot(a, b), 0.0f); | |
} | |
public static bool isOrtagonal(Vector2 a, Vector2 b) | |
{ |
This file contains hidden or 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 requests | |
import shutil | |
URL = "https://" | |
save_as = 'img.png' | |
response = requests.get(URL) | |
response = requests.get(URL, stream=True) | |
with open(save_as, 'wb') as out_file: | |
shutil.copyfileobj(response.raw, out_file) |
This file contains hidden or 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 matplotlib.pyplot as plt | |
import numpy as np | |
from PIL import Image | |
#generating | |
w, h = 512, 512 | |
data = np.zeros((h, w, 3), dtype=np.uint8) | |
data[0:256, 0:256] = [50, 150, 200] # red patch in upper left | |
#displaying |
This file contains hidden or 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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace MLib.BuildInMaterialsTools.HDR | |
{ | |
public class Lit | |
{ | |
public static void SetBaseColorMap(ref Renderer renderer,in RenderTexture render_texture) | |
{ |
This file contains hidden or 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
private static Texture2D toTexture2D(RenderTexture rTex) | |
{ | |
int widht = rTex.width; | |
int height = rTex.height; | |
Texture2D tex = new Texture2D(widht, height, TextureFormat.RGB24, false); | |
RenderTexture.active = rTex; | |
tex.ReadPixels(new Rect(0, 0, rTex.width, rTex.height), 0, 0); | |
tex.Apply(); | |
return tex; |
This file contains hidden or 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
private static void ConveretTexture2dIntoRenderTexture(out RenderTexture out_renderTexture, in Texture2D input_texture2d, int resolution) | |
{ | |
//int resolution = 1024 * 4; | |
// texRef is your Texture2D | |
// You can also reduice your texture 2D that way | |
out_renderTexture = new RenderTexture(resolution, resolution, 0); | |
out_renderTexture.enableRandomWrite = true; | |
RenderTexture.active = out_renderTexture; | |
// Copy your texture ref to the render texture | |
Graphics.Blit(input_texture2d, out_renderTexture); |
This file contains hidden or 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
private static Texture2D LoadPNG(string filePath) | |
{ | |
Texture2D tex = null; | |
byte[] fileData; | |
if (System.IO.File.Exists(filePath)) | |
{ | |
fileData = System.IO.File.ReadAllBytes(filePath); | |
tex = new Texture2D(2, 2); |