Ejemplo n.º 1
0
        public override void apply(List <VertIndexWeight> verts, float intensity, bool alternate)
        {
            if (verts.Count == 0)
            {
                return;
            }

            BTileBoundingBox vertexTouchedExtends = new BTileBoundingBox();

            // Go through points and adjust accordingly.
            for (int i = 0; i < verts.Count; i++)
            {
                int   index  = verts[i].index;
                float weight = verts[i].weight;

                int z = (int)(index / TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumXPoints());
                int x = (int)(index % TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumZPoints());

                SimTileData.eTileTypeOverrideVal passV = TerrainGlobals.getEditor().getSimRep().getDataTiles().getTileTypeBrushState();
                if (passV == SimTileData.eTileTypeOverrideVal.cTileType_None || alternate)
                {
                    TerrainGlobals.getEditor().getSimRep().getDataTiles().setJaggedTileType(x - 1, z - 1, 0);
                }
                else
                {
                    {
                        //find the override index, and set it to the type.
                        int idx = SimTerrainType.getTileTypeIndexByName(TerrainGlobals.getEditor().getSimRep().getDataTiles().getTileTypeOverrideSelection());
                        TerrainGlobals.getEditor().getSimRep().getDataTiles().setJaggedTileType(x - 1, z - 1, idx);
                    }
                }
                vertexTouchedExtends.addPoint(x, z);
            }
            TerrainGlobals.getEditor().getSimRep().updateAfterPainted(vertexTouchedExtends.minX, vertexTouchedExtends.minZ, vertexTouchedExtends.maxX, vertexTouchedExtends.maxZ);
        }
Ejemplo n.º 2
0
        void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                Thread.Sleep(500); //Sleep a little bit to ensure everyone is properly finished
                deleteExistingJobs();
                deleteExistingInputFile();

                TerrainGlobals.getEditor().clearAmbientOcclusion();
                if (TerrainGlobals.getTerrain().getQuadNodeRoot() != null)
                {
                    TerrainGlobals.getTerrain().getQuadNodeRoot().clearVisibleDatHandle();
                }
            }
            else if (e.Error != null)
            {
                //Console.WriteLine("Worker exception: " + e.Error.ToString());
            }
            else //completed OK
            {
                Thread.Sleep(500); //Sleep a little bit to ensure everyone is properly finished
                //clean up the directory
                deleteExistingResults();

                deleteExistingInputFile();
            }
        }
Ejemplo n.º 3
0
        public override void apply(List <VertIndexWeight> verts, float intensity, bool alternate)
        {
            float            speedFactor          = 0.4f;
            BTileBoundingBox vertexTouchedExtends = new BTileBoundingBox();

            float factor = speedFactor * intensity;

            if (alternate)
            {
                factor *= -1.0f;
            }

            // Go through points and adjust accordingly.
            for (int i = 0; i < verts.Count; i++)
            {
                int   index  = verts[i].index;
                float weight = verts[i].weight;

                int z = (int)(index / TerrainGlobals.getEditor().getCameraRep().getNumXPoints());
                int x = (int)(index % TerrainGlobals.getEditor().getCameraRep().getNumZPoints());

                TerrainGlobals.getEditor().getCameraRep().setJaggedHeight(x, z, CameraHeightRep.cJaggedEmptyValue);

                vertexTouchedExtends.addPoint(x, z);
            }

            TerrainGlobals.getEditor().getCameraRep().updateAfterPainted(vertexTouchedExtends.minX, vertexTouchedExtends.minZ, vertexTouchedExtends.maxX, vertexTouchedExtends.maxZ);
        }
Ejemplo n.º 4
0
        static public void createCursor()
        {
            // Release first
            if (gCircleVB != null)
            {
                gCircleVB.Dispose();
                gCircleVB = null;
            }

            gCircleVB = new VertexBuffer(typeof(CursorCircleVert), cNumCircleVBVerts, BRenderDevice.getDevice(), Usage.WriteOnly, VertexFormats.Position, Pool.Default);

            CursorCircleVert[] circularVerts = new CursorCircleVert[cNumCircleVBVerts];

            float angle    = 0;
            float angleInc = (float)((Math.PI * 2.0f) / (cNumCircleVBVerts - 1));
            float radius   = TerrainGlobals.getEditor().getCurrentBrushInfo().mRadius;

            for (int i = 0; i < cNumCircleVBVerts; i++)
            {
                float x = (float)(Math.Cos(angle));
                float y = (float)(Math.Sin(angle));
                circularVerts[i].xyz = new Vector3(x, y, 0.0f);
                angle += angleInc;
            }

            //copy verts over
            unsafe
            {
                using (GraphicsStream stream = gCircleVB.Lock(0, cNumCircleVBVerts * sizeof(CursorCircleVert), LockFlags.None))// (void**)&pVertices, 0))
                {
                    stream.Write(circularVerts);
                    gCircleVB.Unlock();
                }
            }
        }
