添加插件
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ComputeAerodynamicConstraints : ComputeConstraintsImpl<ComputeAerodynamicConstraintsBatch>
|
||||
{
|
||||
public ComputeShader constraintsShader;
|
||||
public int projectKernel;
|
||||
|
||||
public ComputeAerodynamicConstraints(ComputeSolverImpl solver) : base(solver, Oni.ConstraintType.Aerodynamics)
|
||||
{
|
||||
constraintsShader = GameObject.Instantiate(Resources.Load<ComputeShader>("Compute/AerodynamicConstraints"));
|
||||
projectKernel = constraintsShader.FindKernel("Project");
|
||||
}
|
||||
|
||||
public override IConstraintsBatchImpl CreateConstraintsBatch()
|
||||
{
|
||||
var dataBatch = new ComputeAerodynamicConstraintsBatch(this);
|
||||
batches.Add(dataBatch);
|
||||
return dataBatch;
|
||||
}
|
||||
|
||||
public override void RemoveBatch(IConstraintsBatchImpl batch)
|
||||
{
|
||||
batches.Remove(batch as ComputeAerodynamicConstraintsBatch);
|
||||
batch.Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5bb44136361b4a2d948bf85825e53b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obi
|
||||
{
|
||||
public class ComputeAerodynamicConstraintsBatch : ComputeConstraintsBatchImpl, IAerodynamicConstraintsBatchImpl
|
||||
{
|
||||
GraphicsBuffer aerodynamicCoeffs;
|
||||
|
||||
public ComputeAerodynamicConstraintsBatch(ComputeAerodynamicConstraints constraints)
|
||||
{
|
||||
m_Constraints = constraints;
|
||||
m_ConstraintType = Oni.ConstraintType.Aerodynamics;
|
||||
}
|
||||
|
||||
public void SetAerodynamicConstraints(ObiNativeIntList particleIndices, ObiNativeFloatList aerodynamicCoeffs, int count)
|
||||
{
|
||||
this.particleIndices = particleIndices.AsComputeBuffer<int>();
|
||||
this.aerodynamicCoeffs = aerodynamicCoeffs.AsComputeBuffer<float>();
|
||||
|
||||
m_ConstraintCount = count;
|
||||
}
|
||||
|
||||
public override void Evaluate(float stepTime, float substepTime, int steps, float timeLeft)
|
||||
{
|
||||
if (m_ConstraintCount > 0)
|
||||
{
|
||||
var shader = ((ComputeAerodynamicConstraints)m_Constraints).constraintsShader;
|
||||
int projectKernel = ((ComputeAerodynamicConstraints)m_Constraints).projectKernel;
|
||||
|
||||
shader.SetBuffer(projectKernel, "particleIndices", particleIndices);
|
||||
shader.SetBuffer(projectKernel, "aerodynamicCoeffs", aerodynamicCoeffs);
|
||||
|
||||
shader.SetBuffer(projectKernel, "positions", solverImplementation.positionsBuffer);
|
||||
shader.SetBuffer(projectKernel, "normals", solverImplementation.normalsBuffer);
|
||||
shader.SetBuffer(projectKernel, "wind", solverImplementation.windBuffer);
|
||||
shader.SetBuffer(projectKernel, "invMasses", solverImplementation.invMassesBuffer);
|
||||
shader.SetBuffer(projectKernel, "velocities", solverImplementation.velocitiesBuffer);
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84f8c85144ba84d59bdf603d907ae5fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user