/// <summary> /// Set to use import data /// </summary> public void UseImportData() { FileName = string.Empty; FreeImportData(); ImportData = new ImportData(); ImportData.DeleteInputData = true; }
public void UseImportData() { this.FileName = string.Empty; FreeImportData(); this.ImportData = new ImportData(); // we're going to own all the data in the def this.ImportData.DeleteInputData = true; }
/// <summary> /// Destroy temp import resources /// </summary> public void FreeImportData() { ImportData = null; }
/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="importData"></param> public void DefineTerrain(long x, long y, ImportData importData) { TerrainSlot slot = GetTerrainSlot(x, y, true); slot.Def.UseImportData(); slot.Def.ImportData = importData; slot.Def.ImportData.TerrainAlign = _alignment; slot.Def.ImportData.TerrainSize = _terrainSize; slot.Def.ImportData.WorldSize = _terrainWorldSize; }
/// <summary> /// Constructor. /// </summary> /// <param name="sm">The SceneManager which will parent the terrain instances.</param> /// <param name="align">The alignment that all terrain instances will use</param> /// <param name="terrainSize">The size of each terrain down one edge in vertices (2^n+1)</param> /// <param name="terrainWorldSize">The world size of each terrain instance</param> public TerrainGroup(SceneManager sm, Alignment align, ushort terrainSize, float terrainWorldSize) { _sceneManager = sm; _alignment = align; _terrainSize = terrainSize; _terrainWorldSize = terrainWorldSize; _origin = Vector3.Zero; _filenamePrefix = "terrain"; _filenameExtension = "dat"; _resourceGroup = ResourceGroupManager.DefaultResourceGroupName; _terrainSlots = new Dictionary<uint, TerrainSlot>(); _defaultImportData = new ImportData(); _defaultImportData.TerrainAlign = align; _defaultImportData.WorldSize = terrainWorldSize; _defaultImportData.DeleteInputData = true; }
public ImportData( ImportData d ) { this.TerrainAlign = d.TerrainAlign; this.TerrainSize = d.TerrainSize; this.MaxBatchSize = d.MaxBatchSize; this.MinBatchSize = d.MinBatchSize; this.Pos = d.Pos; this.WorldSize = d.WorldSize; this.InputImage = d.InputImage; this.InputFloat = d.InputFloat; this.ConstantHeight = d.ConstantHeight; this.LayerList = new List<LayerInstance>( d.LayerList ); this.DeleteInputData = d.DeleteInputData; this.InputScale = d.InputScale; this.InputBias = d.InputBias; }
public bool Prepare( ImportData importData ) { FreeTemporaryResources(); FreeCPUResources(); CopyGlobalOptions(); //validate if ( !( Bitwise.IsPow2( importData.TerrainSize - 1 ) && Bitwise.IsPow2( importData.MinBatchSize - 1 ) && Bitwise.IsPow2( importData.MaxBatchSize - 1 ) ) ) { throw new AxiomException( "terrainSize, minBatchSize and maxBatchSize must all be n^2 + 1. Terrain.Prepare" ); } if ( importData.MinBatchSize > importData.MaxBatchSize ) { throw new AxiomException( "MinBatchSize must be less then or equal to MaxBatchSize. Terrain.Prepare" ); } if ( importData.MaxBatchSize > TERRAIN_MAX_BATCH_SIZE ) { throw new AxiomException( "MaxBatchSize must be not larger then {0} . Terrain.Prepare", TERRAIN_MAX_BATCH_SIZE ); } Alignment = importData.TerrainAlign; this.mSize = importData.TerrainSize; this.mWorldSize = importData.WorldSize; this.mLayerDecl = importData.LayerDeclaration; CheckDeclaration(); this.mLayers = importData.LayerList; CheckLayers( false ); DeriveUVMultipliers(); this.mMaxBatchSize = importData.MaxBatchSize; this.mMinBatchSize = importData.MinBatchSize; this.mPos = importData.Pos; UpdateBaseScale(); DetermineLodLevels(); int numVertices = this.mSize*this.mSize; this.mHeightData = new float[numVertices]; if ( importData.InputFloat != null ) { if ( Utility.RealEqual( importData.InputBias, 0.0f ) && Utility.RealEqual( importData.InputScale, 1.0f ) ) { //straigt copy this.mHeightData = new float[numVertices]; Array.Copy( importData.InputFloat, this.mHeightData, this.mHeightData.Length ); } else { // scale & bias, lets do it unsafe, should be faster :) var src = importData.InputFloat; for ( var i = 0; i < numVertices; ++i ) { this.mHeightData[ i ] = ( src[ i ]*importData.InputScale ) + importData.InputBias; } } } else if ( importData.InputImage != null ) { var img = importData.InputImage; if ( img.Width != this.mSize || img.Height != this.mSize ) { img.Resize( this.mSize, this.mSize ); } // convert image data to floats // Do this on a row-by-row basis, because we describe the terrain in // a bottom-up fashion (ie ascending world coords), while Image is top-down var pSrcBaseF = BufferBase.Wrap( img.Data ); var pHeightDataF = BufferBase.Wrap( this.mHeightData, mHeightData.Length * sizeof(float) ); for ( var i = 0; i < this.mSize; ++i ) { var srcy = this.mSize - i - 1; using ( var pSrc = pSrcBaseF + srcy*img.RowSpan ) { using ( var pDest = pHeightDataF + i*this.mSize*sizeof ( float ) ) { PixelConverter.BulkPixelConversion( pSrc, img.Format, pDest, PixelFormat.FLOAT32_R, this.mSize ); } } } pSrcBaseF.Dispose(); pHeightDataF.Dispose(); if ( !Utility.RealEqual( importData.InputBias, 0.0f ) || !Utility.RealEqual( importData.InputScale, 1.0f ) ) { for ( int i = 0; i < numVertices; ++i ) { this.mHeightData[ i ] = ( this.mHeightData[ i ]*importData.InputScale ) + importData.InputBias; } } } else { // start with flat terrain this.mHeightData = new float[this.mSize*this.mSize]; } var deltaData = new float[numVertices]; this.mHeightDataPtr = BufferBase.Wrap( this.mHeightData,mHeightData.Length * sizeof(float) ); this.mDeltaDataPtr = BufferBase.Wrap( deltaData, deltaData.Length * sizeof(float) ); var numLevel = (ushort)(int)( NumLodLevels - 1 ); QuadTree = new TerrainQuadTreeNode( this, null, 0, 0, this.mSize, (ushort)( NumLodLevels - 1 ), 0, 0 ); QuadTree.Prepare(); //calculate entire terrain var rect = new Rectangle(); rect.Top = 0; rect.Bottom = this.mSize; rect.Left = 0; rect.Right = this.mSize; CalculateHeightDeltas( rect ); FinalizeHeightDeltas( rect, true ); DistributeVertexData(); // Imported data is treated as modified because it's not saved IsModified = true; IsHeightDataModified = true; return true; }
public void FreeImportData() { if ( this.ImportData != null ) { this.ImportData.Dispose(); this.ImportData = null; } }
public virtual void DefineTerrain( long x, long y, ImportData importData ) { var slot = GetTerrainSlot( x, y, true ); slot.Def.UseImportData(); // Copy all settings, but make sure our primary settings are immutable slot.Def.ImportData = importData; slot.Def.ImportData.TerrainAlign = this._alignment; slot.Def.ImportData.TerrainSize = this._terrainSize; slot.Def.ImportData.WorldSize = this._terrainWorldSize; }
public TerrainGroup( SceneManager sm, Alignment align, ushort terrainSize, Real terrainWorldSize ) { this._sceneManager = sm; this._alignment = align; this._terrainSize = terrainSize; this._terrainWorldSize = terrainWorldSize; this._origin = Vector3.Zero; this._filenamePrefix = "terrain"; this._filenameExtension = "dat"; this._resourceGroup = ResourceGroupManager.DefaultResourceGroupName; this._defaultImportData = new ImportData(); this._defaultImportData.TerrainAlign = align; this._defaultImportData.WorldSize = terrainWorldSize; // by default we delete input data because we copy it, unless user // passes us an ImportData where they explicitly don't want it copied this._defaultImportData.DeleteInputData = true; WorkQueue wq = Root.Instance.WorkQueue; this._workQueueChannel = wq.GetChannel( "Axiom/TerrainGroup" ); wq.AddRequestHandler( this._workQueueChannel, this ); wq.AddResponseHandler( this._workQueueChannel, this ); }