예제 #1
0
        public static void ModifyOperationsOnSelected(CSGOperationType operationType)
        {
            var modified = false;

            foreach (var gameObject in Selection.gameObjects)
            {
                var brush = gameObject.GetComponent <CSGBrush>();
                if (brush != null &&
                    brush.OperationType != operationType)
                {
                    modified = true;
                    Undo.RecordObject(brush, "Modifying csg operation of brush component");
                    brush.OperationType = operationType;
                }

                var operation = gameObject.GetComponent <CSGOperation>();
                if (operation == null || operation.OperationType == operationType)
                {
                    continue;
                }

                modified = true;
                Undo.RecordObject(operation, "Modifying csg operation of operation component");
                operation.PassThrough   = false;
                operation.OperationType = operationType;
            }
            if (modified)
            {
                InternalCSGModelManager.Refresh();
                EditorApplication.RepaintHierarchyWindow();
            }
        }
예제 #2
0
        static void ChooseOperation(EditModeGenerate tool, bool isSceneGUI)
        {
            var  generator = tool.CurrentGenerator;
            bool enabled   = generator.HaveBrushes;

            EditorGUI.BeginDisabledGroup(!enabled);
            {
                if (isSceneGUI)
                {
                    GUILayout.BeginVertical(GUI.skin.box, Width100);
                }
                else
                {
                    GUILayout.BeginVertical(GUIStyle.none);
                }
                {
                    bool             mixedValues = !enabled;
                    CSGOperationType operation   = generator.CurrentCSGOperationType;
                    EditorGUI.BeginChangeCheck();
                    operation = CSG_EditorGUIUtility.ChooseOperation(operation, mixedValues);
                    if (EditorGUI.EndChangeCheck())
                    {
                        generator.CurrentCSGOperationType = operation;
                    }
                }
                GUILayout.EndVertical();
            }
            EditorGUI.EndDisabledGroup();
        }
예제 #3
0
        static void SetMenuOperation(MenuCommand menuCommand, CSGOperationType operationType)
        {
            var context    = (menuCommand.context as GameObject);
            var gameObject = (context == null) ? Selection.activeGameObject : context;

            if (!gameObject)
            {
                return;
            }

            var generator = gameObject.GetComponent <ChiselGeneratorComponent>();

            if (generator && generator.Operation != operationType)
            {
                Undo.RecordObject(generator, "Modified Operation");
                generator.Operation = operationType;
            }
            var composite = gameObject.GetComponent <ChiselComposite>();

            if (composite && composite.Operation != operationType)
            {
                Undo.RecordObject(generator, "Modified Operation");
                composite.Operation = operationType;
            }
        }
예제 #4
0
        /// <summary>Generates a branch and returns a <see cref="Chisel.Core.CSGTreeBranch"/> struct that contains a reference to it.</summary>
        /// <param name="userID">A unique id to help identify this particular branch. For instance, this could be an InstanceID to a [UnityEngine.Object](https://docs.unity3d.com/ScriptReference/Object.html)</param>
        /// <param name="children">The child nodes that are children of this branch. A branch may not have duplicate children, contain itself or contain a <see cref="Chisel.Core.CSGTree"/>.</param>
        /// <returns>A new <see cref="Chisel.Core.CSGTreeBranch"/>. May be an invalid node if it failed to create it.</returns>
        public static CSGTreeBranch Create(Int32 userID = 0, CSGOperationType operation = CSGOperationType.Additive, params CSGTreeNode[] children)
        {
            int branchNodeID;

            if (!GenerateBranch(userID, out branchNodeID))
            {
                return new CSGTreeBranch()
                       {
                           branchNodeID = 0
                       }
            }
            ;
            if (children != null && children.Length > 0)
            {
                if (operation != CSGOperationType.Additive)
                {
                    CSGTreeNode.SetNodeOperationType(userID, operation);
                }
                if (!CSGTreeNode.SetChildNodes(branchNodeID, children))
                {
                    CSGTreeNode.DestroyNode(branchNodeID);
                    return(new CSGTreeBranch()
                    {
                        branchNodeID = 0
                    });
                }
            }
            return(new CSGTreeBranch()
            {
                branchNodeID = branchNodeID
            });
        }
