示例#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();
        }
示例#2
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);
        }
示例#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;
            }
        }
示例#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();
                }
            }
        }
示例#5
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();
            }
        }
示例#6
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;
        }
示例#7
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)
        }
示例#8
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);
        }
示例#9
0
        //queary
        public BTerrainVisual.eLODLevel getLODLevel(Vector3 pt, Vector3 Eye)
        {
            if (!TerrainGlobals.getVisual().isDynamicLODEnabled())
            {
                return(TerrainGlobals.getVisual().getStaticLODLevel());
            }

            Vector3 d    = pt - Eye;
            float   dist = d.Length();

            if (dist > (float)BTerrainVisual.eLODLevelDists.cLOD3Dist)
            {
                return(BTerrainVisual.eLODLevel.cLOD3);
            }
            else if (dist > (float)BTerrainVisual.eLODLevelDists.cLOD2Dist)
            {
                return(BTerrainVisual.eLODLevel.cLOD2);
            }
            else if (dist > (float)BTerrainVisual.eLODLevelDists.cLOD1Dist)
            {
                return(BTerrainVisual.eLODLevel.cLOD1);
            }

            return(BTerrainVisual.eLODLevel.cLOD0);
        }
示例#10
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);
        }
示例#11
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();
        }
示例#12
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);
        }
示例#13
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());
        }
示例#14
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);
        }
示例#15
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);
        }
示例#16
0
        public static void init()
        {
            mVertData = new JaggedContainer <FoliageVertData>(TerrainGlobals.getTerrain().getNumXVerts() * TerrainGlobals.getTerrain().getNumZVerts());
            mVertData.SetEmptyValue(cEmptyVertData);

            loadShader();
        }
示例#17
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();
            }
        }
示例#18
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);
        }
示例#19
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);
        }
示例#20
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();
        }
示例#21
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();
        }
示例#22
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();
        }
示例#23
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);
            }
        }
示例#24
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);
        }
示例#25
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);
        }
示例#26
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;
                    }
                }
            }
        }
示例#27
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);
        }
示例#28
0
        public void ensureProperLayerOrdering()
        {
            ensureProperNumberLayers();
            int numSplatLayers = TerrainGlobals.getTexturing().getActiveTextureCount();

            //create N floatN vectors
            floatN[] layerVecs = new floatN[numSplatLayers];
            for (uint k = 0; k < numSplatLayers; k++)
            {
                layerVecs[k]    = new floatN((uint)numSplatLayers);
                layerVecs[k][k] = 1;
            }

            //now, calculate a VContrib vector for the current layering.
            floatN vContrib = layerVecs[0].Clone();//start with 100% base layer

            for (uint k = 1; k < numSplatLayers; k++)
            {
                byte  b     = mLayers[(int)k].mAlphaContrib;
                int   lIdx  = mLayers[(int)k].mActiveTextureIndex;
                float alpha = ((float)b) / 255.0f;
                vContrib = (
                    (layerVecs[lIdx] * alpha) + (vContrib * (1 - alpha))
                    );
            }

            //vContrib now holds at each vector element, the amount the layer is visible to the final pixel
            //although it's not sorted in the current layer ordering
            //so, calculate the xF for the new layer ordering, and store it in a temp var
            floatN vContribSorted = new floatN((uint)numSplatLayers);

            //back solve to calculate new alpha value.
            vContribSorted[(uint)(numSplatLayers - 1)] = vContrib[(uint)(numSplatLayers - 1)];
            for (int k = (numSplatLayers - 2); k >= 0; k--)
            {
                uint  invK  = (uint)((numSplatLayers - 2) - k);
                float Vc    = vContrib[(uint)(k + 1)]; //vContrib for upper layer
                float invVc = 1.0f - Vc;

                //current layer vContrib
                float cVc = vContrib[(uint)(k)];
                float xF  = invVc == 0 ? 0 : (cVc / invVc);

                //move back
                vContribSorted[(uint)k] = xF;
            }

            //now copy back to the unsorted layer index
            for (int k = 0; k < numSplatLayers; k++)
            {
                mLayers[k].mAlphaContrib = (byte)(vContribSorted[(uint)mLayers[k].mActiveTextureIndex] * 255);
            }

            //ensure layers are sorted
            ensureProperSorting();
        }
示例#29
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));
            }
        }
示例#30
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;
            }
        }