Skip to content

Commit 3926edb

Browse files
committed
TRIANGLES
triangle meshes work now!!!!!!!!!! Very slow though, shall fix soon!
1 parent ff39666 commit 3926edb

File tree

2 files changed

+78
-24
lines changed

2 files changed

+78
-24
lines changed

Assets/Scenes/pond_testing.unity

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,8 +1329,8 @@ MonoBehaviour:
13291329
solidRestDistance: 0.25
13301330
fluidRestDistance: 0.25
13311331
dynamicFriction: 0
1332-
staticFriction: 0
1333-
particleFriction: 0
1332+
staticFriction: 0.01
1333+
particleFriction: 0.01
13341334
restitution: 0
13351335
adhesion: 0
13361336
sleepThreshold: 0
@@ -1361,9 +1361,9 @@ MonoBehaviour:
13611361
diffuseDrag: 0
13621362
diffuseBallistic: 0
13631363
diffuseLifetime: 0
1364-
collisionDistance: 0.125
1365-
particleCollisionMargin: 0.0625
1366-
shapeCollisionMargin: 0.0625
1364+
collisionDistance: 0.25
1365+
particleCollisionMargin: 0.0125
1366+
shapeCollisionMargin: 0.0125
13671367
planes:
13681368
- 0
13691369
- 0
@@ -8093,6 +8093,7 @@ GameObject:
80938093
- component: {fileID: 5996178392539408367}
80948094
- component: {fileID: 7067008026687570811}
80958095
- component: {fileID: 8926586527191735974}
8096+
- component: {fileID: 8926586527191735975}
80968097
m_Layer: 0
80978098
m_Name: pumpkin_tri
80988099
m_TagString: Untagged
@@ -8267,7 +8268,7 @@ Transform:
82678268
m_PrefabAsset: {fileID: 0}
82688269
m_GameObject: {fileID: 384974586029215134}
82698270
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
8270-
m_LocalPosition: {x: 16.15, y: -1.68, z: -2.013523}
8271+
m_LocalPosition: {x: 16.15, y: -1.68, z: 36.97}
82718272
m_LocalScale: {x: 1, y: 1, z: 1}
82728273
m_ConstrainProportionsScale: 0
82738274
m_Children: []
@@ -8294,9 +8295,37 @@ MonoBehaviour:
82948295
Trigger: 0
82958296
TriMesh: {fileID: -2432090755550338912, guid: 233f2689b63bcc34aa56a377edba3f51,
82968297
type: 3}
8297-
DetectCollision: 0
8298+
DetectCollision: 1
82988299
MethodToRunOnDetectCollision:
82998300
m_PersistentCalls:
8300-
m_Calls: []
8301+
m_Calls:
8302+
- m_Target: {fileID: 8926586527191735975}
8303+
m_TargetAssemblyTypeName: ParticlePainter, Assembly-CSharp
8304+
m_MethodName: PaintParticle
8305+
m_Mode: 0
8306+
m_Arguments:
8307+
m_ObjectArgument: {fileID: 0}
8308+
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
8309+
m_IntArgument: 0
8310+
m_FloatArgument: 0
8311+
m_StringArgument:
8312+
m_BoolArgument: 0
8313+
m_CallState: 2
83018314
BatchSize: 256
83028315
debug: 0
8316+
--- !u!114 &8926586527191735975
8317+
MonoBehaviour:
8318+
m_ObjectHideFlags: 0
8319+
m_CorrespondingSourceObject: {fileID: 0}
8320+
m_PrefabInstance: {fileID: 0}
8321+
m_PrefabAsset: {fileID: 0}
8322+
m_GameObject: {fileID: 384974586029215134}
8323+
m_Enabled: 1
8324+
m_EditorHideFlags: 0
8325+
m_Script: {fileID: 11500000, guid: 4a32f6aecacaa0a449cac2a9da46396b, type: 3}
8326+
m_Name:
8327+
m_EditorClassIdentifier:
8328+
CollisionMachine: {fileID: 8926586527191735974}
8329+
NewColours:
8330+
- serializedVersion: 2
8331+
rgba: 4278190080