예제 #5
0
        static void OnHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
        {
            var o = EditorUtility.InstanceIDToObject(instanceID) as GameObject;

            if (selectionRect.Contains(Event.current.mousePosition))
            {
                Transform t = (o == null) ? null : o.transform;
                OnHandleDragAndDrop(inSceneView: false, transformInInspector: t, selectionRect: selectionRect);
            }

            if (o == null)
            {
                return;
            }

            GUIStyleUtility.InitStyles();

            var node = o.GetComponent <CSGNode>();

            if (node == null ||
                !node.enabled || (node.hideFlags & (HideFlags.HideInHierarchy | HideFlags.HideInInspector)) != 0)
            {
                return;
            }

            CSGOperationType operationType = CSGOperationType.Additive;

            var brush = node as CSGBrush;

            if (brush != null)
            {
                operationType = brush.OperationType;
                var skin = GUIStyleUtility.Skin;
                GUI.Label(selectionRect, skin.hierarchyOperations[(int)operationType], GUIStyleUtility.rightAlignedLabel);
                return;
            }
            var operation = node as CSGOperation;

            if (operation != null)
            {
                var skin = GUIStyleUtility.Skin;
                if (!operation.PassThrough)
                {
                    operationType = operation.OperationType;
                    var operationTypeIndex = (int)operationType;
                    if (operationTypeIndex >= 0 && operationTypeIndex < skin.hierarchyOperations.Length)
                    {
                        GUI.Label(selectionRect, skin.hierarchyOperations[operationTypeIndex], GUIStyleUtility.rightAlignedLabel);
                    }
                }
                else
                {
                    GUI.Label(selectionRect, skin.hierarchyPassThrough, GUIStyleUtility.rightAlignedLabel);
                }
                return;
            }
        }
 public CompactNodeID CreateBranch(NodeID nodeID, float4x4 transformation, CSGOperationType operation = CSGOperationType.Additive, Int32 userID = 0)
 {
     return(CreateNode(nodeID, new CompactNode
     {
         userID = userID,
         operation = operation,
         transformation = transformation,
         brushMeshHash = Int32.MaxValue
     }));
 }
 public static GeneratedNode GenerateBranch(float4x4 transformation, CSGOperationType operation = CSGOperationType.Additive, int parentIndex = -1)
 {
     return(new GeneratedNode
     {
         parentIndex = parentIndex,
         transformation = transformation,
         operation = operation,
         brushMesh = ChiselBlobAssetReference <BrushMeshBlob> .Null
     });
 }
예제 #8
0
        public static Texture2D[] GetIcons(CSGOperationType operation, string name)
        {
            int typeIndex = (int)operation;

            if (typeIndex < 0 || typeIndex > s_NamesWithOperations.Length)
            {
                typeIndex = 0;
            }
            return(ChiselEditorResources.LoadIconImages(s_OperationIcons[typeIndex]));
        }
예제 #9
0
        public static GUIContent[] GetIconContent(CSGOperationType operation, string name)
        {
            int typeIndex = (int)operation;

            if (typeIndex < 0 || typeIndex > s_NamesWithOperations.Length)
            {
                typeIndex = 0;
            }
            return(ChiselEditorResources.GetIconContent(s_OperationIcons[typeIndex], GetOperationName(typeIndex, name)));
        }
예제 #10
0
        static BrushMeshInstance CreateBox(Vector3 size, CSGOperationType operation = CSGOperationType.Additive, Material material = null)
        {
            if (material == null)
            {
                material = material2;
            }
            var       brushMaterial = ChiselBrushMaterial.CreateInstance(material);
            BrushMesh brushMesh     = TestUtility.CreateBox(size, brushMaterial);

            return(BrushMeshInstance.Create(brushMesh));
        }
예제 #11
0
        public static GUIContent[] GetIconContent(CSGOperationType operation, string name)
        {
            switch (operation)
            {
            default:
            case CSGOperationType.Additive:     return(ChiselEditorResources.GetIconContent(kAdditiveIconName, $"{nameof(CSGOperationType.Additive)} {name}"));

            case CSGOperationType.Subtractive:  return(ChiselEditorResources.GetIconContent(kSubtractiveIconName, $"{nameof(CSGOperationType.Subtractive)} {name}"));

            case CSGOperationType.Intersecting: return(ChiselEditorResources.GetIconContent(kIntersectingIconName, $"{nameof(CSGOperationType.Intersecting)} {name}"));
            }
        }
        public static CSGOperationType ChooseOperation(CSGOperationType operation, bool mixedValues)
        {
            InitStyles();

            var rcsgSkin = Skin;

            if (rcsgSkin == null)
            {
                return(operation);
            }

            var oldColor = GUI.color;

            GUI.color = Color.white;

            GUILayout.BeginVertical();
            try
            {
                GUIContent content;
                GUIStyle   style;
                bool       have_selection = !mixedValues && GUI.enabled;
                for (int i = 0; i < operationTypeCount; i++)
                {
                    if (!have_selection || (int)operation != i)
                    {
                        content = rcsgSkin.operationNames[i];
                        style   = unselectedIconLabelStyle;
                    }
                    else
                    {
                        content = rcsgSkin.operationNamesOn[i];
                        style   = selectedIconLabelStyle;
                    }
                    if (content == null || style == null)
                    {
                        continue;
                    }
                    if (GUILayout.Button(content, style))
                    {
                        operation   = (CSGOperationType)i;
                        GUI.changed = true;
                    }
                    TooltipUtility.SetToolTip(operationTooltip[i]);
                }
            }
            finally
            {
                GUILayout.EndVertical();
            }

            GUI.color = oldColor;
            return(operation);
        }
