void SetPointsToLine()
    {
        //create old positions if they dont match
        if (linePositionsOld.Length != linePositions.Length)
        {
            linePositionsOld = new Vector3[linePositions.Length];
        }

        //check if line points have moved
        bool moved = false;

        for (int i = 0; i < linePositions.Length; i++)
        {
            //compare
            if (linePositions[i] != linePositionsOld[i])
            {
                moved = true;
            }
        }

        //update if moved
        if (moved == true)
        {
            LineRenderer line = this.GetComponent <LineRenderer>();

            //get smoothed values
            Vector3[] smoothedPoints = LineSmoother.SmoothLine(linePositions, lineSegmentSize);

            //set line settings
            line.SetVertexCount(smoothedPoints.Length);
            line.SetPositions(smoothedPoints);
            line.SetWidth(lineWidth, lineWidth);
        }
    }
    public void UpdateLineRenderer()
    {
        if (trans == null)
        {
            trans = transform;
        }

        if (lineRenderer == null)
        {
            lineRenderer = trans.GetComponent <LineRenderer> ();
        }
        //get smoothed values
        Vector3[] smoothedPoints = LineSmoother.SmoothLine(linePoints, lineSegmentSize);
        for (int i = 0; i < smoothedPoints.Length; i++)
        {
            //convert the local space points to global space
            smoothedPoints[i] = trans.TransformPoint(smoothedPoints[i]);
        }

        //set line settings
        lineRenderer.SetVertexCount(smoothedPoints.Length);
        lineRenderer.SetPositions(smoothedPoints);
        lineRenderer.SetWidth(lineWidth, lineWidth);
        lineRenderer.material = lineMaterial;
    }
Exemplo n.º 3
0
    public override void OnDraggingInUpdate()
    {
        Vector3 notNormalized    = transform.position - transform.parent.position;
        Vector3 direction        = notNormalized.normalized;
        float   distanceToTarget = (direction * 2.3f).magnitude;

        if (notNormalized.magnitude > distanceToTarget)
        {
            linePoints = lr.gameObject.GetComponentsInChildren <CurvedLinePoint>();

            Vector3 midPoint = Vector3.Lerp(transform.parent.position, transform.position - direction * 2.3f, 0.5f);
            linePositions = new Vector3[linePoints.Length];

            midPoint += new Vector3(0, 0, -lr.positionCount * 0.1f);
            if (midPoint.z > 0)
            {
                midPoint.z = 0;
            }
            if (midPoint.z < -10f)
            {
                midPoint.z = -10f;
            }

            if (lr.positionCount < 2)
            {
                midPoint.z = 0;
            }

            linePoints[0].transform.position = transform.parent.position;
            linePoints[1].transform.position = midPoint;
            linePoints[2].transform.position = transform.position - direction * 1.5f;

            linePositions[0] = linePoints[0].transform.position;
            linePositions[1] = linePoints[1].transform.position;
            linePositions[2] = linePoints[2].transform.position;

            if (linePositionsOld.Length != linePositions.Length)
            {
                linePositionsOld = new Vector3[linePositions.Length];
            }

            Vector3[] smoothedPoints = LineSmoother.SmoothLine(linePositions, 2);

            lr.positionCount = smoothedPoints.Length;
            lr.SetPositions(smoothedPoints);

            lr.enabled                    = true;
            triangleSR.enabled            = true;
            triangleSR.transform.position = transform.position - 1.35f * direction;

            float rot_z = Mathf.Atan2(notNormalized.y, notNormalized.x) * Mathf.Rad2Deg;
            triangleSR.transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90);
        }
        else
        {
            lr.enabled         = false;
            triangleSR.enabled = false;
        }
    }
    /// <summary>
    /// Simplify the drawn line and assign it to the road editor.
    /// </summary>
    private void finalizeLine()
    {
        MeshRoad road = (MeshRoad)target;

        List <Vector3> simplifiedLine = LineSmoother.biasedMovingAverages(roadLinePoints, road.averageWindow);

        road.setRoadLinePoints(simplifiedLine);
        roadLinePoints.Clear(); // No need to keep this data twice

        road.debugRoadLine();
    }
Exemplo n.º 5
0
    private void SetPoints()
    {
        if (this.coroutine != null)
        {
            StopCoroutine(this.coroutine);
            this.coroutine = null;
        }

        this.line.positionCount = 0;
        this.smoothPoints       = LineSmoother.SmoothLine(this.Points.ToArray(), 0.4f);
        this.coroutine          = StartCoroutine(this.AddPoint());
    }
Exemplo n.º 6
0
    private void DrawLine(List <Vector3> posList)
    {
        var x = LineSmoother.SmoothLine(posList.ToArray(), 0.5f);

        linerenderer.material      = lineMat;
        linerenderer.textureMode   = LineTextureMode.Tile;
        linerenderer.startWidth    = 0.5f;
        linerenderer.endWidth      = 0.5f;
        linerenderer.positionCount = x.Length - 1;
        linerenderer.SetPositions(x);
        linerenderer.useWorldSpace = true;
    }
Exemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Mouse0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.tag == "Player1")
                {
                    drawLine1          = true;
                    lineRender.enabled = true;
                }


                if (Distancetolastpiont(hit.point) > .5f && drawLine1)
                {
                    pionts.Add(hit.point);

                    lineRender.positionCount = pionts.Count;

                    lineRender.SetPositions(pionts.ToArray());
                    LineSmoother.SmoothLine(pionts.ToArray(), .1f);
                }


                if (hit.collider.tag == "Finish1")
                {
                    drawLine1 = false;
                    FindObjectOfType <CollsionDetection>().ResetPosition();
                    FindObjectOfType <LineFollower>().speed = 10;
                }
            }
        }
        else if (Input.GetKeyUp(KeyCode.Mouse0))
        {
            if (lineRender.enabled)
            {
                print("mouseup");
                behaviour1.enabled = true;
            }
            else
            {
                behaviour1.enabled = false;
            }
        }
    }
Exemplo n.º 8
0
    public void UpdateEllipse()
    {
        //Ellipse points;
        float imax = 10;

        Vector3[] points = new Vector3[(int)imax + 1];
        for (float i = 1; i <= imax + 1; ++i)
        {
            float x = systemCenter.x + (semimajor * Mathf.Cos(Mathf.PI * (i / (imax / 2.0f))));
            float y = systemCenter.y + (semiminor * Mathf.Sin(Mathf.PI * (i / (imax / 2.0f))));
            points[(int)i - 1] = new Vector3(x, y, transform.position.z);
        }


        Vector3[] smoothPoints = LineSmoother.SmoothLine(points, 0.1f);

        ellipseRenderer = GetComponent <LineRenderer>();
        ellipseRenderer.positionCount = smoothPoints.Length;
        ellipseRenderer.SetPositions(smoothPoints);

        transform.position = points[0];
    }
Exemplo n.º 9
0
    // Update is called once per frame
    public void UpdateRender(float segLength, float kStand,
                             float connectLength, float connectKStand,
                             float exponent, float scale,
                             float guideConnectK, float guideConnectLength, float guideConnectDamp)
    {
        //get all hair positions at current time (then won't be inconsistencies when doing math with connections)
        List <Vector3> hairPointPos = new List <Vector3>();

        for (int i = 0; i < segAmount; i++)
        {
            hairPointPos.Add(segment[i].Position);
        }

        //get current grav and k strengths
        float   k         = calculateK(kStand, area, segLength);
        float   connectK  = calculateK(connectKStand, area, connectLength);
        Vector3 anchorPos = anchor.transform.position + anchorOffset;


        //previous point in hair chain
        Vector3 prevObjectPos = anchorPos;
        //slightly offset anchors for points close to anchor to connect to (adds curl at top of hair)
        Vector3 anchorStand1 = anchorPos - new Vector3(1, 1, 2);
        Vector3 anchorStand2 = anchorPos - new Vector3(-1, 2, 1);

        //Math time
        for (int i = 0; i < segAmount; i++)
        {
            //get force from gravity and connection to previous hair point
            Vector3 springForce = calculateSpringForce(segLength, k, damping, segment[i].Position, prevObjectPos, segment[i].Velocity);
            Vector3 force       = springForce;

            //add force from connection to next hair point
            if (i < segAmount - 1)
            {
                Vector3 nextobjpos = hairPointPos[i + 1];
                force += calculateSpringForce(segLength, k, damping, segment[i].Position, nextobjpos, segment[i].Velocity);
            }

            //add connection to offset anchors for first two points in hair chain (ensures curl at top of chain)
            switch (i)
            {
            case 0:
                force += calculateSpringForce(connectLength, connectK, connectDamping, segment[i].Position, anchorStand1, segment[i].Velocity);

                goto case 1;

            case 1:
                force += calculateSpringForce(connectLength, connectK, connectDamping, segment[i].Position, anchorStand2, segment[i].Velocity);
                break;
            }

            //add connections to 2 point before and 2 points after immediate hair neighbors
            List <Vector3> connectPositions = new List <Vector3>();
            if (i == 1 || i == 2)
            {
                connectPositions.Add(anchorPos);
            }
            if (i > 1)
            {
                connectPositions.Add(hairPointPos[i - 2]);
            }
            if (i > 2)
            {
                connectPositions.Add(hairPointPos[i - 3]);
            }
            if (i < segAmount - 2)
            {
                connectPositions.Add(hairPointPos[i + 2]);
            }
            if (i < segAmount - 3)
            {
                connectPositions.Add(hairPointPos[i + 3]);
            }

            for (int j = 0; j < connectPositions.Count; j++)
            {
                force += calculateSpringForce(connectLength, connectK, connectDamping, segment[i].Position, connectPositions[j], segment[i].Velocity);
            }

            //add force to guide
            Vector3 approxPos = guideCreator.segment[i].Position;
            force += calculateSpringForce(guideConnectLength, guideConnectK, guideConnectDamp, segment[i].Position, approxPos, segment[i].Velocity, false);

            //calculate new position for hair point
            Vector3 acceleration = force / segment[i].Mass;
            Vector3 newVel       = segment[i].Velocity + acceleration * timestep;
            Vector3 newPos       = segment[i].Position + newVel * timestep;

            //adjust new position based on current distance from guide strand
            float distance   = (newPos - guideCreator.segment[i].Position).magnitude;
            float difference = Mathf.Abs(distance - guideConnectLength);

            // multiplier between 0 and 1: 0 when distance is very small and near 1 when distance is large
            float multiplier = 1 - (1 / (scale * difference + 1));
            multiplier    = Mathf.Pow(multiplier, exponent);
            acceleration *= multiplier;
            newVel        = segment[i].Velocity + acceleration * timestep;
            newVel       *= multiplier / 2;
            newPos        = segment[i].Position + newVel * timestep;

            segment[i].Velocity = newVel;
            segment[i].Position = newPos;


            prevObjectPos = segment[i].Position;
        }

        //NOT MY CODE; lifted from internet to make a smooth curve between all the points instead of jagged lines
        Vector3[] linePositions = new Vector3[segAmount + 1];
        linePositions[0] = anchorPos;
        for (int i = 0; i < segAmount; i++)
        {
            linePositions[i + 1] = segment[i].Position;
        }
        float lineSegmentSize = 3f;

        //get smoothed values
        Vector3[] smoothedPoints = LineSmoother.SmoothLine(linePositions, lineSegmentSize);

        //set line settings
        hair.positionCount = smoothedPoints.Length;
        hair.SetPositions(smoothedPoints);
    }
