Пример #1
0
        public static bool IsPartOfDefaultModel(UnityEngine.Object[] targetObjects)
        {
            if (targetObjects == null)
            {
                return(false);
            }

            for (int i = 0; i < targetObjects.Length; i++)
            {
                ChiselNode node = targetObjects[i] as ChiselNode;
                if (Equals(node, null))
                {
                    var gameObject = targetObjects[i] as GameObject;
                    if (gameObject)
                    {
                        node = gameObject.GetComponent <ChiselNode>();
                    }
                }
                if (node)
                {
                    if (ChiselGeneratedComponentManager.IsDefaultModel(node.hierarchyItem.Model))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        public static IEnumerable <KeyValuePair <GameObject, CSGTreeBrushIntersection> > GetAllOverlapping(Vector2 position)
        {
            var allOverlapping = new List <GameObject>();

            while (true)
            {
                GameObject[]             ignore = allOverlapping.ToArray();
                GameObject[]             filter = null;
                CSGTreeBrushIntersection intersection;
                var go = PickClosestGameObjectDelegated(position, ref ignore, ref filter, out intersection);
                if (go == null)
                {
                    break;
                }

                if (allOverlapping.Count > 0 && allOverlapping.Contains(go))
                {
                    break;
                }

                if (!ChiselGeneratedComponentManager.IsObjectGenerated(go))
                {
                    yield return(new KeyValuePair <GameObject, CSGTreeBrushIntersection>(go, intersection));
                }

                allOverlapping.Add(go);
            }
        }
Пример #3
0
        static GameObject PickModelOrGameObject(Camera camera, Vector2 pickposition, int layers, ref GameObject[] ignore, ref GameObject[] filter, out ChiselModel model, out Material material)
        {
            model    = null;
            material = null;

            var        flagState       = ChiselGeneratedComponentManager.BeginPicking();
            GameObject gameObject      = null;
            bool       foundGameObject = false;
            int        materialIndex   = -1;

            try
            {
                if (PickClosestGO != null)
                {
#if UNITY_2020_2_OR_NEWER
                    gameObject = PickClosestGO(camera, layers, pickposition, ignore, filter, true, out materialIndex);
#else
                    gameObject = PickClosestGO(camera, layers, pickposition, ignore, filter, out materialIndex);
#endif
                }
                else
                {
                    gameObject = HandleUtility.PickGameObject(pickposition, ignore, out materialIndex);
                }
            }
            finally
            {
                foundGameObject = ChiselGeneratedComponentManager.EndPicking(flagState, gameObject, out model) && model;
            }
            if (object.Equals(gameObject, null))
            {
                return(null);
            }

            if (!foundGameObject)
            {
                return(gameObject);
            }

            if (materialIndex >= 0 &&
                gameObject.TryGetComponent <Renderer>(out var renderer))
            {
                renderer.GetSharedMaterials(sSharedMaterials);
                material = materialIndex < sSharedMaterials.Count ? sSharedMaterials[materialIndex] : null;
                sSharedMaterials.Clear(); // We don't want to keep references to Materials alive
                if (!material)
                {
                    material = null;
                }
            }
            return(gameObject);
        }
Пример #4
0
        bool IsDefaultModel()
        {
            if (serializedObject.targetObjects == null)
            {
                return(false);
            }

            for (int i = 0; i < serializedObject.targetObjects.Length; i++)
            {
                if (ChiselGeneratedComponentManager.IsDefaultModel(serializedObject.targetObjects[i]))
                {
                    return(true);
                }
            }
            return(false);
        }
        internal static GameObject PickModel(Camera camera, Vector2 pickposition, int layers, ref GameObject[] ignore, ref GameObject[] filter, out ChiselModel model, out Material material)
        {
            model    = null;
            material = null;
            var        flagState       = ChiselGeneratedComponentManager.BeginPicking();
            GameObject gameObject      = null;
            bool       foundGameObject = false;

            try
            {
                int materialIndex = -1;
                if (pickClosestGO == null ||
                    pickClosestGameObjectDelegate == null)
                {
                    gameObject = HandleUtility.PickGameObject(pickposition, ignore, out materialIndex);
                }
                else
                {
                    gameObject = pickClosestGO(camera, layers, pickposition, ignore, filter, out materialIndex);
                }
            }
            finally
            {
                foundGameObject = ChiselGeneratedComponentManager.EndPicking(flagState, gameObject, out model) && model;
            }
            if (object.Equals(gameObject, null))
            {
                return(null);
            }

            if (!foundGameObject)
            {
                return(gameObject);
            }

            var renderer = gameObject.GetComponent <Renderer>();

            if (renderer)
            {
                material = renderer.sharedMaterial;
                if (!material)
                {
                    material = null;
                }
            }
            return(gameObject);
        }
Пример #6
0
        static bool RemoveGeneratedMeshesFromArray(ref UnityEngine.Object[] selection)
        {
            var found = new List <UnityEngine.Object>();

            for (int i = selection.Length - 1; i >= 0; i--)
            {
                var obj = selection[i];
                if (ChiselGeneratedComponentManager.IsObjectGenerated(obj))
                {
                    continue;
                }
                found.Add(obj);
            }
            if (selection.Length != found.Count)
            {
                selection = found.ToArray();
                return(true);
            }
            return(false);
        }
Пример #7
0
        bool NeedLightmapRebuild()
        {
            if (target == null)
            {
                return(false);
            }

            foreach (var target in targets)
            {
                var model = target as ChiselModel;
                if (!model)
                {
                    continue;
                }
                if (ChiselGeneratedComponentManager.NeedUVGeneration(model))
                {
                    return(true);
                }
            }
            return(false);
        }
        static GameObject PickNodeOrGameObject(Camera camera, Vector2 pickposition, int layers, ref GameObject[] ignore, ref GameObject[] filter, out ChiselModel model, out ChiselNode node, out ChiselIntersection intersection)
        {
TryNextSelection:
            intersection = ChiselIntersection.None;

            node = null;
            Material sharedMaterial;
            var      gameObject = PickModelOrGameObject(camera, pickposition, layers, ref ignore, ref filter, out model, out sharedMaterial);

            if (object.Equals(gameObject, null))
            {
                return(null);
            }

            if (ChiselGeneratedComponentManager.IsValidModelToBeSelected(model))
            {
                int filterLayerParameter0 = (sharedMaterial) ? sharedMaterial.GetInstanceID() : 0;
                {
                    var worldRay       = camera.ScreenPointToRay(pickposition);
                    var worldRayStart  = worldRay.origin;
                    var worldRayVector = (worldRay.direction * (camera.farClipPlane - camera.nearClipPlane));
                    var worldRayEnd    = worldRayStart + worldRayVector;

                    if (ChiselSceneQuery.FindFirstWorldIntersection(model, worldRayStart, worldRayEnd, filterLayerParameter0, layers, ignore, filter, out var tempIntersection))
                    {
                        node = tempIntersection.node;
                        if (node)
                        {
                            if (ignore != null &&
                                ignore.Contains(node.gameObject))
                            {
                                node = null;
                                return(null);
                            }
                            intersection = tempIntersection;
                            return(node.gameObject);
                        }
                        else
                        {
                            node = null;
                        }
                    }
                }

                if (ignore == null)
                {
                    return(null);
                }

                ArrayUtility.Add(ref ignore, gameObject);
                goto TryNextSelection;
            }

            if (object.Equals(gameObject, null))
            {
                return(null);
            }

            if (ignore != null &&
                ignore.Contains(gameObject))
            {
                return(null);
            }

            return(gameObject);
        }
 private static void OnVisibilityChanged()
 {
     ChiselGeneratedComponentManager.OnVisibilityChanged();
 }
Пример #10
0
        void RenderMeshSettingsGUI()
        {
            if (serializedObject == null || gameObjectsSerializedObject == null || gameObjectsSerializedObject.targetObjects.Length == 0)
            {
                return;
            }

            gameObjectsSerializedObject.Update();

#if UNITY_2018_2_OR_ABOVE
            if (SupportedRenderingFeatures.active.rendererSupportsMotionVectors)
#endif
            EditorGUILayout.PropertyField(motionVectorsProp, MotionVectorsContent, true);

            EditorGUILayout.Space();
            LightmapStaticSettings();

            if (!(Lightmapping.bakedGI || Lightmapping.realtimeGI) && !IsPrefabAsset)
            {
                EditorGUILayout.HelpBox(GINotEnabledInfoContents.text, MessageType.Info);
                return;
            }

#if UNITY_2019_2_OR_NEWER
            bool enableSettings = (staticEditorFlagsProp.intValue & (int)StaticEditorFlags.ContributeGI) != 0;
#else
            bool enableSettings = (staticEditorFlagsProp.intValue & (int)StaticEditorFlags.LightmapStatic) != 0;
#endif
            if (enableSettings)
            {
                EditorGUILayout.Space();
                var needLightmapRebuild = NeedLightmapRebuild();
                if (!autoRebuildUVsProp.boolValue && needLightmapRebuild)
                {
                    EditorGUILayout.HelpBox(NeedsLightmapRebuildContents.text, MessageType.Warning);
                }

                var buttonRect     = EditorGUILayout.GetControlRect();
                int buttonId       = EditorGUIUtility.GetControlID(RebuildButtonHashCode, FocusType.Keyboard, buttonRect);
                var buttonPropRect = EditorGUI.PrefixLabel(buttonRect, buttonId, LightmapUVsContents);
                var buttonContents = needLightmapRebuild ? ForceBuildUVsContents : ForceRebuildUVsContents;
                if (GUI.Button(buttonPropRect, buttonContents))
                {
                    ChiselGeneratedComponentManager.DelayedUVGeneration(force: true);
                }
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(autoRebuildUVsProp, AutoRebuildUVsContents);
                if (EditorGUI.EndChangeCheck())
                {
                    if (autoRebuildUVsProp.boolValue)
                    {
                        ChiselGeneratedComponentManager.ForceUpdateDelayedUVGeneration();
                    }
                }

                showUnwrapParams = EditorGUILayout.Foldout(showUnwrapParams, UnwrapParamsContents, true);
                if (showUnwrapParams)
                {
                    EditorGUI.indentLevel += 1;
                    EditorGUILayout.PropertyField(angleErrorProp);
                    EditorGUILayout.PropertyField(areaErrorProp);
                    EditorGUILayout.PropertyField(hardAngleProp);
                    EditorGUILayout.PropertyField(packMarginPixelsProp);
                    EditorGUI.indentLevel -= 1;
                }

#if UNITY_2017_2_OR_ABOVE
                showEnlightenSettings = IsPrefabAsset || Lightmapping.realtimeGI || (Lightmapping.bakedGI && LightmapEditorSettings.lightmapper == (Lightmapper)0);
                var showProgressiveSettings = IsPrefabAsset || (Lightmapping.bakedGI && LightmapEditorSettings.lightmapper != (Lightmapper)0);
#else
                bool showEnlightenSettings = IsPrefabAsset || Lightmapping.realtimeGI || Lightmapping.bakedGI;
#endif

                if (showEnlightenSettings)
                {
                    showChartingSettings = EditorGUILayout.Foldout(showChartingSettings, UVChartingContents, true);
                    if (showChartingSettings)
                    {
                        RendererUVSettings();
                    }
                }

                showLightmapSettings = EditorGUILayout.Foldout(showLightmapSettings, LightmapSettingContents, true);
                if (showLightmapSettings)
                {
                    EditorGUI.indentLevel += 1;

                    float lightmapScale = LightmapScaleGUI(1.0f);

                    ShowClampedSizeInLightmapGUI(lightmapScale);

                    if (showEnlightenSettings)
                    {
                        EditorGUILayout.PropertyField(importantGIProp, ImportantGIContents);
                    }

#if UNITY_2017_2_OR_ABOVE
                    if (showProgressiveSettings)
                    {
                        EditorGUILayout.PropertyField(stitchLightmapSeamsProp, StitchLightmapSeamsContents);
                    }
#endif

                    if (LightmapParametersGUI != null)
                    {
                        LightmapParametersGUI(lightmapParametersProp, LightmapParametersContents);
                    }

                    EditorGUI.indentLevel -= 1;
                }

                if (TargetsHaveClampedResolution())
                {
                    EditorGUILayout.HelpBox(ClampedPackingResolutionContents.text, MessageType.Warning);
                }

                if ((vertexChannelMaskProp.intValue & (int)VertexChannelFlags.Normal) != (int)VertexChannelFlags.Normal)
                {
                    EditorGUILayout.HelpBox(NoNormalsNoLightmappingContents.text, MessageType.Warning);
                }

                if (TargetsHaveUVOverlaps())
                {
                    EditorGUILayout.HelpBox(UVOverlapContents.text, MessageType.Warning);
                }

                serializedObject.ApplyModifiedProperties();
            }
            else
            {
                EditorGUILayout.HelpBox(LightmapInfoBoxContents.text, MessageType.Info);
            }
        }
Пример #11
0
        void UpdateBrushSelection()
        {
            brushDirectlySelected.Clear();
            var objects = Selection.objects;

            if (objects.Length > 0)
            {
                for (int i = 0; i < objects.Length; i++)
                {
                    var          obj        = objects[i];
                    ChiselNode[] nodes      = null;
                    var          gameObject = obj as GameObject;
                    if (!Equals(null, gameObject))
                    {
                        nodes = gameObject.GetComponentsInChildren <ChiselNode>();
                    }
                    else
                    {
                        var behaviour = obj as Behaviour;
                        if (!Equals(null, behaviour))
                        {
                            nodes = behaviour.GetComponents <ChiselNode>();
                        }
                    }

                    if (nodes != null &&
                        nodes.Length > 0)
                    {
                        for (int n = 0; n < nodes.Length; n++)
                        {
                            var node = nodes[n] as ChiselGeneratorComponent;
                            if (node == null)
                            {
                                continue;
                            }
                            foundTreeBrushes.Clear();
                            ChiselGeneratedComponentManager.GetAllTreeBrushes(node, foundTreeBrushes);
                            if (foundTreeBrushes.Count > 0)
                            {
                                var directSelected = (// if component is directly select
                                    (gameObject == null) ||
                                    // or when the component is part of the selected gameObject
                                    (gameObject == node.gameObject)) &&
                                                     // if we find CSGTreeBrushes directly on this node, but this node
                                                     // can also have child nodes, then we assume the CSGTreeBrushes are generated
                                                     // and we don't want to show those as directly selected
                                                     !node.IsContainer;
                                var transform = ChiselNodeHierarchyManager.FindModelTransformOfTransform(node.hierarchyItem.Transform);
                                foreach (var treeBrush in foundTreeBrushes)
                                {
                                    if (directSelected)
                                    {
                                        brushDirectlySelected.Add(treeBrush);
                                    }
                                    var outline = new BrushOutline(transform, treeBrush);
                                    foundBrushOutlines.Add(outline);
                                }
                            }
                        }
                    }
                }
            }

            if (foundTreeBrushes.Count == 0)
            {
                brushOutlines.Clear();
                brushOutlineRenderer.Clear();
            }
            else
            {
                foreach (var outline in brushOutlines.Keys)
                {
                    if (!foundBrushOutlines.Contains(outline) ||
                        !outline.brush.Valid ||
                        outline.brush.BrushMesh == BrushMeshInstance.InvalidInstance)
                    {
                        removedBrushes.Add(outline);
                    }
                }

                if (removedBrushes.Count > 0)
                {
                    foreach (var outline in removedBrushes)
                    {
                        brushOutlines.Remove(outline);
                    }
                }
                removedBrushes.Clear();

                foreach (var outline in foundBrushOutlines)
                {
                    if (brushOutlines.ContainsKey(outline))
                    {
                        continue;
                    }

                    if (!outline.brush.Valid ||
                        outline.brush.BrushMesh == BrushMeshInstance.InvalidInstance)
                    {
                        continue;
                    }

                    // TODO: should only re-create the wireframe when the brush has changed it's hashes
                    var wireframe = ChiselWireframe.CreateWireframe(outline.brush);
                    brushOutlines[outline] = wireframe;
                }
            }

            foundBrushOutlines.Clear();
            updateBrushWireframe = true;
        }