예제 #13
0
 public virtual void Reset()
 {
     editMode                     = EditMode.CreatePlane;
     brushPosition                = MathConstants.zeroVector3;
     parentGameObject             = null;
     parentModel                  = null;
     operationGameObject          = null;
     parentTransform              = null;
     generatedGameObjects         = null;
     generatedBrushes             = null;
     undoGroupIndex               = -1;
     forceCurrentCSGOperationType = invalidCSGOperationType;
     currentCSGOperationType      = invalidCSGOperationType;
 }
    static BrushMeshInstance CreateCube(Vector3 size, CSGOperationType operation = CSGOperationType.Additive, Material material = null)
    {
        if (material == null)
        {
            material = material2;
        }
        ControlMesh controlMesh;
        Shape       shape;

        BrushFactory.CreateCubeControlMesh(out controlMesh, out shape, size, material);
        BrushMesh brushMesh = RealtimeCSG.Legacy.BrushFactory.GenerateFromControlMesh(controlMesh, shape);

        return(BrushMeshInstance.Create(brushMesh));
    }
        static BrushMeshInstance CreateBox(Vector3 size, CSGOperationType operation = CSGOperationType.Additive, Material material = null)
        {
            if (material == null)
            {
                material = material2;
            }
            var layers = new SurfaceLayers
            {
                layerUsage      = LayerUsageFlags.All,
                layerParameter1 = (material) ? material.GetInstanceID() : 0
            };
            BrushMesh brushMesh = TestUtility.CreateBox(size, layers);

            return(BrushMeshInstance.Create(brushMesh));
        }
예제 #16
0
		protected void UpdateOperationType(CSGOperationType opType)
		{
			if (operationGameObject != null)
			{
				var operation = operationGameObject.GetComponent<CSGOperation>();
				if (operation != null)
					operation.OperationType = opType;

				var brush = operationGameObject.GetComponent<CSGBrush>();
				if (brush != null)
					brush.OperationType = opType;
			}
			InternalCSGModelManager.CheckForChanges();
			EditorApplication.RepaintHierarchyWindow();
		}
예제 #17
0
        public static unsafe CSGTreeBranch Create(Int32 userID = 0, CSGOperationType operation = CSGOperationType.Additive, params CSGTreeNode[] children)
        {
            if (children == null || children.Length == 0)
            {
                return(CreateUnsafe(userID, operation, null, 0));
            }

            var length   = children.Length;
            var arrayPtr = (CSGTreeNode *)Unity.Collections.LowLevel.Unsafe.UnsafeUtility.PinGCArrayAndGetDataAddress(children, out var handle);

            try
            {
                return(CreateUnsafe(userID, operation, arrayPtr, length));
            }
            finally { Unity.Collections.LowLevel.Unsafe.UnsafeUtility.ReleaseGCObject(handle); }
        }
예제 #18
0
        public static unsafe CSGTreeBranch CreateUnsafe(Int32 userID = 0, CSGOperationType operation = CSGOperationType.Additive, CSGTreeNode *childrenArray = null, int childrenArrayLength = 0)
        {
            var branchNodeID = CompactHierarchyManager.CreateBranch(operation, userID);

            Debug.Assert(CompactHierarchyManager.IsValidNodeID(branchNodeID));
            if (childrenArray != null && childrenArrayLength > 0)
            {
                if (!CompactHierarchyManager.SetChildNodes(branchNodeID, childrenArray, childrenArrayLength))
                {
                    CompactHierarchyManager.DestroyNode(branchNodeID);
                    return(CSGTreeBranch.Invalid);
                }
            }
            CompactHierarchyManager.SetDirty(branchNodeID);
            return(CSGTreeBranch.Find(branchNodeID));
        }
예제 #19
0
        public static void SetOperationForSelection(CSGOperationType newOperation)
        {
            if (currOperation == newOperation)
            {
                return;
            }

            foreach (var hasOperation in operationNodes)
            {
                hasOperation.Operation = newOperation;
            }

            var prevOperation = currOperation;

            UpdateOperationSelection();
            if (prevOperation != currOperation)
            {
                NodeOperationUpdated?.Invoke();
            }
        }