Exemplo n.º 10
0
 void ApplyToLineRenderer()
 {
     linePositions = LineSmoother.SmoothLine(linePositions, 50f);
 }
Exemplo n.º 11
0
    public override void OnDraggingInUpdate()
    {
        Vector3 notNormalized    = transform.position - transform.parent.position;
        Vector3 direction        = notNormalized.normalized;
        float   distanceToTarget = (direction * 2.3f).magnitude;

        if (notNormalized.magnitude > distanceToTarget)
        {
            //find curved points in children
            linePoints = lr.gameObject.GetComponentsInChildren <CurvedLinePoint>();

            //add positions
            Vector3 midPoint = Vector3.Lerp(transform.parent.position, transform.position - direction, 0.5f);
            linePositions = new Vector3[linePoints.Length];

            //Define midpoint height via numbers of line positions and set min max heights.
            midPoint += new Vector3(0, 0, -lr.positionCount * 0.1f);
            if (midPoint.z > 0)
            {
                midPoint.z = 0;
            }
            if (midPoint.z < -5f)
            {
                midPoint.z = -5f;
            }

            //If linerendere distance is short, set heights to zero, if we don't do this there will be a "height artifact" when line is short
            if (lr.positionCount < 2)
            {
                midPoint.z = 0;
            }

            //Set line points according to start mid and end of line
            linePoints[0].transform.position = transform.parent.position;
            linePoints[1].transform.position = midPoint;
            linePoints[2].transform.position = transform.position - direction * 2f;

            //Set linerender positions defined by line points
            linePositions[0] = linePoints[0].transform.position;
            linePositions[1] = linePoints[1].transform.position;
            linePositions[2] = linePoints[2].transform.position;

            //create old positions if they dont match
            if (linePositionsOld.Length != linePositions.Length)
            {
                linePositionsOld = new Vector3[linePositions.Length];
            }

            //get smoothed values
            Vector3[] smoothedPoints = LineSmoother.SmoothLine(linePositions, 2);

            //set line settings
            lr.positionCount = smoothedPoints.Length;
            lr.SetPositions(smoothedPoints);

            lr.enabled = true;

            // position the end of the arrow between near the target.
            triangleSR.enabled            = true;
            triangleSR.transform.position = transform.position - 1.5f * direction;

            // proper rotarion of arrow end
            float rot_z = Mathf.Atan2(notNormalized.y, notNormalized.x) * Mathf.Rad2Deg;
            triangleSR.transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90);
        }
        else
        {
            // if the target is not far enough from creature, do not show the arrow
            lr.enabled         = false;
            triangleSR.enabled = false;
        }
    }
