修改水
This commit is contained in:
@@ -20,8 +20,6 @@ namespace Obi
|
||||
[HideInInspector] public List<int> parentIndices = new List<int>();
|
||||
[HideInInspector] public List<float> normalizedLengths = new List<float>();
|
||||
|
||||
[HideInInspector] public int[] deformableEdges = null; /**< Indices of deformable edges (2 per edge)*/
|
||||
|
||||
[HideInInspector] [NonSerialized] public List<ObiBone.IgnoredBone> ignored;
|
||||
[HideInInspector] [NonSerialized] public ObiBone.BonePropertyCurve mass;
|
||||
[HideInInspector] [NonSerialized] public ObiBone.BonePropertyCurve rotationalMass;
|
||||
@@ -40,24 +38,6 @@ namespace Obi
|
||||
return null;
|
||||
}
|
||||
|
||||
public ObiBoneOverride GetOverride(int particleIndex, out float normalizedLength)
|
||||
{
|
||||
int overrideIndex = particleIndex;
|
||||
normalizedLength = normalizedLengths[overrideIndex];
|
||||
|
||||
while (overrideIndex >= 0)
|
||||
{
|
||||
if (transforms[overrideIndex].TryGetComponent(out ObiBoneOverride over))
|
||||
{
|
||||
normalizedLength = 1 - (1 - normalizedLengths[particleIndex]) / Mathf.Max(ObiUtils.epsilon,1 - normalizedLengths[overrideIndex]);
|
||||
return over;
|
||||
}
|
||||
|
||||
overrideIndex = parentIndices[overrideIndex];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override IEnumerator Initialize()
|
||||
{
|
||||
ClearParticleGroups();
|
||||
@@ -184,21 +164,12 @@ namespace Obi
|
||||
filters[i] = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
|
||||
colors[i] = Color.white;
|
||||
|
||||
var group = ScriptableObject.CreateInstance<ObiParticleGroup>();
|
||||
group.SetSourceBlueprint(this);
|
||||
group.name = transforms[i].name;
|
||||
group.particleIndices.Add(i);
|
||||
groups.Add(group);
|
||||
|
||||
if (i % 100 == 0)
|
||||
yield return new CoroutineJob.ProgressInfo("ObiRod: generating particles...", i / (float)m_ActiveParticleCount);
|
||||
}
|
||||
|
||||
colorizer = new GraphColoring(m_ActiveParticleCount);
|
||||
|
||||
// Deformable edges:
|
||||
CreateDeformableEdges();
|
||||
|
||||
// Create edge simplices:
|
||||
CreateSimplices();
|
||||
|
||||
@@ -214,23 +185,9 @@ namespace Obi
|
||||
IEnumerator sc = CreateSkinConstraints(particlePositions);
|
||||
while (sc.MoveNext()) yield return sc.Current;
|
||||
|
||||
// Create aerodynamic constraints:
|
||||
IEnumerator ac = CreateAerodynamicConstraints();
|
||||
while (ac.MoveNext()) yield return ac.Current;
|
||||
|
||||
yield return new CoroutineJob.ProgressInfo("ObiBone: complete", 1);
|
||||
}
|
||||
|
||||
protected void CreateDeformableEdges()
|
||||
{
|
||||
deformableEdges = new int[(parentIndices.Count - 1) * 2];
|
||||
for (int i = 0; i < parentIndices.Count - 1; ++i)
|
||||
{
|
||||
deformableEdges[i * 2] = i + 1;
|
||||
deformableEdges[i * 2 + 1] = parentIndices[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
protected void CreateSimplices()
|
||||
{
|
||||
edges = new int[(parentIndices.Count - 1) * 2];
|
||||
@@ -241,29 +198,9 @@ namespace Obi
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual IEnumerator CreateAerodynamicConstraints()
|
||||
{
|
||||
aerodynamicConstraintsData = new ObiAerodynamicConstraintsData();
|
||||
var aeroBatch = new ObiAerodynamicConstraintsBatch();
|
||||
aerodynamicConstraintsData.AddBatch(aeroBatch);
|
||||
|
||||
for (int i = 0; i < m_ActiveParticleCount; i++)
|
||||
{
|
||||
aeroBatch.AddConstraint(i, 2 * principalRadii[i].x, 1, 1);
|
||||
|
||||
if (i % 500 == 0)
|
||||
yield return new CoroutineJob.ProgressInfo("ObiRope generating aerodynamic constraints...", i / (float)m_ActiveParticleCount);
|
||||
}
|
||||
|
||||
// Set initial amount of active constraints:
|
||||
for (int i = 0; i < aerodynamicConstraintsData.batches.Count; ++i)
|
||||
{
|
||||
aerodynamicConstraintsData.batches[i].activeConstraintCount = m_ActiveParticleCount;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual IEnumerator CreateStretchShearConstraints(List<Vector3> particlePositions)
|
||||
{
|
||||
|
||||
colorizer.Clear();
|
||||
|
||||
for (int i = 1; i < particlePositions.Count; ++i)
|
||||
@@ -291,7 +228,7 @@ namespace Obi
|
||||
int cIndex = constraintIndices[i];
|
||||
|
||||
// Add a new batch if needed:
|
||||
if (color >= stretchShearConstraintsData.batchCount)
|
||||
if (color >= stretchShearConstraintsData.GetBatchCount())
|
||||
stretchShearConstraintsData.AddBatch(new ObiStretchShearConstraintsBatch());
|
||||
|
||||
int index1 = particleIndices[cIndex];
|
||||
@@ -337,7 +274,7 @@ namespace Obi
|
||||
int cIndex = constraintIndices[i];
|
||||
|
||||
// Add a new batch if needed:
|
||||
if (color >= bendTwistConstraintsData.batchCount)
|
||||
if (color >= bendTwistConstraintsData.GetBatchCount())
|
||||
bendTwistConstraintsData.AddBatch(new ObiBendTwistConstraintsBatch());
|
||||
|
||||
int index1 = particleIndices[cIndex];
|
||||
|
||||
@@ -127,9 +127,6 @@ namespace Obi
|
||||
yield return new CoroutineJob.ProgressInfo("ObiRod: generating particles...", i / (float)m_ActiveParticleCount);
|
||||
}
|
||||
|
||||
// Deformable edges:
|
||||
CreateDeformableEdges(numSegments);
|
||||
|
||||
// Create edge simplices:
|
||||
CreateSimplices(numSegments);
|
||||
|
||||
@@ -145,12 +142,6 @@ namespace Obi
|
||||
while (bc.MoveNext())
|
||||
yield return bc.Current;
|
||||
|
||||
// Create aerodynamic constraints:
|
||||
IEnumerator ac = CreateAerodynamicConstraints();
|
||||
|
||||
while (ac.MoveNext())
|
||||
yield return ac.Current;
|
||||
|
||||
// Create chain constraints:
|
||||
IEnumerator cc = CreateChainConstraints();
|
||||
|
||||
@@ -159,6 +150,7 @@ namespace Obi
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected virtual IEnumerator CreateStretchShearConstraints(List<Vector3> particleNormals)
|
||||
{
|
||||
stretchShearConstraintsData = new ObiStretchShearConstraintsData();
|
||||
@@ -167,7 +159,8 @@ namespace Obi
|
||||
stretchShearConstraintsData.AddBatch(new ObiStretchShearConstraintsBatch());
|
||||
|
||||
// rotation minimizing frame:
|
||||
ObiPathFrame frame = ObiPathFrame.Identity;
|
||||
ObiPathFrame frame = new ObiPathFrame();
|
||||
frame.Reset();
|
||||
|
||||
for (int i = 0; i < totalParticles - 1; i++)
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Obi
|
||||
[CreateAssetMenu(fileName = "rope blueprint", menuName = "Obi/Rope Blueprint", order = 140)]
|
||||
public class ObiRopeBlueprint : ObiRopeBlueprintBase
|
||||
{
|
||||
|
||||
public int pooledParticles = 100;
|
||||
|
||||
public const float DEFAULT_PARTICLE_MASS = 0.1f;
|
||||
@@ -112,9 +113,6 @@ namespace Obi
|
||||
yield return new CoroutineJob.ProgressInfo("ObiRope: generating particles...", i / (float)m_ActiveParticleCount);
|
||||
}
|
||||
|
||||
// Deformable edges:
|
||||
CreateDeformableEdges(numSegments);
|
||||
|
||||
// Create edge simplices:
|
||||
CreateSimplices(numSegments);
|
||||
|
||||
@@ -130,12 +128,6 @@ namespace Obi
|
||||
while (bc.MoveNext())
|
||||
yield return bc.Current;
|
||||
|
||||
// Create aerodynamic constraints:
|
||||
IEnumerator ac = CreateAerodynamicConstraints();
|
||||
|
||||
while (ac.MoveNext())
|
||||
yield return ac.Current;
|
||||
|
||||
// Recalculate rest length:
|
||||
m_RestLength = 0;
|
||||
foreach (float length in restLengths)
|
||||
@@ -201,7 +193,7 @@ namespace Obi
|
||||
var batch = bendConstraintsData.batches[i % 3] as ObiBendConstraintsBatch;
|
||||
|
||||
Vector3Int indices = new Vector3Int(i, i + 2, i + 1);
|
||||
float restBend = 0;//ObiUtils.RestBendingConstraint(restPositions[indices[0]], restPositions[indices[1]], restPositions[indices[2]]);
|
||||
float restBend = ObiUtils.RestBendingConstraint(restPositions[indices[0]], restPositions[indices[1]], restPositions[indices[2]]);
|
||||
batch.AddConstraint(indices, restBend);
|
||||
|
||||
if (i < m_ActiveParticleCount - 2)
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace Obi
|
||||
[HideInInspector] [SerializeField] protected int totalParticles;
|
||||
[HideInInspector] [SerializeField] protected float m_RestLength;
|
||||
|
||||
[HideInInspector] public int[] deformableEdges = null; /**< Indices of deformable edges (2 per edge)*/
|
||||
[HideInInspector] public float[] restLengths;
|
||||
|
||||
public float interParticleDistance
|
||||
@@ -63,44 +62,13 @@ namespace Obi
|
||||
RemoveParticleGroupAt(index);
|
||||
}
|
||||
|
||||
protected virtual IEnumerator CreateAerodynamicConstraints()
|
||||
{
|
||||
aerodynamicConstraintsData = new ObiAerodynamicConstraintsData();
|
||||
var aeroBatch = new ObiAerodynamicConstraintsBatch();
|
||||
aerodynamicConstraintsData.AddBatch(aeroBatch);
|
||||
|
||||
for (int i = 0; i < totalParticles; i++)
|
||||
{
|
||||
aeroBatch.AddConstraint(i, 2 * principalRadii[i].x, 1, 1);
|
||||
|
||||
if (i % 500 == 0)
|
||||
yield return new CoroutineJob.ProgressInfo("ObiRope generating aerodynamic constraints...", i / (float)totalParticles);
|
||||
}
|
||||
|
||||
// Set initial amount of active constraints:
|
||||
for (int i = 0; i < aerodynamicConstraintsData.batches.Count; ++i)
|
||||
{
|
||||
aerodynamicConstraintsData.batches[i].activeConstraintCount = m_ActiveParticleCount;
|
||||
}
|
||||
}
|
||||
|
||||
protected void CreateDeformableEdges(int numSegments)
|
||||
{
|
||||
deformableEdges = new int[numSegments * 2];
|
||||
for (int i = 0; i < numSegments; ++i)
|
||||
{
|
||||
deformableEdges[i * 2] = i % activeParticleCount;
|
||||
deformableEdges[i * 2 + 1] = (i + 1) % activeParticleCount;
|
||||
}
|
||||
}
|
||||
|
||||
protected void CreateSimplices(int numSegments)
|
||||
{
|
||||
edges = new int[numSegments * 2];
|
||||
for (int i = 0; i < numSegments; ++i)
|
||||
{
|
||||
edges[i * 2] = i % activeParticleCount;
|
||||
edges[i * 2 + 1] = (i + 1) % activeParticleCount;
|
||||
edges[i * 2] = i % totalParticles;
|
||||
edges[i * 2 + 1] = (i + 1) % totalParticles;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user