예제 #20
0
        static void SetMenuOperation(MenuCommand menuCommand, CSGOperationType operationType)
        {
            var gameObject = (menuCommand.context as GameObject) ?? Selection.activeGameObject;

            if (!gameObject)
            {
                return;
            }

            var generator = gameObject.GetComponent <ChiselGeneratorComponent>();

            if (generator && generator.Operation != operationType)
            {
                Undo.RecordObject(generator, "Modified Operation");
                generator.Operation = operationType;
            }
            var operation = gameObject.GetComponent <ChiselOperation>();

            if (operation && operation.Operation != operationType)
            {
                Undo.RecordObject(generator, "Modified Operation");
                operation.Operation = operationType;
            }
        }
예제 #21
0
        static void ShowCSGOperations(bool isSceneGUI, EditModePlace tool, FilteredSelection filteredSelection)
        {
            bool operations_enabled = (tool != null &&
                                       filteredSelection.NodeTargets.Length > 0 &&
                                       filteredSelection.NodeTargets.Length == (filteredSelection.BrushTargets.Length + filteredSelection.OperationTargets.Length));

            EditorGUI.BeginDisabledGroup(!operations_enabled);
            {
                bool             mixedValues   = tool == null || ((filteredSelection.BrushTargets.Length == 0) && (filteredSelection.OperationTargets.Length == 0));
                CSGOperationType operationType = CSGOperationType.Additive;
                if (tool != null)
                {
                    if (filteredSelection.BrushTargets.Length > 0)
                    {
                        operationType = filteredSelection.BrushTargets[0].OperationType;
                        for (int i = 1; i < filteredSelection.BrushTargets.Length; i++)
                        {
                            if (filteredSelection.BrushTargets[i].OperationType != operationType)
                            {
                                mixedValues = true;
                            }
                        }
                    }
                    else
                    if (filteredSelection.OperationTargets.Length > 0)
                    {
                        operationType = filteredSelection.OperationTargets[0].OperationType;
                    }

                    if (filteredSelection.OperationTargets.Length > 0)
                    {
                        for (int i = 0; i < filteredSelection.OperationTargets.Length; i++)
                        {
                            if (filteredSelection.OperationTargets[i].OperationType != operationType)
                            {
                                mixedValues = true;
                            }
                        }
                    }
                }

                GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none);
                {
                    bool passThroughValue = false;
                    if (tool != null &&
                        filteredSelection.BrushTargets.Length == 0 &&
                        filteredSelection.OperationTargets.Length > 0 &&
                        filteredSelection.OperationTargets.Length == filteredSelection.NodeTargets.Length)                         // only operations
                    {
                        bool?passThrough = filteredSelection.OperationTargets[0].PassThrough;
                        for (int i = 1; i < filteredSelection.OperationTargets.Length; i++)
                        {
                            if (passThrough.HasValue && passThrough.Value != filteredSelection.OperationTargets[i].PassThrough)
                            {
                                passThrough = null;
                                break;
                            }
                        }

                        mixedValues = !passThrough.HasValue || passThrough.Value;

                        var ptMixedValues = !passThrough.HasValue;
                        passThroughValue = passThrough.HasValue ? passThrough.Value : false;
                        if (CSG_EditorGUIUtility.PassThroughButton(passThroughValue, ptMixedValues))
                        {
                            Undo.RecordObjects(filteredSelection.OperationTargets, "Changed CSG operation of nodes");
                            foreach (var operation in filteredSelection.OperationTargets)
                            {
                                operation.PassThrough = true;
                            }
                            InternalCSGModelManager.CheckForChanges();
                            EditorApplication.RepaintHierarchyWindow();
                        }

                        if (passThroughValue)
                        {
                            operationType = (CSGOperationType)255;
                        }
                    }
                    EditorGUI.BeginChangeCheck();
                    {
                        operationType = CSG_EditorGUIUtility.ChooseOperation(operationType, mixedValues);
                    }
                    if (EditorGUI.EndChangeCheck() && tool != null)
                    {
                        Undo.RecordObjects(filteredSelection.NodeTargets, "Changed CSG operation of nodes");
                        for (int i = 0; i < filteredSelection.BrushTargets.Length; i++)
                        {
                            filteredSelection.BrushTargets[i].OperationType = operationType;
                        }
                        for (int i = 0; i < filteredSelection.OperationTargets.Length; i++)
                        {
                            filteredSelection.OperationTargets[i].PassThrough   = false;
                            filteredSelection.OperationTargets[i].OperationType = operationType;
                        }
                        InternalCSGModelManager.CheckForChanges();
                        EditorApplication.RepaintHierarchyWindow();
                    }
                }
                GUILayout.EndVertical();
            }
            EditorGUI.EndDisabledGroup();
        }
