Exemple #1
0
        void writeTempTerrainToZip(ZipArchive zip)
        {
            int version = 0;

            //Write our terrain information
            AbstractFile md = zip.CreateFile("terrain.tdl", true);

            //Write the size of our data..
            Stream       stream = md.OpenWrite(true);//File.Open(filename, FileMode.OpenOrCreate, FileAccess.Write);
            BinaryWriter bw     = new BinaryWriter(stream);

            bw.Write(version);
            bw.Write(TerrainGlobals.getTerrain().getNumXVerts());
            bw.Write(TerrainGlobals.getTerrain().getNumZVerts());
            bw.Write(TerrainGlobals.getTerrain().getTileScale());

            //min
            Vector3 min = TerrainGlobals.getTerrain().getQuadNodeRoot().getDesc().m_min;

            bw.Write(min.X); bw.Write(min.Y); bw.Write(min.Z);

            //max
            Vector3 max = TerrainGlobals.getTerrain().getQuadNodeRoot().getDesc().m_max;

            bw.Write(max.X); bw.Write(max.Y); bw.Write(max.Z);

            //write terrain positions
            for (int x = 0; x < TerrainGlobals.getTerrain().getNumXVerts(); x++)
            {
                for (int z = 0; z < TerrainGlobals.getTerrain().getNumZVerts(); z++)
                {
                    Vector3 pos = TerrainGlobals.getTerrain().getRelPos(x, z);
                    bw.Write(pos.X); bw.Write(pos.Y); bw.Write(pos.Z);
                }
            }

            for (int x = 0; x < TerrainGlobals.getTerrain().getNumXVerts(); x++)
            {
                for (int z = 0; z < TerrainGlobals.getTerrain().getNumZVerts(); z++)
                {
                    Vector3 pos = TerrainGlobals.getTerrain().getNormal(x, z);
                    bw.Write(pos.X); bw.Write(pos.Y); bw.Write(pos.Z);
                }
            }



            //write quadnodes
            BTerrainQuadNode[] mNodes = TerrainGlobals.getTerrain().getQuadNodeLeafArray();
            bw.Write(mNodes.Length);
            for (int i = 0; i < mNodes.Length; i++)
            {
                BTerrainQuadNodeDesc desc = mNodes[i].getDesc();
                bw.Write(desc.mMinXVert);
                bw.Write(desc.mMinZVert);
            }

            bw.Close();
            stream.Close();
        }
Exemple #2
0
        static public void setBladeToGrid(int idx, string setName, int bladeIndex, bool erase, bool forceErase)
        {
            int x = idx / TerrainGlobals.getTerrain().getNumXVerts();
            int z = idx - x * TerrainGlobals.getTerrain().getNumXVerts();

            setBladeToGrid(x, z, setName, bladeIndex, erase, forceErase);
        }
Exemple #3
0
        //-----------------------------------------------------------------------------------

        //-----------------------------------------------------------------------------------
        void calculateWorldBounds(bool includeSimMod)
        {
            float tileScale = TerrainGlobals.getTerrain().getTileScale();

            mWorldMin    = TerrainGlobals.getTerrain().getQuadNodeRoot().getDesc().m_min;
            mWorldMax    = TerrainGlobals.getTerrain().getQuadNodeRoot().getDesc().m_max;
            mWorldMin.Y -= 1.0f;
            mWorldMax.Y += 1.0f;
            mWorldMin.X  = (float)Math.Floor(mWorldMin.X);
            mWorldMin.Y  = (float)Math.Floor(mWorldMin.Y);
            mWorldMin.Z  = (float)Math.Floor(mWorldMin.Z);
            mWorldMax.X  = (float)Math.Ceiling(mWorldMax.X);
            mWorldMax.Y  = (float)Math.Ceiling(mWorldMax.Y);
            mWorldMax.Z  = (float)Math.Ceiling(mWorldMax.Z);

            if (includeSimMod)
            {
                //include any bounding boxes from objects we're including..
                BBoundingBox bb = SimGlobals.getSimMain().getBBoxForDecalObjects();
                bb.addPoint(mWorldMax);
                bb.addPoint(mWorldMin);
                mWorldMin.Y = bb.min.Y;
                mWorldMax.Y = bb.max.Y;
            }
            if (mWorldMin.X < 0)
            {
                mWorldMin.X = 0;
            }
            if (mWorldMin.Z < 0)
            {
                mWorldMin.Z = 0;
            }
        }
