Пример #1
0
        /**Duplicates first vertex and set it at last position with UV coord (1,y). This has to be called as the last
         * of all the polyline modifier functions **/
        public void duplicateFirstVertex()
        {
            InitialPolyline newPolyline = new InitialPolyline(getSize() + 1);

            for (int i = 0; i < getSize(); ++i)
            {
                newPolyline.setVertex(i, getVertex(i));
            }
            Vertex lastV = new Vertex(getVertex(0));

            newPolyline.setVertex(getSize(), lastV);
            Vector2 newUV = lastV.getUV();

            newUV.x = 1.0f;
            lastV.setUV(newUV);
            this.mVertices = newPolyline.mVertices;
        }
Пример #2
0
        //******** Smooth ********//

        public void smoothMean()
        {
            InitialPolyline newPolyline = new InitialPolyline(getSize() * 2);

            //Add new mid-points
            for (int i = 0; i < getSize(); ++i)
            {
                newPolyline.addPosition(getVertex(i).getPosition());
                newPolyline.addPosition(new Vector3());
                newPolyline.getVertex(i * 2 + 1).Lerp(getVertex(i), getVertex(i + 1), 0.5f);
            }

            //Take the mean of the vertices previously existing with the new vertices
            for (int i = 0; i < newPolyline.getSize(); i += 2)
            {
                newPolyline.getVertex(i).Lerp(newPolyline.getVertex(i - 1), newPolyline.getVertex(i + 1), 0.5f);
            }
            this.mVertices = newPolyline.mVertices;
        }
Пример #3
0
        /** From existing polyline, generates a new one by projecting the original to a plane on it's normal direction.
         * It is also smoothed and scaled.  **/
        public static InitialPolyline generateProjection(InitialPolyline polyHole, int projectionSize, int smoothIterations)
        {
            //projectionSize must be pair!
            //Get the plane to project to
            Plane tunnelEntrance = polyHole.generateNormalPlane();
            //Generate the polyline by projecting to the plane
            InitialPolyline planePoly = new InitialPolyline(projectionSize);
            int             holePos   = 0;
            int             incr      = ((polyHole.getSize() / 2) - 1) / ((projectionSize / 2) - 1);

            for (int i = 0; i < projectionSize / 2; ++i)
            {
                planePoly.addPosition(Geometry.Utils.getPlaneProjection(tunnelEntrance, polyHole.getVertex(holePos).getPosition()));
                //planePoly.getVertex(i).setUV(polyHole.getVertex (holePos).getUV());
                holePos += incr;
            }
            holePos = polyHole.getSize() / 2;
            for (int i = 0; i < projectionSize / 2; ++i)
            {
                planePoly.addPosition(Geometry.Utils.getPlaneProjection(tunnelEntrance, polyHole.getVertex(holePos).getPosition()));
                //planePoly.getVertex(i+projectionSize / 2).setUV(polyHole.getVertex (holePos).getUV());
                holePos += incr;
            }

            //Smooth it
            for (int j = 0; j < smoothIterations; ++j)
            {
                planePoly.smoothMean();
            }

            //Scale to an approximate size of the real size of the original
            float maxActualRadius = planePoly.computeRadius();
            float destinyRadius   = polyHole.computeProjectionRadius();

            planePoly.scale(destinyRadius / maxActualRadius);

            return(planePoly);
        }