예제 #22
0
 public void GenerateFromPolygon(Camera camera, CSGBrush brush, CSGPlane plane, Vector3 direction, Vector3[] meshVertices, int[] indices, uint[] smoothingGroups, bool drag, CSGOperationType forceDragSource, bool autoCommitExtrusion)
 {
     BuilderMode = ShapeMode.FreeDraw;
     freedrawGenerator.GenerateFromPolygon(camera, brush, plane, direction, meshVertices, indices, smoothingGroups, drag, forceDragSource, autoCommitExtrusion);
 }
예제 #23
0
 void SetOperationType(CSGOperationType operationType)
 {
     CurrentGenerator.CurrentCSGOperationType = operationType;
 }
예제 #24
0
 internal static bool    SetNodeOperationType(Int32 nodeID, CSGOperationType operation)
 {
     return(CSGManager.SetNodeOperationType(nodeID, operation));
 }
예제 #25
0
        public static void GenerateFromSurface(CSGBrush cSGBrush, CSGPlane polygonPlane, Vector3 direction, Vector3[] points, int[] pointIndices, uint[] smoothingGroups, bool drag, CSGOperationType forceDragSource, bool autoCommitExtrusion)
        {
            EditModeManager.EditMode = ToolEditMode.Generate;
            UpdateTool();
            var generateBrushTool = brushTools[(int)ToolEditMode.Generate] as EditModeGenerate;

            generateBrushTool.GenerateFromPolygon(cSGBrush, polygonPlane, direction, points, pointIndices, smoothingGroups, drag, forceDragSource, autoCommitExtrusion);
        }