Ejemplo n.º 5
0
        //------------------------------------------

        public override void render()
        {
            BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, true);
            BRenderDevice.getDevice().SetRenderState(RenderStates.SourceBlend, (int)Microsoft.DirectX.Direct3D.Blend.SourceAlpha);
            BRenderDevice.getDevice().SetRenderState(RenderStates.DestinationBlend, (int)Microsoft.DirectX.Direct3D.Blend.InvSourceAlpha);


            List <BTerrainQuadNode> nodes = new List <BTerrainQuadNode>();
            int closestX = 0;
            int closestZ = 0;

            {
                // in this node, find the CLOSEST vertex to this actual position.
                BTerrainEditor.findClosestVertex(ref closestX, ref closestZ, ref TerrainGlobals.getEditor().mBrushIntersectionPoint, TerrainGlobals.getEditor().mBrushIntersectionNode);

                TerrainGlobals.getTerrain().getQuadNodeRoot().getTileBoundsIntersection(nodes, (int)(closestX - mDecalRadius),
                                                                                        (int)(closestX + mDecalRadius),
                                                                                        (int)(closestZ - mDecalRadius),
                                                                                        (int)(closestZ + mDecalRadius));
            }
            for (int i = 0; i < nodes.Count; i++)
            {
                nodes[i].renderCursor();
            }


            BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, false);
        }
Ejemplo n.º 6
0
        private void setShaderParams()
        {
            //specific to cursor rendering
            Terrain.BrushInfo bi        = TerrainGlobals.getEditor().getCurrentBrushInfo();
            Vector4           brushInfo = new Vector4(bi.mRadius,
                                                      (bi.mHotspot * bi.mRadius),
                                                      0, 0);



            Vector4 selectionColor = new Vector4(1, 1, 0, 1);



            brushInfo.Y = TerrainGlobals.getEditor().mBrushInfo.mIntensity;
            brushInfo.Z = TerrainGlobals.getEditor().mBrushInfo.mRotation;
            brushInfo.W = 1;


            // TerrainGlobals.getRender().mTerrainGPUWidgetShader.mShader.SetValue(mWidgetColorHandle, mCursorColorTint);



            // mTerrainGPUWidgetShader.mShader.SetValue(mWidgetShaderBrushHandle, brushInfo);
            // mTerrainGPUWidgetShader.mShader.SetValue(mWidgetShaderInterPointHandle, shaderIntPt);
        }
Ejemplo n.º 7
0
        public override void render()
        {
            BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, true);
            BRenderDevice.getDevice().SetRenderState(RenderStates.SourceBlend, (int)Microsoft.DirectX.Direct3D.Blend.SourceAlpha);
            BRenderDevice.getDevice().SetRenderState(RenderStates.DestinationBlend, (int)Microsoft.DirectX.Direct3D.Blend.InvSourceAlpha);

            Texture            mask = TerrainGlobals.getTerrainFrontEnd().getSelectedMaskTexture();
            SurfaceDescription sd   = mask.GetLevelDescription(0);

            float validRadius             = sd.Width / 2;
            List <BTerrainQuadNode> nodes = new List <BTerrainQuadNode>();
            int closestX = 0;
            int closestZ = 0;

            {
                // in this node, find the CLOSEST vertex to this actual position.
                BTerrainEditor.findClosestVertex(ref closestX, ref closestZ, ref TerrainGlobals.getEditor().mBrushIntersectionPoint, TerrainGlobals.getEditor().mBrushIntersectionNode);

                TerrainGlobals.getTerrain().getQuadNodeRoot().getTileBoundsIntersection(nodes, (int)(closestX - validRadius),
                                                                                        (int)(closestX + validRadius),
                                                                                        (int)(closestZ - validRadius),
                                                                                        (int)(closestZ + validRadius));
            }
            for (int i = 0; i < nodes.Count; i++)
            {
                nodes[i].renderCursor();
            }


            BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, false);
        }
Ejemplo n.º 8
0
        //----------------------------------
        public void render(bool renderCursor)
        {
            if (!mRenderHeights)
            {
                return;
            }

            List <SpatialQuadTreeCell> nodes = new List <SpatialQuadTreeCell>();

            getVisibleNodes(nodes, TerrainGlobals.getTerrain().getFrustum());

            //update any visual handles that need it..
            for (int i = 0; i < nodes.Count; i++)
            {
                RealLOSRepQuadCell cell = ((RealLOSRepQuadCell)nodes[i].mExternalData);
                Debug.Assert(cell != null);

                if (cell.mVisualHandle == null)
                {
                    cell.mVisualHandle = newVisualHandle((int)cell.mMinXVert, (int)cell.mMinZVert);
                }

                renderCell(cell.mVisualHandle);
            }

            if (renderCursor)
            {
                ((BTerrainCameraBrush)TerrainGlobals.getEditor().getCurrentBrush()).render();
            }
        }
Ejemplo n.º 9
0
        public void apply(List <VertIndexWeight> verts, float intesinty, bool alternate)
        {
            //CLM DEBUGGING
            //  return;


            //   FoliageManager.setSelectedBladeToGrid(0, 0, alternate , false);
            //   FoliageManager.setSelectedBladeToGrid(16, 16, alternate, false);
            //   FoliageManager.setSelectedBladeToGrid(20, 20, alternate, false);
            //   return;


            // Go through points and adjust accordingly.
            for (int i = 0; i < verts.Count; i++)
            {
                int   index  = verts[i].index;
                float weight = verts[i].weight * 0.25f;

                double rnd = rand.NextDouble();
                //use our 'weight' as a randomization factor..
                if (rnd > (double)weight)
                {
                    continue;
                }

                int x = index / TerrainGlobals.getTerrain().getNumZVerts();
                int z = index % TerrainGlobals.getTerrain().getNumZVerts();

                FoliageManager.setSelectedBladeToGrid(x, z, alternate,
                                                      TerrainGlobals.getEditor().getMode() == BTerrainEditor.eEditorMode.cModeFoliageErase);
            }
        }
