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(); }
void renderLeafNode(BTerrainQuadNode node) { int lod = (int)BTerrainVisual.eLODLevel.cLOD0; BTerrainQuadNodeDesc desc = node.getDesc(); float scale = TerrainGlobals.getTerrain().getTileScale() * ((int)Math.Pow(2, lod)); Vector4 DataVals = new Vector4(2 * (BTerrainQuadNode.getMaxNodeWidth() >> lod), scale, desc.mMinXVert, desc.mMinZVert); mTerrainGPUShader.mShader.SetValue(mShaderDataValsHandle, DataVals); mTerrainGPUShader.mShader.CommitChanges(); BRenderDevice.getDevice().DrawPrimitives(PrimitiveType.TriangleList, 0, (int)mNumPrims); }
//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; }
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()); }
//------------------------------------------ //called to apply a texutre directly to a masked area public unsafe bool applyToMask(BTerrainQuadNode node) { bool changed = false; BTerrainQuadNodeDesc desc = node.getDesc(); changed = Texturing_LayerEditor.setIndexToMaskedArea(node, desc.mMinXVert, desc.mMinZVert, desc.mMaxXVert, desc.mMaxZVert, (char)mTexArrayIndex); if (changed) { //node.getTextureData().free(); for (int i = 0; i < Terrain.BTerrainTexturing.cMaxNumLevels; i++) { node.getTextureData(i).free(); } } return(changed); }
public void init(int owningNodeIndex) { mOwnerQNIndex = owningNodeIndex; mOwnerNodeDesc = TerrainGlobals.getTerrain().getQuadNodeLeafArray()[mOwnerQNIndex].getDesc(); }
//---------------------------------------------- unsafe static public bool setMaskAlphaToTextureBlending(BTerrainQuadNode node, uint dstImgWidth, uint dstImgHeight, UInt32 *mskImg, uint mskImgWidth, uint mskImgHeight, float intensity, int xpos, int ypos, bool alternate) { BTerrainQuadNodeDesc desc = node.getDesc(); bool changed = false; //create our position in the dst img, adjust for boundries int mskMaxX = (int)mskImgWidth; if (mskImgWidth + xpos >= dstImgWidth) { mskMaxX -= ((int)mskImgWidth) + xpos - ((int)dstImgWidth); } int mskMaxY = (int)mskImgHeight; if (mskImgHeight + ypos >= dstImgHeight) { mskMaxY -= ((int)mskImgHeight) + ypos - ((int)dstImgHeight); } int mskMinX = 0; int mskMinY = 0; if (xpos < 0) { mskMinX = -xpos; } if (ypos < 0) { mskMinY = -ypos; } //validate extents... if (mskMinX > mskImgWidth || mskMinY > mskImgHeight) { return(false); } int minX = (int)(desc.m_min.X / TerrainGlobals.getTerrain().getTileScale()); int maxX = (int)(desc.m_max.X / TerrainGlobals.getTerrain().getTileScale()); int minZ = (int)(desc.m_min.Z / TerrainGlobals.getTerrain().getTileScale()); int maxZ = (int)(desc.m_max.Z / TerrainGlobals.getTerrain().getTileScale()); for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { int maskX = x - minX + mskMinX; int maskY = z - minZ + mskMinY; int mIP = maskX * ((int)mskImgWidth) + maskY; char alpha = (char)(((mskImg[mIP] & 0xFF000000) >> 24)); float factor = alpha / 255.0f * intensity;; int vertIndex = (int)(x * TerrainGlobals.getTerrain().getNumZVerts() + z); float curWeight = Masking.getCurrSelectionMaskWeights().GetMaskWeight(vertIndex); float newWeight; if (!alternate) { newWeight = (curWeight > factor) ? curWeight : factor; } else//CLM Changes to erasing.. { newWeight = BMathLib.Clamp(curWeight - factor, 0, 1); } Masking.addSelectedVert(x, z, newWeight); changed = true; } } return(changed); }