예제 #26
0
        static public void OnInspectorGUI(Editor editor, UnityEngine.Object[] targets)
        {
            TooltipUtility.InitToolTip(editor);
            try
            {
                var models = new CSGModel[targets.Length];

                for (int i = targets.Length - 1; i >= 0; i--)
                {
                    models[i] = targets[i] as CSGModel;
                    if (!models[i])
                    {
                        ArrayUtility.RemoveAt(ref models, i);
                    }
                }

                CSG_GUIStyleUtility.InitStyles();
                ShowRealtimeCSGDisabledMessage();

                if (models.Length > 0 && models.Length == targets.Length)
                {
                    CSGModelComponentInspectorGUI.OnInspectorGUI(targets);
                    return;
                }

                var filteredSelection = EditModeManager.FilteredSelection;
                var targetNodes       = filteredSelection.NodeTargets;
                var targetModels      = filteredSelection.ModelTargets;
                var targetBrushes     = filteredSelection.BrushTargets;
                var targetOperations  = filteredSelection.OperationTargets;
                if (targetNodes == null)
                {
                    return;
                }



                bool?isPrefab = false;
                PrefabInstantiateBehaviour?prefabBehaviour            = PrefabInstantiateBehaviour.Reference;
                PrefabSourceAlignment?     prefabSourceAlignment      = PrefabSourceAlignment.AlignedTop;
                PrefabDestinationAlignment?prefabDestinationAlignment = PrefabDestinationAlignment.AlignToSurface;

                if (targetNodes.Length > 0)
                {
                    var gameObject = targetNodes[0].gameObject;
                    isPrefab                   = CSGPrefabUtility.IsPrefabAsset(gameObject);
                    prefabBehaviour            = targetNodes[0].PrefabBehaviour;
                    prefabSourceAlignment      = targetNodes[0].PrefabSourceAlignment;
                    prefabDestinationAlignment = targetNodes[0].PrefabDestinationAlignment;
                    for (int i = 1; i < targetNodes.Length; i++)
                    {
                        gameObject = targetNodes[i].gameObject;

                        var currentIsPrefab                   = CSGPrefabUtility.IsPrefabAsset(gameObject);
                        var currentPrefabBehaviour            = targetNodes[i].PrefabBehaviour;
                        var currentPrefabSourceAlignment      = targetNodes[i].PrefabSourceAlignment;
                        var currentPrefabDestinationAlignment = targetNodes[i].PrefabDestinationAlignment;
                        if (isPrefab.HasValue && isPrefab.Value != currentIsPrefab)
                        {
                            isPrefab = null;
                        }
                        if (prefabBehaviour.HasValue && prefabBehaviour.Value != currentPrefabBehaviour)
                        {
                            prefabBehaviour = null;
                        }
                        if (prefabSourceAlignment.HasValue && prefabSourceAlignment.Value != currentPrefabSourceAlignment)
                        {
                            prefabSourceAlignment = null;
                        }
                        if (prefabDestinationAlignment.HasValue && prefabDestinationAlignment.Value != currentPrefabDestinationAlignment)
                        {
                            prefabDestinationAlignment = null;
                        }
                    }
                }

                GUILayout.BeginVertical(GUI.skin.box);
                {
                    if (isPrefab.HasValue && isPrefab.Value)
                    {
                        EditorGUILayout.LabelField(PrefabLabelContent);
                    }
                    else
                    {
                        EditorGUILayout.LabelField(RaySnappingLabelContent);
                        TooltipUtility.SetToolTip(RaySnappingBehaviourTooltip);
                    }

                    EditorGUI.indentLevel++;
                    {
                        if (isPrefab.HasValue && isPrefab.Value)
                        {
                            EditorGUI.showMixedValue = !prefabBehaviour.HasValue;
                            var prefabBehavour = prefabBehaviour.HasValue ? prefabBehaviour.Value : PrefabInstantiateBehaviour.Reference;
                            EditorGUI.BeginChangeCheck();
                            {
                                prefabBehavour = (PrefabInstantiateBehaviour)EditorGUILayout.EnumPopup(PrefabInstantiateBehaviourContent, prefabBehavour);
                                TooltipUtility.SetToolTip(PrefabInstantiateBehaviourTooltip);
                            }
                            if (EditorGUI.EndChangeCheck())
                            {
                                Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes");
                                for (int i = 0; i < targetNodes.Length; i++)
                                {
                                    targetNodes[i].PrefabBehaviour = prefabBehavour;
                                }
                            }
                            EditorGUI.showMixedValue = false;
                        }


                        EditorGUI.showMixedValue = !prefabDestinationAlignment.HasValue;
                        var destinationAlignment = prefabDestinationAlignment.HasValue ? prefabDestinationAlignment.Value : PrefabDestinationAlignment.AlignToSurface;
                        EditorGUI.BeginChangeCheck();
                        {
                            destinationAlignment = (PrefabDestinationAlignment)EditorGUILayout.EnumPopup(DestinationAlignmentContent, destinationAlignment);
                            TooltipUtility.SetToolTip(DestinationAlignmentTooltip);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes");
                            for (int i = 0; i < targetNodes.Length; i++)
                            {
                                targetNodes[i].PrefabDestinationAlignment = destinationAlignment;
                            }
                        }
                        EditorGUI.showMixedValue = false;


                        EditorGUI.showMixedValue = !prefabSourceAlignment.HasValue;
                        var sourceAlignment = prefabSourceAlignment.HasValue ? prefabSourceAlignment.Value : PrefabSourceAlignment.AlignedFront;
                        EditorGUI.BeginChangeCheck();
                        {
                            sourceAlignment = (PrefabSourceAlignment)EditorGUILayout.EnumPopup(SourceAlignmentContent, sourceAlignment);
                            TooltipUtility.SetToolTip(SourceAlignmentTooltip);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes");
                            for (int i = 0; i < targetNodes.Length; i++)
                            {
                                targetNodes[i].PrefabSourceAlignment = sourceAlignment;
                            }
                        }
                        EditorGUI.showMixedValue = false;
                    }
                    EditorGUI.indentLevel--;
                }
                GUILayout.EndVertical();
                GUILayout.Space(10);


                if (targetModels.Length == 0)
                {
                    int              invalidOperationType = 999;
                    bool?            handleAsOne          = null;
                    bool             selMixedValues       = false;
                    CSGOperationType operationType        = (CSGOperationType)invalidOperationType;
                    bool             opMixedValues        = false;
                    if (targetBrushes.Length > 0)
                    {
                        operationType = targetBrushes[0].OperationType;
                    }
                    for (int b = 1; b < targetBrushes.Length; b++)
                    {
                        var brush = targetBrushes[b];
                        if (operationType != brush.OperationType)
                        {
                            opMixedValues = true;
                        }
                    }
                    foreach (var operation in targetOperations)
                    {
                        if (operationType == (CSGOperationType)invalidOperationType)
                        {
                            operationType = operation.OperationType;
                        }
                        else
                        if (operationType != operation.OperationType)
                        {
                            opMixedValues = true;
                        }

                        if (!handleAsOne.HasValue)
                        {
                            handleAsOne = operation.HandleAsOne;
                        }
                        else
                        if (handleAsOne.Value != operation.HandleAsOne)
                        {
                            selMixedValues = true;
                        }
                    }
                    GUILayout.BeginVertical(GUI.skin.box);
                    {
                        bool passThroughValue = false;
                        if (targetBrushes.Length == 0 && targetOperations.Length > 0)                         // only operations
                        {
                            bool?passThrough = targetOperations[0].PassThrough;
                            for (int i = 1; i < targetOperations.Length; i++)
                            {
                                if (passThrough.HasValue && passThrough.Value != targetOperations[i].PassThrough)
                                {
                                    passThrough = null;
                                    break;
                                }
                            }

                            opMixedValues = !passThrough.HasValue || passThrough.Value;

                            var ptMixedValues = !passThrough.HasValue;
                            passThroughValue = passThrough.HasValue ? passThrough.Value : false;
                            if (CSG_EditorGUIUtility.PassThroughButton(passThroughValue, ptMixedValues))
                            {
                                Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes");
                                foreach (var operation in targetOperations)
                                {
                                    operation.PassThrough = true;
                                }
                                InternalCSGModelManager.CheckForChanges();
                                EditorApplication.RepaintHierarchyWindow();
                            }

                            if (passThroughValue)
                            {
                                operationType = (CSGOperationType)255;
                            }
                        }
                        EditorGUI.BeginChangeCheck();
                        {
                            operationType = CSG_EditorGUIUtility.ChooseOperation(operationType, opMixedValues);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes");
                            foreach (var brush in targetBrushes)
                            {
                                brush.OperationType = operationType;
                            }
                            foreach (var operation in targetOperations)
                            {
                                operation.PassThrough   = false;
                                operation.OperationType = operationType;
                            }
                            InternalCSGModelManager.CheckForChanges();
                            EditorApplication.RepaintHierarchyWindow();
                        }
                    }
                    GUILayout.EndVertical();

                    if (targetOperations.Length == 0 && targetModels.Length == 0)
                    {
                        GUILayout.Space(10);
                        if (targetBrushes.Length == 1)
                        {
                            GUILayout.BeginVertical(GUI.skin.box);
                            {
                                EditorGUI.indentLevel++;
                                OpenSurfaces = EditorGUILayout.Foldout(OpenSurfaces, SurfacesContent);
                                EditorGUI.indentLevel--;
                                if (OpenSurfaces)
                                {
                                    var targetShape     = targetBrushes[0].Shape;
                                    var texGens         = targetShape.TexGens;
                                    var texGenFlagArray = targetShape.TexGenFlags;
                                    for (int t = 0; t < texGens.Length; t++)
                                    {
                                        GUILayout.Space(2);

                                        var texGenFlags = texGenFlagArray[t];
                                        var material    = targetShape.TexGens[t].RenderMaterial;
                                        var physicsMat  = targetShape.TexGens[t].PhysicsMaterial;
                                        EditorGUI.BeginChangeCheck();
                                        {
                                            GUILayout.BeginHorizontal();
                                            {
                                                GUILayout.Space(4);
                                                material = CSG_EditorGUIUtility.MaterialImage(material);
                                                GUILayout.Space(2);
                                                GUILayout.BeginVertical();
                                                {
                                                    //EditorGUI.BeginDisabledGroup(texGenFlags != TexGenFlags.None);
                                                    {
                                                        material = EditorGUILayout.ObjectField(material, typeof(Material), true) as Material;
                                                    }
                                                    //EditorGUI.EndDisabledGroup();
                                                    physicsMat = EditorGUILayout.ObjectField(physicsMat, typeof(PhysicMaterial), true) as PhysicMaterial;

                                                    texGenFlags = EditModeCommonGUI.OnSurfaceFlagButtons(texGenFlags);
                                                }
                                                GUILayout.EndVertical();
                                                GUILayout.Space(4);
                                            }
                                            GUILayout.EndHorizontal();
                                        }
                                        if (EditorGUI.EndChangeCheck())
                                        {
                                            var selectedBrushSurfaces = new []
                                            {
                                                new SelectedBrushSurface(targetBrushes[0], t)
                                            };
                                            using (new UndoGroup(selectedBrushSurfaces, "discarding surface"))
                                            {
                                                texGenFlagArray[t] = texGenFlags;
                                                targetShape.TexGens[t].RenderMaterial  = material;
                                                targetShape.TexGens[t].PhysicsMaterial = physicsMat;
                                            }
                                        }
                                        GUILayout.Space(4);
                                    }
                                }
                            }
                            GUILayout.EndVertical();
                        }
                    }

                    if (handleAsOne.HasValue)
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            EditorGUI.showMixedValue = selMixedValues;
                            handleAsOne = EditorGUILayout.Toggle(HandleAsOneLabel, handleAsOne.Value);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObjects(targetNodes, "Changed CSG operation 'Handle as one object'");
                            foreach (var operation in targetOperations)
                            {
                                operation.HandleAsOne = handleAsOne.Value;
                            }
                            EditorApplication.RepaintHierarchyWindow();
                        }
                    }
                }

