/// <summary> /// Resets heights of the Unity terrain and recreate native instance. /// </summary> public void ResetHeights() { if (Native != null && Simulation.HasInstance) { GetSimulation().remove(Native); Native = null; } ResetTerrainDataHeightsAndTransform(); InitializeNative(); PropertySynchronizer.Synchronize(this); }
private void OnPreStepForwardUpdate() { if (Native == null || !Native.getValid()) { return; } SynchronizeNativeFramesWithAttachmentPair(); if (m_isAnimated) { var controllers = GetElementaryConstraintControllers(); for (int i = 0; i < controllers.Length; ++i) { PropertySynchronizer.Synchronize(controllers[i]); } } }
public static agx.RigidBody InstantiateTemplate(RigidBody template, Shape[] shapes) { if (template == null) { return(null); } var native = new agx.RigidBody(template.name); foreach (var shape in shapes) { var geometry = shape.CreateTemporaryNative(); geometry.setEnable(shape.IsEnabled); if (shape.Material != null) { geometry.setMaterial(shape.Material.GetInitialized <ShapeMaterial>().Native); } native.add(geometry, shape.GetNativeRigidBodyOffset(template)); } template.SyncNativeTransform(native); // MassProperties (synchronization below) wont write any data if UseDefault = true. native.getMassProperties().setAutoGenerateMask((uint)agx.MassProperties.AutoGenerateFlags.AUTO_GENERATE_ALL); native.updateMassProperties(); template.MassProperties.SetDefaultCalculated(native); native.getMassProperties().setAutoGenerateMask(0u); var prevNative = template.m_rb; try { template.m_rb = native; PropertySynchronizer.Synchronize(template); PropertySynchronizer.Synchronize(template.MassProperties); } finally { template.m_rb = prevNative; } return(native); }
private void OnPreStepForwardUpdate() { if (Native == null || !Native.getValid()) { return; } SynchronizeNativeFramesWithAttachmentPair(); // It's not possible to check which properties an animator // is controlling, for now we update all properties in the // controllers if we have an animator. This could probably // be a flag (IsAnimated). var isAnimated = GetComponent <Animator>() != null; if (isAnimated) { var controllers = GetElementaryConstraintControllers(); for (int i = 0; i < controllers.Length; ++i) { PropertySynchronizer.Synchronize(controllers[i]); } } }
/// <summary> /// Callback when undo or redo has been performed. There's a significant /// delay to e.g., Inspector update when this happens so we're explicitly /// telling Unity to update selected object (if ScriptComponent). /// </summary> private static void UndoRedoPerformedCallback() { // Trigger repaint of inspector GUI for our targets. var targets = ToolManager.ActiveTools.SelectMany(tool => tool.Targets); foreach (var target in targets) { EditorUtility.SetDirty(target); } // Collecting scripts that may require synchronize of // data post undo/redo where the private serialized // field has been changed but the public property with // native synchronizations isn't touched. if (EditorApplication.isPlaying) { var objectsToSynchronize = new List <Object>(); Action <Object> addUnique = obj => { if (!objectsToSynchronize.Contains(obj)) { objectsToSynchronize.Add(obj); } }; foreach (var obj in Selection.objects) { if (obj is AGXUnity.ScriptAsset) { addUnique(obj); } else if (obj is GameObject) { var scripts = (obj as GameObject).GetComponents <AGXUnity.ScriptComponent>(); foreach (var script in scripts) { addUnique(script); } } } foreach (var obj in objectsToSynchronize) { PropertySynchronizer.Synchronize(obj); } } // Synchronizing all shape sizes with visuals - it's not possible // to determine affected shapes from tools targets or selection // since it may have changed when undo is performed. var shapes = Object.FindObjectsOfType <AGXUnity.Collide.Shape>(); foreach (var shape in shapes) { var visual = AGXUnity.Rendering.ShapeVisual.Find(shape); if (visual) { visual.OnSizeUpdated(); } } if (targets.Count() > 0) { SceneView.RepaintAll(); } }