Skip to content

Commit 84bc55d

Browse files
committed
extra data
added an option for particles to store extra data
1 parent f00f070 commit 84bc55d

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

Assets/Scenes/pond_testing.unity

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2620,7 +2620,7 @@ BoxCollider:
26202620
m_GameObject: {fileID: 1599316680}
26212621
m_Material: {fileID: 0}
26222622
m_IsTrigger: 0
2623-
m_Enabled: 0
2623+
m_Enabled: 1
26242624
serializedVersion: 2
26252625
m_Size: {x: 1, y: 1, z: 1}
26262626
m_Center: {x: 0, y: 0, z: 0}
@@ -7988,6 +7988,7 @@ MonoBehaviour:
79887988
rgba: 4292915235
79897989
debug: 0
79907990
Burst: 0
7991+
ExtraData: 0
79917992
--- !u!1 &1952657746
79927993
GameObject:
79937994
m_ObjectHideFlags: 0

Assets/Scripts/FlexStuff/FlexContainer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class FlexContainer : MonoBehaviour
1919
public int MaxDiffuseParticles = 0;
2020
[System.NonSerialized]
2121
public Color32[] ParticleColours;
22+
[System.NonSerialized]
23+
public int[] ExtraData;
2224
public float RParticleRadius = 0.15f;
2325
public int Substeps = 1;
2426

@@ -87,7 +89,7 @@ public class FlexContainer : MonoBehaviour
8789
public int CurrentSlot;
8890

8991
//bool ShapesChanged = true;
90-
FlexCollider[] Shapes;
92+
//FlexCollider[] Shapes;
9193

9294
bool FirstTime = true;
9395

@@ -303,6 +305,7 @@ public int AddShape()
303305
// Start is called before the first frame update
304306
void Start()
305307
{
308+
ExtraData = new int[MaxParticles];
306309
unsafe
307310
{
308311
Library = Methods.NvFlexInit();

Assets/Scripts/FlexStuff/FlexEmitter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
using System.Collections.Generic;
33
using UnityEngine;
44
using FlexSharp;
5+
using FlexSharpExt;
56
using Unity.Burst;
7+
using Methods = FlexSharp.Methods;
8+
using ExtMethods = FlexSharpExt.Methods;
69

710
public class FlexEmitter : MonoBehaviour
811
{
@@ -19,6 +22,8 @@ public class FlexEmitter : MonoBehaviour
1922
public Color32[] Colours;
2023
public bool debug = false;
2124
public bool Burst;
25+
public ExtDat ExtraData;
26+
//public ExtDatApplyType WayToApplyExtraData;
2227

2328
float SecondsUntilNext = 0;
2429

@@ -74,6 +79,7 @@ void EmitParticles()
7479
Container.PBuf.Velocities.data[Container.CurrentSlot] = new Vector3(VelocityX, VelocityY, VelocityZ);
7580
Container.PBuf.Phases.data[Container.CurrentSlot] = Methods.NvFlexMakePhaseWithChannels(0, (int)NvFlexPhase.eNvFlexPhaseSelfCollide | (int)NvFlexPhase.eNvFlexPhaseFluid, (int)NvFlexPhase.eNvFlexPhaseShapeChannel0);
7681
Container.ParticleColours[Container.CurrentSlot] = Colours[Random.Range(0,Colours.Length)];
82+
Container.ExtraData[Container.CurrentSlot] = (int)ExtraData;
7783

7884
Container.SlotsUsed++;
7985
Mathf.Clamp(Container.SlotsUsed, 0, Container.MaxParticles);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace FlexSharpExt
2+
{
3+
[System.Flags]
4+
public enum ExtDat
5+
{
6+
None = 0,
7+
Fun1 = 1,
8+
Fun2 = 2,
9+
Fun3 = 4
10+
}
11+
12+
public enum ExtDatApplyType
13+
{
14+
Set,
15+
Unset,
16+
Toggle,
17+
Replace,
18+
Nothing
19+
}
20+
}

Assets/Scripts/FlexStuff/FlexSharpExt/ExtraDataEnum.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/FlexStuff/FlexSharpExt/Methods.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ namespace FlexSharpExt
55
{
66
public static unsafe partial class Methods
77
{
8+
public static bool HasFlag(ExtDat a, ExtDat b)
9+
{
10+
return (a & b) == b;
11+
}
12+
813
[DllImport("NvFlexExtReleaseD3D_x64.dll", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
914
public static extern void NvFlexExtMovingFrameInit(NvFlexExtMovingFrame* frame, [NativeTypeName("const float *")] float* worldTranslation, [NativeTypeName("const float *")] float* worldRotation);
1015

0 commit comments

Comments
 (0)