Skip to content

Commit 6f9a0e6

Browse files
committed
jiggle changes
1 parent ed53f7d commit 6f9a0e6

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

Basis/Packages/com.gator-dragon-games.jigglephysics/Scripts/JiggleJobPrepareRender.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public void Execute() {
4040

4141
for (int i = 0; i < personalColliderCount; i++) {
4242
var collider = personalColliders[i];
43+
// Retired slots keep their last matrix, and freshly added ones are counted before the
44+
// collider TransformAccessArray flips — so until the read job has visited them their
45+
// matrix is whatever it was built with (or all zeros). Drawing either one pins a gizmo
46+
// wherever the avatar was when it spawned. worldRadius is only ever set by Read, so it
47+
// doubles as "this slot has been sampled at least once".
48+
if (!collider.enabled || collider.worldRadius <= 0f) {
49+
continue;
50+
}
4351
var position = collider.localToWorldMatrix.c3.xyz;
4452
switch (collider.type) {
4553
case JiggleCollider.JiggleColliderType.Sphere: {
@@ -67,6 +75,9 @@ public void Execute() {
6775

6876
for (int i = 0; i < sceneColliderCount; i++) {
6977
var collider = sceneColliders[i];
78+
if (!collider.enabled || collider.worldRadius <= 0f) {
79+
continue;
80+
}
7081
var position = collider.localToWorldMatrix.c3.xyz;
7182
switch (collider.type) {
7283
case JiggleCollider.JiggleColliderType.Sphere: {

Basis/Packages/com.gator-dragon-games.jigglephysics/Scripts/JigglePhysics.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,16 @@ public static void Dispose() {
129129
jiggleRootLookup = new Dictionary<Transform, JiggleTreeSegment>();
130130
_globalDirty = true;
131131
jobs = null;
132+
// JiggleRenderer.Dispose released the instancers and chunk buffers, so leaving this latched
133+
// would skip the OnEnable that rebuilds them and silently stop drawing gizmos for the rest
134+
// of the session (Initialize only runs again on a domain reload).
135+
initializedRendering = false;
132136
}
133137

134138
public static void ScheduleRender() {
139+
if (jobs == null) {
140+
return;
141+
}
135142
if (!initializedRendering) {
136143
JiggleRenderer.OnEnable(jobs);
137144
initializedRendering = true;
@@ -140,6 +147,9 @@ public static void ScheduleRender() {
140147
}
141148

142149
public static void CompleteRender(Material proceduralMaterial, Mesh sphere, Mesh capsule) {
150+
if (jobs == null) {
151+
return;
152+
}
143153
if (!initializedRendering) {
144154
JiggleRenderer.OnEnable(jobs);
145155
initializedRendering = true;

Basis/Packages/com.gator-dragon-games.jigglephysics/Scripts/JiggleRenderInstancer.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ private void GenerateChunks(NativeArray<GPUChunk> chunks, int count) {
3030
bufferCapacity = desiredChunkCount;
3131
}
3232

33-
bufferCount = count;
34-
chunkBuffer.SetData(chunks, 0, 0, count);
33+
bufferCount = math.clamp(count, 0, desiredChunkCount);
34+
if (bufferCount == 0) {
35+
return;
36+
}
37+
chunkBuffer.SetData(chunks, 0, 0, bufferCount);
3538
}
3639

3740
public void Render(Bounds bounds, Mesh mesh, Material material, NativeArray<GPUChunk> chunks, int count) {
3841
GenerateChunks(chunks, count);
39-
if (chunkBuffer == null) {
42+
if (chunkBuffer == null || bufferCount == 0) {
4043
return;
4144
}
4245

@@ -51,6 +54,9 @@ public void Render(Bounds bounds, Mesh mesh, Material material, NativeArray<GPUC
5154

5255
public void Dispose() {
5356
chunkBuffer?.Release();
57+
chunkBuffer = null;
58+
bufferCapacity = 0;
59+
bufferCount = 0;
5460
}
5561
}
5662

Basis/Packages/com.gator-dragon-games.jigglephysics/Scripts/JiggleRenderer.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private static float4 ColorToFloat4(Color color) {
4343

4444
private static void FlipData(JiggleJobs job, double simulatedTime) {
4545
var sceneColliderCapacity = job.GetSceneColliderCapacity();
46-
var personalColliderCapacity = job.GetSceneColliderCapacity();
46+
var personalColliderCapacity = job.GetPersonalColliderCapacity();
4747
var transformCapacity = job.GetTransformCapcity();
4848

4949
int desiredSphereCount = math.max(sceneColliderCapacity + personalColliderCapacity + transformCapacity, 1);
@@ -80,18 +80,21 @@ public static void PrepareRender(JiggleJobs job) {
8080
jobPrepareRender.sceneColliders = job.GetSceneColliders(out jobPrepareRender.sceneColliderCount);
8181
jobPrepareRender.outputPoses = job.GetInterpolatedOutputPoses(out jobPrepareRender.transformCount);
8282
jobPrepareRender.trees = job.GetTrees(out jobPrepareRender.treeCount);
83+
// Latch only when the job actually got scheduled. Flagging unconditionally meant a frame
84+
// where the sim dependencies weren't ready still completed and re-rendered the previous
85+
// frame's chunk data, pinning gizmos at stale positions.
8386
if (job.TryGetRenderDependencies(out var handle)) {
8487
handleRender = jobPrepareRender.Schedule(handle);
88+
hasHandleRender = true;
8589
}
86-
87-
hasHandleRender = true;
8890
}
8991

9092
public static void FinishRender(Material gpuInstanceMaterial, Mesh sphere, Mesh capsule) {
9193
if (!hasHandleRender) {
9294
return;
9395
}
9496
handleRender.Complete();
97+
hasHandleRender = false;
9598
if (sphereChunks.IsCreated && sphere != null) {
9699
sphereInstancer.Render(jobPrepareRender.sphereBounds.Value, sphere, gpuInstanceMaterial, sphereChunks, jobPrepareRender.sphereCount.Value);
97100
}
@@ -101,6 +104,10 @@ public static void FinishRender(Material gpuInstanceMaterial, Mesh sphere, Mesh
101104
}
102105

103106
public static void Dispose() {
107+
if (hasHandleRender) {
108+
handleRender.Complete();
109+
hasHandleRender = false;
110+
}
104111
sphereInstancer?.Dispose();
105112
sphereInstancer = null;
106113
capsuleInstancer?.Dispose();

0 commit comments

Comments
 (0)