Ejemplo n.º 10
0
        public override void apply(List <VertIndexWeight> verts, float intensity, bool alternate)
        {
            if (verts.Count == 0)
            {
                return;
            }

            // Set convolution size based on intesity.
            if (intensity <= 0.5f)
            {
                mConvolutionSize = 3;
            }
            else if (intensity <= 0.75f)
            {
                mConvolutionSize = 5;
            }
            else if (intensity <= 0.9f)
            {
                mConvolutionSize = 7;
            }
            else if (intensity <= 1.0f)
            {
                mConvolutionSize = 11;
            }

            mHalfConvolutionSize = (short)(mConvolutionSize / 2);
            int   numConvolutionCoefficients = mConvolutionSize * mConvolutionSize;
            float newVertPos_Y = 0;

            float            speedFactor          = 0.4f;
            BTileBoundingBox vertexTouchedExtends = new BTileBoundingBox();

            float factor = speedFactor * intensity;

            if (alternate)
            {
                factor *= -1.0f;
            }

            // Go through points and adjust accordingly.
            for (int i = 0; i < verts.Count; i++)
            {
                int   index         = verts[i].index;
                float weight        = verts[i].weight;
                float weight_scaled = verts[i].weight * intensity;

                int z = (int)(index / TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumXPoints());
                int x = (int)(index % TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumZPoints());


                applyFastLowPassFilter((int)x, (int)z, out newVertPos_Y);

                TerrainGlobals.getEditor().getSimRep().getHeightRep().setJaggedHeight(x, z, newVertPos_Y);

                vertexTouchedExtends.addPoint(x, z);
            }

            TerrainGlobals.getEditor().getSimRep().updateAfterPainted(vertexTouchedExtends.minX, vertexTouchedExtends.minZ, vertexTouchedExtends.maxX, vertexTouchedExtends.maxZ);
        }
