Exemple #1
0
    private static bool MappingBoneWeightToMeshUV(Mesh mesh, UVChannel weightChannel, UVChannel indexChannel, bool overwrite)
    {
        var            boneWeights = mesh.boneWeights;
        List <Vector2> wUV = new List <Vector2>(), iUV = new List <Vector2>();

        mesh.GetUVs((int)weightChannel, wUV);
        mesh.GetUVs((int)indexChannel, iUV);
        if (((wUV != null && wUV.Count != 0) || (iUV != null && iUV.Count != 0)) && !overwrite)
        {
            return(false);
        }
        wUV = new List <Vector2>();
        iUV = new List <Vector2>();
        for (int i = 0; i < boneWeights.Length; i++)
        {
            var bw = boneWeights[i];
            iUV.Add(new Vector2(bw.boneIndex0,
                                bw.boneIndex1));
            wUV.Add(new Vector2(bw.weight0, bw.weight1));
        }
        mesh.SetUVs((int)weightChannel, wUV);
        mesh.SetUVs((int)indexChannel, iUV);
        return(true);
    }
Exemple #2
0
    void OnGUI()
    {
        bakeMode = (BakeMode)EditorGUILayout.EnumPopup("Bake Mode", bakeMode);
        if (bakeMode != BakeMode.BentNormal)
        {
            EditorGUI.BeginDisabledGroup(true);
        }
        bentNormalsSpace = (NormalsSpace)EditorGUILayout.EnumPopup("Normals Space", bentNormalsSpace);
        if (bakeMode != BakeMode.BentNormal)
        {
            EditorGUI.EndDisabledGroup();
        }
        if (bakeMode != BakeMode.NormalsConversion)
        {
            EditorGUI.BeginDisabledGroup(true);
        }
        normalsConversionMode = (NormalsConversionMode)EditorGUILayout.EnumPopup("Conversion Mode", normalsConversionMode);
        if (bakeMode != BakeMode.NormalsConversion)
        {
            EditorGUI.EndDisabledGroup();
        }
        uvChannel = (UVChannel)EditorGUILayout.EnumPopup(new GUIContent("Texture Channel", "The UV channel to use when generating the output texture(s)."), uvChannel);
        bakeRes   = (Resolution)EditorGUILayout.EnumPopup(new GUIContent("Output resolution", "The resolution of the output texture(s)."), bakeRes);
        if (bakeMode == BakeMode.NormalsConversion)
        {
            EditorGUI.BeginDisabledGroup(true);
        }
        samples      = EditorGUILayout.IntSlider(new GUIContent("Sample Count", "The number of depth map samples used for each pixel."), samples, 64, 8192);
        shadowMapRes = (Resolution)EditorGUILayout.EnumPopup(new GUIContent("Depth Map Resolution", "The resolution of the depth map. Probably only have to increase this if baking high-resolution maps for multiple, large objects."), shadowMapRes);
        if (bakeMode == BakeMode.NormalsConversion)
        {
            EditorGUI.EndDisabledGroup();
        }
        dilation = Mathf.Max(EditorGUILayout.IntField(new GUIContent("Dilation", "Adds edge padding to the output."), dilation), 0);
        if (bakeMode == BakeMode.NormalsConversion)
        {
            EditorGUI.BeginDisabledGroup(true);
        }
        shadowBias = EditorGUILayout.Slider(new GUIContent("Depth Bias", "Depth map sampling bias. A larger value will generally give you less artifacts at the cost of loss of accuracy."), shadowBias, 0f, 1f);
        if (bakeMode == BakeMode.NormalsConversion)
        {
            EditorGUI.EndDisabledGroup();
        }
        if (bakeMode != BakeMode.AmbientOcclusion)
        {
            EditorGUI.BeginDisabledGroup(true);
        }
        aoBias = EditorGUILayout.Slider(new GUIContent("AO Bias", "Ambient Occlusion output bias. A value of 0.5 is considered neutral."), aoBias, 0f, 1f);
        if (bakeMode != BakeMode.AmbientOcclusion)
        {
            EditorGUI.EndDisabledGroup();
        }
        if (bakeMode == BakeMode.NormalsConversion)
        {
            EditorGUI.BeginDisabledGroup(true);
        }
        clampToHemisphere = EditorGUILayout.Toggle(new GUIContent("Clamp To Hemisphere", "Discard samples that would intersect the pixel's own surface."), clampToHemisphere);
        includeScene      = EditorGUILayout.Toggle(new GUIContent("Include Scene", "If checked, will include other non-selected objects in the scene when rendering the depth map."), includeScene);
        if (bakeMode == BakeMode.NormalsConversion)
        {
            EditorGUI.EndDisabledGroup();
        }
        forceSharedTexture = EditorGUILayout.Toggle(new GUIContent("Force Shared Texture", "If checked, will render all selected objects into the same output texture. Useful if you are baking multiple objects which share a texture, but don't share materials. Objects with the same material will still be grouped even if this is not checked."), forceSharedTexture);
        if (bakeMode == BakeMode.NormalsConversion)
        {
            EditorGUI.BeginDisabledGroup(true);
        }
        if (forceSharedTexture)
        {
            EditorGUI.BeginDisabledGroup(true);
        }
        useNormalMaps = EditorGUILayout.Toggle(new GUIContent("Use Normal Maps", "If checked, the baker will include any normal maps present on the original materials when baking. This can give a higher quality result if the bake resolution is high enough."), useNormalMaps);
        if (forceSharedTexture)
        {
            EditorGUI.EndDisabledGroup();
        }
        useOriginalShaders = EditorGUILayout.Toggle(new GUIContent("Use Original Shaders", "Bake the depth maps using the objects' original shaders. This is useful if you are using vertex-modifying shaders, but also prevents overriding the face cull mode."), useOriginalShaders);
        if (useOriginalShaders)
        {
            EditorGUI.BeginDisabledGroup(true);
        }
        cullOverrideMode = (CullOverrideMode)EditorGUILayout.EnumPopup(new GUIContent("Face Cull Override", "Force double or single-sided rendering. In most cases you probably want to force double-sided."), cullOverrideMode);
        if (useOriginalShaders)
        {
            EditorGUI.EndDisabledGroup();
        }
        if (bakeMode == BakeMode.NormalsConversion)
        {
            EditorGUI.EndDisabledGroup();
        }

        transparentPixels = EditorGUILayout.Toggle(new GUIContent("Transparent Background", "Whether to fill background pixels in the output texture with neutral values or leave them blank."), transparentPixels);
        GUILayout.Space(4);
        outputPath = EditorGUILayout.TextField("Output Folder", outputPath);
        nameMode   = (NameMode)EditorGUILayout.EnumPopup(new GUIContent("Output Names", "How to determine the output file name. Only used if multiple objects which share materials are selected."), nameMode);
        var rect = GUILayoutUtility.GetLastRect();

        if (Selection.gameObjects.Length < 1)
        {
            EditorGUI.BeginDisabledGroup(true);
        }
        if (GUILayout.Button(Selection.gameObjects.Length < 1 ? "Select some objects to bake!" : (Selection.gameObjects.Length == 1 ? "Bake Selected Object" : "Bake Selected Objects")))
        {
            Bake(Selection.gameObjects);
        }
        if (Selection.gameObjects.Length < 1)
        {
            EditorGUI.EndDisabledGroup();
        }
    }
