Exemplo n.º 1
0
        /// <summary>
        ///     Picking sobre un triangulo
        /// </summary>
        public bool pickTriangle(out TgcTriangle triangle, out int triangleIndex)
        {
            pickingRay.updateRay();
            var segmentA = pickingRay.Ray.Origin;
            var segmentB = segmentA + TGCVector3.Scale(pickingRay.Ray.Direction, 10000f);
            var minDist  = float.MaxValue;

            triangle      = null;
            triangleIndex = -1;

            //Buscar la menor colision rayo-triangulo
            for (var i = 0; i < Triangles.Count; i++)
            {
                var tri = Triangles[i];

                float      t;
                TGCVector3 uvw;
                TGCVector3 col;
                if (TgcCollisionUtils.intersectLineTriangle(segmentA, segmentB, tri.A, tri.B, tri.C, out uvw, out t,
                                                            out col))
                {
                    var dist = TGCVector3.Length(col - segmentA);
                    if (dist < minDist)
                    {
                        minDist       = dist;
                        triangle      = tri;
                        triangleIndex = i;
                    }
                }
            }

            return(triangle != null);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Crear a partir de un mesh
        /// </summary>
        public static TgcTriangleArray fromMesh(TgcMesh mesh, TgcD3dInput input)
        {
            var triangleArray = new TgcTriangleArray(input);

            var vertices  = mesh.getVertexPositions();
            var triCount  = vertices.Length / 3;
            var triangles = new List <TgcTriangle>(triCount);

            for (var i = 0; i < triCount; i++)
            {
                var v1 = vertices[i * 3];
                var v2 = vertices[i * 3 + 1];
                var v3 = vertices[i * 3 + 2];

                var t = new TgcTriangle();
                t.A     = v1;
                t.B     = v2;
                t.C     = v3;
                t.Color = Color.Red;
                t.updateValues();
                triangles.Add(t);
            }

            triangleArray.Triangles.AddRange(triangles);
            return(triangleArray);
        }