Ejemplo n.º 11
0
        public void updateLandObstructions(float visTileScale, int minX, int minZ, int maxX, int maxZ)
        {
            //use height
            const double maxSlopeAngle = 35;
            float        maxSlope      = (float)Math.Sin(Math.PI * maxSlopeAngle / 180);
            float        tileScale     = visTileScale / mVisToSimMultiplier;

            float maxDotSlope = 0.7f;


            for (int x = minX; x < maxX; x++)
            {
                for (int z = minZ; z < maxZ; z++)
                {
                    int xIndex = (int)BMathLib.Clamp(x + 1, 0, mNumXTiles);
                    int zIndex = (int)BMathLib.Clamp(z + 1, 0, mNumXTiles);



                    // Calculate the 4 corners
                    Vector3 v0 = new Vector3(x * tileScale,
                                             TerrainGlobals.getEditor().getSimRep().getHeightRep().getCompositeHeight(x, z),
                                             z * tileScale);
                    Vector3 v1 = new Vector3((x + 1) * tileScale,
                                             TerrainGlobals.getEditor().getSimRep().getHeightRep().getCompositeHeight(xIndex, z),
                                             z * tileScale);
                    Vector3 v2 = new Vector3(x * tileScale,
                                             TerrainGlobals.getEditor().getSimRep().getHeightRep().getCompositeHeight(x, zIndex),
                                             (z + 1) * tileScale);
                    Vector3 v3 = new Vector3((x + 1) * tileScale,
                                             TerrainGlobals.getEditor().getSimRep().getHeightRep().getCompositeHeight(xIndex, zIndex),
                                             (z + 1) * tileScale);

                    float highest = v0.Y > v1.Y ? v0.Y : v1.Y;
                    highest = highest > v2.Y ? highest : v2.Y;
                    highest = highest > v3.Y ? highest : v3.Y;

                    float lowest = v0.Y < v1.Y ? v0.Y : v1.Y;
                    lowest = lowest < v2.Y ? lowest : v2.Y;
                    lowest = lowest < v3.Y ? lowest : v3.Y;


                    float slp = (highest - lowest) / mTileScale;


                    xIndex = (int)BMathLib.Clamp(x, 0, mNumXTiles - 1);
                    zIndex = (int)BMathLib.Clamp(z, 0, mNumXTiles - 1);

                    if (slp > maxSlope)
                    {
                        mSimLandObstructions[xIndex * mNumXTiles + zIndex] = true;
                    }
                    else
                    {
                        mSimLandObstructions[xIndex * mNumXTiles + zIndex] = false;
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public bool issueAOGenJob(AmbientOcclusion.eAOQuality quality, bool includeObjects, Controls.AOGenDialog primDlg)
        {
            networkAOInterface.ensureDirectories();

            deleteExistingInputFile();
            deleteExistingResults();
            deleteExistingJobs();

            if (doIHavePendingJobs())
            {
                MessageBox.Show("There are still jobs still being processed from this client. \n Please try again in a few moments.");
                return(false);
            }


            string mHostName = Dns.GetHostName();

            mCurrJobGUID    = System.Guid.NewGuid().ToString();
            mIncludeObjects = includeObjects;

            //Now, start up a thread to watch for file IO
            mControllingDialog = primDlg;
            if (mControllingDialog != null)
            {
                mControllingDialog.setNumWorkUnits(cNumSections);
            }

            mNumSectionsToComplete = cNumSections;


            mWorkerThread = new BackgroundWorker();
            mWorkerThread.WorkerReportsProgress      = true;
            mWorkerThread.WorkerSupportsCancellation = true;
            mWorkerThread.DoWork             += bw_DoWork;
            mWorkerThread.ProgressChanged    += bw_ProgressChanged;
            mWorkerThread.RunWorkerCompleted += bw_RunWorkerCompleted;

            mWorkerThread.RunWorkerAsync(quality);


            {
                //clear current AO Values to zero
                float[] AOVals = TerrainGlobals.getEditor().getAmbientOcclusionValues();
                for (int i = 0; i < AOVals.Length; i++)
                {
                    AOVals[i] = 0.0f;
                }

                if (TerrainGlobals.getTerrain().getQuadNodeRoot() != null)
                {
                    TerrainGlobals.getTerrain().getQuadNodeRoot().clearVisibleDatHandle();
                }
            }



            return(true);
        }
Ejemplo n.º 13
0
        void blackoutAO()
        {
            int count = TerrainGlobals.getTerrain().getNumXVerts() * TerrainGlobals.getTerrain().getNumZVerts();

            float[] mAmbientOcclusionValues = TerrainGlobals.getEditor().getAmbientOcclusionValues();
            for (int i = 0; i < count; i++)
            {
                mAmbientOcclusionValues[i] = 0.0f;
            }
        }
Ejemplo n.º 14
0
        public void moveSelectdDecalsFromEditorInput()
        {
            if (mDecalInstances.Count == 0)
            {
                return;
            }

            int xCenterGlobal = 0;
            int zCenterGlobal = 0;

            //CLM THIS MATH IS VERY TRICKY!! PLEASE TALK TO ME BEFORE SCREWING WITH IT!!!!
            //CLM THIS MATH IS VERY TRICKY!! PLEASE TALK TO ME BEFORE SCREWING WITH IT!!!!

            float vertsToHighResPixelSpaceRatio = BTerrainTexturing.getTextureWidth() / BTerrainQuadNode.cMaxWidth;

            int mVisTileIntetersectionX = TerrainGlobals.getEditor().mVisTileIntetersectionX;
            int mVisTileIntetersectionZ = TerrainGlobals.getEditor().mVisTileIntetersectionZ;

            Vector3 intpt = TerrainGlobals.getEditor().mBrushIntersectionPoint;

            for (int i = 0; i < mDecalInstances.Count; i++)
            {
                if (mDecalInstances[i].mIsSelected)
                {
                    int myTileX = mVisTileIntetersectionX; // (int)((mDecalInstances[i].mTileCenter.X / vertsToHighResPixelSpaceRatio) + (diffX));
                    int myTileZ = mVisTileIntetersectionZ; // (int)((mDecalInstances[i].mTileCenter.Y / vertsToHighResPixelSpaceRatio) + (diffZ));

                    BTerrainActiveDecalContainer dcl = mActiveDecals[mDecalInstances[i].mActiveDecalIndex];

                    Vector3 a = TerrainGlobals.getTerrain().getPostDeformPos(myTileX, myTileZ);
                    Vector3 b = TerrainGlobals.getTerrain().getPostDeformPos(myTileX + 1, myTileZ);
                    Vector3 c = TerrainGlobals.getTerrain().getPostDeformPos(myTileX, myTileZ + 1);
                    Vector3 d = TerrainGlobals.getTerrain().getPostDeformPos(myTileX + 1, myTileZ + 1);

                    //find the max def for this tile
                    float x1  = (float)Math.Abs(a.X - b.X);
                    float x2  = (float)Math.Abs(c.X - d.X);
                    float xM  = x1 > x2 ? x1 : x2;
                    float xPT = xM > 0 ? (intpt.X - a.X) / xM : 0; //gives us percentage IN THE TILE

                    float z1  = (float)Math.Abs(a.Z - c.Z);
                    float z2  = (float)Math.Abs(b.Z - d.Z);
                    float zM  = z1 > z2 ? z1 : z2;
                    float zPT = zM > 0 ? (intpt.Z - a.Z) / zM : 0; //gives us percentage IN THE TILE

                    //scale that up to percentages in the space of our pixels
                    mDecalInstances[i].mTileCenter.X = ((xPT * vertsToHighResPixelSpaceRatio) + (myTileX * vertsToHighResPixelSpaceRatio));
                    mDecalInstances[i].mTileCenter.Y = ((zPT * vertsToHighResPixelSpaceRatio) + (myTileZ * vertsToHighResPixelSpaceRatio));

                    recomputeDecalInstanceBounds(i, true);
                }
            }
        }
Ejemplo n.º 15
0
        public void applyFastLowPassFilter(int xPos, int zPos, out float newVertPos_Y)
        {
            int minX = xPos - mHalfConvolutionSize;
            int maxX = xPos + mHalfConvolutionSize;
            int minZ = zPos - mHalfConvolutionSize;
            int maxZ = zPos + mHalfConvolutionSize;


            // Clamp to valid values
            if (minX < 0)
            {
                minX = 0;
            }
            if (minZ < 0)
            {
                minZ = 0;
            }
            if (maxX >= TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumXPoints())
            {
                maxX = (int)(TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumXPoints() - 1);
            }
            if (maxZ >= TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumXPoints())
            {
                maxZ = (int)(TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumXPoints() - 1);
            }

            newVertPos_Y = 0.0f;

            float vec = 0;
            int   numCoefficents = 0;
            int   x, y;

            for (x = minX; x <= maxX; x++)
            {
                for (y = minZ; y <= maxZ; y++)
                {
                    float yJ = TerrainGlobals.getEditor().getSimRep().getHeightRep().getJaggedHeight(x, y);
                    if (yJ == SimHeightRep.cJaggedEmptyValue)
                    {
                        yJ = TerrainGlobals.getEditor().getSimRep().getHeightRep().getHeight(x, y);
                    }
                    newVertPos_Y += yJ;
                    numCoefficents++;
                }
            }

            //  int numCoefficients = TerrainGlobals.getTerrain().getAddedPostDeformRelPos(minX, minZ, maxX, maxZ, out newVertPos_Y);

            float invNumConvCoefficients = 1.0f / numCoefficents;

            newVertPos_Y *= invNumConvCoefficients;
        }
Ejemplo n.º 16
0
        void finalGatherSingleThreaded(gatherWorkerData wd)
        {
            {
                float[]   AOVals      = TerrainGlobals.getEditor().getAmbientOcclusionValues();
                Vector3[] normals     = TerrainGlobals.getEditor().getNormals();
                int       numXVerts   = TerrainGlobals.getTerrain().getNumXVerts();
                int       numZVerts   = TerrainGlobals.getTerrain().getNumZVerts();
                Matrix    worldToProj = wd.workdToProj;

                for (int x = 0; x < numXVerts; x++)
                {
                    for (int z = 0; z < numZVerts; z++)
                    {
                        int index = z + x * numXVerts;

                        //only cast rays towards the light..
                        Vector3 nrm = -normals[index];
                        if (BMathLib.Dot(ref nrm, ref wd.rayDir) < 0)
                        {
                            continue;
                        }


                        Vector3 pos  = TerrainGlobals.getTerrain().getPos(x, z);
                        Vector4 vPos = new Vector4(pos.X, pos.Y, pos.Z, 1);
                        Vector4 rPos = BMathLib.vec4Transform(ref vPos, ref worldToProj);
                        rPos = rPos * (1.0f / rPos.W);
                        float depth = rPos.Z;// +0.07f;//CLM this matches the shader...

                        if (rPos.X < -1 || rPos.X >= 1 || rPos.Y < -1 || rPos.Y >= 1)
                        {
                            continue;
                        }

                        //grab our location in the depthGrid (screen space)
                        float xPos = BMathLib.Clamp(0.5f * rPos.Y + 0.5f, 0, 1);
                        float yPos = BMathLib.Clamp(0.5f * rPos.X + 0.5f, 0, 1);


                        int xGridLoc = (int)((wd.imgWidth - 1) * (1 - xPos));
                        int yGridLoc = (int)((wd.imgHeight - 1) * (yPos));

                        if (!wd.fragList[xGridLoc, yGridLoc].anyValueSmaller(depth))
                        {
                            AOVals[index] += wd.rcpNumSamples;
                            Debug.Assert(AOVals[index] <= 1);
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
        public Texture giveEntireTerrainInTexture()
        {
            try
            {
                int     width   = TerrainGlobals.getTerrain().getNumXVerts();
                int     height  = TerrainGlobals.getTerrain().getNumXVerts();
                Texture mainTex = new Texture(BRenderDevice.getDevice(), width, height, 1, Usage.None, Format.A32B32G32R32F, Pool.Managed);

                Vector3[] details = TerrainGlobals.getEditor().getDetailPoints();
                unsafe
                {
                    GraphicsStream streamPos = mainTex.LockRectangle(0, LockFlags.None);
                    Vector4 *      pos       = (Vector4 *)streamPos.InternalDataPointer;

                    for (int x = 0; x < width; x++)
                    {
                        for (int y = 0; y < height; y++)
                        {
                            int     srcIndex = x * width + y;
                            int     dstIndex = x * width + y;
                            Vector3 input    = details[srcIndex];
                            pos[dstIndex].X = input.X;
                            pos[dstIndex].Y = input.Y;
                            pos[dstIndex].Z = input.Z;
                            pos[dstIndex].W = 1;
                        }
                    }

                    mainTex.UnlockRectangle(0);
                }

                return(mainTex);
            }
            catch (OutOfVideoMemoryException eGPU)
            {
                if (!CoreGlobals.IsBatchExport)
                {
                    MessageBox.Show("giveEntireTerrainInTexture: You've run out of graphics card memory... Talk to the editor guys..");
                }
                return(null);
            }
            catch (OutOfMemoryException eCPU)
            {
                if (!CoreGlobals.IsBatchExport)
                {
                    MessageBox.Show("giveEntireTerrainInTexture: You've run out of memory... Talk to the editor guys..");
                }
                return(null);
            }
            return(null);
        }
Ejemplo n.º 18
0
        public void issueAOGenLocal(AmbientOcclusion.eAOQuality quality, bool includeObjects, Controls.AOGenDialog primDlg)
        {
            mControllingDialog = primDlg;
            if (mControllingDialog != null)
            {
                mControllingDialog.setNumWorkUnits(1);
            }

            TerrainGlobals.getEditor().computeAmbientOcclusion(quality, includeObjects);
            if (mControllingDialog != null)
            {
                mControllingDialog.increaseWorkUnitCount();
            }
        }
Ejemplo n.º 19
0
        static private void clearLightInfluence(int minXVert, int minZVert)
        {
            Vector3[] lht = TerrainGlobals.getEditor().getLightValues();
            for (int x = 0; x < BTerrainQuadNode.cMaxWidth; x++)
            {
                for (int y = 0; y < BTerrainQuadNode.cMaxHeight; y++)
                {
                    int index = (minXVert + x) * TerrainGlobals.getTerrain().getNumXVerts() + (minZVert + y);

                    lht[index].X = 0;
                    lht[index].Y = 0;
                    lht[index].Z = 0;
                }
            }
        }
Ejemplo n.º 20
0
        // applyOnBrush
        public virtual void applyOnBrush(List <int> indexes, ref Vector3 brushApplyPt, ref Vector3 brushApplyNormal, ref BrushInfo brushInfo, bool alternate)
        {
            //using (PerfSection p = new PerfSection("applyOnBrush"))
            {
                if (brushInfo.mRadius < 0.001)
                {
                    return;
                }

                List <VertIndexWeight> verts = new List <VertIndexWeight>();

                // Loop through all points
                for (int i = 0; i < indexes.Count; i++)
                {
                    int index = indexes[i];

                    int z = (int)(index / TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumXPoints());
                    int x = (int)(index % TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumZPoints());

                    if (z > TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumXPoints() ||
                        x > TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumZPoints())
                    {
                        continue;
                    }
                    float vertSelectionWeight = 1.0f;// TerrainGlobals.getTerrain().getSoftSelectionWeight(x, z);
                    //if (vertSelectionWeight == 0.0f)
                    //   continue;

                    //Vector3 vertCurrentPos = TerrainGlobals.getTerrain().getPostDeformPos(x, z);
                    //Vector3 vertCurrentPos = TerrainGlobals.getEditor().getSimRep()getOverridePos(x, z);
                    Vector3 vertCurrentPos = TerrainGlobals.getEditor().getSimRep().getHeightRep().getWorldspacePoint(x, z).toVec3();

                    float factor = 0f;
                    if (!TerrainGlobals.getEditor().vertInBrushArea(ref vertCurrentPos, ref brushApplyPt, brushInfo.mRadius, brushInfo.mHotspot * brushInfo.mRadius, brushInfo.mCurveType, brushInfo.mIntersectionShape, out factor))
                    {
                        continue;
                    }


                    verts.Add(new VertIndexWeight(index, vertSelectionWeight * factor));
                }

                if (verts.Count > 0)
                {
                    apply(verts, brushInfo.mIntensity, alternate);
                }
            }
        }
Ejemplo n.º 21
0
        static public void rasterLightsToNode(worldChunk wc)
        {
            if (!TerrainGlobals.getEditor().doShowLighting())
            {
                return;
            }

            clearLightInfluence(wc.mQNPointer.getDesc().mMinXVert, wc.mQNPointer.getDesc().mMinZVert);
            wc.mQNPointer.mDirty = true;
            wc.mQNPointer.clearVisibleDatHandle();
            for (int i = 0; i < wc.mLightsAffectingMe.Count; i++)
            {
                SimEditor.LocalLight ll = wc.mLightsAffectingMe[i].mSimEditorObject;
                rasterLightToGrid(ll, TerrainGlobals.getEditor().getLightValues(), wc.mQNPointer.getDesc().mMinXVert, wc.mQNPointer.getDesc().mMinZVert);
            }
        }
Ejemplo n.º 22
0
        public Vector3 getIntersectPointFromScreenCursor()
        {
            float3  currIntersectionPt = float3.Empty;
            Vector3 orig = TerrainGlobals.getEditor().getRayPosFromMouseCoords(false);
            Vector3 dir  = TerrainGlobals.getEditor().getRayPosFromMouseCoords(true) - orig;

            dir = BMathLib.Normalize(dir);

            //get our intersect point
            if (!getClosestIntersectionPoint(new float3(orig), new float3(dir), out currIntersectionPt))
            {
                return(Vector3.Empty);
            }

            return(currIntersectionPt.toVec3());
        }
Ejemplo n.º 23
0
        public void applyUnitLOS(bool alternate)
        {
            if (TerrainGlobals.getEditor().getStrokeInputType() == BTerrainEditor.eEditorStrokeInput.cStrokeInputMouse)
            {
                //raycast and get our intersection
                Vector3 orig = TerrainGlobals.getEditor().getRayPosFromMouseCoords(false);
                Vector3 dir  = TerrainGlobals.getEditor().getRayPosFromMouseCoords(true) - orig;
                dir = BMathLib.Normalize(dir);

                //get our intersect point
                if (!getClosestIntersectionPoint(new float3(orig), new float3(dir), out mLastMoustIntPt))
                {
                    return;
                }


                int X = (int)(mLastMoustIntPt.X / mTileScale); //Math.Pow(2, 6));
                int Z = (int)(mLastMoustIntPt.Z / mTileScale); //Math.Pow(2, 6));

                TileInfo t = mTileLOS[X * mWidth + Z];

                int index = (int)(X * mWidth + Z);


                if (t.mbHasUnit == alternate)
                {
                    return;
                }

                t.mbHasUnit = alternate;

                if (alternate)
                {
                    mColors[index] = 0;
                }
                else
                {
                    mColors[index] = 0x44ff0000;
                }


                TestLOS();


                recalculateVisuals();
            }
        }
Ejemplo n.º 24
0
        public void applySimRepBrush(bool alternate)
        {
            if (TerrainGlobals.getEditor().getStrokeInputType() == BTerrainEditor.eEditorStrokeInput.cStrokeInputMouse)
            {
                //raycast and get our intersection
                Vector3 orig = TerrainGlobals.getEditor().getRayPosFromMouseCoords(false);
                Vector3 dir  = TerrainGlobals.getEditor().getRayPosFromMouseCoords(true) - orig;
                dir = BMathLib.Normalize(dir);

                //get our intersect point
                if (!getClosestIntersectionPoint(new float3(orig), new float3(dir), out mLastMoustIntPt))
                {
                    return;
                }

                //If we're in tile mode, shift our center over to better match what our cursor is doing...
                if (TerrainGlobals.getEditor().getMode() == BTerrainEditor.eEditorMode.cModeSimBuildibility ||
                    TerrainGlobals.getEditor().getMode() == BTerrainEditor.eEditorMode.cModeSimPassibility ||
                    TerrainGlobals.getEditor().getMode() == BTerrainEditor.eEditorMode.cModeSimFloodPassibility ||
                    TerrainGlobals.getEditor().getMode() == BTerrainEditor.eEditorMode.cModeSimScarabPassibility)
                {
                    mLastMoustIntPt.X += mTileScale;
                    mLastMoustIntPt.Z += mTileScale;
                }

                // Undo info
                // addVertexUndoNodes(nodes, false);

                // Find affected points
                List <int> points = new List <int>();
                getPointsIntersectingSphere(points, mLastMoustIntPt, TerrainGlobals.getEditor().mBrushInfo.mRadius);

                Vector3   intPoint  = mLastMoustIntPt.toVec3();
                Vector3   intNormal = BMathLib.unitY;
                BrushInfo bi        = TerrainGlobals.getEditor().getCurrentBrushInfo();
                ((BTerrainSimBrush)TerrainGlobals.getEditor().getCurrentBrush()).applyOnBrush(points, ref intPoint, ref intNormal,
                                                                                              ref bi,
                                                                                              alternate);

                // addVertexUndoNodes(nodes, true);
            }
            else if (TerrainGlobals.getEditor().getStrokeInputType() == BTerrainEditor.eEditorStrokeInput.cStrokeInputKeyboard)
            {
                BrushInfo bi = TerrainGlobals.getEditor().getCurrentBrushInfo();
                ((BTerrainSimBrush)TerrainGlobals.getEditor().getCurrentBrush()).applyOnSelection(Masking.getCurrSelectionMaskWeights(), bi.mIntensity, alternate);
            }
        }
Ejemplo n.º 25
0
        public void applyCameraRepBrush(bool alternate)
        {
            if (TerrainGlobals.getEditor().getStrokeInputType() == BTerrainEditor.eEditorStrokeInput.cStrokeInputMouse)
            {
                //raycast and get our intersection
                Vector3 orig = TerrainGlobals.getEditor().getRayPosFromMouseCoords(false);
                Vector3 dir  = TerrainGlobals.getEditor().getRayPosFromMouseCoords(true) - orig;
                dir = BMathLib.Normalize(dir);

                //get our intersect point
                if (!getClosestIntersectionPoint(new float3(orig), new float3(dir), out mLastMoustIntPt))
                {
                    return;
                }

                // Undo info
                // addVertexUndoNodes(nodes, false);

                // Find affected points
                List <int> points = new List <int>();
                getPointsIntersectingSphere(points, mLastMoustIntPt, TerrainGlobals.getEditor().mBrushInfo.mRadius);

                Vector3   intPoint  = mLastMoustIntPt.toVec3();
                Vector3   intNormal = BMathLib.unitY;
                BrushInfo bi        = TerrainGlobals.getEditor().getCurrentBrushInfo();
                ((BTerrainCameraBrush)TerrainGlobals.getEditor().getCurrentBrush()).applyOnBrush(points, ref intPoint, ref intNormal,
                                                                                                 ref bi,
                                                                                                 alternate);

                // addVertexUndoNodes(nodes, true);
            }
            else if (TerrainGlobals.getEditor().getStrokeInputType() == BTerrainEditor.eEditorStrokeInput.cStrokeInputKeyboard)
            {
                //int multiplier = 10;
                //// Apply on selection

                //List<BTerrainQuadNode> nodes = new List<BTerrainQuadNode>();
                //TerrainGlobals.getTerrain().getQuadNodeRoot().getTileBoundsIntersection(nodes, Masking.mCurrSelectionMaskExtends.minX, Masking.mCurrSelectionMaskExtends.maxX,
                //                                                                         Masking.mCurrSelectionMaskExtends.minZ, Masking.mCurrSelectionMaskExtends.maxZ);



                //((BTerrainFoliageBrush)mCurrBrush).applyOnSelection(Masking.getCurrSelectionMaskWeights(), this.mBrushInfo.mIntensity,
                //   alternate || mCurrMode == eEditorMode.cModeFoliageErase);
            }
        }
Ejemplo n.º 26
0
        public override void apply(List <VertIndexWeight> verts, float intensity, bool alternate)
        {
            if (verts.Count == 0)
            {
                return;
            }
            BTileBoundingBox vertexTouchedExtends = new BTileBoundingBox();

            if (alternate)
            {
                return;
            }


            // Go through points and adjust accordingly.
            for (int i = 0; i < verts.Count; i++)
            {
                int   index  = verts[i].index;
                float weight = verts[i].weight;

                int z = (int)(index / TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumXPoints());
                int x = (int)(index % TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumZPoints());


                //float currHeight = TerrainGlobals.getTerrain().getPos(z, x).Y;
                //float suggHeight = mSampledHeight * weight;

                //float targetHeight = (Math.Abs(mSampledHeight - suggHeight) > Math.Abs(mSampledHeight - currHeight)) ? currHeight : suggHeight;


                //// Change the vertex.
                //float overideHeight = heights.GetValue(transIndex);
                //if (overideHeight != BTerrainSimRep.cJaggedEmptyValue)
                //{
                //   targetHeight = (Math.Abs(mSampledHeight - overideHeight) > Math.Abs(mSampledHeight - targetHeight)) ? targetHeight : overideHeight;
                //}


                TerrainGlobals.getEditor().getSimRep().getHeightRep().setJaggedHeight(x, z, mSampledHeight);

                vertexTouchedExtends.addPoint(x, z);
            }


            TerrainGlobals.getEditor().getSimRep().updateAfterPainted(vertexTouchedExtends.minX, vertexTouchedExtends.minZ, vertexTouchedExtends.maxX, vertexTouchedExtends.maxZ);
        }
Ejemplo n.º 27
0
        //CLM USED FOR GAME
        public unsafe void convertLayersToTexturingDataHandle(BTerrainLayerContainer input, BTerrainCompositeTexture output, BTerrainQuadNode node, int lod)
        {
            //lock in our alpha texture
            BTerrainQuadNodeDesc desc         = node.getDesc();
            int numlayers                     = input.getNumLayers();
            BTerrainLayerContainer tContainer = TerrainGlobals.getEditor().generateContainerFromTexDeformations(desc.mMinXVert, desc.mMinZVert);

            if (tContainer == null)
            {
                tContainer = input;
            }


            tContainer.toTextureArray(ref mTempAlphaTextures, desc.mMinXVert, desc.mMinZVert);
            convertLayersToTexturingDataHandle(tContainer, mTempAlphaTextures, output, desc.mMinXVert, desc.mMinZVert, lod, (int)BTerrainTexturing.eTextureChannels.cSplatChannelCount);

            tContainer = null;
        }
Ejemplo n.º 28
0
        void updateBetterSim(bool restore)
        {
            TerrainCreationParams prms = new TerrainCreationParams();

            if (!restore)
            {
                mOldSimTileScale = 1.0f / TerrainGlobals.getEditor().getSimRep().getVisToSimScale();
                prms.initFromVisData(TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumZVerts(), TerrainGlobals.getTerrain().getTileScale(), 1);
                TerrainGlobals.getEditor().getSimRep().reinit(prms.mNumSimXTiles, prms.mNumSimZTiles, prms.mSimTileSpacing, 1);
            }
            else
            {
                prms.initFromVisData(TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumZVerts(), TerrainGlobals.getTerrain().getTileScale(), mOldSimTileScale);

                TerrainGlobals.getEditor().getSimRep().reinit(prms.mNumSimXTiles, prms.mNumSimZTiles, prms.mSimTileSpacing, 1.0f / (float)mOldSimTileScale);
            }

            TerrainGlobals.getEditor().getSimRep().update(false, false);//updateSimRep(TerrainGlobals.getEditor().getDetailPoints(), TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getTileScale(), false);
        }
Ejemplo n.º 29
0
        public override void applyOnSelection(IMask selection, float intensity, bool alternate)
        {
            //using (PerfSection p = new PerfSection("applyOnSelection"))
            {
                if (!isApplyOnSelectionEnabled())
                {
                    return;
                }

                List <VertIndexWeight> verts = new List <VertIndexWeight>();

                //Dictionary<long, float>.Enumerator pointsIterator = points.GetEnumerator();
                long  index;
                float weight;
                selection.ResetIterator();
                while (selection.MoveNext(out index, out weight))
                {
                    if (weight == 0.0f)
                    {
                        continue;
                    }

                    //mask indicies are in vis-vert space
                    int x = (int)(index / TerrainGlobals.getTerrain().getNumZVerts());
                    int z = (int)(index % TerrainGlobals.getTerrain().getNumZVerts());

                    //convert to local vert space (scale values here to match up with what "apply" expects)
                    x = (int)Math.Ceiling(x * TerrainGlobals.getEditor().getSimRep().getVisToSimScale()) + 1;
                    z = (int)Math.Ceiling(z * TerrainGlobals.getEditor().getSimRep().getVisToSimScale()) + 1;

                    if (x < 0 || z < 0)
                    {
                        continue;
                    }

                    index = x + TerrainGlobals.getEditor().getSimRep().getHeightRep().getNumXPoints() * z;
                    verts.Add(new VertIndexWeight((int)index, weight));
                }

                apply(verts, intensity, alternate);
            }
        }
Ejemplo n.º 30
0
        static public void rebuildVisualsAfterSelection()
        {
            TerrainGlobals.getTerrain().getQuadNodeRoot().clearVisibleDatHandle();
            List <BTerrainQuadNode> nodes = new List <BTerrainQuadNode>();


            TerrainGlobals.getTerrain().getQuadNodeRoot().getTileBoundsIntersection(nodes, mCurrSelectionMaskExtends.minX, mCurrSelectionMaskExtends.maxX,
                                                                                    mCurrSelectionMaskExtends.minZ, mCurrSelectionMaskExtends.maxZ);


            for (int k = 0; k < nodes.Count; k++)
            {
                nodes[k].mDirty = true;
                BTerrainQuadNodeDesc desc = nodes[k].getDesc();

                BTerrain.computeBasis(TerrainGlobals.getEditor().getDetailPoints(), TerrainGlobals.getEditor().getNormals(),
                                      TerrainGlobals.getTerrain().getTileScale(), TerrainGlobals.getTerrain().getNumXVerts(),
                                      desc.mMinXVert, desc.mMaxXVert, desc.mMinZVert, desc.mMaxZVert);
            }

            TerrainGlobals.getTerrain().rebuildDirtyPostDeform(BRenderDevice.getDevice());
        }