#if false
                if (targetNodes.Length == 1)
                {
                    var node  = targetNodes[0];
                    var brush = node as CSGBrush;
                    if (brush != null)
                    {
                        var brush_cache = CSGSceneManager.GetBrushCache(brush);
                        if (brush_cache == null ||
                            brush_cache.childData == null ||
                            brush_cache.childData.modelTransform == null)
                        {
                            EditorGUILayout.LabelField("brush-cache: null");
                        }
                        else
                        {
                            EditorGUILayout.LabelField("node-id: " + brush.brushNodeID);
                        }
                    }
                    var operation = node as CSGOperation;
                    if (operation != null)
                    {
                        var operation_cache = CSGSceneManager.GetOperationCache(operation);
                        if (operation_cache == null ||
                            operation_cache.childData == null ||
                            operation_cache.childData.modelTransform == null)
                        {
                            EditorGUILayout.LabelField("operation-cache: null");
                        }
                        else
                        {
                            EditorGUILayout.LabelField("operation-id: " + operation.operationNodeID);
                        }
                    }
                    var model = node as CSGModel;
                    if (model != null)
                    {
                        var model_cache = CSGSceneManager.GetModelCache(model);
                        if (model_cache == null ||
                            model_cache.meshContainer == null)
                        {
                            EditorGUILayout.LabelField("model-cache: null");
                        }
                        else
                        {
                            EditorGUILayout.LabelField("model-id: " + model.modelNodeID);
                        }
                    }
                }