Exemple #4
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);
        }
Exemple #5
0
        public override void render()
        {
            BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, true);
            BRenderDevice.getDevice().SetRenderState(RenderStates.SourceBlend, (int)Blend.SourceAlpha);
            BRenderDevice.getDevice().SetRenderState(RenderStates.DestinationBlend, (int)Blend.InvSourceAlpha);
            BRenderDevice.getDevice().SetRenderState(RenderStates.CullMode, (int)Cull.None);

            int xRad = mWidth >> 1;
            int zRad = mHeight >> 1;



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

            TerrainGlobals.getTerrain().getQuadNodeRoot().getVertBoundsIntersection(nodes, mCenterX - xRad, mCenterX + xRad, mCenterZ - zRad, mCenterZ + zRad);
            for (int i = 0; i < nodes.Count; i++)
            {
                nodes[i].renderWidget(0);
            }


            BRenderDevice.getDevice().SetRenderState(RenderStates.AlphaBlendEnable, false);
            BRenderDevice.getDevice().SetRenderState(RenderStates.CullMode, (int)Cull.CounterClockwise);

            base.render();
        }
Exemple #6
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);
        }
Exemple #7
0
        void calculateWorldBounds(ref Vector3 mWorldMin, ref Vector3 mWorldMax, ref BBoundingBox worldBounds, bool renderWorldObjects)
        {
            float tileScale = TerrainGlobals.getTerrain().getTileScale();

            mWorldMin    = TerrainGlobals.getTerrain().getQuadNodeRoot().getDesc().m_min; // -new Vector3(tileScale, tileScale, tileScale);
            mWorldMax    = TerrainGlobals.getTerrain().getQuadNodeRoot().getDesc().m_max; // +new Vector3(tileScale, tileScale, tileScale);
            mWorldMin.Y -= 1.0f;
            mWorldMax.Y += 1.0f;
            mWorldMin.X  = (float)Math.Floor(mWorldMin.X);
            mWorldMin.Y  = (float)Math.Floor(mWorldMin.Y);
            mWorldMin.Z  = (float)Math.Floor(mWorldMin.Z);
            mWorldMax.X  = (float)Math.Ceiling(mWorldMax.X);
            mWorldMax.Y  = (float)Math.Ceiling(mWorldMax.Y);
            mWorldMax.Z  = (float)Math.Ceiling(mWorldMax.Z);

            //CLM TEMPORARY!!!
            //if(renderWorldObjects)
            //{
            //   //include any bounding boxes from objects we're including..
            //   BBoundingBox bb = SimGlobals.getSimMain().getBBoxForAOObjects();
            //   bb.addPoint(mWorldMax);
            //   bb.addPoint(mWorldMin);


            //   mWorldMin.Y = bb.min.Y;
            //   mWorldMax.Y = bb.max.Y;
            //}

            worldBounds.min    = mWorldMin;
            worldBounds.min.Y -= 2;
            worldBounds.max    = mWorldMax;
            worldBounds.max.Y += 2;
        }
Exemple #8
0
        //CLM Called when a light is moved by the user
        static public void moveLight(int editorObjectIndex)
        {
            int lightIndex = giveLightIndex(editorObjectIndex);

            if (lightIndex == -1)
            {
                return;
            }

            //copy our influence list
            List <worldChunk> wcList = new List <worldChunk>();

            copyList(mLights[lightIndex].mWorldChunksImAffecting, wcList);

            //remove this light from the world grid
            removeLightFromGrid(mLights[lightIndex]);

            //add this light to the world grid
            addLightToGrid(mLights[lightIndex]);

            //merge the two lists
            mergeList(mLights[lightIndex].mWorldChunksImAffecting, wcList);

            //reload affected qns
            for (int i = 0; i < wcList.Count; i++)
            {
                rasterLightsToNode(wcList[i]);
            }

            TerrainGlobals.getTerrain().rebuildDirtyPostDeform(BRenderDevice.getDevice());
        }
Exemple #9
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();
            }
        }