Exemplo n.º 12
0
    public void ParseFile()
    {
        topY              = -99999; bottomY = 99999; leftX = 99999; rightX = -99999; frontZ = 99999; backZ = -99999;
        startTime         = Time.realtimeSinceStartup;
        ConsoleText.text += string.Format(" Reading in DSSP file...");
        DSSPfile          = GetComponent <HttpTest>().outputfile;
        string pattern = @"([0-9]+)\s+(\S+)\s+([A-Z]+)\s+([A-Z]+)..(.)...........(....)(...)(...)(............)(...........)(...........)(...........)(........)(......)(......)(......)(......)\s+(\S+)\s+(\S+)\s+(\S+..)";

        string getnumAA = @"([0-9]+)\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+TOTAL NUMBER OF RESIDUES";

        string newmolpattern = @"!*             0   0    0      0, 0.0     0, 0.0     0, 0.0     0, 0.0   0.000 360.0 360.0 360.0 360.0    0.0    0.0    0.0";

        string header = @"#  RESIDUE AA STRUCTURE BP1 BP2  ACC     N-H-->O    O-->H-N    N-H-->O    O-->H-N    TCO  KAPPA ALPHA  PHI   PSI    X-CA   Y-CA   Z-CA            CHAIN AUTHCHAIN";

        // get total num of amino acids in the protein complex
        Regex getnumAAr = new Regex(getnumAA);
        int   numaa     = Convert.ToInt32(getnumAAr.Match(DSSPfile).Groups[1].ToString());

        ConsoleText.text += string.Format("\n Total number of amino acids: {0}", numaa);

        if (Regex.Split(Regex.Split(DSSPfile, header)[1], newmolpattern) == null)
        {
            ConsoleText.text += string.Format("\n string[] molecules is null.");
        }

        string[] molecules = Regex.Split(Regex.Split(DSSPfile, header)[1], newmolpattern);
        int      totmolnum = molecules.Length;                                                         // index of molecule. total num of molecules in a protein complex

        List <SecondaryStructure[]> MoleculesSecondaryAssignments = new List <SecondaryStructure[]>(); // We want to make lists of the above vectors per molecule
        List <Vector3[]>            MoleculesCAPoints             = new List <Vector3[]>();

        foreach (string molecule in molecules)
        {
            int te = 0; // temp
            SecondaryStructure[] structure = new SecondaryStructure[Regex.Matches(molecule, pattern).Count];
            Vector3[]            points    = new Vector3[Regex.Matches(molecule, pattern).Count];

            if (Regex.Matches(molecule, pattern) == null)
            {
                ConsoleText.text += string.Format("\n Error reading DSSP file. Regex pattern returned no matches. Matches is null.");
            }

            foreach (Match matches in Regex.Matches(molecule, pattern))
            {
                structure[te].structure = matches.Groups[5].ToString();

                points[te] = new Vector3(float.Parse(matches.Groups[18].ToString()),
                                         float.Parse(matches.Groups[19].ToString()),
                                         float.Parse(matches.Groups[20].ToString()));
                te++;
            }

            MoleculesSecondaryAssignments.Add(structure);
            MoleculesCAPoints.Add(points);
        }

        GameObject ThisFile = new GameObject();

        ThisFile.name                    = string.Format("File {0}", GetComponent <Load>().FileNumber);
        ThisFile.transform.parent        = GameObject.Find("MoleculeCollection").transform;
        ThisFile.transform.localPosition = Vector3.zero;
        ThisFile.transform.localScale    = Vector3.one;
        GameObject RibbonCollection = new GameObject();

        RibbonCollection.name                    = "RibbonCollection";
        RibbonCollection.transform.parent        = ThisFile.transform;
        RibbonCollection.transform.localPosition = Vector3.zero;
        RibbonCollection.transform.localScale    = Vector3.one;
        // TODO : Put this in script Ribbon.cs as "DrawRibbon(Vector3 points)"
        GameObject ThisPDB = new GameObject();

        ThisPDB.name                 = string.Format("PDB{0}", GetComponent <Load>().FileNumber);
        ThisPDB.transform.parent     = RibbonCollection.transform;
        ThisPDB.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
        //ThisPDB.transform.localPosition = new Vector3(0.75f, 0, 0) * (numPDB - 1);

        GameObject MoleculeHolder = new GameObject();

        MoleculeHolder.transform.parent = ThisPDB.transform;
        MeshFilter[] meshFilters = new MeshFilter[totmolnum];
        ConsoleText.text += string.Format("\n Total number of molecules: {0}.", totmolnum);
        Vector3    offset = new Vector3(0, 0f, 0f);
        GameObject parent = GameObject.Find("Hologram Collection"); // TODO: Remove find

        for (int tem = 0; tem < totmolnum; tem++)
        {
            // Make a new vector that has more points in it so it is smoother
            // The higher the second number, the more points and thus smoother lines. Changes smoothness exponentially relative to number of amino acids.
            Vector3[] newPoints = LineSmoother.SmoothLine(MoleculesCAPoints[tem], 0.8f * (float)Math.Exp(-10f / (float)numaa));
            if (newPoints == null)
            {
                ConsoleText.text += string.Format("\n Error initializing smoothing array. NewPoints is null.");
            }

            // Second argument adjusts the smoothness. Smaller = smoother
            // TODO: Second argument can be adjusted for changing quality using slider


            // TODO: These three parameters can be adjustable with sliders
            float lineWidth  = 0.006f;
            float rescale    = 100f;
            int   numofsides = 12;

            int[]     triangles = new int[6 * numofsides * newPoints.Length];
            Vector3[] quad      = new Vector3[newPoints.Length * numofsides];
            Color[]   colors    = new Color[quad.Length];

            float a = lineWidth;
            float b = lineWidth / 2.5f;

            ConsoleText.text += string.Format("\n Initialized arrays and variables for molecule {0}...", tem);

            //foreach (Vector3 point in newPoints)
            foreach (Vector3 point in newPoints)
            {
                tiltFactor = 30;
                int i                = Array.IndexOf(newPoints, point);
                int totnumofsides    = i * numofsides;
                int totnumofvertices = totnumofsides * 6;
                int div              = Convert.ToInt32(Math.Floor(i / ((float)newPoints.Length / (float)MoleculesCAPoints[tem].Length)));

                // Adds color based on secondary structure assignment
                for (int z = 0; z < numofsides; z++)
                {
                    colors[totnumofsides + z] = Colors(MoleculesSecondaryAssignments[tem][div].structure);
                }
            }

            Parallel.ForEach(newPoints, point =>
            {
                tiltFactor           = 30;
                int i                = Array.IndexOf(newPoints, point);
                int totnumofsides    = i * numofsides;
                int totnumofvertices = totnumofsides * 6;

                int div = Convert.ToInt32(Math.Floor(i / ((float)newPoints.Length / (float)MoleculesCAPoints[tem].Length)));



                // for padding on the z axis:
                if (totnumofsides < (newPoints.Length - 2) * 6 && Mathf.Abs(point.z - newPoints[i + 1].z) > Mathf.Abs(point.x - newPoints[i + 1].x) && Mathf.Abs(point.z - newPoints[i + 1].z) > Mathf.Abs(point.y - newPoints[i + 1].y))
                {
                    tiltFactor = 45;
                }

                // Makes an oval
                // TODO: Find a way to fix thinness of certain axes (the padding on z axis method right above doesn't entirely work)

                for (int side = 0; side < numofsides; side++)
                {
                    float angle = (side * (360f / numofsides)) * Mathf.Deg2Rad;
                    float x     = ((float)a * b) / (float)Mathf.Sqrt(((float)Math.Pow(b, 2) + ((float)Math.Pow(a, 2) * (float)Math.Pow(Mathf.Tan(angle), 2))));
                    float y     = ((float)a * b) / (float)Mathf.Sqrt((float)Mathf.Pow(a, 2) + ((float)Mathf.Pow(b, 2) / (float)Mathf.Pow(Mathf.Tan(angle), 2)));

                    if (side * (360f / numofsides) > 90 && side * (360f / numofsides) < 270)
                    {
                        x = -1 * x;
                    }

                    if (side * (360f / numofsides) > 180 && side * (360f / numofsides) < 360)
                    {
                        y = -1 * y;
                    }

                    // Determine the max/min vertices for resizing and positioning later
                    if ((point / rescale).y + y > topY)
                    {
                        topY = (point / rescale).y + y;
                    }
                    if ((point / rescale).y + y < bottomY)
                    {
                        bottomY = (point / rescale).y + y;
                    }
                    if ((point / rescale).x + x > rightX)
                    {
                        rightX = (point / rescale).x + x;
                    }
                    if ((point / rescale).x + x < leftX)
                    {
                        leftX = (point / rescale).x + x;
                    }
                    if ((point / rescale).z > backZ)
                    {
                        backZ = (point / rescale).z;
                    }
                    if ((point / rescale).z < frontZ)
                    {
                        frontZ = (point / rescale).z;
                    }

                    quad[totnumofsides + side] = (point / rescale) + offset + new Vector3(x, y, 0);
                }

                // Creates an array for the triangles
                if (i < (newPoints.Length - 1))
                {
                    for (int p = 0; p < totnumofsides; p++)
                    {
                        triangles[(p * 6) + 0] = p + 0;
                        triangles[(p * 6) + 1] = p + numofsides;
                        triangles[(p * 6) + 2] = p + 1;
                        triangles[(p * 6) + 3] = p + 1;
                        triangles[(p * 6) + 4] = p + numofsides;
                        triangles[(p * 6) + 5] = p + numofsides + 1;
                    }
                }
            }
                             );

            // Draw the molecule
            GameObject Protein = new GameObject();

            Protein.transform.parent = MoleculeHolder.transform; // remove find
            Protein.name             = string.Format("PDB.{0}.molecule.{1}", GetComponent <Load>().FileNumber, tem);

            // some sanity checks
            if (GameObject.Find(string.Format("PDB.{0}.molecule.{1}", GetComponent <Load>().FileNumber, tem)) == null)
            {
                ConsoleText.text += string.Format("\n Molecule {0} GameObject does not exist.", tem);
            }
            if (quad == null)
            {
                ConsoleText.text += string.Format("\nQuad is null");
            }
            if (triangles == null)
            {
                ConsoleText.text += string.Format("\n Triangles is null.");
            }

            Protein.AddComponent <MeshFilter>();
            Protein.AddComponent <MeshRenderer>();

            //Protein.GetComponent<MeshRenderer>().material = new Material(Shader.Find("VertexColorLightmaps"));
            Protein.GetComponent <MeshFilter>().mesh.vertices  = quad;
            Protein.GetComponent <MeshFilter>().mesh.triangles = triangles;
            Protein.GetComponent <MeshFilter>().mesh.colors    = colors;

            Protein.GetComponent <MeshRenderer>().material = new Material(Shader.Find("Custom/SpecularHighlight"));

            Protein.GetComponent <MeshFilter>().mesh.RecalculateNormals();

            //meshFilters[tem] = Protein.GetComponent<MeshFilter>();
        }

        /*
         *      ThisPDB.AddComponent<MeshCollider>();
         *      ThisPDB.AddComponent<MeshFilter>();
         *      CombineInstance[] combine = new CombineInstance[meshFilters.Length];
         *      int inde = 0;
         *      while (inde < meshFilters.Length)
         *      {
         *              combine[inde].mesh = meshFilters[inde].sharedMesh;
         *              combine[inde].transform = meshFilters[inde].transform.localToWorldMatrix;
         *              //meshFilters[inde].gameObject.SetActive(false);
         *              inde++;
         *      }
         *      ThisPDB.transform.GetComponent<MeshFilter>().mesh = new Mesh();
         *      ThisPDB.transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);
         *      ThisPDB.transform.gameObject.SetActive(true);
         *      ThisPDB.transform.GetComponent<MeshCollider>().sharedMesh = ThisPDB.transform.GetComponent<MeshFilter>().mesh;
         *      ThisPDB.AddComponent<MeshRenderer>().material = new Material(Shader.Find("Custom/SpecularHighlight"));
         */
        MoleculeHolder.transform.localPosition -= new Vector3((rightX + leftX) / 2f, (topY + bottomY) / 2f, (backZ + frontZ) / 2f);
        ThisPDB.transform.localPosition         = Vector3.zero;

        //ThisPDB.AddComponent<BoxCollider>().size = new Vector3(0.5f, 0.5f, 0.5f);
        //ThisPDB.AddComponent<MeshRenderer>().material = GameObject.Find("MoleculeCollection").GetComponent<MeshRenderer>().material;



        if (Math.Abs(topY - bottomY) >= Math.Abs(rightX - leftX))
        {
            if (Math.Abs(backZ - frontZ) >= Math.Abs(topY - bottomY))
            {
                MoleculeHolder.transform.localScale /= Math.Abs(backZ - frontZ) / .3f; // instead of .48f make this localscale of moelculecolelctin
            }
            else
            {
                MoleculeHolder.transform.localScale /= Math.Abs(topY - bottomY) / .3f;
            }
        }
        else
        {
            MoleculeHolder.transform.localScale /= Math.Abs(rightX - leftX) / .3f;
        }

        // change back to interpolated strings
        ConsoleText.text += string.Format("\n Cartoon structure drawn for PDB #{0}.", GetComponent <Load>().FileNumber);
        finishTime        = Time.realtimeSinceStartup;
        ConsoleText.text += string.Format("\n Time taken to draw: {0} seconds.\n", (finishTime - startTime));
        Debug.Log($"Time to draw protein: {finishTime - startTime}");

        //ThisPDB.AddComponent<BoxCollider>().size = new Vector3(0.48f / ThisPDB.transform.localScale.x, 0.48f / ThisPDB.transform.localScale.x, 0.48f / ThisPDB.transform.localScale.x);
        //GameObject.Find("RibbonCollection").GetComponent<BoxCollider>().enabled = true;
        //MoleculeHolder.transform.localScale = new Vector3(3, 3, 3);

        RibbonCollection.AddComponent <BoundingBoxRig>().ScaleHandleMaterial  = BoundingBoxHandle;
        RibbonCollection.GetComponent <BoundingBoxRig>().RotateHandleMaterial = BoundingBoxHandle;
        RibbonCollection.GetComponent <BoundingBoxRig>().InteractingMaterial  = BoundingBoxHandleGrabbed;
        RibbonCollection.GetComponent <BoundingBoxRig>().BoundingBoxPrefab    = BoundingBoxBasic;
        RibbonCollection.GetComponent <BoundingBoxRig>().appBarPrefab         = AppBar;
        RibbonCollection.AddComponent <MixedRealityToolkit.InputModule.Utilities.Interations.TwoHandManipulatable>().BoundingBoxPrefab = BoundingBoxBasic;

        RibbonCollection.GetComponent <MixedRealityToolkit.InputModule.Utilities.Interations.TwoHandManipulatable>().SetManipulationMode(MixedRealityToolkit.InputModule.Utilities.Interations.TwoHandManipulatable.TwoHandedManipulation.MoveRotateScale);

        ThisPDB.AddComponent <MeshFilter>().mesh = GameObject.Find("MoleculeCollection").GetComponent <MeshFilter>().mesh;

        ThisPDB.AddComponent <MeshCollider>().sharedMesh = ThisPDB.GetComponent <MeshFilter>().mesh;
        ThisPDB.AddComponent <MeshRenderer>().material   = GameObject.Find("MoleculeCollection").GetComponent <MeshRenderer>().material;
        ThisPDB.GetComponent <MeshRenderer>().enabled    = false;
        GetComponent <Load>().FileNumber++;
    }
Exemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        print(drawLine + " drawline");

        if (drawLine)
        {
            if (FindObjectOfType <LineFollower>().endPointReached)
            {
                print("---");
                Application.LoadLevel(Application.loadedLevel);
            }
        }

        if (Input.GetKey(KeyCode.Mouse0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.tag == "Player")
                {
                    drawLine           = true;
                    lineRender.enabled = true;
                }


                if (Distancetolastpiont(hit.point) > .9f && drawLine)
                {
                    pionts.Add(hit.point);

                    lineRender.positionCount = pionts.Count;

                    lineRender.SetPositions(pionts.ToArray());
                    LineSmoother.SmoothLine(pionts.ToArray(), .1f);
                }


                if (hit.collider.tag == "Finish")
                {
                    drawLine = false;
                    //  onnewpathcreat(pionts);
                    if (FindObjectOfType <CollisonDetection1>() != null)
                    {
                        //  FindObjectOfType<CollisonDetection1>().ResetPosition();
                    }
                    if (FindObjectsOfType <LineFollower1>() != null)
                    {
                        // FindObjectOfType<LineFollower1>().speed = 10;
                    }
                }
            }
        }
        else if

        {
            onnewpathcreat(pionts);
            if (lineRender.enabled)
            {
                behaviour.enabled = true;
            }
            else
            {
                behaviour.enabled = false;
            }
        }
    }
