Пример #1
0
        void Start()
        {
            // Add TubeRendeder component.
            TubeRenderer tube = gameObject.AddComponent <TubeRenderer>();

            // Optimise for realtime manipulation.
            tube.MarkDynamic();

            // Set a texture and a uv mapping.
            tube.GetComponent <Renderer>().material.mainTexture          = Helpers.CreateTileTexture(12);
            tube.GetComponent <Renderer>().material.mainTexture.wrapMode = TextureWrapMode.Repeat;
            tube.uvRect    = new Rect(0, 0, 6, 1);
            tube.uvRectCap = new Rect(0, 0, 4 / 12f, 4 / 12f);

            // Add a SplineMaker component.
            _splineMaker = gameObject.AddComponent <SplineMaker>();

            // Set the spline resolution.
            _splineMaker.pointsPerSegment = 16;

            // Route curve points from spline to tube.
            _splineMaker.onUpdated.AddListener((points) => tube.points = points);

            // Create anchor points for curve.
            _anchorPoints = new Vector3[6];
            for (int a = 0; a < _anchorPoints.Length; a++)
            {
                _anchorPoints[a] = new Vector3();
            }
        }
    // Update is called once per frame
    void Update()
    {
        lineRenderer.SetPosition(0, this.transform.position);
        if (triggerPressed)
        {
            lineRenderer.SetPosition(1, this.transform.position + this.transform.forward * sizeRay);
            TubeRenderer closestTube = pickingTube(this.transform.position, this.transform.position + this.transform.forward * sizeRay);
            if (closestTube != null)
            {
                closestTube.GetComponent <Renderer>().material.color = lineRenderer.material.color;
            }
            //Test of the line segments distance;


            //RaycastHit hit;
            //if (Physics.Raycast(transform.position, this.transform.forward, out hit, 100.0f))
            //{
            //    Debug.Log("Hit something");
            //}
        }



        else
        {
            lineRenderer.SetPosition(1, this.transform.position + this.transform.forward * 0.2f);
        }
    }
Пример #3
0
        void Start()
        {
            // Create tubes for outer and inner surface.
            _outerTube = new GameObject("Outer Tube").AddComponent <TubeRenderer>();
            _innerTube = new GameObject("Inner Tube").AddComponent <TubeRenderer>();
            _outerTube.transform.parent = transform;
            _innerTube.transform.parent = transform;

            // Optimise for realtime manipulation.
            _outerTube.MarkDynamic();
            _innerTube.MarkDynamic();

            // Invert the mesh of the inner tube.
            _innerTube.invertMesh = true;

            // Only cap the beginning of the tubes.
            _outerTube.caps = TubeRenderer.CapMode.Begin;
            _innerTube.caps = TubeRenderer.CapMode.Begin;

            // Create point and radius arrays.
            _outerTube.points   = new Vector3[POINT_COUNT];
            _outerTube.radiuses = new float[POINT_COUNT];
            _innerTube.points   = new Vector3[POINT_COUNT + 1];
            _innerTube.radiuses = new float[POINT_COUNT + 1];

            // Define points.
            for (int p = 0; p < POINT_COUNT; p++)
            {
                float norm = p / (POINT_COUNT - 1f);
                _outerTube.points[p] = Vector3.right * Mathf.Lerp(0.6f, -0.4f, norm);
                _innerTube.points[p] = _outerTube.points[p];
            }
            _innerTube.points[POINT_COUNT] = _innerTube.points[POINT_COUNT - 1];           // double last point

            // Add a texutre and adjust the uv mapping of the caps.
            _outerTube.GetComponent <Renderer>().sharedMaterial.mainTexture = TubeRendererExamples.Helpers.CreateTileTexture(12);
            _innerTube.GetComponent <Renderer>().sharedMaterial.mainTexture = _outerTube.GetComponent <Renderer>().sharedMaterial.mainTexture;
            _outerTube.uvRectCap = new Rect(0, 0, 4 / 12f, 4 / 12f);
            _innerTube.uvRectCap = _outerTube.uvRectCap;
        }
