summaryrefslogtreecommitdiff
path: root/VRCSDK3Worlds/Assets/MeshBaker/scripts/AssignToMeshCustomizers/CustomizerPutSliceIndexInUV0_z.cs
diff options
context:
space:
mode:
authortylermurphy534 <tylermurphy534@gmail.com>2022-11-06 15:12:42 -0500
committertylermurphy534 <tylermurphy534@gmail.com>2022-11-06 15:12:42 -0500
commiteb84bb298d2b95aec7b2ae12cbf25ac64f25379a (patch)
treeefd616a157df06ab661c6d56651853431ac6b08b /VRCSDK3Worlds/Assets/MeshBaker/scripts/AssignToMeshCustomizers/CustomizerPutSliceIndexInUV0_z.cs
downloadunityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.gz
unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.bz2
unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.zip
move to self host
Diffstat (limited to 'VRCSDK3Worlds/Assets/MeshBaker/scripts/AssignToMeshCustomizers/CustomizerPutSliceIndexInUV0_z.cs')
-rw-r--r--VRCSDK3Worlds/Assets/MeshBaker/scripts/AssignToMeshCustomizers/CustomizerPutSliceIndexInUV0_z.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/VRCSDK3Worlds/Assets/MeshBaker/scripts/AssignToMeshCustomizers/CustomizerPutSliceIndexInUV0_z.cs b/VRCSDK3Worlds/Assets/MeshBaker/scripts/AssignToMeshCustomizers/CustomizerPutSliceIndexInUV0_z.cs
new file mode 100644
index 00000000..6a2fb77f
--- /dev/null
+++ b/VRCSDK3Worlds/Assets/MeshBaker/scripts/AssignToMeshCustomizers/CustomizerPutSliceIndexInUV0_z.cs
@@ -0,0 +1,44 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using DigitalOpus.MB.Core;
+
+namespace DigitalOpus.MB.Core
+{
+ /// <summary>
+ /// This MeshAssignCustomizer alters the UV data as it is being assigned to the mesh.
+ /// It appends the Texture Array slice index in the UV.z channel.
+ ///
+ /// Shaders must be modified to read the slice index from the UV.z channel to use this.
+ /// </summary>
+ [CreateAssetMenu(fileName = "MeshAssignCustomizerPutSliceIdxInUV0_z", menuName = "Mesh Baker/Assign To Mesh Customizer/Put Slice Index In UV0.z", order = 1)]
+ public class CustomizerPutSliceIndexInUV0_z : MB_DefaultMeshAssignCustomizer
+ {
+ public override void meshAssign_UV0(int channel, MB_IMeshBakerSettings settings, MB2_TextureBakeResults textureBakeResults, Mesh mesh, Vector2[] uvs, float[] sliceIndexes)
+ {
+ if (textureBakeResults.resultType == MB2_TextureBakeResults.ResultType.atlas)
+ {
+ mesh.uv = uvs;
+ }
+ else
+ {
+ {
+ if (uvs.Length == sliceIndexes.Length)
+ {
+ List<Vector3> nuvs = new List<Vector3>();
+ for (int i = 0; i < uvs.Length; i++)
+ {
+ nuvs.Add(new Vector3(uvs[i].x, uvs[i].y, sliceIndexes[i]));
+ }
+
+ mesh.SetUVs(0, nuvs);
+ }
+ else
+ {
+ Debug.LogError("UV slice buffer was not the same size as the uv buffer");
+ }
+ }
+ }
+ }
+ }
+}