Exemple #10
0
        //NOTE, PASS 0 or numPoints for "I DON'T CARE"
        public void generateNavMesh(uint vertQuantizationDist, uint maxNumQuantizedPoints)
        {
            updateBetterSim(false);

            Export360.XTD_DeulanyTIN tin = new Export360.XTD_DeulanyTIN();

            //add edges into the mix.
            List <Point> primeSimVerts = new List <Point>();

            addEdgeVerts(primeSimVerts);

            identifyPrimeSimVerts(primeSimVerts, vertQuantizationDist, maxNumQuantizedPoints);

            ////  removeUnWantedVerts(primeSimVerts);

            //  add the sim verts to the TIN
            for (int i = 0; i < primeSimVerts.Count; i++)
            {
                tin.addVertex(TerrainGlobals.getTerrain().getPostDeformPos(primeSimVerts[i].X, primeSimVerts[i].Y));
            }



            //create our TIN
            tin.Triangulate();


            mPathMeshVerts = tin.getVertList();
            //remove impassible tris & Tris w/ no area
            mPathMeshTris = tin.getTriList();
            pruneTriList(mPathMeshTris, primeSimVerts); //NOTE, this may leave some un-used verts in the list.. do we care? humm..
            //  pruneUnusedVerts(mPathMeshTris, primeSimVerts); //If we do, call this....?

            updateBetterSim(true); //put the sim back.. (temp)
        }
Exemple #11
0
        static public void scaleSelection(float amt, bool addOrPercent)
        {
            int totalNumVerts = TerrainGlobals.getTerrain().getNumXVerts();

            float fact = 0;

            for (int x = 0; x < totalNumVerts; x++)
            {
                for (int z = 0; z < totalNumVerts; z++)
                {
                    if (Masking.isPointSelected(x, z, ref fact))
                    {
                        if (addOrPercent)
                        {
                            fact = BMathLib.Clamp(fact + amt, 0, 1);
                        }
                        else
                        {
                            fact = BMathLib.Clamp(fact * amt, 0, 1);
                        }
                        Masking.addSelectedVert(x, z, fact);
                    }
                }
            }
            rebuildVisualsAfterSelection();
        }
Exemple #12
0
        //used as a filter.
        static public void createSelectionMaskFromTerrain(float minHeight, float maxHeight, float slopeValue, float range)
        {
            //clearSelectionMask();

            int totalNumVerts = TerrainGlobals.getTerrain().getNumXVerts();
            int i             = -1;

            //range = 0.1f;

            for (int x = 0; x < totalNumVerts; x++)
            {
                for (int z = 0; z < totalNumVerts; z++)
                {
                    i++;
                    if (TerrainGlobals.getTerrain().getPostDeformPos(x, z).Y < minHeight ||
                        TerrainGlobals.getTerrain().getPostDeformPos(x, z).Y > maxHeight)
                    {
                        continue;
                    }

                    float factor = Vector3.Dot(TerrainGlobals.getTerrain().getPostDeformNormal(x, z), BMathLib.unitY);
                    if (factor < 0 || Math.Abs(slopeValue - factor) > range)
                    {
                        continue;
                    }

                    addSelectedVert(x, z, factor);
                }
            }
            smoothFilter();
        }
Exemple #13
0
        //light deleted, remove from our manager
        static public void freeLight(int editorObjectIndex)
        {
            int lightIndex = giveLightIndex(editorObjectIndex);

            if (lightIndex == -1)
            {
                return;
            }
            List <worldChunk> wcList = new List <worldChunk>();

            copyList(mLights[lightIndex].mWorldChunksImAffecting, wcList);

            //remove this light from the world grid
            removeLightFromGrid(mLights[lightIndex]);

            //reload affected qns
            for (int i = 0; i < wcList.Count; i++)
            {
                rasterLightsToNode(wcList[i]);
            }

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

            //remove this light from the main list
            mLights.RemoveAt(lightIndex);
        }
Exemple #14
0
        static public void clearSelectionMask()
        {
            if (mCurrSelectionMask.HasData())
            {
                if (CoreGlobals.getEditorMain().mIMaskPickerUI == null)
                {
                    CoreGlobals.getEditorMain().mIGUI.ShowDialog("MaskLayers");
                }
                CoreGlobals.getEditorMain().mIMaskPickerUI.SetLastMask(mCurrSelectionMask);
            }

            mCurrSelectionMask.Clear();

            if (TerrainGlobals.getTerrain().getQuadNodeRoot() != null)
            {
                List <BTerrainQuadNode> nodes = new List <BTerrainQuadNode>();
                TerrainGlobals.getTerrain().getQuadNodeRoot().getTileBoundsIntersection(nodes, mCurrSelectionMaskExtends.minX, mCurrSelectionMaskExtends.maxX,
                                                                                        mCurrSelectionMaskExtends.minZ, mCurrSelectionMaskExtends.maxZ);

                for (int i = 0; i < nodes.Count; i++)
                {
                    nodes[i].mDirty = true;
                }
                TerrainGlobals.getTerrain().rebuildDirtyPostDeform(BRenderDevice.getDevice());
            }

            // Reset extends
            mCurrSelectionMaskExtends.empty();
        }