#endif
            }
            finally
            {
                TooltipUtility.DrawToolTip(getLastRect: true, goUp: true);
            }
        }
예제 #27
0
        public static CSGTreeBrush Create(Int32 userID, float4x4 localTransformation, BrushMeshInstance brushMesh = default(BrushMeshInstance), CSGOperationType operation = CSGOperationType.Additive)
        {
            var brushNodeID = CompactHierarchyManager.CreateBrush(brushMesh, localTransformation, operation, userID);

            Debug.Assert(CompactHierarchyManager.IsValidNodeID(brushNodeID));
            CompactHierarchyManager.SetDirty(brushNodeID);
            return(CSGTreeBrush.Find(brushNodeID));
        }
예제 #28
0
 public static GUIContent GetHierarchyIcon(CSGOperationType operation, string name)
 {
     return(GetIconContent(operation, name)[0]);
 }
예제 #29
0
 /// <summary>Generates a brush and returns a <see cref="Chisel.Core.CSGTreeBrush"/> struct that contains a reference to it.</summary>
 /// <param name="localTransformation">The transformation of the brush relative to the tree root</param>
 /// <param name="brushMesh">A <see cref="Chisel.Core.BrushMeshInstance"/>, which is a reference to a <see cref="Chisel.Core.BrushMesh"/>.</param>
 /// <param name="operation">The <see cref="Chisel.Core.CSGOperationType"/> that needs to be performed with this <see cref="Chisel.Core.CSGTreeBrush"/>.</param>
 /// <param name="flags"><see cref="Chisel.Core.CSGTreeBrush"/> specific flags</param>
 /// <returns>A new <see cref="Chisel.Core.CSGTreeBrush"/>. May be an invalid node if it failed to create it.</returns>
 public static CSGTreeBrush Create(Matrix4x4 localTransformation, Int32 userID = 0, BrushMeshInstance brushMesh = default(BrushMeshInstance), CSGOperationType operation = CSGOperationType.Additive)
 {
     return(Create(userID, localTransformation, brushMesh, operation));
 }
예제 #30
0
 /// <summary>Generates a brush and returns a <see cref="Chisel.Core.CSGTreeBrush"/> struct that contains a reference to it.</summary>
 /// <param name="userID">A unique id to help identify this particular brush. For instance, this could be an InstanceID to a [UnityEngine.Object](https://docs.unity3d.com/ScriptReference/Object.html)</param>
 /// <param name="brushMesh">A <see cref="Chisel.Core.BrushMeshInstance"/>, which is a reference to a <see cref="Chisel.Core.BrushMesh"/>.</param>
 /// <param name="operation">The <see cref="Chisel.Core.CSGOperationType"/> that needs to be performed with this <see cref="Chisel.Core.CSGTreeBrush"/>.</param>
 /// <param name="flags"><see cref="Chisel.Core.CSGTreeBrush"/> specific flags</param>
 /// <returns>A new <see cref="Chisel.Core.CSGTreeBrush"/>. May be an invalid node if it failed to create it.</returns>
 public static CSGTreeBrush Create(Int32 userID = 0, BrushMeshInstance brushMesh = default(BrushMeshInstance), CSGOperationType operation = CSGOperationType.Additive)
 {
     return(Create(userID, float4x4.identity, brushMesh, operation));
 }