Assets/Scripts/FlexStuff/FlexCollider.cs

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class FlexCollider : MonoBehaviour
4949
[System.NonSerialized]
5050
unsafe public NvFlexBuffer* Indices;
5151

52-
unsafe public Vector3* RWVertices;
52+
unsafe public Vector4* RWVertices;
5353

5454
unsafe public int* RWIndices;
5555

@@ -83,9 +83,9 @@ void Start()
8383

8484
if (Shape == NvFlexCollisionShapeType.eNvFlexShapeTriangleMesh)
8585
{
86-
Container.MappingQueue += InitTri;
87-
Container.MappingQueue += MapTri;
88-
Container.UnmappingQueue += UnMapTri;
86+
//Container.MappingQueue += InitTri;
87+
//Container.MappingQueue += MapTri;
88+
//Container.UnmappingQueue += UnMapTri;
8989
Container.DestroyQueue += DestroyTri;
9090
}
9191
}
@@ -139,6 +139,15 @@ void DealWithShape()
139139
Container.SBuf.Geometry.data[ShapeIndex].sphere.radius = transform.lossyScale.x / 2;
140140
break;
141141
case NvFlexCollisionShapeType.eNvFlexShapeTriangleMesh:
142+
143+
Vertices = Methods.NvFlexAllocBuffer(Container.Library, TriMesh.vertexCount, sizeof(Vector4), NvFlexBufferType.eNvFlexBufferHost);
144+
Indices = Methods.NvFlexAllocBuffer(Container.Library, TriMesh.triangles.Length, sizeof(int), NvFlexBufferType.eNvFlexBufferHost);
145+
146+
MeshId = Methods.NvFlexCreateTriangleMesh(Container.Library);
147+
148+
RWVertices = (Vector4*)Methods.NvFlexMap(Vertices, (int)NvFlexMapFlags.eNvFlexMapWait);
149+
RWIndices = (int*)Methods.NvFlexMap(Indices, (int)NvFlexMapFlags.eNvFlexMapWait);
150+
142151
for (int i = 0; i < TriMesh.vertices.Length; i++)
143152
{
144153
RWVertices[i] = TriMesh.vertices[i];
@@ -148,30 +157,35 @@ void DealWithShape()
148157
{
149158
RWIndices[i] = TriMesh.triangles[i];
150159

151-
Debug.DrawLine(RWVertices[RWIndices[i]], RWVertices[RWIndices[i + 1]], Color.blue, float.PositiveInfinity);
160+
//Debug.DrawLine(RWVertices[RWIndices[i]], RWVertices[RWIndices[i + 1]], Color.blue, float.PositiveInfinity);
152161
}
153162

154-
for (int i = 0; i < TriMesh.triangles.Length; i += 3)
155-
{
156-
Debug.DrawLine(RWVertices[RWIndices[i]], RWVertices[RWIndices[i + 1]], Color.blue, float.PositiveInfinity);
157-
Debug.DrawLine(RWVertices[RWIndices[i + 1]], RWVertices[RWIndices[i + 2]], Color.blue, float.PositiveInfinity);
158-
Debug.DrawLine(RWVertices[RWIndices[i + 2]], RWVertices[RWIndices[i]], Color.blue, float.PositiveInfinity);
159-
}
163+
//for (int i = 0; i < TriMesh.triangles.Length; i += 3)
164+
//{
165+
// Debug.DrawLine(RWVertices[RWIndices[i]], RWVertices[RWIndices[i + 1]], Color.blue, float.PositiveInfinity);
166+
// Debug.DrawLine(RWVertices[RWIndices[i + 1]], RWVertices[RWIndices[i + 2]], Color.blue, float.PositiveInfinity);
167+
// Debug.DrawLine(RWVertices[RWIndices[i + 2]], RWVertices[RWIndices[i]], Color.blue, float.PositiveInfinity);
168+
//}
160169

161170
var min = TriMesh.bounds.min * 2;
162171
var LowerBoundsPtr = &min;
163172

164173
var max = TriMesh.bounds.max * 2;
165174
var UpperBoundsPtr = &max;
166175

167-
Methods.NvFlexUpdateTriangleMesh(Container.Library, MeshId, Vertices, Indices, TriMesh.vertices.Length, TriMesh.triangles.Length / 3, (float*)LowerBoundsPtr, (float*)UpperBoundsPtr);
168-
//Methods.NvFlexUpdateTriangleMesh(library, MeshId, Vertices, Indices, TriMesh.vertices.Length, TriMesh.triangles.Length / 3, null, null);
169-
170176
Container.SBuf.Geometry.data[ShapeIndex].triMesh.mesh = MeshId;
171177
Container.SBuf.Geometry.data[ShapeIndex].triMesh.scale[0] = transform.lossyScale.x;
172178
Container.SBuf.Geometry.data[ShapeIndex].triMesh.scale[1] = transform.lossyScale.y;
173179
Container.SBuf.Geometry.data[ShapeIndex].triMesh.scale[2] = transform.lossyScale.z;
174180

181+
182+
183+
Methods.NvFlexUnmap(Vertices);
184+
Methods.NvFlexUnmap(Indices);
185+
186+
//Methods.NvFlexUpdateTriangleMesh(Container.Library, MeshId, Vertices, Indices, TriMesh.vertices.Length, TriMesh.triangles.Length / 3, null, null);
187+
Methods.NvFlexUpdateTriangleMesh(Container.Library, MeshId, Vertices, Indices, TriMesh.vertices.Length, TriMesh.triangles.Length / 3, (float*)LowerBoundsPtr, (float*)UpperBoundsPtr);
188+
175189
break;
176190
}
177191
}
@@ -180,20 +194,31 @@ void DealWithShape()
180194

