initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,113 @@
#if DEBUG_CUSTOM_STATIC_BATCHING
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Unity.Jobs;
using System.Linq;
using SLZ.CustomStaticBatching;
using Unity.Collections;
namespace SLZ.CustomStaticBatching.Editor
{
public class DebugSB
{
[MenuItem("Tools/Print SB Debug Message")]
public static void PrintDebugMessage()
{
GameObject[] selection = Selection.gameObjects;
List<MeshRenderer> renderers = new List<MeshRenderer>();
for (int i =0; i < selection.Length; i++)
{
MeshRenderer[] mf2 = selection[i].GetComponentsInChildren<MeshRenderer>();
renderers.AddRange(mf2);
}
int numRenderers = renderers.Count;
int rendererIdx = 0;
List<MeshFilter> meshFilters = new List<MeshFilter>(numRenderers);
for (int i = 0; i < numRenderers; i++)
{
MeshRenderer mr = renderers[i];
GameObject go = mr.gameObject;
if (!GameObjectUtility.AreStaticEditorFlagsSet(go, StaticEditorFlags.BatchingStatic))
{
continue;
}
MeshFilter mf = go.GetComponent<MeshFilter>();
if (mf == null || mf.sharedMesh == null)
{
continue;
}
if (mf.sharedMesh.indexFormat == UnityEngine.Rendering.IndexFormat.UInt32)
{
continue;
}
if (mr.sharedMaterials.Length == 0 || mr.sharedMaterials[0] == null)
{
continue;
}
renderers[rendererIdx] = mr;
meshFilters.Add(mf);
rendererIdx++;
}
if (numRenderers != rendererIdx) renderers.RemoveRange(rendererIdx, numRenderers - rendererIdx);
renderers.TrimExcess();
meshFilters.TrimExcess();
RendererData[] sortedData = RendererSort.GetSortedData(renderers, meshFilters);
ComputeShader transferVtxCompute = SBCombineMeshEditor.GetTransferVtxComputeShader();
SBCombineMeshList combiner = new SBCombineMeshList(transferVtxCompute);
combiner.FetchGlobalProjectSettings();
combiner.GenerateStaticBatches(sortedData);
}
[MenuItem("Tools/Create Hilbert Curve")]
public static void TestHilbert()
{
NativeArray<Vector3> points = new NativeArray<Vector3>(16 * 16 * 16, Allocator.TempJob);
for (int z = 0; z < 16; z++)
{
for (int y = 0; y < 16; y++)
{
for (int x = 0; x < 16; x++)
{
points[256 * z + 16 * y + x] = new Vector3(x, y, z);
}
}
}
/*
NativeArray<ulong> sortIdxes = HilbertIndex.GetHilbertIndices(points, new Bounds(new Vector3(8, 8, 8), new Vector3(16, 16, 16)), new Vector3(1,1.0f,1), Allocator.TempJob);
//NativeSortExtension.Sort<SortIdx>(sortIdxes);
string message = "";
for (int i = 0; i < 16; i++)
{
message += sortIdxes[i].ToString() + "\n";
}
Debug.Log(message);
GameObject lineObj = new GameObject();
LineRenderer lineRenderer = lineObj.AddComponent<LineRenderer>();
lineRenderer.positionCount = points.Length;
lineRenderer.widthMultiplier = 0.02f;
lineRenderer.alignment = LineAlignment.View;
lineRenderer.useWorldSpace = false;
for (int i = 0; i < points.Length; i++)
{
lineRenderer.SetPosition(i, points[sortIdxes[i].arrayIdx]);
}
sortIdxes.Dispose();
*/
points.Dispose();
}
}
}
#endif

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 278aaa5095519464fa745c2e05185d5d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,85 @@
#if DEBUG_CUSTOM_STATIC_BATCHING
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.Rendering;
using System.Text;
public class PrintMeshLayout
{
[MenuItem("Tools/Print Mesh Attributes")]
public static void PrintLayout()
{
GameObject sel = Selection.activeGameObject;
Renderer r = sel.GetComponent<Renderer>();
Mesh m = null;
if (r == null) return;
if (r.GetType() == typeof(MeshRenderer))
{
m = r.GetComponent<MeshFilter>().sharedMesh;
}
else if (r.GetType() == typeof(SkinnedMeshRenderer))
{
m = ((SkinnedMeshRenderer)r).sharedMesh;
}
if (m == null) return;
VertexAttributeDescriptor[] attr = m.GetVertexAttributes();
StringBuilder sb = new StringBuilder();
sb.AppendLine("Vertex Layout:\n");
for (int i = 0; i < attr.Length; i++)
{
switch (attr[i].attribute)
{
case VertexAttribute.Position:
sb.Append("Position");
break;
case VertexAttribute.Normal:
sb.Append("Normal");
break;
case VertexAttribute.Tangent:
sb.Append("Tangent");
break;
case VertexAttribute.Color:
sb.Append("Color");
break;
case VertexAttribute.TexCoord0:
sb.Append("TexCoord0");
break;
case VertexAttribute.TexCoord1:
sb.Append("TexCoord1");
break;
case VertexAttribute.TexCoord2:
sb.Append("TexCoord2");
break;
case VertexAttribute.TexCoord3:
sb.Append("TexCoord3");
break;
case VertexAttribute.TexCoord4:
sb.Append("TexCoord4");
break;
case VertexAttribute.TexCoord5:
sb.Append("TexCoord5");
break;
case VertexAttribute.TexCoord6:
sb.Append("TexCoord6");
break;
case VertexAttribute.TexCoord7:
sb.Append("TexCoord7");
break;
case VertexAttribute.BlendIndices:
sb.Append("BlendIndices");
break;
case VertexAttribute.BlendWeight:
sb.Append("BlendWeight");
break;
}
sb.Append(string.Format(": Stream:{0}, Format: {1}, Dimension: {2}\n", attr[i].stream, VertexAttributeFormat.GetName(typeof(VertexAttributeFormat), attr[i].format), attr[i].dimension));
}
Debug.Log(sb.ToString());
}
}
#endif

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9f9b2a05487f93a458dee382a3776abd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,28 @@
#if DEBUG_CUSTOM_STATIC_BATCHING
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace SLZ.CustomStaticBatching
{
public class TestLocalKWs
{
[MenuItem("Tools/Print Shader Keyword Idxs")]
public static void Test()
{
Shader selection = (Shader)Selection.activeObject;
if (selection != null )
{
UnityEngine.Rendering.LocalKeyword[] kws = selection.keywordSpace.keywords;
string message = "Local Keywords: \n";
for ( int i = 0; i < kws.Length; i++ )
{
message += string.Format("{0} : {1}\n", ReflectKWFields.GetIndex(kws[i]), kws[i].name);
}
Debug.Log(message);
}
}
}
}
#endif

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 355abbf7ca534a2499e389b1424761a9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: