2
2
using AGXUnity . Collide ;
3
3
using AGXUnity . Utils ;
4
4
using System ;
5
- using System . Collections . Generic ;
6
5
using UnityEngine ;
7
- using GUI = AGXUnity . Utils . GUI ;
8
6
9
7
namespace AGXUnity . Model
10
8
{
@@ -42,37 +40,6 @@ public Terrain Terrain
42
40
[ HideInInspector ]
43
41
public int TerrainDataResolution { get { return TerrainUtils . TerrainDataResolution ( TerrainData ) ; } }
44
42
45
- [ SerializeField ]
46
- private List < DeformableTerrainShovel > m_shovels = new List < DeformableTerrainShovel > ( ) ;
47
-
48
- [ SerializeField ]
49
- private bool m_tempDisplayShovelForces = false ;
50
-
51
- [ HideInInspector ]
52
- public bool TempDisplayShovelForces
53
- {
54
- get { return m_tempDisplayShovelForces ; }
55
- set
56
- {
57
- m_tempDisplayShovelForces = value ;
58
-
59
- if ( ! Application . isPlaying )
60
- return ;
61
-
62
- if ( m_tempDisplayShovelForces &&
63
- Shovels . Length > 0 &&
64
- GUIWindowHandler . Instance . GetWindowData ( ShowForces ) == null ) {
65
- var windowSize = new Vector2 ( 750 , 125 ) ;
66
- GUIWindowHandler . Instance . Show ( ShowForces ,
67
- windowSize ,
68
- new Vector2 ( Screen . width - windowSize . x - 20 , 20 ) ,
69
- "Shovel forces" ) ;
70
- }
71
- else if ( ! m_tempDisplayShovelForces && GUIWindowHandler . HasInstance )
72
- GUIWindowHandler . Instance . Close ( ShowForces ) ;
73
- }
74
- }
75
-
76
43
/// <summary>
77
44
/// Resets heights of the Unity terrain and recreate native instance.
78
45
/// </summary>
@@ -104,8 +71,6 @@ protected override bool Initialize()
104
71
// Only printing the errors if something is wrong.
105
72
LicenseManager . LicenseInfo . HasModuleLogError ( LicenseInfo . Module . AGXTerrain | LicenseInfo . Module . AGXGranular , this ) ;
106
73
107
- RemoveInvalidShovels ( true , true ) ;
108
-
109
74
m_initialHeights = TerrainData . GetHeights ( 0 , 0 , TerrainDataResolution , TerrainDataResolution ) ;
110
75
111
76
InitializeNative ( ) ;
@@ -135,9 +100,6 @@ protected override void OnDestroy()
135
100
}
136
101
Native = null ;
137
102
138
- if ( GUIWindowHandler . HasInstance )
139
- GUIWindowHandler . Instance . Close ( ShowForces ) ;
140
-
141
103
base . OnDestroy ( ) ;
142
104
}
143
105
@@ -156,10 +118,6 @@ private void InitializeNative()
156
118
157
119
Native . setTransform ( Utils . TerrainUtils . CalculateNativeOffset ( transform , TerrainData ) ) ;
158
120
159
-
160
- foreach ( var shovel in Shovels )
161
- Native . add ( shovel . GetInitialized < DeformableTerrainShovel > ( ) ? . Native ) ;
162
-
163
121
GetSimulation ( ) . add ( Native ) ;
164
122
}
165
123
@@ -209,108 +167,18 @@ private void UpdateHeights( agxTerrain.ModifiedVerticesVector modifiedVertices )
209
167
TerrainData . SyncHeightmap ( ) ;
210
168
}
211
169
212
- private GUIStyle m_textLabelStyle = null ;
213
- private void ShowForces ( EventType eventType )
214
- {
215
- if ( m_textLabelStyle == null ) {
216
- m_textLabelStyle = new GUIStyle ( GUI . Skin . label ) ;
217
- m_textLabelStyle . alignment = TextAnchor . MiddleLeft ;
218
-
219
- var fonts = Font . GetOSInstalledFontNames ( ) ;
220
- foreach ( var font in fonts ) {
221
- if ( font == "Consolas" ) {
222
- m_textLabelStyle . font = Font . CreateDynamicFontFromOSFont ( font , 24 ) ;
223
- break ;
224
- }
225
- }
226
- }
227
-
228
- var textColor = Color . Lerp ( Color . black , Color . white , 1.0f ) ;
229
- var valueColor = Color . Lerp ( Color . green , Color . white , 0.45f ) ;
230
- Func < string , agx . Vec3 , GUIContent > Vec3Content = ( name , v ) =>
231
- {
232
- return GUI . MakeLabel ( string . Format ( "{0} [{1}, {2}, {3}] kN" ,
233
- GUI . AddColorTag ( name , textColor ) ,
234
- GUI . AddColorTag ( v . x . ToString ( "0.00" ) . PadLeft ( 7 , ' ' ) , valueColor ) ,
235
- GUI . AddColorTag ( v . y . ToString ( "0.00" ) . PadLeft ( 7 , ' ' ) , valueColor ) ,
236
- GUI . AddColorTag ( v . z . ToString ( "0.00" ) . PadLeft ( 7 , ' ' ) , valueColor ) ) ) ;
237
- } ;
238
-
239
- var shovel = m_shovels [ 0 ] . Native ;
240
- var penetrationForce = new agx . Vec3 ( ) ;
241
- var penetrationTorque = new agx . Vec3 ( ) ;
242
- Native . getPenetrationForce ( shovel , ref penetrationForce , ref penetrationTorque ) ;
243
- var separationForce = - Native . getSeparationContactForce ( shovel ) ;
244
- var deformerForce = - Native . getDeformationContactForce ( shovel ) ;
245
- var contactForce = - Native . getContactForce ( shovel ) ;
246
-
247
- GUILayout . Label ( Vec3Content ( "Penetration force:" , 1.0E-3 * penetrationForce ) , m_textLabelStyle ) ;
248
- GUILayout . Space ( 4 ) ;
249
- GUILayout . Label ( Vec3Content ( "Separation force: " , 1.0E-3 * separationForce ) , m_textLabelStyle ) ;
250
- GUILayout . Space ( 4 ) ;
251
- GUILayout . Label ( Vec3Content ( "Deformer force: " , 1.0E-3 * deformerForce ) , m_textLabelStyle ) ;
252
- GUILayout . Space ( 4 ) ;
253
- GUILayout . Label ( Vec3Content ( "Contact force: " , 1.0E-3 * contactForce ) , m_textLabelStyle ) ;
254
- }
255
-
256
170
private Terrain m_terrain = null ;
257
171
private float [ , ] m_initialHeights = null ;
258
172
259
173
// -----------------------------------------------------------------------------------------------------------
260
174
// ------------------------------- Implementation of DeformableTerrainBase -----------------------------------
261
175
// -----------------------------------------------------------------------------------------------------------
262
176
public override float ElementSize => TerrainData . size . x / ( TerrainDataResolution - 1 ) ;
263
- public override DeformableTerrainShovel [ ] Shovels => m_shovels . ToArray ( ) ;
264
177
public override agx . GranularBodyPtrArray GetParticles ( ) { return Native ? . getSoilSimulationInterface ( ) ? . getSoilParticles ( ) ; }
265
178
public override Uuid GetParticleMaterialUuid ( ) => Native ? . getMaterial ( agxTerrain . Terrain . MaterialType . PARTICLE ) . getUuid ( ) ;
266
179
public override agxTerrain . SoilSimulationInterface GetSoilSimulationInterface ( ) { return Native ? . getSoilSimulationInterface ( ) ; }
267
180
public override agxTerrain . TerrainProperties GetProperties ( ) { return Native ? . getProperties ( ) ; }
268
181
269
- public override bool Add ( DeformableTerrainShovel shovel )
270
- {
271
- if ( shovel == null || m_shovels . Contains ( shovel ) )
272
- return false ;
273
-
274
- m_shovels . Add ( shovel ) ;
275
-
276
- // Initialize shovel if we're initialized.
277
- if ( Native != null )
278
- Native . add ( shovel . GetInitialized < DeformableTerrainShovel > ( ) . Native ) ;
279
-
280
- return true ;
281
- }
282
-
283
- public override bool Remove ( DeformableTerrainShovel shovel )
284
- {
285
- if ( shovel == null || ! m_shovels . Contains ( shovel ) )
286
- return false ;
287
-
288
- if ( Native != null )
289
- Native . remove ( shovel . Native ) ;
290
-
291
- return m_shovels . Remove ( shovel ) ;
292
- }
293
-
294
- public override bool Contains ( DeformableTerrainShovel shovel )
295
- {
296
- return shovel != null && m_shovels . Contains ( shovel ) ;
297
- }
298
-
299
- public override void RemoveInvalidShovels ( bool removeDisabled = false , bool warn = false )
300
- {
301
- m_shovels . RemoveAll ( shovel => shovel == null ) ;
302
- if ( removeDisabled ) {
303
- int removed = m_shovels . RemoveAll ( shovel => ! shovel . isActiveAndEnabled ) ;
304
- if ( removed > 0 ) {
305
- if ( warn )
306
- Debug . LogWarning ( $ "Removed { removed } disabled shovels from terrain { gameObject . name } ." +
307
- " Disabled shovels should not be added to the terrain on play and should instead be added manually when enabled during runtime." +
308
- " To fix this warning, please remove any disabled shovels from the terrain." ) ;
309
- else
310
- Debug . Log ( $ "Removed { removed } disabled shovels from terrain { gameObject . name } ." ) ;
311
- }
312
- }
313
- }
314
182
public override void ConvertToDynamicMassInShape ( Shape failureVolume )
315
183
{
316
184
if ( ! IsNativeNull ( ) )
0 commit comments