181195
unsafe void InitTri()
182196
{
183-
Vertices = Methods.NvFlexAllocBuffer(Container.Library, TriMesh.vertexCount, sizeof(Vector3), NvFlexBufferType.eNvFlexBufferHost);
197+
Container.MappingQueue -= InitTri;
198+
Vertices = Methods.NvFlexAllocBuffer(Container.Library, TriMesh.vertexCount, sizeof(Vector4), NvFlexBufferType.eNvFlexBufferHost);
184199
Indices = Methods.NvFlexAllocBuffer(Container.Library, TriMesh.triangles.Length, sizeof(int), NvFlexBufferType.eNvFlexBufferHost);
200+
201+
MeshId = Methods.NvFlexCreateTriangleMesh(Container.Library);
202+
203+
Debug.Log("attempting to create a tri mesh");
185204
}
186205

187206
unsafe void MapTri()
188207
{
189-
RWVertices = (Vector3*)Methods.NvFlexMap(Vertices, (int)NvFlexMapFlags.eNvFlexMapWait);
208+
RWVertices = (Vector4*)Methods.NvFlexMap(Vertices, (int)NvFlexMapFlags.eNvFlexMapWait);
190209
RWIndices = (int*)Methods.NvFlexMap(Indices, (int)NvFlexMapFlags.eNvFlexMapWait);
191210
}
192211

193212
unsafe void UnMapTri()
194213
{
195214
Methods.NvFlexUnmap(Vertices);
196215
Methods.NvFlexUnmap(Indices);
216+
217+
if (transform.hasChanged)
218+
{
219+
Methods.NvFlexUpdateTriangleMesh(Container.Library, MeshId, Vertices, Indices, TriMesh.vertices.Length, TriMesh.triangles.Length / 3, null, null);
220+
transform.hasChanged = false;
221+
}
197222
}
198223

199224
unsafe void DestroyTri()

0 commit comments

Comments
 (0)