Exemple #15
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);
            }
        }
Exemple #16
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();
            }
        }
Exemple #17
0
        static public void setSelectedBladeToGrid(int idx, bool erase, bool forceErase)
        {
            int x = idx / TerrainGlobals.getTerrain().getNumXVerts();
            int z = idx - x * TerrainGlobals.getTerrain().getNumXVerts();

            setSelectedBladeToGrid(x, z, erase, forceErase);
        }
Exemple #18
0
        public static void init()
        {
            mVertData = new JaggedContainer <FoliageVertData>(TerrainGlobals.getTerrain().getNumXVerts() * TerrainGlobals.getTerrain().getNumZVerts());
            mVertData.SetEmptyValue(cEmptyVertData);

            loadShader();
        }
Exemple #19
0
        public static Image ExportMask(IMask mask)
        {
            int       width  = TerrainGlobals.getTerrain().getNumXVerts();
            int       height = TerrainGlobals.getTerrain().getNumZVerts();
            Rectangle r      = new Rectangle(0, 0, width, height);

            Bitmap destination = new Bitmap(width, height, PixelFormat.Format24bppRgb);

            unsafe
            {
                BitmapData outputData = destination.LockBits(r, ImageLockMode.WriteOnly, destination.PixelFormat);
                if (outputData.PixelFormat == PixelFormat.Format24bppRgb)
                {
                    PixelData24 *outputBase = (PixelData24 *)outputData.Scan0;

                    for (int x = 0; x < width; x++)
                    {
                        for (int y = 0; y < height; y++)
                        {
                            PixelData24 *pPixel      = outputBase + y * width + x;
                            long         index       = y * width + x;
                            float        value       = mask.GetMaskWeight(index);
                            byte         outputValue = (byte)(value * byte.MaxValue);
                            pPixel->blue  = outputValue;
                            pPixel->red   = outputValue;
                            pPixel->green = outputValue;
                        }
                    }
                    destination.UnlockBits(outputData);
                }
            }
            return((Image)destination);
        }
Exemple #20
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);
        }
Exemple #21
0
        void identifyPrimeSimVerts(List <Point> primeSimVerts, uint vertQuantizationDist, uint maxNumQuantizedPoints)
        {
            int width = TerrainGlobals.getTerrain().getNumXVerts();

            //walk the tiles, generate a 3x3 bit definition
            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < width; z++)
                {
                    //get the 4 tiles touching me

                    int val = giveSimValueForVisVert(x, z, false);

                    //if this mapping is in our ignore list, then ignore it.
                    bool ok = false;
                    for (int i = 0; i < mSimTileCornerDefn16.Length; i++)
                    {
                        if (val == mSimTileCornerDefn16[i])
                        {
                            ok = true;
                            break;
                        }
                    }


                    if (ok)
                    {
                        primeSimVerts.Add(new Point(x, z));
                    }
                }
            }

            //don't quantize if we aren't told to
            if (maxNumQuantizedPoints == 0)
            {
                return;
            }

            //Now, QUANTIZE these verts into a working set...
            //CLM is this really what we want to do? We need to minimize the concave hull, but this actually eliminates the concave hull if the number of points are
            //small enough..
            int numDesiredQuantizedPoints = (int)(primeSimVerts.Count * 0.5f);// (int)Math.Min(maxNumQuantizedPoints, primeSimVerts.Count * 0.8f);
            Weighted_MinMax_Quantizer vq  = new Weighted_MinMax_Quantizer();

            for (int i = 0; i < primeSimVerts.Count; i++)
            {
                Vector3 p = new Vector3(primeSimVerts[i].X, primeSimVerts[i].Y, 0);
                vq.insert(p, 1.0f);
            }
            vq.quantize(vertQuantizationDist, numDesiredQuantizedPoints);
            primeSimVerts.Clear();
            for (int i = 0; i < vq.num_output_cells(); i++)
            {
                primeSimVerts.Add(new Point((int)vq.output_cell(i).X, (int)vq.output_cell(i).Y));
            }
        }
