修改水

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,61 +0,0 @@
using System;
using UnityEngine;
namespace Obi
{
public class ComputePinConstraints : ComputeConstraintsImpl<ComputePinConstraintsBatch>
{
public ComputeShader constraintsShader;
public int clearKernel;
public int initializeKernel;
public int projectKernel;
public int applyKernel;
public int projectRenderableKernel;
public ComputePinConstraints(ComputeSolverImpl solver) : base(solver, Oni.ConstraintType.Pin)
{
constraintsShader = GameObject.Instantiate(Resources.Load<ComputeShader>("Compute/PinConstraints"));
clearKernel = constraintsShader.FindKernel("Clear");
initializeKernel = constraintsShader.FindKernel("Initialize");
projectKernel = constraintsShader.FindKernel("Project");
applyKernel = constraintsShader.FindKernel("Apply");
projectRenderableKernel = constraintsShader.FindKernel("ProjectRenderable");
}
public override IConstraintsBatchImpl CreateConstraintsBatch()
{
var dataBatch = new ComputePinConstraintsBatch(this);
batches.Add(dataBatch);
return dataBatch;
}
public override void RemoveBatch(IConstraintsBatchImpl batch)
{
batches.Remove(batch as ComputePinConstraintsBatch);
batch.Destroy();
}
public void RequestDataReadback()
{
foreach (var batch in batches)
batch.RequestDataReadback();
}
public void WaitForReadback()
{
foreach (var batch in batches)
batch.WaitForReadback();
}
public void ProjectRenderablePositions()
{
for (int i = 0; i < batches.Count; ++i)
{
if (batches[i].enabled)
{
batches[i].ProjectRenderablePositions();
}
}
}
}
}

View File

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

View File

