유니티 셋팅

This commit is contained in:
2026-03-27 16:34:08 +09:00
parent 474bda26cd
commit d76f078a89
1400 changed files with 116263 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: CombinedAtlas
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 3eb1e10b5853f924194fcc4ce6d4bac5
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 31895
packageName: Mesh Baker Free
packageVersion: 3.40.1
assetPath: Assets/MeshBaker/Examples/HackTextureAtlas/CombinedAtlas.mat
uploadId: 797180

View File

@@ -0,0 +1,79 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Hide
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SwizzleNormalMapChannelsNM: 0
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0, g: 1, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 6c823e4cb13cd6248a6952ad8037fbc7
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 31895
packageName: Mesh Baker Free
packageVersion: 3.40.1
assetPath: Assets/MeshBaker/Examples/HackTextureAtlas/Hide.mat
uploadId: 797180

View File

@@ -0,0 +1,78 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Hoof
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0, g: 1, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: f8bb38b73aeca074ca7999c8babba4f4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 31895
packageName: Mesh Baker Free
packageVersion: 3.40.1
assetPath: Assets/MeshBaker/Examples/HackTextureAtlas/Hoof.mat
uploadId: 797180

View File

@@ -0,0 +1,78 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Horns
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: c6ca4112ed67b6a409e9f4c59e2d7a97
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 31895
packageName: Mesh Baker Free
packageVersion: 3.40.1
assetPath: Assets/MeshBaker/Examples/HackTextureAtlas/Horns.mat
uploadId: 797180

View File