Пример #4
0
        void Start()
        {
            // Add TubeRenderer component.
            _tube = gameObject.AddComponent <TubeRenderer>();

            // Optimise for realtime manipulation.
            _tube.MarkDynamic();

            // No caps please.
            _tube.caps = TubeRenderer.CapMode.None;

            // Create point and radius arrays.
            _tube.points   = new Vector3[POINT_COUNT];
            _tube.radiuses = new float[POINT_COUNT];

            // Define radiuses.
            for (int p = 0; p < POINT_COUNT; p++)
            {
                float norm = p / (POINT_COUNT - 1f);
                _tube.radiuses[p] = Mathf.Cos(norm * Mathf.PI * 0.5f) * 0.4f;
            }

            // Create tiled texture and assign it to the tube.
            _tube.GetComponent <Renderer>().sharedMaterial.mainTexture = TubeRendererExamples.Helpers.CreateTileTexture(12);

            // Position.
            _tube.transform.position = -Vector3.forward * RADIUS;

            // Create a bunch of other objects and share the tube mesh.
            for (int t = 1; t < TUBE_COUNT; t++)
            {
                float      angle     = (t / (float)TUBE_COUNT) * 360;
                GameObject cloneTube = new GameObject("Clone Tube");
                cloneTube.transform.rotation = Quaternion.Euler(0, angle, 0);
                cloneTube.transform.position = cloneTube.transform.rotation * -Vector3.forward * RADIUS;
                cloneTube.AddComponent <MeshFilter>().sharedMesh       = _tube.mesh;
                cloneTube.AddComponent <MeshRenderer>().sharedMaterial = _tube.GetComponent <Renderer>().sharedMaterial;
            }
        }
Пример #5
0
        void Start()
        {
            // Add TubeRendeder component.
            _tube = gameObject.AddComponent <TubeRenderer>();

            // Optimise for realtime manipulation.
            _tube.MarkDynamic();

            // Create point and radius arrays.
            _tube.points   = new Vector3[POINT_COUNT];
            _tube.radiuses = new float[POINT_COUNT];

            // Define points.
            for (int p = 0; p < POINT_COUNT; p++)
            {
                float norm = p / (POINT_COUNT - 1f);
                float x    = Mathf.Lerp(-1.5f, 1.5f, norm);
                float y    = Mathf.Lerp(-1f, 1f, Mathf.PerlinNoise(0, norm));
                float z    = Mathf.Lerp(-1f, 1f, Mathf.PerlinNoise(norm * 2, 0));
                _tube.points[p] = new Vector3(x, y, z);
            }

            // Set a texture and a uv mapping.
            _tube.GetComponent <Renderer>().material.mainTexture          = Helpers.CreateTileTexture(12);
            _tube.GetComponent <Renderer>().material.mainTexture.wrapMode = TextureWrapMode.Repeat;
            _tube.uvRect    = new Rect(0, 0, 6, 1);
            _tube.uvRectCap = new Rect(0, 0, 4 / 12f, 4 / 12f);

            // Create an array to hold animated radiuses.
            _normalizedRadiuses = new float[POINT_COUNT];

            // Enable post processing by assigning a callback method.
            _tube.AddPostprocess(Distort);

            // Display mesh gizmos for debugging. this is convinient when you write your own post process method.
            _tube.showMeshGizmos = true;
        }
