Files
Pal3.Unity/Assets/Scripts/Pal3.Game/Effect/Original/EffectMeshBuffer.cs
Jiaqi (0x7c13) Liu fc982180f0 Implement native SPar playback and PAL3A transport effects
Add SPar emitter simulation, native blending and billboard rendering for the
remaining 26 script/scene groups. Restore PAL3A transport geometry and seven
styles in game, the editor and ResourceViewer.

Preserve native live-state initial-frame behavior and mark the runtime UV
table non-serialized. Update the README and add format, playback, geometry
and resource-lifetime regression coverage.

Validation: targeted tests 106/106 for both variants; general regressions
PAL3 293/293 and PAL3A 310/310. Both-variant formatting checks passed.
2026-11-14 03:46:07 +08:00

87 lines
3.2 KiB
C#

// ------------------------------------------------------------------------
// Copyright (c) 2026, Jiaqi (0x7c13) Liu. All rights reserved.
// See LICENSE file in the project root for license information.
// ------------------------------------------------------------------------
namespace Pal3.Game.Effect.Original
{
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
internal sealed class EffectMeshBuffer : IDisposable
{
private readonly Mesh _mesh;
private readonly bool _reverseWinding;
private readonly MeshRenderer _renderer;
private readonly List<Vector3> _vertices = new();
private readonly List<Vector2> _uv = new();
private readonly List<Color32> _colors = new();
private readonly List<int> _indices = new();
public int QuadCount => _vertices.Count / 4;
public EffectMeshBuffer(GameObject root, Material material, bool reverseWinding = false)
{
_reverseWinding = reverseWinding;
_mesh = new Mesh { name = "Original effect mesh", indexFormat = IndexFormat.UInt32, hideFlags = HideFlags.DontSave };
_mesh.MarkDynamic();
root.AddComponent<MeshFilter>().sharedMesh = _mesh;
_renderer = root.AddComponent<MeshRenderer>();
_renderer.sharedMaterial = material;
_renderer.shadowCastingMode = ShadowCastingMode.Off;
_renderer.receiveShadows = false;
_renderer.lightProbeUsage = LightProbeUsage.Off;
_renderer.reflectionProbeUsage = ReflectionProbeUsage.Off;
}
public void Clear()
{
_vertices.Clear();
_uv.Clear();
_colors.Clear();
_indices.Clear();
}
public void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Vector2 uv0, Vector2 uv1, Color32 color)
=> Quad(a, b, c, d, uv0, uv1, color, color, color, color);
public void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Vector2 uv0, Vector2 uv1,
Color32 colorA, Color32 colorB, Color32 colorC, Color32 colorD)
{
int n = _vertices.Count;
_vertices.Add(a);
_vertices.Add(b);
_vertices.Add(c);
_vertices.Add(d);
_uv.Add(uv0);
_uv.Add(new Vector2(uv1.x, uv0.y));
_uv.Add(uv1);
_uv.Add(new Vector2(uv0.x, uv1.y));
_colors.Add(colorA);
_colors.Add(colorB);
_colors.Add(colorC);
_colors.Add(colorD);
_indices.Add(n);
_indices.Add(n + (_reverseWinding ? 2 : 1));
_indices.Add(n + (_reverseWinding ? 1 : 2));
_indices.Add(n);
_indices.Add(n + (_reverseWinding ? 3 : 2));
_indices.Add(n + (_reverseWinding ? 2 : 3));
}
public void Upload()
{
_renderer.enabled = _vertices.Count > 0;
_mesh.Clear(false);
_mesh.SetVertices(_vertices);
_mesh.SetUVs(0, _uv);
_mesh.SetColors(_colors);
_mesh.SetTriangles(_indices, 0, true);
}
public void Dispose() => OriginalEffectResources.Destroy(_mesh);
}
}