修改水
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using System.IO;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
@@ -17,9 +16,7 @@ namespace Obi
|
||||
public delegate void BlueprintCallback(ObiActorBlueprint blueprint);
|
||||
public event BlueprintCallback OnBlueprintGenerate;
|
||||
|
||||
[HideInInspector] [SerializeField] protected uint m_Checksum;
|
||||
[HideInInspector] [SerializeField] protected bool m_Empty = true;
|
||||
[HideInInspector] [SerializeField] protected bool m_Edited = false; /**< Whether there's been any modifications to blueprint data since generating it. This is used to tell whether it can be re-generated without data loss.*/
|
||||
[HideInInspector] [SerializeField] protected int m_ActiveParticleCount = 0;
|
||||
[HideInInspector] [SerializeField] protected int m_InitialActiveParticleCount = 0;
|
||||
[HideInInspector] [SerializeField] protected Bounds _bounds = new Bounds();
|
||||
@@ -27,7 +24,6 @@ namespace Obi
|
||||
/**Particle components*/
|
||||
[HideInInspector] public Vector3[] positions = null; /**< Particle positions.*/
|
||||
[HideInInspector] public Vector4[] restPositions = null; /**< Particle rest positions, used to filter collisions.*/
|
||||
[HideInInspector] public Vector4[] restNormals = null; /**< Particle local-space normal in xyz, SDF in w. Used for softbody collisions.*/
|
||||
|
||||
[HideInInspector] public Quaternion[] orientations = null; /**< Particle orientations.*/
|
||||
[HideInInspector] public Quaternion[] restOrientations = null; /**< Particle rest orientations.*/
|
||||
@@ -39,7 +35,7 @@ namespace Obi
|
||||
[HideInInspector] public float[] invRotationalMasses = null;
|
||||
|
||||
[FormerlySerializedAs("phases")]
|
||||
[HideInInspector] public int[] filters = null; /**< Particle filters*/
|
||||
[HideInInspector] public int[] filters = null; /**< Particle filters*/
|
||||
[HideInInspector] public Vector3[] principalRadii = null; /**< Particle ellipsoid principal radii. These are the ellipsoid radius in each axis.*/
|
||||
[HideInInspector] public Color[] colors = null; /**< Particle colors (not used by all actors, can be null)*/
|
||||
|
||||
@@ -63,14 +59,6 @@ namespace Obi
|
||||
/** Particle groups.*/
|
||||
[HideInInspector] public List<ObiParticleGroup> groups = new List<ObiParticleGroup>();
|
||||
|
||||
/**
|
||||
* Checksum value generated from particle positions and orientations.
|
||||
*/
|
||||
public uint checksum
|
||||
{
|
||||
get { return m_Checksum; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of particles used by this blueprint.
|
||||
*/
|
||||
@@ -84,16 +72,6 @@ namespace Obi
|
||||
get { return m_ActiveParticleCount; }
|
||||
}
|
||||
|
||||
public Oni.SimplexType simplexTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
return Oni.SimplexType.Point | // points (single particles) are always available.
|
||||
(edges != null ? Oni.SimplexType.Edge : 0) |
|
||||
(triangles != null ? Oni.SimplexType.Triangle : 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this group uses oriented particles.
|
||||
*/
|
||||
@@ -102,11 +80,12 @@ namespace Obi
|
||||
get
|
||||
{
|
||||
return invRotationalMasses != null && invRotationalMasses.Length > 0 &&
|
||||
orientations != null && orientations.Length > 0;
|
||||
orientations != null && orientations.Length > 0 &&
|
||||
restOrientations != null && restOrientations.Length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool usesTethers
|
||||
public virtual bool usesTethers
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
@@ -120,7 +99,6 @@ namespace Obi
|
||||
{
|
||||
positions.Swap(index, m_ActiveParticleCount);
|
||||
restPositions.Swap(index, m_ActiveParticleCount);
|
||||
restNormals.Swap(index, m_ActiveParticleCount);
|
||||
orientations.Swap(index, m_ActiveParticleCount);
|
||||
restOrientations.Swap(index, m_ActiveParticleCount);
|
||||
velocities.Swap(index, m_ActiveParticleCount);
|
||||
@@ -130,14 +108,6 @@ namespace Obi
|
||||
filters.Swap(index, m_ActiveParticleCount);
|
||||
principalRadii.Swap(index, m_ActiveParticleCount);
|
||||
colors.Swap(index, m_ActiveParticleCount);
|
||||
|
||||
m_Edited = true;
|
||||
}
|
||||
|
||||
public bool edited
|
||||
{
|
||||
get { return m_Edited; }
|
||||
set { m_Edited = value; }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +148,7 @@ namespace Obi
|
||||
{
|
||||
if (positions.Length > 0)
|
||||
{
|
||||
_bounds = new Bounds(positions[0], Vector3.zero);
|
||||
_bounds = new Bounds(positions[0],Vector3.zero);
|
||||
for (int i = 1; i < positions.Length; ++i)
|
||||
_bounds.Encapsulate(positions[i]);
|
||||
}
|
||||
@@ -191,42 +161,27 @@ namespace Obi
|
||||
get { return _bounds; }
|
||||
}
|
||||
|
||||
protected void GenerateChecksum()
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
if (positions != null)
|
||||
foreach (var p in positions) ms.Concatenate(p);
|
||||
|
||||
if (orientations != null)
|
||||
foreach (var o in orientations) ms.Concatenate(o);
|
||||
|
||||
ms.Flush();
|
||||
m_Checksum = ObiUtils.Adler32(ms.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IObiConstraints> GetConstraints()
|
||||
{
|
||||
if (distanceConstraintsData != null && distanceConstraintsData.batchCount > 0)
|
||||
if (distanceConstraintsData != null && distanceConstraintsData.GetBatchCount() > 0)
|
||||
yield return distanceConstraintsData;
|
||||
if (bendConstraintsData != null && bendConstraintsData.batchCount > 0)
|
||||
if (bendConstraintsData != null && bendConstraintsData.GetBatchCount() > 0)
|
||||
yield return bendConstraintsData;
|
||||
if (skinConstraintsData != null && skinConstraintsData.batchCount > 0)
|
||||
if (skinConstraintsData != null && skinConstraintsData.GetBatchCount() > 0)
|
||||
yield return skinConstraintsData;
|
||||
if (tetherConstraintsData != null && tetherConstraintsData.batchCount > 0)
|
||||
if (tetherConstraintsData != null && tetherConstraintsData.GetBatchCount() > 0)
|
||||
yield return tetherConstraintsData;
|
||||
if (stretchShearConstraintsData != null && stretchShearConstraintsData.batchCount > 0)
|
||||
if (stretchShearConstraintsData != null && stretchShearConstraintsData.GetBatchCount() > 0)
|
||||
yield return stretchShearConstraintsData;
|
||||
if (bendTwistConstraintsData != null && bendTwistConstraintsData.batchCount > 0)
|
||||
if (bendTwistConstraintsData != null && bendTwistConstraintsData.GetBatchCount() > 0)
|
||||
yield return bendTwistConstraintsData;
|
||||
if (shapeMatchingConstraintsData != null && shapeMatchingConstraintsData.batchCount > 0)
|
||||
if (shapeMatchingConstraintsData != null && shapeMatchingConstraintsData.GetBatchCount() > 0)
|
||||
yield return shapeMatchingConstraintsData;
|
||||
if (aerodynamicConstraintsData != null && aerodynamicConstraintsData.batchCount > 0)
|
||||
if (aerodynamicConstraintsData != null && aerodynamicConstraintsData.GetBatchCount() > 0)
|
||||
yield return aerodynamicConstraintsData;
|
||||
if (chainConstraintsData != null && chainConstraintsData.batchCount > 0)
|
||||
if (chainConstraintsData != null && chainConstraintsData.GetBatchCount() > 0)
|
||||
yield return chainConstraintsData;
|
||||
if (volumeConstraintsData != null && volumeConstraintsData.batchCount > 0)
|
||||
if (volumeConstraintsData != null && volumeConstraintsData.GetBatchCount() > 0)
|
||||
yield return volumeConstraintsData;
|
||||
}
|
||||
|
||||
@@ -271,24 +226,6 @@ namespace Obi
|
||||
return Quaternion.identity;
|
||||
}
|
||||
|
||||
public Vector3 GetParticleRestPosition(int index)
|
||||
{
|
||||
if (restPositions != null && index < restPositions.Length)
|
||||
{
|
||||
return restPositions[index];
|
||||
}
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
public Quaternion GetParticleRestOrientation(int index)
|
||||
{
|
||||
if (restOrientations != null && index < restOrientations.Length)
|
||||
{
|
||||
return restOrientations[index];
|
||||
}
|
||||
return Quaternion.identity;
|
||||
}
|
||||
|
||||
public void GetParticleAnisotropy(int index, ref Vector4 b1, ref Vector4 b2, ref Vector4 b3)
|
||||
{
|
||||
if (orientations != null && index < orientations.Length)
|
||||
@@ -333,7 +270,7 @@ namespace Obi
|
||||
public void GenerateImmediate()
|
||||
{
|
||||
var g = Generate();
|
||||
while (g.MoveNext()) { }
|
||||
while (g.MoveNext()){}
|
||||
}
|
||||
|
||||
public IEnumerator Generate()
|
||||
@@ -351,37 +288,24 @@ namespace Obi
|
||||
m_InitialActiveParticleCount = m_ActiveParticleCount;
|
||||
|
||||
foreach (IObiConstraints constraints in GetConstraints())
|
||||
for (int i = 0; i < constraints.batchCount; ++i)
|
||||
for (int i = 0; i < constraints.GetBatchCount(); ++i)
|
||||
constraints.GetBatch(i).initialActiveConstraintCount = constraints.GetBatch(i).activeConstraintCount;
|
||||
|
||||
CommitBlueprintChanges();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
EditorUtility.SetDirty(this);
|
||||
#endif
|
||||
|
||||
OnBlueprintGenerate?.Invoke(this);
|
||||
}
|
||||
|
||||
// Called at the end of blueprint generation. Also automatically called when exiting blueprint editor.
|
||||
// This generates a checksum for the blueprint, and in some case extra data (such as default skinmaps for cloth and softbodies).
|
||||
public virtual void CommitBlueprintChanges()
|
||||
{
|
||||
GenerateChecksum();
|
||||
if (OnBlueprintGenerate != null)
|
||||
OnBlueprintGenerate(this);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
m_Empty = true;
|
||||
edited = false;
|
||||
|
||||
m_ActiveParticleCount = 0;
|
||||
positions = null;
|
||||
restPositions = null;
|
||||
restNormals = null;
|
||||
orientations = null;
|
||||
restOrientations = null;
|
||||
velocities = null;
|
||||
@@ -389,6 +313,7 @@ namespace Obi
|
||||
invMasses = null;
|
||||
invRotationalMasses = null;
|
||||
filters = null;
|
||||
//phases = null;
|
||||
principalRadii = null;
|
||||
colors = null;
|
||||
|
||||
@@ -430,7 +355,7 @@ namespace Obi
|
||||
{
|
||||
EditorUtility.SetDirty(this);
|
||||
if (saveImmediately)
|
||||
AssetDatabase.SaveAssetIfDirty(this);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -439,8 +364,6 @@ namespace Obi
|
||||
groups.Insert(index, group);
|
||||
}
|
||||
|
||||
edited = true;
|
||||
|
||||
return group;
|
||||
}
|
||||
return null;
|
||||
@@ -470,7 +393,7 @@ namespace Obi
|
||||
{
|
||||
EditorUtility.SetDirty(this);
|
||||
if (saveImmediately)
|
||||
AssetDatabase.SaveAssetIfDirty(this);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -483,8 +406,6 @@ namespace Obi
|
||||
DestroyImmediate(group, true);
|
||||
}
|
||||
|
||||
edited = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -504,7 +425,7 @@ namespace Obi
|
||||
{
|
||||
EditorUtility.SetDirty(this);
|
||||
if (saveImmediately)
|
||||
AssetDatabase.SaveAssetIfDirty(this);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -513,39 +434,26 @@ namespace Obi
|
||||
groups[index].name = name;
|
||||
}
|
||||
|
||||
edited = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ClearParticleGroups(bool registerUndo = true, bool saveImmediately = true)
|
||||
public void ClearParticleGroups(bool saveImmediately = true)
|
||||
{
|
||||
if (groups.Count == 0) return;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
if (registerUndo)
|
||||
{
|
||||
Undo.RecordObject(this, "Clear particle groups");
|
||||
for (int i = 0; i < groups.Count; ++i)
|
||||
if (groups[i] != null)
|
||||
Undo.DestroyObjectImmediate(groups[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < groups.Count; ++i)
|
||||
if (groups[i] != null)
|
||||
DestroyImmediate(groups[i], true);
|
||||
}
|
||||
Undo.RecordObject(this, "Clear particle groups");
|
||||
for (int i = 0; i < groups.Count; ++i)
|
||||
if (groups[i] != null)
|
||||
Undo.DestroyObjectImmediate(groups[i]);
|
||||
|
||||
if (EditorUtility.IsPersistent(this))
|
||||
{
|
||||
EditorUtility.SetDirty(this);
|
||||
if (saveImmediately)
|
||||
AssetDatabase.SaveAssetIfDirty(this);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -580,7 +488,7 @@ namespace Obi
|
||||
private bool DoesParticleShareConstraints(IObiConstraints constraints, int index, List<int> particles, bool[] selected)
|
||||
{
|
||||
bool shared = false;
|
||||
for (int i = 0; i < constraints.batchCount; ++i)
|
||||
for (int i = 0; i < constraints.GetBatchCount(); ++i)
|
||||
{
|
||||
var batch = constraints.GetBatch(i);
|
||||
for (int j = 0; j < batch.activeConstraintCount; ++j)
|
||||
@@ -600,7 +508,7 @@ namespace Obi
|
||||
|
||||
private void DeactivateConstraintsWithInactiveParticles(IObiConstraints constraints, List<int> particles)
|
||||
{
|
||||
for (int j = 0; j < constraints.batchCount; ++j)
|
||||
for (int j = 0; j < constraints.GetBatchCount(); ++j)
|
||||
{
|
||||
var batch = constraints.GetBatch(j);
|
||||
|
||||
@@ -618,8 +526,6 @@ namespace Obi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
edited = true;
|
||||
}
|
||||
|
||||
private void ParticlesSwappedInGroups(int index, int newIndex)
|
||||
@@ -635,11 +541,9 @@ namespace Obi
|
||||
group.particleIndices[i] = newIndex;
|
||||
}
|
||||
}
|
||||
|
||||
edited = true;
|
||||
}
|
||||
|
||||
public virtual void RemoveSelectedParticles(ref bool[] selected, bool optimize = true)
|
||||
public void RemoveSelectedParticles(ref bool[] selected, bool optimize = true)
|
||||
{
|
||||
List<int> particles = new List<int>();
|
||||
|
||||
@@ -667,7 +571,7 @@ namespace Obi
|
||||
|
||||
// Update constraints:
|
||||
foreach (IObiConstraints constraints in GetConstraints())
|
||||
for (int j = 0; j < constraints.batchCount; ++j)
|
||||
for (int j = 0; j < constraints.GetBatchCount(); ++j)
|
||||
constraints.GetBatch(j).ParticlesSwapped(i, m_ActiveParticleCount);
|
||||
|
||||
// Update groups:
|
||||
@@ -681,9 +585,6 @@ namespace Obi
|
||||
foreach (IObiConstraints constraints in GetConstraints())
|
||||
DeactivateConstraintsWithInactiveParticles(constraints, particles);
|
||||
|
||||
CommitBlueprintChanges();
|
||||
|
||||
edited = true;
|
||||
}
|
||||
|
||||
public void RestoreRemovedParticles()
|
||||
@@ -691,10 +592,9 @@ namespace Obi
|
||||
m_ActiveParticleCount = m_InitialActiveParticleCount;
|
||||
|
||||
foreach (IObiConstraints constraints in GetConstraints())
|
||||
for (int j = 0; j < constraints.batchCount; ++j)
|
||||
for (int j = 0; j < constraints.GetBatchCount(); ++j)
|
||||
constraints.GetBatch(j).activeConstraintCount = constraints.GetBatch(j).initialActiveConstraintCount;
|
||||
|
||||
CommitBlueprintChanges();
|
||||
|
||||
}
|
||||
|
||||
public virtual void GenerateTethers(bool[] selected) { }
|
||||
|
||||
Reference in New Issue
Block a user