@@ -0,0 +1,162 @@
using System.IO;
using System.Text;
using DigitalOpus.MB.Core;
using UnityEngine;
using UnityEngine.Assertions;
using DigitalOpus.MB;
namespace MeshBaker_Examples_2017.HackTextureAtlas
{
/// <summary>
/// The MB_CustomizeCharacterGUI class is a simple example implementation that shows how
/// the MB_TextureBakerQuickHack can be used to customize a character's texture without
/// using the TextureBaker, which is more robust but slower.
///
/// The reasoning for this is because the regular TextureBaker is too slow to use at runtime
/// without lag spikes.
/// </summary>
public class MB_CustomizeCharacterGUI : MonoBehaviour
{
public Material[] sourceMaterials;
public GameObject[] objectsToBeCombined;
[Header("Mesh Baker Config")]
public MB3_MeshBaker targetMeshBaker;
private MB_TextureBakerQuickHack textureBakerQuickHack;
private string colorTintPropertyName;
private string albedoTexturePropertyName;
private string shaderName;
// Start is called before the first frame update
void Start()
{
// Detect the current pipeline and set the shader names accordingly
switch (MBVersion.DetectPipeline())
{
case MBVersion.PipelineType.Default:
{
colorTintPropertyName = "_Color";
albedoTexturePropertyName = "_MainTex";
shaderName = "Standard";
break;
}
case MBVersion.PipelineType.URP:
{
colorTintPropertyName = "_BaseColor";
albedoTexturePropertyName = "_BaseMap";
shaderName = "Universal Render Pipeline/Lit";
break;
}
case MBVersion.PipelineType.HDRP:
{
colorTintPropertyName = "_BaseColor";
albedoTexturePropertyName = "_BaseColorMap";
shaderName = "HDRP/Lit";
break;
}
default:
{
Debug.LogError("Unknown pipeline type");
break;
}
}
textureBakerQuickHack = GetComponent<MB_TextureBakerQuickHack>();
Debug.Log("Creating atlas using TextureBakerQuickHack method");
{
textureBakerQuickHack.colorTintPropertyName = colorTintPropertyName;
textureBakerQuickHack.albedoTexturePropertyName = albedoTexturePropertyName;
textureBakerQuickHack.shaderName = shaderName;
}
textureBakerQuickHack.CreateAtlas(sourceMaterials); // Generate a custom texture atlas without using the TextureBaker
Debug.Log("Baking MeshBaker using TextureBakerQuickHack output");
BakeMeshBaker(); // This is the function that bakes the combined mesh
}
// OnGUI is called for rendering and handling GUI events
void OnGUI()
{
string textureBakerQuickHackInfo =
"This example demonstrates how to create\r\n" +
"solid-color-rectangle texture atlases at\r\n" +
"runtime for character customization. This\r\n" +
"is MUCH faster and more flexible than using\r\n" +
"the full TextureBaker. These atlases can be\r\n" +
"used at runtime with a Mesh Baker.\r\n";
GUILayout.BeginHorizontal();
GUILayout.Label(textureBakerQuickHackInfo.ToString());
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Hoof Color");
if (GUILayout.Button("Red"))
{
SetColorInMaterialBakeResultAndBakeMeshBaker(sourceMaterials[0], Color.red);
}
if (GUILayout.Button("Green"))
{
SetColorInMaterialBakeResultAndBakeMeshBaker(sourceMaterials[0], Color.green);
}
if (GUILayout.Button("Blue"))
{
SetColorInMaterialBakeResultAndBakeMeshBaker(sourceMaterials[0], Color.blue);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Body Color");
if (GUILayout.Button("Red"))
{
SetColorInMaterialBakeResultAndBakeMeshBaker(sourceMaterials[1], Color.red);
}
if (GUILayout.Button("Green"))
{
SetColorInMaterialBakeResultAndBakeMeshBaker(sourceMaterials[1], Color.green);
}
if (GUILayout.Button("Blue"))
{
SetColorInMaterialBakeResultAndBakeMeshBaker(sourceMaterials[1], Color.blue);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Horns Color");
if (GUILayout.Button("Red"))
{
SetColorInMaterialBakeResultAndBakeMeshBaker(sourceMaterials[2], Color.red);
}
if (GUILayout.Button("Green"))
{
SetColorInMaterialBakeResultAndBakeMeshBaker(sourceMaterials[2], Color.green);
}
if (GUILayout.Button("Blue"))
{
SetColorInMaterialBakeResultAndBakeMeshBaker(sourceMaterials[2], Color.blue);
}
GUILayout.EndHorizontal();
}
private void SetColorInMaterialBakeResultAndBakeMeshBaker(Material bodyPartMaterial, Color color)
{
Debug.Log("Changing color of material " + bodyPartMaterial + " used in atlas generation");
bodyPartMaterial.SetColor(colorTintPropertyName, color);
Debug.Log("Creating atlas using TextureBakerQuickHack method");
textureBakerQuickHack.CreateAtlas(sourceMaterials);
Debug.Log("Baking MeshBaker using TextureBakerQuickHack output");
BakeMeshBaker();
}
[ContextMenu("Bake Mesh Baker")]
private void BakeMeshBaker()
{
Assert.IsNotNull(targetMeshBaker, "targetMeshBaker is null. Make sure one is assigned in the inspector.");
targetMeshBaker.textureBakeResults = textureBakerQuickHack.materialBakeResult;
targetMeshBaker.ClearMesh();
if (targetMeshBaker.AddDeleteGameObjects(objectsToBeCombined, null, true))
{
targetMeshBaker.Apply();
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 00fa755a6276b3c4cb929cf9dfc0d947
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 31895
packageName: Mesh Baker Free
packageVersion: 3.40.1
assetPath: Assets/MeshBaker/Examples/HackTextureAtlas/MB_CustomizeCharacterGUI.cs
uploadId: 797180

View File

@@ -0,0 +1,214 @@
using System.Collections.Generic;
using System.Text;
using DigitalOpus.MB.Core;
using UnityEngine;
namespace MeshBaker_Examples_2017.HackTextureAtlas
{
/// <summary>
/// Sometimes we want to create a custom texture atlas without using the TextureBaker. Examples:
///
/// - We have some solid colors that we want in an atlas.
/// - The texture baker has a lot of features which makes it slow at runtime.
///
/// This script creates an atlas, combinedMaterial, Material Bake Result without using the TextureBaker.
/// </summary>
public class MB_TextureBakerQuickHack : MonoBehaviour
{
[Header("Hack Atlas Generation")]
public string colorTintPropertyName;
public string albedoTexturePropertyName;
public string shaderName;
public Material[] sourceMaterials;
[Space(20)]
[Header("Generated Output")]
// materialBakeResult can't be modified by users, but we want to see it in the inspector.
public MB2_TextureBakeResults materialBakeResult;
public Material atlasMaterial;
public Texture2D atlasTexture;
[ContextMenu("Generate Material Bake Result")]
public void CreateAtlas(Material[] passedInSourceMaterials)
{
// Validation of source materials
Debug.Log("Validating source materials");
{
bool doProceed = true;
{
// passedInSourceMaterials must be unique
HashSet<Material> uniqueMaterialsChecker = new HashSet<Material>(passedInSourceMaterials);
if (uniqueMaterialsChecker.Count != passedInSourceMaterials.Length)
{
Debug.LogError("Source materials are not unique");
doProceed = false;
}
// there must be at least one source material
if (passedInSourceMaterials.Length == 0)
{
Debug.LogError("No source materials were passed in");
doProceed = false;
}
// colorTintProperty must be a valid string
if (string.IsNullOrEmpty(colorTintPropertyName))
{
Debug.LogError("ColorTintProperty is not set");
doProceed = false;
}
}
// copy passed in source materials to sourceMaterials
sourceMaterials = new Material[passedInSourceMaterials.Length];
for (int i = 0; i < passedInSourceMaterials.Length; i++)
{
// validate each passed in source material
{
// all passedInSourceMaterials must exist
if (passedInSourceMaterials[i] == null)
{
Debug.LogError("Source material " + i + " is null");
doProceed = false;
}
// all passedInSourceMaterials must have colorTintProperty
if (!passedInSourceMaterials[i].HasProperty(colorTintPropertyName))
{
Debug.LogError("Source material " + i + " does not have the colorTint property");
doProceed = false;
}
}
sourceMaterials[i] = passedInSourceMaterials[i];
sourceMaterials[i].shader = Shader.Find(shaderName);
}
if (!doProceed)
{
Debug.LogError("Some validation of the source materials failed and the atlas was not generated.");
return;
}
}
int padding = 2;
int colorBlockSize = 8;
bool isProjectLinear = MBVersion.GetProjectColorSpace() == ColorSpace.Linear;
// Visit each source material and generate a solid color texture matching the color tint.
// Building a string for debug output at the end of this function
Texture2D[] solidColorTextures = new Texture2D[sourceMaterials.Length];
{
StringBuilder colorTintsFromSourceMaterials = new StringBuilder("Collecting color tints from source materials: \n");
Color[] colorsToSet = new Color[colorBlockSize * colorBlockSize];
for (int matIdx = 0; matIdx < sourceMaterials.Length; matIdx++)
{
// Get the color tint
Material m = sourceMaterials[matIdx];
Debug.Assert(m.HasProperty(colorTintPropertyName), "Material was missing the colorTint property");
Color colorTint = m.GetColor(colorTintPropertyName);
colorTintsFromSourceMaterials.Append("Material: " + m.name + " - colorTint: " + colorTint + "\n");
// Generate a small solid color block texture
Texture2D tex = solidColorTextures[matIdx] = new Texture2D(colorBlockSize, colorBlockSize, TextureFormat.ARGB32, false, isProjectLinear);
for (int cIdx = 0; cIdx < colorsToSet.Length; cIdx++)
{
colorsToSet[cIdx] = colorTint;
}
tex.SetPixels(colorsToSet);
tex.Apply();
}
Debug.Log(colorTintsFromSourceMaterials);
}
// Calculate the atlas dimensions
Debug.Log("Calculating the atlas dimensions");
int atlasSize_pixels;
{
float numTexPerRow = Mathf.Ceil(Mathf.Sqrt(sourceMaterials.Length));
atlasSize_pixels = (int) numTexPerRow * colorBlockSize;
}
// creating atlas for sourceMaterials.Length textures.
Debug.Log("Creating atlas for " + sourceMaterials.Length + " textures");
Rect[] atlasRects;
{
// Create the atlas
atlasTexture = new Texture2D(atlasSize_pixels, atlasSize_pixels, TextureFormat.ARGB32, false, isProjectLinear);
{
// Pass in padding 0. We will subtract some area from the edges of the rectangles to create padding
// We do it this way so that the padding is filled with block color not black.
atlasRects = atlasTexture.PackTextures(solidColorTextures, 0, atlasSize_pixels);
}
Debug.Log("Atlas size: w:" + atlasTexture.width + " h:" + atlasTexture.height + " numTex: " + solidColorTextures.Length + " (" + colorBlockSize + "x" + colorBlockSize + " each)");
atlasTexture.filterMode = FilterMode.Point;
}
// Generate a combined material
atlasMaterial = new Material(Shader.Find(shaderName)); // has to be different based on default, URP, HDRP
atlasMaterial.SetTexture(albedoTexturePropertyName, atlasTexture); // has to be different based on default, URP, HDRP
atlasMaterial.SetColor(colorTintPropertyName, Color.white);
{
StringBuilder atlasRectanglesInformation = new StringBuilder("Creating MB2_TextureBakeResult for storing atlas rectangle information: \n");
for (int i = 0; i < solidColorTextures.Length; i++)
{
atlasRectanglesInformation.Append("Material: " + sourceMaterials[i].name + " will use rectangle: " + atlasRects[i] + "\n");
}
Debug.Log(atlasRectanglesInformation);
}
// Create and setup the material bake result
Debug.Log("Creating and setting up MB2_TextureBakeResults");
{
materialBakeResult = ScriptableObject.CreateInstance<MB2_TextureBakeResults>();
materialBakeResult.resultType = MB2_TextureBakeResults.ResultType.atlas;
materialBakeResult.materialsAndUVRects = new MB_MaterialAndUVRect[solidColorTextures.Length];
float paddingWidth = ((float) padding) / atlasTexture.width;
float paddingHeight = ((float)padding) / atlasTexture.height;
for (int i = 0; i < solidColorTextures.Length; i++)
{
Rect rectangleInAtlas = atlasRects[i];
{
// Pad the rectangle in the atlas.
// We packed the atlas with padding 0. Now we shrink the rectangles to create
// padding around the edges of each rectangle that is filled with each rectangles color.
rectangleInAtlas.x += paddingWidth;
rectangleInAtlas.y += paddingHeight;
rectangleInAtlas.width -= 2f * paddingWidth;
rectangleInAtlas.height -= 2f * paddingHeight;
}
// See the MB_MaterialAndUVRect for explanations of these parameters.
bool allPropsUseSameTiling = true;
materialBakeResult.materialsAndUVRects[i] = new MB_MaterialAndUVRect(
sourceMaterials[i],
rectangleInAtlas,
allPropsUseSameTiling,
new Rect(0, 0, 1, 1),
new Rect(0, 0, 1, 1),
new Rect(0, 0, 0, 0),
MB_TextureTilingTreatment.none,
sourceMaterials[i].name
);
}
materialBakeResult.resultMaterials = new MB_MultiMaterial[1];
materialBakeResult.resultMaterials[0] = new MB_MultiMaterial();
materialBakeResult.resultMaterials[0].combinedMaterial = atlasMaterial;
materialBakeResult.resultMaterials[0].considerMeshUVs = false;
List<Material> smats = new List<Material>();
smats.AddRange(sourceMaterials);
materialBakeResult.resultMaterials[0].sourceMaterials = smats;
}
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 10aa5b9a0cb8b9d4abc9b0108b3f473a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 31895
packageName: Mesh Baker Free
packageVersion: 3.40.1
assetPath: Assets/MeshBaker/Examples/HackTextureAtlas/MB_TextureBakerQuickHack.cs
uploadId: 797180