From 8e13e7e2874adc8982e16d1d2ed2e28d7480b45f Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Sun, 19 May 2024 16:05:58 +0800 Subject: +1.57 --- .../NGS.MeshFusionPro/JobsMeshMoverSTD.cs | 144 +++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 Thronefall_1_57/Decompile/NGS.MeshFusionPro/JobsMeshMoverSTD.cs (limited to 'Thronefall_1_57/Decompile/NGS.MeshFusionPro/JobsMeshMoverSTD.cs') diff --git a/Thronefall_1_57/Decompile/NGS.MeshFusionPro/JobsMeshMoverSTD.cs b/Thronefall_1_57/Decompile/NGS.MeshFusionPro/JobsMeshMoverSTD.cs new file mode 100644 index 0000000..535b8af --- /dev/null +++ b/Thronefall_1_57/Decompile/NGS.MeshFusionPro/JobsMeshMoverSTD.cs @@ -0,0 +1,144 @@ +using System; +using System.Collections.Generic; +using Unity.Burst; +using Unity.Collections; +using Unity.Jobs; +using UnityEngine; + +namespace NGS.MeshFusionPro; + +public class JobsMeshMoverSTD : IAsyncCombinedMeshMover, ICombinedMeshMover, IDisposable +{ + [BurstCompile] + private struct MovePartsJob : IJobParallelFor + { + [NativeDisableParallelForRestriction] + public NativeArray vertices; + + [NativeDisableParallelForRestriction] + public NativeArray normals; + + [NativeDisableParallelForRestriction] + public NativeArray tangents; + + [WriteOnly] + [NativeDisableParallelForRestriction] + public NativeArray bounds; + + [ReadOnly] + [NativeDisableParallelForRestriction] + public NativeArray localBounds; + + [ReadOnly] + public NativeList moveInfos; + + public void Execute(int idx) + { + PartMoveInfo partMoveInfo = moveInfos[idx]; + int partIndex = partMoveInfo.partIndex; + int vertexStart = partMoveInfo.vertexStart; + int num = vertexStart + partMoveInfo.vertexCount; + Matrix4x4 targetTransform = partMoveInfo.targetTransform; + Matrix4x4 inverse = partMoveInfo.currentTransform.inverse; + for (int i = vertexStart; i < num; i++) + { + Vector3 point = vertices[i]; + Vector3 vector = normals[i]; + Vector4 vector2 = tangents[i]; + float w = vector2.w; + point = inverse.MultiplyPoint3x4(point); + point = targetTransform.MultiplyPoint3x4(point); + vector = inverse.MultiplyVector(vector); + vector = targetTransform.MultiplyVector(vector); + vector2 = inverse.MultiplyVector(vector2); + vector2 = targetTransform.MultiplyVector(vector2); + vector2.w = w; + vertices[i] = point; + normals[i] = vector; + tangents[i] = vector2; + } + bounds[partIndex] = localBounds[partIndex].Transform(targetTransform); + } + } + + [BurstCompile] + private struct RecalculateBoundsJob : IJob + { + public NativeArray bounds; + + public NativeArray boundingBox; + + public void Execute() + { + Bounds value = boundingBox[0]; + for (int i = 0; i < bounds.Length; i++) + { + value.Encapsulate(bounds[i]); + } + boundingBox[0] = value; + } + } + + private MeshDataNativeArraysSTD _meshData; + + private NativeList _moveInfos; + + private JobHandle _handle; + + public JobsMeshMoverSTD(MeshDataNativeArraysSTD meshData) + { + _meshData = meshData; + _moveInfos = new NativeList(Allocator.Persistent); + } + + public void MoveParts(IList moveInfos) + { + MovePartsAsync(moveInfos); + FinishAsyncMoving(); + } + + public void MovePartsAsync(IList moveInfos) + { + NativeArray bounds = _meshData.Bounds; + bounds[0] = new Bounds(_meshData.GetBounds().center, Vector3.zero); + _moveInfos.Clear(); + for (int i = 0; i < moveInfos.Count; i++) + { + ref NativeList moveInfos2 = ref _moveInfos; + PartMoveInfo value = moveInfos[i]; + moveInfos2.Add(in value); + } + MovePartsJob movePartsJob = default(MovePartsJob); + movePartsJob.vertices = _meshData.Vertices; + movePartsJob.normals = _meshData.Normals; + movePartsJob.tangents = _meshData.Tangents; + movePartsJob.bounds = _meshData.PartsBounds; + movePartsJob.localBounds = _meshData.PartsBoundsLocal; + movePartsJob.moveInfos = _moveInfos; + MovePartsJob jobData = movePartsJob; + RecalculateBoundsJob recalculateBoundsJob = default(RecalculateBoundsJob); + recalculateBoundsJob.bounds = _meshData.PartsBounds; + recalculateBoundsJob.boundingBox = bounds; + RecalculateBoundsJob jobData2 = recalculateBoundsJob; + _handle = jobData2.Schedule(IJobParallelForExtensions.Schedule(jobData, _moveInfos.Length, 4)); + } + + public void FinishAsyncMoving() + { + _handle.Complete(); + } + + public void ApplyData() + { + if (!_handle.IsCompleted) + { + FinishAsyncMoving(); + } + _meshData.ApplyDataToMesh(); + } + + public void Dispose() + { + _moveInfos.Dispose(); + } +} -- cgit v1.1-26-g67d0