Beispiel #1
0
        override public void PaintSegments(StrokeSegment[] segments, IOnPaint editContext)
        {
            for (int i = 0; i < segments.Length; i++)
            {
                StrokeSegment segment = segments[i];

                Smudge(segment.currTerrain, editContext, segment.currUV, segment.prevUV);
            }
        }
Beispiel #2
0
        override public void PaintSegments(StrokeSegment[] segments, IOnPaint editContext, BrushSettings brushSettings)
        {
            for (int i = 0; i < segments.Length; i++)
            {
                StrokeSegment segment = segments[i];

                PaintTexture(segment.currTerrain, editContext, segment.currUV, brushSettings);
            }
        }
Beispiel #3
0
        override public void PaintSegments(StrokeSegment[] segments, IOnPaint editContext)
        {
            for (int i = 0; i < segments.Length; i++)
            {
                StrokeSegment segment = segments[i];

                Bridge(segment.currTerrain, editContext, segment.currUV, segment.pct, segment.stroke, segment.startPoint);
            }
        }
Beispiel #4
0
        override public void PaintSegments(StrokeSegment[] segments, IOnPaint editContext)
        {
            for (int i = 0; i < segments.Length; i++)
            {
                // first item doesn't have prevUV
                if (i == 0)
                {
                    continue;
                }

                StrokeSegment segment = segments[i];

                Smudge(segment.currTerrain, editContext, segment.currUV, segment.prevUV);
            }
        }
Beispiel #5
0
        override public void Update(StrokeSegment[] segments)
        {
#if VEGETATION_STUDIO_PRO
            if (segments.Length > 0)
            {
                StrokeSegment segment = segments[0];
                Bounds        bounds  = new Bounds(new Vector3(segment.currUV.x, 0, segment.currUV.y), Vector3.zero);;
                for (int i = 1; i < segments.Length; i++)
                {
                    segment = segments[i];

                    Vector2 boundsWS = TransformUtilities.transformToWorld(segment.currTerrain, segment.currUV);
                    bounds.Encapsulate(new Vector3(boundsWS.x, 0, boundsWS.y));
                }

                VegetationStudioManager.RefreshTerrainHeightMap(bounds);
            }
#endif
        }
Beispiel #6
0
        private StrokeSegment[] GetStrokeSegments(Terrain terrain, IOnPaint editContext)
        {
            Vector2 uv = editContext.uv;

            //get the target position & height
            float   targetHeight = terrain.terrainData.GetInterpolatedHeight(uv.x, uv.y) / terrain.terrainData.size.y;
            Vector3 targetPos    = new Vector3(uv.x, uv.y, targetHeight);

            if (terrain != m_StartTerrain)
            {
                //figure out the stroke vector in uv,height space
                Vector2 targetWorld = TransformUtilities.transformToWorld(terrain, uv);
                Vector2 targetUVs   = TransformUtilities.transformToUVSpace(m_StartTerrain, targetWorld);
                targetPos.x = targetUVs.x;
                targetPos.y = targetUVs.y;
            }

            Vector3 stroke       = targetPos - m_StartPoint;
            float   strokeLength = stroke.magnitude;
            int     numSplats    = 1; // (int)(strokeLength / (0.001f * m_Spacing)); <= TODO keeping numsplats at 1 for now, otherwise it would drain performance in paint mode; see also paintDirection.magnitude > 1

            Terrain currTerrain = m_StartTerrain;

            Vector2 posOffset = new Vector2(0.0f, 0.0f);
            Vector2 currUV    = new Vector2();

            Vector2 jitterVec = new Vector2(-stroke.z, stroke.x); //perpendicular to stroke direction

            jitterVec.Normalize();

            Vector2 prevUV = Vector2.zero;

            StrokeSegment[] segments = new StrokeSegment[numSplats];

            for (int i = 0; i < numSplats; i++)
            {
                float pct = (float)i / (float)numSplats;

                float jitterOffset = jitterProfile.Evaluate(pct) / Mathf.Max(currTerrain.terrainData.size.x, currTerrain.terrainData.size.z);

                Vector3 currPos = m_StartPoint + pct * stroke;

                //add in jitter offset (needs to happen before tile correction)
                currPos.x += posOffset.x + jitterOffset * jitterVec.x;
                currPos.y += posOffset.y + jitterOffset * jitterVec.y;

                if (currPos.x >= 1.0f && (currTerrain.rightNeighbor != null))
                {
                    currTerrain  = currTerrain.rightNeighbor;
                    currPos.x   -= 1.0f;
                    posOffset.x -= 1.0f;
                }
                if (currPos.x <= 0.0f && (currTerrain.leftNeighbor != null))
                {
                    currTerrain  = currTerrain.leftNeighbor;
                    currPos.x   += 1.0f;
                    posOffset.x += 1.0f;
                }
                if (currPos.y >= 1.0f && (currTerrain.topNeighbor != null))
                {
                    currTerrain  = currTerrain.topNeighbor;
                    currPos.y   -= 1.0f;
                    posOffset.y -= 1.0f;
                }
                if (currPos.y <= 0.0f && (currTerrain.bottomNeighbor != null))
                {
                    currTerrain  = currTerrain.bottomNeighbor;
                    currPos.y   += 1.0f;
                    posOffset.y += 1.0f;
                }

                currUV.x = currPos.x;
                currUV.y = currPos.y;


                StrokeSegment ctx = new StrokeSegment();

                ctx.pct         = pct;
                ctx.currTerrain = currTerrain;
                ctx.currUV      = currUV;
                ctx.stroke      = stroke;
                ctx.prevUV      = prevUV;

                ctx.startPoint = m_StartPoint;

                segments[i] = ctx;

                prevUV = currUV;
            }

            return(segments);
        }