Ejemplo n.º 1
0
    private int VertexCast(Vector2 viewpos)
    {
        Ray ray = _previewutility.camera.ViewportPointToRay(viewpos);

        if (ray.direction == Vector3.zero || target == null || target.vertices == null)
        {
            return(-1);
        }
        PatternMatch   match          = new PatternMatch(invx, invy, 0);
        float          nearest_t      = Mathf.Infinity;
        int            nearest_sphere = -1;
        float          near_clip      = _previewutility.camera.nearClipPlane;
        float          far_clip       = _previewutility.camera.farClipPlane;
        List <Vector3> vertices       = target.vertices;

        for (int k = 0; k < vertices.Count; k++)
        {
            Vector3 vertex       = Vx.TransformVertex(vertices[k], Vx.ReflVector, match);
            Vector3 point_vector = ray.origin - vertex;
            float   proj_pv      = Vector3.Dot(ray.direction, point_vector);
            float   sqr_magn     = Vector3.SqrMagnitude(point_vector - (proj_pv * ray.direction));
            //check if ray intersects point
            if (sqr_magn > VxlGUI.POINT_RADIUSSQR)
            {
                continue;
            }
            //get t of impact and check if in range
            float t = Mathf.Abs(proj_pv) - Mathf.Sqrt(Mathf.Max(0, VxlGUI.POINT_RADIUSSQR - sqr_magn));
            if (t < near_clip || t > far_clip)
            {
                continue;
            }
            if (t >= nearest_t)
            {
                continue;
            }
            nearest_t      = t;
            nearest_sphere = k;
        }
        return(nearest_sphere);
    }
Ejemplo n.º 2
0
    private void UpdateMesh()
    {
        _meshvertex.Clear();
        _meshnormals.Clear();
        _meshuvs.Clear();
        _meshtriangles.Clear();
        _mesh.Clear();
        if (target == null || !target.IsValid())
        {
            UploadMeshChanges();
            return;
        }
        bool            flip      = (invx && !invy) || (!invx && invy);
        PatternMatch    match     = new PatternMatch(invx, invy, 0);
        List <Vector3>  vertices  = target.vertices;
        List <Triangle> triangles = target.triangles;

        for (int k = 0; k < triangles.Count; k++)
        {
            Triangle tri = triangles[k];
            if (!tri.IsValid(vertices.Count, null, null))
            {
                continue;
            }
            if (flip)
            {
                tri = Triangle.Flip(tri);
            }
            Vector2 uv      = GetTriangleUV(k);
            Vector3 vertex0 = Vx.TransformVertex(vertices[tri.vertex0], Vx.ReflVector, match);
            Vector3 vertex1 = Vx.TransformVertex(vertices[tri.vertex1], Vx.ReflVector, match);
            Vector3 vertex2 = Vx.TransformVertex(vertices[tri.vertex2], Vx.ReflVector, match);
            AddTriangle(vertex0, vertex1, vertex2, uv);
        }
        UploadMeshChanges();
    }
Ejemplo n.º 3
0
    private void DrawVertex()
    {
        if (target == null || !target.IsValid())
        {
            return;
        }
        if (vertex_mesh == null || vertex_mat == null)
        {
            return;
        }
        if (_vertexmode == VertexMode.None)
        {
            return;
        }
        PatternMatch   match   = new PatternMatch(invx, invy, 0);
        List <Vector3> vectors = target.vertices;

        if (_vertexmode == VertexMode.PrimarySelectTriangle)
        {
            int             super_vertex0 = -1; int super_vertex1 = -1; int super_vertex2 = -1;
            HashSet <int>   trivertex = new HashSet <int>();
            List <Triangle> triangles = target.triangles;
            for (int k = 0; k < _primarylist.Count; k++)
            {
                int tri_index = _primarylist[k];
                if (tri_index < 0 || tri_index >= triangles.Count)
                {
                    continue;
                }
                Triangle tri = triangles[tri_index];
                if (!tri.IsValid(vectors.Count, null, null))
                {
                    continue;
                }
                trivertex.Add(tri.vertex0);
                trivertex.Add(tri.vertex1);
                trivertex.Add(tri.vertex2);
                if (k == _primarylist.Count - 1)
                {
                    super_vertex0 = tri.vertex0;
                    super_vertex1 = tri.vertex1;
                    super_vertex2 = tri.vertex2;
                }
            }
            for (int k = 0; k < vectors.Count; k++)
            {
                bool primary_superselect = false;
                bool primary_select      = trivertex.Contains(k);
                if (primary_select)
                {
                    primary_superselect = (super_vertex0 == k) || (super_vertex1 == k) || (super_vertex2 == k);
                }
                bool secondary_superselect = false;
                bool secondary_select      = _secondarytset.Contains(k);
                if (secondary_select)
                {
                    secondary_superselect = _secondarylist[_secondarylist.Count - 1] == k;
                }
                SetMaterialBlock(primary_select, primary_superselect, secondary_select, secondary_superselect);
                _previewutility.DrawMesh(vertex_mesh, Vx.TransformVertex(vectors[k], Vx.ReflVector, match), Quaternion.identity, vertex_mat, 0, _previewblock);
            }
        }
        else
        {
            for (int k = 0; k < vectors.Count; k++)
            {
                bool primary_superselect = false;
                bool primary_select      = _primarytset.Contains(k);
                if (primary_select)
                {
                    primary_superselect = _primarylist[_primarylist.Count - 1] == k;
                }
                bool secondary_superselect = false;
                bool secondary_select      = _secondarytset.Contains(k);
                if (secondary_select)
                {
                    secondary_superselect = _secondarylist[_secondarylist.Count - 1] == k;
                }

                SetMaterialBlock(primary_select, primary_superselect, secondary_select, secondary_superselect);
                _previewutility.DrawMesh(vertex_mesh, Vx.TransformVertex(vectors[k], Vx.ReflVector, match), Quaternion.identity, vertex_mat, 0, _previewblock);
            }
        }
    }