Exemple #22
0
 static public bool checkBaseWritePermission(int x, int z, out float value)
 {
     value = 1.0f;
     if (mBaseMaskingMask != null)
     {
         int i = x * TerrainGlobals.getTerrain().getNumXVerts() + z;
         return(checkBaseWritePermission(i, out value));
     }
     return(true);
 }
Exemple #23
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;
            }
        }
Exemple #24
0
 unsafe static public void newSplatLayerEverywhere(char index)
 {
     BTerrainQuadNode[] nodes = TerrainGlobals.getTerrain().getQuadNodeLeafArray();
     for (int i = 0; i < nodes.Length; i++)
     {
         if (-1 == nodes[i].mLayerContainer.giveLayerIndex(index, BTerrainTexturingLayer.eLayerType.cLayer_Splat))
         {
             nodes[i].mLayerContainer.newSplatLayer(index);
         }
     }
 }
Exemple #25
0
        static public void setBladeToGrid(int x, int z, string setName, int bladeIndex, bool erase, bool forceErase)
        {
            int terrainToFoliageGridMultiple = (int)(BTerrainQuadNode.cMaxWidth / FoliageManager.cNumUsedXBladesPerChunk);

            if (x % terrainToFoliageGridMultiple != 0 || z % terrainToFoliageGridMultiple != 0)
            {
                return;
            }

            int setIndex = giveIndexOfSet(setName);

            int idx = x + TerrainGlobals.getTerrain().getNumXVerts() * z;


            int minQNX     = (int)(x / BTerrainQuadNode.cMaxWidth);
            int minQNZ     = (int)(z / BTerrainQuadNode.cMaxHeight);
            int numXChunks = (int)(TerrainGlobals.getTerrain().getNumXVerts() / BTerrainQuadNode.cMaxWidth);
            int qnIndex    = minQNX + numXChunks * minQNZ;
            int idex       = giveChunkWithParentIndex(qnIndex);


            if (erase)
            {
                if (mVertData.ContainsValue(idx))
                {
                    if (!forceErase)
                    {
                        FoliageVertData vRep = mVertData.GetValue(idx);
                        if (giveIndexOfSet(vRep.mFoliageSetName) != setIndex || vRep.mFoliageSetBladeIndex != bladeIndex)
                        {
                            return;
                        }
                    }

                    mVertData.SetValue(idx, new FoliageVertData()); //Default 'empty' for a jagged<T> value is the default constructor..
                    if (idex != -1)
                    {
                        mQNChunks[idex].destroyRenderVBs();
                    }
                }
            }
            else
            {
                mVertData.SetValue(idx, new FoliageVertData(setName, bladeIndex));

                if (idex == -1)//we need to add a new chunk
                {
                    idex = mQNChunks.Count;
                    addNewChunk(qnIndex);
                }
                mQNChunks[idex].bladeAdded(mFoliageSets[setIndex].mFullFileName);
            }
        }
Exemple #26
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);
                }
            }
        }
Exemple #27
0
        //CLM called when a light's properties have been changed
        static public void lightChangedMinor(int editorObjectIndex)
        {
            int lightIndex = giveLightIndex(editorObjectIndex);

            //reload all of the chunks that this light affected
            for (int i = 0; i < mLights[lightIndex].mWorldChunksImAffecting.Count; i++)
            {
                rasterLightsToNode(mLights[lightIndex].mWorldChunksImAffecting[i]);
            }


            TerrainGlobals.getTerrain().rebuildDirtyPostDeform(BRenderDevice.getDevice());
        }
Exemple #28
0
        static public void addSelectedVert(int x, int z, float selAmt)
        {
            int i = x * TerrainGlobals.getTerrain().getNumXVerts() + z;

            float factor = 1.0f;

            if (checkBaseWritePermission(x, z, out factor))
            {
                selAmt = Masking.combineValueWithBaseMask(factor, selAmt);
                extendCurrSelectionMask(x, z);
                mCurrSelectionMask.SetMaskWeight((int)i, selAmt);
            }
        }
Exemple #29
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);
                        }
                    }
                }
            }
        }
Exemple #30
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);
        }