@@ -1,167 +0,0 @@
using UnityEngine;
namespace Obi
{
public class ComputePinConstraintsBatch : ComputeConstraintsBatchImpl, IPinConstraintsBatchImpl
{
GraphicsBuffer colliderIndices;
GraphicsBuffer offsets;
GraphicsBuffer restDarboux;
GraphicsBuffer stiffnesses;
public ComputePinConstraintsBatch(ComputePinConstraints constraints)
{
m_Constraints = constraints;
m_ConstraintType = Oni.ConstraintType.Pin;
}
public void SetPinConstraints(ObiNativeIntList particleIndices, ObiNativeIntList colliderIndices, ObiNativeVector4List offsets, ObiNativeQuaternionList restDarbouxVectors, ObiNativeFloatList stiffnesses, ObiNativeFloatList lambdas, int count)
{
this.particleIndices = particleIndices.AsComputeBuffer<int>();
this.colliderIndices = colliderIndices.AsComputeBuffer<int>();
this.offsets = offsets.AsComputeBuffer<Vector4>();
this.restDarboux = restDarbouxVectors.AsComputeBuffer<Quaternion>();
this.stiffnesses = stiffnesses.AsComputeBuffer<Vector2>();
this.lambdas = lambdas.AsComputeBuffer<Vector4>();
this.lambdasList = lambdas;
m_ConstraintCount = count;
}
public override void Initialize(float stepTime, float substepTime, int steps, float timeLeft)
{
if (m_ConstraintCount > 0)
{
var shader = ((ComputePinConstraints)m_Constraints).constraintsShader;
int clearKernel = ((ComputePinConstraints)m_Constraints).clearKernel;
int initializeKernel = ((ComputePinConstraints)m_Constraints).initializeKernel;
shader.SetBuffer(clearKernel, "colliderIndices", colliderIndices);
shader.SetBuffer(clearKernel, "shapes", this.solverImplementation.colliderGrid.shapesBuffer);
shader.SetBuffer(clearKernel, "RW_rigidbodies", this.solverImplementation.colliderGrid.rigidbodiesBuffer);
shader.SetBuffer(initializeKernel, "colliderIndices", colliderIndices);
shader.SetBuffer(initializeKernel, "shapes", this.solverImplementation.colliderGrid.shapesBuffer);
shader.SetBuffer(initializeKernel, "RW_rigidbodies", this.solverImplementation.colliderGrid.rigidbodiesBuffer);
shader.SetInt("activeConstraintCount", m_ConstraintCount);
int threadGroups = ComputeMath.ThreadGroupCount(m_ConstraintCount, 128);
shader.Dispatch(clearKernel, threadGroups, 1, 1);
shader.Dispatch(initializeKernel, threadGroups, 1, 1);
}
// clear lambdas:
base.Initialize(stepTime, substepTime, steps, timeLeft);
}
public override void Evaluate(float stepTime, float substepTime, int steps, float timeLeft)
{
if (m_ConstraintCount > 0)
{
var shader = ((ComputePinConstraints)m_Constraints).constraintsShader;
int projectKernel = ((ComputePinConstraints)m_Constraints).projectKernel;
shader.SetBuffer(projectKernel, "particleIndices", particleIndices);
shader.SetBuffer(projectKernel, "colliderIndices", colliderIndices);
shader.SetBuffer(projectKernel, "offsets", offsets);
shader.SetBuffer(projectKernel, "restDarboux", restDarboux);
shader.SetBuffer(projectKernel, "stiffnesses", stiffnesses);
shader.SetBuffer(projectKernel, "lambdas", lambdas);
shader.SetBuffer(projectKernel, "transforms", this.solverImplementation.colliderGrid.transformsBuffer);
shader.SetBuffer(projectKernel, "shapes", this.solverImplementation.colliderGrid.shapesBuffer);
shader.SetBuffer(projectKernel, "rigidbodies", this.solverImplementation.colliderGrid.rigidbodiesBuffer);
shader.SetBuffer(projectKernel, "positions", solverImplementation.positionsBuffer);
shader.SetBuffer(projectKernel, "prevPositions", solverImplementation.prevPositionsBuffer);
shader.SetBuffer(projectKernel, "orientations", solverImplementation.orientationsBuffer);
shader.SetBuffer(projectKernel, "invMasses", solverImplementation.invMassesBuffer);
shader.SetBuffer(projectKernel, "invRotationalMasses", solverImplementation.invRotationalMassesBuffer);
shader.SetBuffer(projectKernel, "deltasAsInt", solverImplementation.positionDeltasIntBuffer);
shader.SetBuffer(projectKernel, "positionConstraintCounts", solverImplementation.positionConstraintCountBuffer);
shader.SetBuffer(projectKernel, "orientationDeltasAsInt", solverImplementation.orientationDeltasIntBuffer);
shader.SetBuffer(projectKernel, "orientationConstraintCounts", solverImplementation.orientationConstraintCountBuffer);
shader.SetBuffer(projectKernel, "linearDeltasAsInt", solverImplementation.rigidbodyLinearDeltasIntBuffer);
shader.SetBuffer(projectKernel, "angularDeltasAsInt", solverImplementation.rigidbodyAngularDeltasIntBuffer);
shader.SetBuffer(projectKernel, "inertialSolverFrame", solverImplementation.inertialFrameBuffer);
shader.SetInt("activeConstraintCount", m_ConstraintCount);
shader.SetFloat("stepTime", stepTime);
shader.SetFloat("substepTime", substepTime);
shader.SetInt("steps", steps);
shader.SetFloat("timeLeft", timeLeft);
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 = ((ComputePinConstraints)m_Constraints).constraintsShader;
int applyKernel = ((ComputePinConstraints)m_Constraints).applyKernel;
shader.SetBuffer(applyKernel, "particleIndices", particleIndices);
shader.SetBuffer(applyKernel, "RW_positions", solverImplementation.positionsBuffer);
shader.SetBuffer(applyKernel, "deltasAsInt", solverImplementation.positionDeltasIntBuffer);
shader.SetBuffer(applyKernel, "positionConstraintCounts", solverImplementation.positionConstraintCountBuffer);
shader.SetBuffer(applyKernel, "RW_orientations", solverImplementation.orientationsBuffer);
shader.SetBuffer(applyKernel, "orientationDeltasAsInt", solverImplementation.orientationDeltasIntBuffer);
shader.SetBuffer(applyKernel, "orientationConstraintCounts", solverImplementation.orientationConstraintCountBuffer);
shader.SetInt("activeConstraintCount", m_ConstraintCount);
shader.SetFloat("sorFactor", parameters.SORFactor);
int threadGroups = ComputeMath.ThreadGroupCount(m_ConstraintCount, 128);
shader.Dispatch(applyKernel, threadGroups, 1, 1);
}
}
public void ProjectRenderablePositions()
{
if (m_ConstraintCount > 0)
{
var shader = ((ComputePinConstraints)m_Constraints).constraintsShader;
int projectRenderableKernel = ((ComputePinConstraints)m_Constraints).projectRenderableKernel;
shader.SetBuffer(projectRenderableKernel, "particleIndices", particleIndices);
shader.SetBuffer(projectRenderableKernel, "colliderIndices", colliderIndices);
shader.SetBuffer(projectRenderableKernel, "offsets", offsets);
shader.SetBuffer(projectRenderableKernel, "restDarboux", restDarboux);
shader.SetBuffer(projectRenderableKernel, "stiffnesses", stiffnesses);
shader.SetBuffer(projectRenderableKernel, "transforms", this.solverImplementation.colliderGrid.transformsBuffer);
shader.SetBuffer(projectRenderableKernel, "RW_positions", solverImplementation.renderablePositionsBuffer);
shader.SetBuffer(projectRenderableKernel, "RW_orientations", solverImplementation.renderableOrientationsBuffer);
shader.SetBuffer(projectRenderableKernel, "inertialSolverFrame", solverImplementation.inertialFrameBuffer);
shader.SetInt("activeConstraintCount", m_ConstraintCount);
int threadGroups = ComputeMath.ThreadGroupCount(m_ConstraintCount, 128);
shader.Dispatch(projectRenderableKernel, threadGroups, 1, 1);
}
}
public void RequestDataReadback()
{
lambdasList.Readback();
}
public void WaitForReadback()
{
lambdasList.WaitForReadback();
}
}
}

View File

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