Пример #6
0
        void Start()
        {
            // add TubeRenderer component
            tube = gameObject.AddComponent<TubeRenderer>();

            // optimise for realtime manipulation
            tube.MarkDynamic();

            // no caps please
            tube.caps = TubeRenderer.CapMode.None;

            // create point and radius arrays
            tube.points = new Vector3[POINT_COUNT];
            tube.radiuses = new float[POINT_COUNT];

            // define radiuses //
            for( int p=0; p<POINT_COUNT; p++ ){
                float norm = p / (POINT_COUNT-1f);
                tube.radiuses[p] = Mathf.Cos( norm * Mathf.PI * 0.5f ) * 0.4f;
            }

            // create tiled texture and assign it to the tube
            tube.GetComponent<Renderer>().sharedMaterial.mainTexture = TubeRendererExamples.Helpers.CreateTileTexture( 12 );

            // position //
            tube.transform.position = -Vector3.forward * RADIUS;

            // create a bunch of other objects and share the tube mesh
            for( int t=1; t<TUBE_COUNT; t++ ){
                float angle = ( t / (float) TUBE_COUNT ) * 360;
                GameObject cloneTube = new GameObject( "Clone Tube" );
                cloneTube.transform.rotation = Quaternion.Euler( 0, angle, 0 );
                cloneTube.transform.position = cloneTube.transform.rotation * -Vector3.forward * RADIUS;
                cloneTube.AddComponent<MeshFilter>().sharedMesh = tube.mesh;
                cloneTube.AddComponent<MeshRenderer>().sharedMaterial = tube.GetComponent<Renderer>().sharedMaterial;
            }
        }
Пример #7
0
        void Start()
        {
            // Add a TubeRenderer component.
            TubeRenderer tube = gameObject.AddComponent <TubeRenderer>();

            // Define uv mapping.
            tube.uvRect    = new Rect(0, 0, 4, 1);
            tube.uvRectCap = new Rect(0.543f, 0, 0.33f, 0.33f);

            // Set a global radius for the tube.
            tube.radius = 0.5f;

            // Reduce tube mesh to three edges.
            tube.edgeCount = 3;

            // Set normal mode to hard edges.
            tube.normalMode = TubeRenderer.NormalMode.HardEdges;

            // Create point array.
            tube.points = new Vector3[POINT_COUNT];

            // Define points.
            for (int p = 0; p < POINT_COUNT; p++)
            {
                float norm   = p / (POINT_COUNT - 1f);
                float angle  = norm * Mathf.PI * 2 * 0.7f;
                float radius = Mathf.Lerp(2, 0.8f, norm);
                float y      = Mathf.Lerp(2, 0, norm);
                tube.points[p] = new Vector3(Mathf.Cos(angle) * radius, y, Mathf.Sin(angle) * radius);
            }

            // IMPORTANT! call ForceUpdate to generate the mesh immediately, before adding the MeshCollder.
            tube.ForceUpdate();

            // Add MeshCollider. The reference to the tube mesh is set automatically.
            gameObject.AddComponent <MeshCollider>();

            // Create a material at apply it to the tube.
            _tileMaterial                                 = new Material(Shader.Find("Diffuse"));
            _tileMaterial.mainTexture                     = Helpers.CreateTileTexture(6);
            _tileMaterial.mainTexture.wrapMode            = TextureWrapMode.Repeat;
            tube.GetComponent <Renderer>().sharedMaterial = _tileMaterial;

            // Destroy the TubeRenderer component to free up memory.
            Destroy(tube);

            // Start the rain.
            StartCoroutine(RainCoroutine());
        }
        void Start()
        {
            // add TubeRendeder component
            tube = gameObject.AddComponent<TubeRenderer>();

            // optimise for realtime manipulation
            tube.MarkDynamic();

            // create point and radius arrays
            tube.points = new Vector3[POINT_COUNT];
            tube.radiuses = new float[POINT_COUNT];

            // define points
            for( int p=0; p<POINT_COUNT; p++ ){
                float norm = p / (POINT_COUNT-1f);
                float x = Mathf.Lerp( -1.5f, 1.5f, norm );
                float y = Mathf.Lerp( -1f, 1f, Mathf.PerlinNoise( 0, norm ) );
                float z = Mathf.Lerp( -1f, 1f, Mathf.PerlinNoise( norm*2, 0 ) );
                tube.points[p] = new Vector3( x, y, z );
            }

            // set a texture and a uv mapping
            tube.GetComponent<Renderer>().material.mainTexture = Helpers.CreateTileTexture(12);
            tube.GetComponent<Renderer>().material.mainTexture.wrapMode = TextureWrapMode.Repeat;
            tube.uvRect = new Rect( 0, 0, 6, 1 );
            tube.uvRectCap = new Rect( 0, 0, 4/12f, 4/12f );

            // create an array to hold animated radiuses
            normalizedRadiuses = new float[ POINT_COUNT ];

            // enable post processing by assigning a callback method
            tube.AddPostprocess( Distort );

            // display mesh gizmos for debugging. this is convinient when you write your own post process method
            tube.meshGizmos = true;
        }
