修改水

This commit is contained in:
2026-01-01 22:00:33 +08:00
parent 040a222bd6
commit 9ceffccd39
1800 changed files with 103929 additions and 139495 deletions

View File

@@ -1,32 +0,0 @@
using System;
using UnityEngine;
namespace Obi
{
public class ComputeChainConstraints : ComputeConstraintsImpl<ComputeChainConstraintsBatch>
{
public ComputeShader constraintsShader;
public int projectKernel;
public int applyKernel;
public ComputeChainConstraints(ComputeSolverImpl solver) : base(solver, Oni.ConstraintType.Chain)
{
constraintsShader = GameObject.Instantiate(Resources.Load<ComputeShader>("Compute/ChainConstraints"));
projectKernel = constraintsShader.FindKernel("Project");
applyKernel = constraintsShader.FindKernel("Apply");
}
public override IConstraintsBatchImpl CreateConstraintsBatch()
{
var dataBatch = new ComputeChainConstraintsBatch(this);
batches.Add(dataBatch);
return dataBatch;
}
public override void RemoveBatch(IConstraintsBatchImpl batch)
{
batches.Remove(batch as ComputeChainConstraintsBatch);
batch.Destroy();
}
}
}

View File

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

View File

@@ -1,97 +0,0 @@
using UnityEngine;
namespace Obi
{
public class ComputeChainConstraintsBatch : ComputeConstraintsBatchImpl, IChainConstraintsBatchImpl
{
GraphicsBuffer firstIndex;
GraphicsBuffer numIndices;
GraphicsBuffer restLengths;
GraphicsBuffer ni;
GraphicsBuffer diagonals;
public ComputeChainConstraintsBatch(ComputeChainConstraints constraints)
{
m_Constraints = constraints;
m_ConstraintType = Oni.ConstraintType.Chain;
}
public void SetChainConstraints(ObiNativeIntList particleIndices, ObiNativeVector2List restLengths, ObiNativeIntList firstIndex, ObiNativeIntList numIndex, int count)
{
this.particleIndices = particleIndices.AsComputeBuffer<int>();
this.firstIndex = firstIndex.AsComputeBuffer<int>();
this.numIndices = numIndex.AsComputeBuffer<int>();
this.restLengths = restLengths.AsComputeBuffer<Vector2>();
int numEdges = 0;
for (int i = 0; i < numIndex.count; ++i)
numEdges += numIndex[i] - 1;
ni = new GraphicsBuffer(GraphicsBuffer.Target.Structured, numEdges, 16);
diagonals = new GraphicsBuffer(GraphicsBuffer.Target.Structured, numEdges, 12);
m_ConstraintCount = count;
}
public override void Destroy()
{
ni.Dispose();
diagonals.Dispose();
}
public override void Evaluate(float stepTime, float substepTime, int steps, float timeLeft)
{
if (m_ConstraintCount > 0)
{
var shader = ((ComputeChainConstraints)m_Constraints).constraintsShader;
int projectKernel = ((ComputeChainConstraints)m_Constraints).projectKernel;
shader.SetBuffer(projectKernel, "particleIndices", particleIndices);
shader.SetBuffer(projectKernel, "firstIndex", firstIndex);
shader.SetBuffer(projectKernel, "numIndices", numIndices);
shader.SetBuffer(projectKernel, "restLengths", restLengths);
shader.SetBuffer(projectKernel, "ni", ni);
shader.SetBuffer(projectKernel, "diagonals", diagonals);
shader.SetBuffer(projectKernel, "positions", solverImplementation.positionsBuffer);
shader.SetBuffer(projectKernel, "invMasses", solverImplementation.invMassesBuffer);
shader.SetBuffer(projectKernel, "deltasAsInt", solverImplementation.positionDeltasIntBuffer);
shader.SetBuffer(projectKernel, "positionConstraintCounts", solverImplementation.positionConstraintCountBuffer);
shader.SetInt("activeConstraintCount", m_ConstraintCount);
shader.SetFloat("deltaTime", substepTime);
int threadGroups = ComputeMath.ThreadGroupCount(m_ConstraintCount, 128);
shader.Dispatch(projectKernel, threadGroups, 1, 1);
}
}
public override void Apply(float substepTime)
{
if (m_ConstraintCount > 0)
{
var parameters = solverAbstraction.GetConstraintParameters(m_ConstraintType);
var shader = ((ComputeChainConstraints)m_Constraints).constraintsShader;
int applyKernel = ((ComputeChainConstraints)m_Constraints).applyKernel;
shader.SetBuffer(applyKernel, "particleIndices", particleIndices);
shader.SetBuffer(applyKernel, "firstIndex", firstIndex);
shader.SetBuffer(applyKernel, "numIndices", numIndices);
shader.SetBuffer(applyKernel, "positions", solverImplementation.positionsBuffer);
shader.SetBuffer(applyKernel, "deltasAsInt", solverImplementation.positionDeltasIntBuffer);
shader.SetBuffer(applyKernel, "positionConstraintCounts", solverImplementation.positionConstraintCountBuffer);
shader.SetInt("activeConstraintCount", m_ConstraintCount);
shader.SetFloat("sorFactor", parameters.SORFactor);
int threadGroups = ComputeMath.ThreadGroupCount(m_ConstraintCount, 128);
shader.Dispatch(applyKernel, threadGroups, 1, 1);
}
}
}
}

View File

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