@@ -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