Exemple #3
0
 public static string GetUVName(this UVChannel channel)
 {
     return(UV[(int)channel]);
 }
 public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability)
 {
     return(channel == UVChannel.UV0);
 }
Exemple #5
0
 public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability)
 {
     return(true);
 }
 public UVMaterialSlot(int slotId, string displayName, string shaderOutputName, UVChannel channel,
                       ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
     : base(slotId, displayName, shaderOutputName, SlotType.Input, Vector2.zero, stageCapability, hidden: hidden)
 {
     this.channel = channel;
 }
Exemple #7
0
 public bool RequiresMeshUV(UVChannel channel)
 {
     return(channel == uvChannel);
 }
Exemple #8
0
        public void Draw(Rect rect, MeshSource meshSource, List <Vector2> uvBuffer, EditorWindow host)
        {
            Rect leftBorder = rect;

            leftBorder.width = 1;

            Rect cursorRect = rect;

            cursorRect.width = 10;
            cursorRect.x    -= 5;

            if (Event.current.type == EventType.MouseDown && cursorRect.Contains(Event.current.mousePosition))
            {
                resize = true;
                Event.current.Use();
            }

            if (resize && Event.current.type == EventType.MouseDrag)
            {
                normalizedPosition = Event.current.mousePosition.x / EditorGUIUtility.currentViewWidth;
                Event.current.Use();

                if (Event.current.type == EventType.MouseDrag)
                {
                    host.Repaint();
                }
            }

            if (Event.current.type == EventType.MouseUp)
            {
                resize = false;
            }

            EditorGUIUtility.AddCursorRect(cursorRect, MouseCursor.ResizeHorizontal);

            rect = rect.Expand(-4);
            GUILayout.BeginArea(rect);

            float labelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 100;

            EditorGUILayout.LabelField("UV", EditorStyles.boldLabel);
            EditorGUI.indentLevel++;

            UVWindowSettings.uvAlpha.value = EditorGUILayout.Slider("Alpha", UVWindowSettings.uvAlpha, 0f, 1f);
            UVWindowSettings.uvColor.value = EditorGUILayout.ColorField(
                new GUIContent("Color"),
                UVWindowSettings.uvColor,
                showEyedropper: true,
                showAlpha: false,
                hdr: false);

            EditorGUI.BeginChangeCheck();
            uvChannel = (UVChannel)EditorGUILayout.EnumPopup("Channel", uvChannel);
            if (EditorGUI.EndChangeCheck())
            {
                if (meshSource != null)
                {
                    meshSource.Mesh.GetUVs((int)uvChannel, uvBuffer);

                    if (uvBuffer.Count == 0)
                    {
                        host.ShowNotification(new GUIContent($"No {uvChannel.ToString()} found."));
                    }
                    else
                    {
                        host.RemoveNotification();
                    }
                }
            }

            EditorGUI.indentLevel--;

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Texture", EditorStyles.boldLabel);
            EditorGUI.indentLevel++;

            EditorGUI.BeginChangeCheck();
            UVWindowSettings.textureAlpha.value = EditorGUILayout.Slider("Alpha", UVWindowSettings.textureAlpha, 0f, 1f);
            if (EditorGUI.EndChangeCheck())
            {
                previewMaterial.SetFloat("_Alpha", UVWindowSettings.textureAlpha);
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Color");

            EditorGUI.BeginChangeCheck();
            colorChannel = (ColorChannel)GUILayout.Toolbar((int)colorChannel, colorChannelLabels, GUI.skin.button, GUI.ToolbarButtonSize.FitToContents);
            if (EditorGUI.EndChangeCheck())
            {
                UpdatePreviewMaterialColorMask();
            }

            EditorGUILayout.EndHorizontal();

            using (new EditorGUI.DisabledScope(meshSource.HasMaterial == false))
            {
                if (meshSource.HasMaterial)
                {
                    string[] names = meshSource.Material.GetTexturePropertyNames()
                                     .Where(x => meshSource.Material.HasProperty(x)).ToArray();

                    int selectedIndex = System.Array.IndexOf(names, texturePropertyName);

                    if (selectedIndex == -1)
                    {
                        selectedIndex = 0;
                    }

                    EditorGUI.BeginChangeCheck();
                    selectedIndex = EditorGUILayout.Popup("Source Map", selectedIndex, names);
                    if (EditorGUI.EndChangeCheck())
                    {
                        texturePropertyName = names[selectedIndex];
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("Source Map", "<None>");
                }
            }

            EditorGUI.indentLevel--;

            EditorGUIUtility.labelWidth = labelWidth;
            GUILayout.EndArea();

            EditorGUI.DrawRect(leftBorder, new Color32(35, 35, 35, 255));
        }
        public static bool RequiresMeshUV(this ISlot slot, UVChannel channel)
        {
            var mayRequireMeshUV = slot as IMayRequireMeshUV;

            return(mayRequireMeshUV != null && mayRequireMeshUV.RequiresMeshUV(channel));
        }
Exemple #10
0
 public UVMaterialSlot(int slotId, string displayName, string shaderOutputName, UVChannel channel,
                       ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
     : base(slotId, displayName, shaderOutputName, SlotType.Input, Vector2.zero, shaderStage, hidden)
 {
     this.channel = channel;
 }
Exemple #11
0
 public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability = ShaderStageCapability.All)
 => channel == UVChannel.UV0 && stageCapability == ShaderStageCapability.Fragment;