Exemplo n.º 14
0
    public override void OnDraggingInUpdate()
    {
        // This code only draws the arrow
        Vector3 notNormalized    = transform.position - transform.parent.position;
        Vector3 direction        = notNormalized.normalized;
        float   distanceToTarget = (direction * 2.3f).magnitude;

        if (notNormalized.magnitude > distanceToTarget)
        {
            //find curved points in children
            linePoints = lr.gameObject.GetComponentsInChildren <CurvedLinePoint>();

            //add positions
            Vector3 midPoint = Vector3.Lerp(transform.parent.position, transform.position - direction * 2.3f, 0.5f);
            // draw a line between the creature and the target
            linePositions = new Vector3[linePoints.Length];

            midPoint += new Vector3(0, 0, -lr.positionCount * 0.1f);
            if (midPoint.z > 0)
            {
                midPoint.z = 0;
            }
            if (midPoint.z < -10f)
            {
                midPoint.z = -10f;
            }

            if (lr.positionCount < 2)
            {
                midPoint.z = 0;
            }

            linePoints[0].transform.position = transform.parent.position;
            linePoints[1].transform.position = midPoint;
            linePoints[2].transform.position = transform.position - direction * 1.5f;

            linePositions[0] = linePoints[0].transform.position;
            linePositions[1] = linePoints[1].transform.position;
            linePositions[2] = linePoints[2].transform.position;

            // Vector3 triangleSizeY = triangle.localScale;
            // triangleSizeY.y = notNormalized.magnitude * 0.04f;

            //triangle.localScale = new Vector3( triangle.localScale.x, Mathf.Clamp(triangleSizeY.y, 0.3f, 0.4f), triangle.localScale.z);

            //create old positions if they dont match
            if (linePositionsOld.Length != linePositions.Length)
            {
                linePositionsOld = new Vector3[linePositions.Length];
            }

            //get smoothed values
            Vector3[] smoothedPoints = LineSmoother.SmoothLine(linePositions, 2);

            //set line settings
            lr.positionCount = smoothedPoints.Length;
            lr.SetPositions(smoothedPoints);

            lr.enabled = true;

            // position the end of the arrow between near the target.
            triangleSR.enabled            = true;
            triangleSR.transform.position = transform.position - 1.35f * direction;

            // proper rotarion of arrow end
            float rot_z = Mathf.Atan2(notNormalized.y, notNormalized.x) * Mathf.Rad2Deg;
            triangleSR.transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90);
        }
        else
        {
            // if the target is not far enough from creature, do not show the arrow
            lr.enabled         = false;
            triangleSR.enabled = false;
        }
    }
