void UpdateBrushState() { if (updateBrushSelection) { updateBrushSelection = false; UpdateBrushSelection(); updateBrushWireframe = true; } if (updateBrushWireframe) { updateBrushWireframe = false; UpdateBrushWireframe(); updateBrushLineCache = true; } if (updateBrushLineCache) { updateBrushLineCache = false; brushOutlineRenderer.Begin(); foreach (var pair in brushOutlines) { var wireframe = pair.Value; if (wireframe == null) { continue; } var outline = pair.Key; if (!outline.brush.Valid) { continue; } // TODO: simplify this var wireframeValue = pair.Value; var modelTransform = outline.transform; //var brushes = outline.brush.AllSynchronizedVariants; //var anySelected = ChiselSyncSelection.IsAnyBrushVariantSelected(brushes); //foreach (var brush in brushes) var brush = outline.brush; var anySelected = ChiselSyncSelection.IsBrushVariantSelected(brush); { Matrix4x4 transformation; if (modelTransform) { transformation = modelTransform.localToWorldMatrix * brush.NodeToTreeSpaceMatrix; } else { transformation = brush.NodeToTreeSpaceMatrix; } if ((VisualizationMode & VisualizationMode.Outline) == VisualizationMode.Outline) { var directSelect = !ChiselEditModeManager.EditMode.ShowCompleteOutline && ((brush == outline.brush && !anySelected) || (anySelected && ChiselSyncSelection.IsBrushVariantSelected(brush))); // TODO: tweak look of selection, figure out how to do backfaced lighting of edges, for clarity // TODO: support selecting surfaces/edges/points (without showing the entire object selection) if (directSelect) { brushOutlineRenderer.DrawOutlines(transformation, wireframeValue, ColorManager.kSelectedOutlineColor, thickness: 3.0f, onlyInnerLines: false); } else { brushOutlineRenderer.DrawOutlines(transformation, wireframeValue, ColorManager.kUnselectedOutlineColor, thickness: 1.0f, onlyInnerLines: false);// (ChiselEditModeManager.EditMode == CSGEditMode.ShapeEdit)); } } if ((VisualizationMode & VisualizationMode.SimpleOutline) == VisualizationMode.SimpleOutline) { brushOutlineRenderer.DrawSimpleOutlines(transformation, wireframeValue, ColorManager.kUnselectedOutlineColor); } } } brushOutlineRenderer.End(); } }
static void OnMoveTool() { var position = Tools.handlePosition; var rotation = Tools.handleRotation; #if SYNC_SUPPORT // TODO: finish and fix this var selectedNodes = Selection.GetFiltered <ChiselNode>(SelectionMode.Editable | SelectionMode.TopLevel); if (selectedNodes.Length == 0) { // TODO: probably need to use our own PositionHandle on non Chisel objects, to be able to snap to grid return; } var transformation = Matrix4x4.identity; var invTransformation = Matrix4x4.identity; // TODO: figure out how to handle this with selecting multiple variants of the same brush (synchronized brushes) if (selectedNodes.Length == 1) { foundTreeBrushes.Clear(); selectedNodes[0].GetAllTreeBrushes(foundTreeBrushes, ignoreSynchronizedBrushes: true); if (foundTreeBrushes.Count == 1) { var transform = ChiselNodeHierarchyManager.FindModelTransformOfTransform(selectedNodes[0].hierarchyItem.Transform); var firstBrush = foundTreeBrushes.First(); var brush = firstBrush; if (!ChiselSyncSelection.IsBrushVariantSelected(brush)) { List <CSGTreeBrush> selectedVariants = new List <CSGTreeBrush>(); if (ChiselSyncSelection.GetSelectedVariantsOfBrush(brush, selectedVariants)) { brush = selectedVariants[0]; } } if (transform) { transformation = transform.localToWorldMatrix * brush.NodeToTreeSpaceMatrix; } else { transformation = brush.NodeToTreeSpaceMatrix; } rotation = Quaternion.LookRotation(transformation.GetColumn(2), transformation.GetColumn(1)); invTransformation = selectedNodes[0].transform.localToWorldMatrix * transformation.inverse; if (Tools.pivotRotation == PivotRotation.Global) { rotation = Quaternion.identity; } position = transformation.GetColumn(3); } } #endif EditorGUI.BeginChangeCheck(); // TODO: make this work with bounds! var newPosition = UnitySceneExtensions.SceneHandles.PositionHandle(position, rotation); if (EditorGUI.EndChangeCheck()) { var delta = newPosition - position; var transforms = Selection.transforms; if (transforms != null && transforms.Length > 0) { MoveTransformsTo(transforms, delta); } } }