Пример #9
0
    public void addLine(GameObject go, GameObject go2, float lineWidth, InteractableMap origin, InteractableMap destination)
    {
        lineNb += 1;

        Vector3 sum   = Vector3.zero;
        int     count = 0;

        int posPointer  = lineTab.Count();
        int lineCounter = beginLineNormal.Count();

        var l = lineTab.OfType <Vector3>().ToList();

        l.AddRange(new Vector3 [lineLenght]);
        lineTab = l.ToArray();


        l = beginLineNormal.OfType <Vector3>().ToList();
        l.Add(Vector3.zero);
        beginLineNormal = l.ToArray();

        l = endLineNormal.OfType <Vector3>().ToList();
        l.Add(Vector3.zero);
        endLineNormal = l.ToArray();

        l = StartNormal.OfType <Vector3>().ToList();
        l.Add(Vector3.zero);
        StartNormal = l.ToArray();

        l = EndNormal.OfType <Vector3>().ToList();
        l.Add(Vector3.zero);
        EndNormal = l.ToArray();


        pointsList.Add(new Tuple <GameObject, GameObject, float>(go, go2, lineWidth));



        GameObject sensorVisu = go2;

        List <Vector3> line = new List <Vector3>();
        Vector3        goP  = go.transform.position;
        Vector3        goVP = sensorVisu.transform.position;
        Vector3        step = (goVP - goP) / (lineLenght - 1);

        Vector3[] pointsTube = new Vector3[lineLenght];
        int       idBegining = posPointer;

        for (int i = 0; i < lineLenght - 1; i++)
        {
            Vector3 interPoint = goP + i * step;
            lineTab[posPointer] = interPoint;
            pointsTube[i]       = lineTab[posPointer];
            posPointer++;
        }

        lineTab[posPointer] = goVP;
        posPointer++;
        sum   += goP;
        sum   += goVP;
        count += 2;

        Vector3 normal1 = go.transform.forward;
        Vector3 normal2 = sensorVisu.transform.forward;

        //beginLineNormal[2 * lineCounter] = go.transform.position;
        beginLineNormal[lineCounter] = normal1;
        //endLineNormal[2 * lineCounter] = sensorVisu.transform.position;
        endLineNormal[lineCounter] = normal2;

        StartNormal[lineCounter] = origin.gameObject.transform.parent.transform.parent.forward;
        EndNormal[lineCounter]   = origin.gameObject.transform.parent.transform.parent.forward;

        lineCounter++;


        GameObject   tubeGO = new GameObject("Tube-" + lineNb.ToString());
        TubeRenderer lr     = tubeGO.AddComponent <TubeRenderer>();

        //LineRenderer lr = tubeGO.AddComponent<LineRenderer>();
        lr.points = pointsTube;
        lr.radius = lineWidth;


        var tempMaterial = new Material(lr.GetComponent <Renderer>().sharedMaterial);

        tempMaterial.shader = Shader.Find("Particles/Standard Surface");
        lr.GetComponent <Renderer>().sharedMaterial = tempMaterial;



        lr.setParents(origin, destination, go, go2);



        //lr.positionCount = pointsTube.Length;

        //lr.SetPositions(pointsTube);
        //lr.startWidth = lineWidth;
        //lr.endWidth = lineWidth;
        Material[] matArray = new Material[1];
        linkMat.color = colorT;
        matArray[0]   = linkMat;
        //lr.colors =
        //lr.materials = matArray;

        tubeList.Add(idBegining, lr);

        //tubeGO.tag = "Tube";
        previousPositions = new List <Vector3[]>();
        for (int i = 0; i < 2; i++)
        {
            Vector3[] tmp = new Vector3[lineTab.Length];
            lineTab.CopyTo(tmp, 0);
            previousPositions.Add(tmp);
        }


        update_shader();
    }