Exemplo n.º 15
0
        public void RenderLine(bool refreshLine = false, bool overrideStartOptional = false)
        {
            if (!isChopping || refreshLine)
            {
                isChopping = true;
                if (!isLineInit || refreshLine)
                {
                    linePositions.Clear();
                    isLineInit        = true;
                    lrComp.startWidth = traceWidth;
                    lrComp.endWidth   = traceWidth;

                    gameObject.transform.localScale = Vector3.one;
                    int startOptional = targetOptional.GetLength(0) > size?targetOptional.GetLength(0) - size : 0;

                    if (overrideStartOptional)
                    {
                        startOptional = 0;
                    }

                    size = Mathf.RoundToInt(size / (targetOptional.GetLength(0) - startOptional));

                    linePositions.Add(transform.position);

                    for (int index = startOptional; index < targetOptional.GetLength(0); ++index)
                    {
                        //InitLinePositions(new Vector3(targetOptional[index, 0], targetOptional[index, 1], targetOptional[index, 2]));
                        linePositions.Add(new Vector3(targetOptional[index, 0], targetOptional[index, 1], targetOptional[index, 2]));
                    }

                    smoothedPoints = LineSmoother.SmoothLine(linePositions.ToArray(), 0.8f);

                    lrComp.positionCount = smoothedPoints.Length;
                    lrComp.SetPositions(smoothedPoints);

                    if (targetOptional.GetLength(0) > 0)
                    {
                        if (m_RingObject != null && endPointGO != null)
                        {
                            GameObject ring = GetRingElement(endPointGO.transform);

                            ring.transform.localPosition    = Vector3.zero;
                            ring.transform.localScale       = Vector3.one * m_RingScale;
                            ring.transform.localEulerAngles = new Vector3(90, 0, 0);
                        }
                    }
                }

                /* if (!areColliderInit)
                 * {
                 *  t_Collider = colliderGO.AddComponent<BoxCollider>();
                 *  t_Collider.isTrigger = true;
                 *
                 *  colliderGO.SetActive(true);
                 *  colliderGO.transform.localScale = Vector3.one;
                 *  collidersGap = Mathf.Clamp(collidersGap, 1, 20);
                 * } */

                /* for (int j = 0; j < smoothedPoints.Length; j++)
                 * {
                 *  //if(j > 0 && !areColliderInit)
                 *  t_Collider.size = new Vector3(colliderSize, colliderSize, colliderSize);
                 *  //lrComp.SetPosition(j, linePositions[j]);
                 *  if (startIndex == -1) startIndex = j;
                 *
                 *  if (j % collidersGap == 0)
                 *  {
                 *
                 *      if (!areColliderInit)
                 *      {
                 *          newCol = GameObject.Instantiate(colliderGO);
                 *          newCol.transform.parent = Colliders.transform;
                 *          newCol.tag = collitionTag;
                 *
                 *          startIndex = -1;
                 *
                 *          Vector3 endPointPosition = transform.InverseTransformPoint(
                 *                  smoothedPoints[j].x,
                 *                  smoothedPoints[j].y,
                 *                  smoothedPoints[j].z
                 *          );
                 *          newCol.transform.localPosition = endPointPosition;
                 *
                 *          colliders.Add(newCol);
                 *
                 *          // Rings Instantiation
                 *          if(m_RingObject != null && j > 0 && (j ==1 || j % m_ringEvery == 0)) {
                 *              GameObject ring = GetRingElement(newCol.transform);
                 *
                 *              ring.transform.localPosition = Vector3.zero;
                 *              ring.transform.localEulerAngles = new Vector3(0, 0, 90);
                 *              if(m_randomizeScale) {
                 *                  ring.transform.localScale = Vector3.one * UnityEngine.Random.Range(1f, m_RingScale);
                 *              } else {
                 *                  ring.transform.localScale = Vector3.one * m_RingScale;
                 *              }
                 *          }
                 *      }
                 *  }
                 * } */

                if (!areColliderInit)
                {
                    colliderGO.SetActive(false);
                    areColliderInit = true;
                }

                if ((endPointGO && !areColliderInit))
                {
                    int index = smoothedPoints.Length - 1;
                    endPointGO.transform.position = gameObject.transform.position;
                    endPointGO.transform.Translate(smoothedPoints[index].x, smoothedPoints[index].y, smoothedPoints[index].z, gameObject.transform);
                }

                // this.LineRenderer.enabled = false;
            }

            isChopping = false;
        }
Exemplo n.º 16
0
 private void UpdateSmoothLineAppearance()
 {
     Vector3[] smoothedPoints = LineSmoother.SmoothLine(keyPoints.ToArray(), lineSmoothness);
     lineRenderer.positionCount = smoothedPoints.Length;
     lineRenderer.SetPositions(smoothedPoints);
 }