Beispiel #1
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = VectorHash.GetHashCode(normal);
         hashCode = (hashCode * 397) ^ VectorHash.GetHashCode(tangent);
         hashCode = (hashCode * 397) ^ VectorHash.GetHashCode(bitangent);
         return(hashCode);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Creates a new hashcode from position, uv0, and normal.
 /// </summary>
 /// <returns>A hashcode for this object.</returns>
 public override int GetHashCode()
 {
     // 783 is 27 * 29
     unchecked
     {
         int hash = 783 + VectorHash.GetHashCode(position);
         hash = hash * 29 + VectorHash.GetHashCode(uv0);
         hash = hash * 31 + VectorHash.GetHashCode(normal);
         return(hash);
     }
 }
        /// <summary>
        /// Select vertex indexes contained within a rect.
        /// </summary>
        /// <param name="camera"></param>
        /// <param name="pickerRect"></param>
        /// <param name="selection"></param>
        /// <param name="doDepthTest"></param>
        /// <param name="renderTextureWidth"></param>
        /// <param name="renderTextureHeight"></param>
        /// <returns>A dictionary of pb_Object selected vertex indexes.</returns>
        public static Dictionary <ProBuilderMesh, HashSet <int> > PickVerticesInRect(
            Camera camera,
            Rect pickerRect,
            IList <ProBuilderMesh> selection,
            bool doDepthTest,
            int renderTextureWidth  = -1,
            int renderTextureHeight = -1)
        {
            Dictionary <uint, SimpleTuple <ProBuilderMesh, int> > map;
            Dictionary <ProBuilderMesh, HashSet <int> >           selected = new Dictionary <ProBuilderMesh, HashSet <int> >();

#if PB_RENDER_PICKER_TEXTURE
            List <Color> rectImg = new List <Color>();
#endif

            Texture2D tex = RenderSelectionPickerTexture(camera, selection, doDepthTest, out map, renderTextureWidth, renderTextureHeight);
            Color32[] pix = tex.GetPixels32();

            int ox          = System.Math.Max(0, Mathf.FloorToInt(pickerRect.x));
            int oy          = System.Math.Max(0, Mathf.FloorToInt((tex.height - pickerRect.y) - pickerRect.height));
            int imageWidth  = tex.width;
            int imageHeight = tex.height;
            int width       = Mathf.FloorToInt(pickerRect.width);
            int height      = Mathf.FloorToInt(pickerRect.height);
            UObject.DestroyImmediate(tex);

            SimpleTuple <ProBuilderMesh, int> hit;
            HashSet <int>  indexes = null;
            HashSet <uint> used    = new HashSet <uint>();

            for (int y = oy; y < System.Math.Min(oy + height, imageHeight); y++)
            {
                for (int x = ox; x < System.Math.Min(ox + width, imageWidth); x++)
                {
                    uint v = DecodeRGBA(pix[y * imageWidth + x]);

#if PB_RENDER_PICKER_TEXTURE
                    rectImg.Add(pix[y * imageWidth + x]);
#endif

                    if (used.Add(v) && map.TryGetValue(v, out hit))
                    {
                        if (selected.TryGetValue(hit.item1, out indexes))
                        {
                            indexes.Add(hit.item2);
                        }
                        else
                        {
                            selected.Add(hit.item1, new HashSet <int>()
                            {
                                hit.item2
                            });
                        }
                    }
                }
            }

            var coincidentSelection = new Dictionary <ProBuilderMesh, HashSet <int> >();

            // workaround for picking vertices that share a position but are not shared
            foreach (var meshSelection in selected)
            {
                var positions      = meshSelection.Key.positionsInternal;
                var sharedVertices = meshSelection.Key.sharedVerticesInternal;
                var positionHash   = new HashSet <int>(meshSelection.Value.Select(x => VectorHash.GetHashCode(positions[sharedVertices[x][0]])));
                var collected      = new HashSet <int>();

                for (int i = 0, c = sharedVertices.Length; i < c; i++)
                {
                    var hash = VectorHash.GetHashCode(positions[sharedVertices[i][0]]);
                    if (positionHash.Contains(hash))
                    {
                        collected.Add(i);
                    }
                }

                coincidentSelection.Add(meshSelection.Key, collected);
            }
            selected = coincidentSelection;

#if PB_RENDER_PICKER_TEXTURE
            if (width > 0 && height > 0)
            {
                Texture2D img = new Texture2D(width, height);
                img.SetPixels(rectImg.ToArray());
                img.Apply();
                System.IO.File.WriteAllBytes("Assets/rect_" + s_RenderTextureFormat.ToString() + ".png", img.EncodeToPNG());
#if UNITY_EDITOR
                UnityEditor.AssetDatabase.Refresh();
#endif
                UObject.DestroyImmediate(img);
            }
#endif

            return(selected);
        }
Beispiel #4
0
 public override int GetHashCode()
 {
     return(VectorHash.GetHashCode(value));
 }