Ejemplo n.º 1
0
    // Use this for initialization
    public ListPooler()
    {
        poolingList        = new List <List <Vector3> >();
        poolingListVector4 = new List <List <Vector4> >();
        poolingListVector2 = new List <List <Vector2> >();

        poolingLinkedList        = new List <BetterLinkedList <Vector3> >();
        poolingLinkedListVector4 = new List <BetterLinkedList <Vector4> >();
        poolingLinkedListVector2 = new List <BetterLinkedList <Vector2> >();

        poolingListBoneWeight = new List <List <BoneWeight> >();

        poolingListIndexes = new List <List <int> >();
        poolingHashSets    = new List <OrderedHashSet <Vector3> >();
        comparer           = new VectorEqualityComparer();
    }
Ejemplo n.º 2
0
        public float StartShaping(Vector3 point, Matrix4 vm, bool isMirror, float radius, ShapeCoefType type)
        {
            EndShape();
            var depth = -10000.0f;

            foreach (var part in headMeshController.RenderMesh.Parts)
            {
                for (var i = 0; i < part.Indices.Count; i += 3)
                {
                    var p0 = Vector3.Transform(part.Vertices[part.Indices[i]].Position, vm);
                    var p1 = Vector3.Transform(part.Vertices[part.Indices[i + 1]].Position, vm);
                    var p2 = Vector3.Transform(part.Vertices[part.Indices[i + 2]].Position, vm);

                    var a = p0.Xy;
                    var b = p1.Xy;
                    var c = p2.Xy;

                    if (TexturingInfo.PointInTriangle(ref a, ref b, ref c, ref point))
                    {
                        var aup = a.X - point.X;
                        var bup = b.X - point.X;
                        var cup = c.X - point.X;
                        var avp = a.Y - point.Y;
                        var bvp = b.Y - point.Y;
                        var cvp = c.Y - point.Y;

                        var f = 1.0f / ((b.X - a.X) * (c.Y - a.Y) - (b.Y - a.Y) * (c.X - a.X));
                        var u = (bup * cvp - bvp * cup) * f;
                        var v = (cup * avp - cvp * aup) * f;
                        var w = 1.0f - (u + v);

                        var z = u * p0.Z + v * p1.Z + w * p2.Z;
                        if (depth < z)
                        {
                            startPart     = part;
                            startTriangle = i;
                            depth         = z;
                        }
                    }
                }
            }

            if (startPart == null || startTriangle < 0)
            {
                return(0.0f);
            }

            ShapePoint          = point;
            ShapePoint.Z        = depth;
            ShapePoint          = Vector3.Transform(ShapePoint, vm.Inverted());
            startTriangleMirror = -1;
            if (isMirror)
            {
                //Ищем точку в оригинальных координатах
                var triangle = new[] { startPart.Indices[startTriangle], startPart.Indices[startTriangle + 1], startPart.Indices[startTriangle + 2] };
                var a        = startPart.Vertices[triangle[0]].OriginalPosition;
                var b        = startPart.Vertices[triangle[1]].OriginalPosition;
                var c        = startPart.Vertices[triangle[2]].OriginalPosition;
                a.X   *= -1.0f;
                b.X   *= -1.0f;
                c.X   *= -1.0f;
                isLeft = ShapePoint.X < 0.0f ? 1.0f : -1.0f;
                int idA = -1, idB = -1, idC = -1;
                for (int i = 0; i < startPart.Vertices.Length; i++)
                {
                    if (idA >= 0 && idB >= 0 && idC >= 0)
                    {
                        break;
                    }
                    var position = startPart.Vertices[i].OriginalPosition;
                    if (position.X * isLeft >= 0.0f)
                    {
                        if (idA < 0 && VectorEqualityComparer.EqualsVector3(position, a))
                        {
                            idA = i;
                            continue;
                        }
                        if (idB < 0 && VectorEqualityComparer.EqualsVector3(position, b))
                        {
                            idB = i;
                            continue;
                        }
                        if (idC < 0 && VectorEqualityComparer.EqualsVector3(position, c))
                        {
                            idC = i;
                            continue;
                        }
                    }
                }
                if (idA >= 0 && idB >= 0 && idC >= 0)
                {
                    for (int i = 0; i < startPart.Indices.Count; i += 3)
                    {
                        var v0 = startPart.Indices[i];
                        var v1 = startPart.Indices[i + 1];
                        var v2 = startPart.Indices[i + 2];
                        if ((v0 == idA || v0 == idB || v0 == idC) && (v1 == idA || v1 == idB || v1 == idC) && (v2 == idA || v2 == idB || v2 == idC))
                        {
                            startTriangleMirror = i;
                            break;
                        }
                    }
                }
            }
            if (!UpdateRadius(radius))
            {
                return(0.0f);
            }
            UpdateCoef(type, radius);
            return(depth);
        }