public void Init(DataVolume data, int filledValue, float3 cellSize, int cellResolution, UVMode uvMode = UVMode.NoScaling, float3 posOffset = default(float3)) { this.data = data; dataExtents = new Extents(data.XLength, data.YLength, data.ZLength); this.filledValue = filledValue; resolution = Mathf.Clamp(cellResolution, MinResolution, MaxResolution); if (resolution != cellResolution) { Debug.LogWarningFormat("cell resolution has been clamped ({0} -> {1})", cellResolution, resolution); } this.cellSize = cellSize; if (this.cellSize.x <= 0f || this.cellSize.y <= 0f || this.cellSize.z <= 0f) { this.cellSize = new float3(1, 1, 1); Debug.LogWarning("Cell size must be greater than zero!"); } this.uvMode = uvMode; this.positionOffset = posOffset; InitMeshArrayLengths(); HeightMap = null; Inited(); }
override public void Dispose() { base.Dispose(); SafeDispose(ref meshArrayLengths); HeightMap = null; }
public static Model CreateTerrain(HeightMapData data) { var width = data.Width; var height = data.Height; var rv = ModelLoader.CreateTerrainVerticies(data.Data, width, height); return(rv); }
public float GetHeight(int x, int z) { if (x < 0 || x >= HeightMapData.GetLength(0)) { return(0); } else if (z < 0 || z >= HeightMapData.GetLength(1)) { return(0); } else { return(HeightMapData[x, z]); } }
public HeightMap(HeightMapData heightMapData) { _heightMapData = heightMapData; Width = (int)heightMapData.Width; Height = (int)heightMapData.Height; Normals = new Vector3[Width, Height]; for (int x = 0; x < Width; ++x) { for (int y = 0; y < Height; ++y) { Normals[x, y] = CalculateNormal(x, y); } } }
public void Create() { this.nameIDs = new Dictionary <string, int>(); this.majorAssets = new Dictionary <string, MajorAsset>(); SubAsset.map = this; Asset.map = this; this.assetList = new AssetList(); this.AddMajorAsset((MajorAsset)this.assetList); this.AddMajorAsset((MajorAsset) new GlobalVersion()); this.heightMap = new HeightMapData(this.mapWidth, this.mapHeight, this.mapBorder); this.AddMajorAsset((MajorAsset)this.heightMap); this.mapWidth = this.heightMap.mapWidth; this.mapHeight = this.heightMap.mapHeight; this.mapBorder = this.heightMap.borderWidth; this.blendTile = new BlendTileData(this.mapWidth, this.mapHeight); this.AddMajorAsset((MajorAsset)this.blendTile); this.worldInfo = new WorldInfo(); this.AddMajorAsset((MajorAsset)this.worldInfo); this.mpPositionList = new MPPositionList(); this.AddMajorAsset((MajorAsset)this.mpPositionList); this.sidesList = new SidesList(); this.AddMajorAsset((MajorAsset)this.sidesList); this.AddMajorAsset((MajorAsset) new LibraryMapLists()); this.AddMajorAsset((MajorAsset) new Teams()); this.AddMajorAsset((MajorAsset) new PlayerScriptsList()); this.AddMajorAsset((MajorAsset) new BuildLists()); this.objectList = new ObjectsList(); this.AddMajorAsset((MajorAsset)this.objectList); /* * this.AddMajorAsset((MajorAsset)new TriggerAreas(this.game)); * this.AddMajorAsset((MajorAsset)new GlobalWaterSettings(this.game)); * this.AddMajorAsset((MajorAsset)new FogSettings(this.game)); * this.AddMajorAsset((MajorAsset)new MissionHotSpots(this.game)); * this.AddMajorAsset((MajorAsset)new MissionObjectives(this.game)); * this.AddMajorAsset((MajorAsset)new StandingWaterAreas(this.game)); * this.AddMajorAsset((MajorAsset)new RiverAreas(this.game)); * this.AddMajorAsset((MajorAsset)new StandingWaveAreas(this.game)); * this.AddMajorAsset((MajorAsset)new GlobalLighting(this.game)); * this.AddMajorAsset((MajorAsset)new PostEffectsChunk(this.game)); * this.AddMajorAsset((MajorAsset)new EnvironmentData(this.game)); * this.AddMajorAsset((MajorAsset)new NamedCameras(this.game)); * this.AddMajorAsset((MajorAsset)new CameraAnimationList(this.game)); * this.AddMajorAsset((MajorAsset)new WaypointsList(this.game)); */ }
public HeightMap(HeightMapData heightMapData) { _heightMapData = heightMapData; _verticalScale = heightMapData.VerticalScale; Width = (int)heightMapData.Width - 1; //last colum is not rendered (in worldbuilder) Height = (int)heightMapData.Height - 1; //last row is not rendered (in worldbuilder) Normals = new Vector3[Width, Height]; for (var x = 0; x < Width; ++x) { for (var y = 0; y < Height; ++y) { Normals[x, y] = CalculateNormal(x, y); } } }
public float SampleHeight(Vector3 position) { float x = ((position.x - OffsetX) * (((float)HeightMapData.GetLength(0) - 1f) / (float)Width)); float z = ((position.z - OffsetZ) * (((float)HeightMapData.GetLength(1) - 1f) / (float)Length)); var hx0z0 = GetHeight(Mathf.FloorToInt(x), Mathf.FloorToInt(z)); var hx1z0 = GetHeight(Mathf.CeilToInt(x), Mathf.FloorToInt(z)); var hx0z1 = GetHeight(Mathf.FloorToInt(x), Mathf.CeilToInt(z)); var hx1z1 = GetHeight(Mathf.CeilToInt(x), Mathf.CeilToInt(z)); if (hx0z0 == hx1z0 && hx1z0 == hx0z1 && hx0z1 == hx1z1) { return(((hx0z0) * Height) + OffsetY); } var u0v0 = hx0z0 * (Mathf.CeilToInt(x) - x) * (Mathf.CeilToInt(z) - z); var u1v0 = hx1z0 * (x - Mathf.FloorToInt(x)) * (Mathf.CeilToInt(z) - z); var u0v1 = hx0z1 * (Mathf.CeilToInt(x) - x) * (z - Mathf.FloorToInt(z)); var u1v1 = hx1z1 * (x - Mathf.FloorToInt(x)) * (z - Mathf.FloorToInt(z)); return(((u0v0 + u1v0 + u0v1 + u1v1) * Height) + OffsetY); }
public HeightMap(HeightMapData heightMapData) { _heightMapData = heightMapData; // Gathered from heights in World Builder's status bar compared to heightmap data. // In Generals, heights are stored as uint8, and scaled by 0.625 // In BFME, heights are stored in uint16, and scale by 0.00625 _verticalScale = heightMapData.ElevationsAre16Bit ? 0.00625f : 0.625f; Width = (int)heightMapData.Width; Height = (int)heightMapData.Height; Normals = new Vector3[Width, Height]; for (int x = 0; x < Width; ++x) { for (int y = 0; y < Height; ++y) { Normals[x, y] = CalculateNormal(x, y); } } }
public void InitHeightMapScaleFromHeightMinOffset(Texture2D heightMap, float maxHeight, bool applyEdgeLerp = false) { HeightMap = HeightMapData.CreateWithScaleFromTexIntervalMinOffset(heightMap, maxHeight, applyEdgeLerp); }
public void InitHeightMap(Texture2D heightMap, float valueScale, float valueOffset = 0, bool applyEdgeLerp = false) { HeightMap = HeightMapData.CreateWithManualInfo(heightMap, valueScale, valueOffset, applyEdgeLerp); }
public override void Load() { m_ImGuiDriver = new ImGuiDriver(); m_ImGuiDriver.Initalise(GraphicsDevice, m_ResourceManager); camera = new GameCamera(new Vector3(40, 40, 40), new Vector3(80, 80, 0), 55, -20); m_QuadBatch = new QuadBatch(); var cubeShader = m_ResourceManager.LoadShaderFromFile("v.cube.glsl", "f.cube.glsl"); var skyboxShader = m_ResourceManager.LoadShaderFromFile("v.skybox.glsl", "f.skybox.glsl"); var terrainShader = m_ResourceManager.LoadShaderFromFile("v.terrain.glsl", "f.terrain.glsl"); var waterShader = m_ResourceManager.LoadShaderFromFile("v.water.glsl", "f.water.glsl"); // Load Textures { m_AwesomeFace = m_ResourceManager.LoadTexture2d("awesomeface.png"); m_Texture = m_ResourceManager.LoadTexture2d("texture1.png"); //m_Default = m_ResourceManager.LoadTexture2d("default.png"); } // Load Terrain { var heightMapData = HeightMapData.LoadHeightmapData("Resources/Textures/Heightmaps/1.png"); var model = ModelLoader.CreateTerrain(heightMapData); var terrainVAO = m_ResourceManager.LoadVAO(model.Verts, model.Indicies, VertexPositionColorTextureNormal.Stride, VertexPositionColorTextureNormal.AttributeLengths, VertexPositionColorTextureNormal.AttributeOffsets); m_TerrainRenderObject = new Terrain(terrainShader.ShaderProgramId, terrainVAO.VaoId, terrainVAO.VertexCount); } // Create Water { var model = ModelLoader.CreatePlane(1024, 1024, 12.2f); var waterVAO = m_ResourceManager.LoadVAO(model.Verts, model.Indicies, VertexPositionColorTextureNormal.Stride, VertexPositionColorTextureNormal.AttributeLengths, VertexPositionColorTextureNormal.AttributeOffsets); m_WaterRenderObject = new Water(waterShader.ShaderProgramId, waterVAO.VaoId, waterVAO.VertexCount); } // Create Bunny { var bunnyVerts = ModelLoader.LoadObj("Resources/Models/bunny.obj"); var bunnyVAO = m_ResourceManager.LoadVAO(bunnyVerts.Verts, bunnyVerts.Indicies, VertexPositionColorTextureNormal.Stride, VertexPositionColorTextureNormal.AttributeLengths, VertexPositionColorTextureNormal.AttributeOffsets); m_BunnyRenderObject = new Bunny(terrainShader.ShaderProgramId, bunnyVAO.VaoId, bunnyVAO.VertexCount); } // Create Cube { Maploader mp = new Maploader(); mp.Load(); var verts = Geometry.CreateCube(); var m_CubeVAO = m_ResourceManager.LoadNonIndexedVAO(verts, VertexPositionColorTexture.Stride, VertexPositionColorTexture.AttributeLengths, VertexPositionColorTexture.AttributeOffsets); m_Cube = new Cube[Maploader.width * Maploader.height]; for (int i = 0; i < Maploader.width * Maploader.height; i++) { m_Cube[i] = new Cube(cubeShader.ShaderProgramId, m_CubeVAO.VaoId, m_CubeVAO.VertexCount); m_Cube[i].i = i; m_Cube[i].TextureIdA = m_AwesomeFace.TextureId; m_Cube[i].TextureIdB = m_Texture.TextureId; } int k = 0; for (int i = 0; i < Maploader.width; i++) { for (int j = 0; j < Maploader.height; j++) { var height = (float)mp.cubes[i, j]; height /= 2.0f; if (height < 0) { height = -100; // Temp } height += 20; m_Cube[k].Position = new Vector3(i, height, j); k++; } } } // Create Skyubox { var verts = Geometry.CreateSkyBoxVerticies(); var skyboxVAO = m_ResourceManager.LoadNonIndexedVAO(verts, VertexPosition.Stride, VertexPosition.AttributeLengths, VertexPosition.AttributeOffsets); var cubeMap = m_ResourceManager.LoadCubeMap("Skybox/front.png", "Skybox/back.png", "Skybox/bottom.png", "Skybox/top.png", "Skybox/left.png", "Skybox/right.png"); m_SkyBoxRenderObject = new SkyBox(skyboxShader.ShaderProgramId, skyboxVAO.VaoId, skyboxVAO.VertexCount, cubeMap.TextureId); } // Load Font { m_FontAriel = m_ResourceManager.LoadTextureFont("ariel.fnt"); } renderTarget = RenderTarget.Create(GameWindow.ScreenWidth, GameWindow.ScreenHeight); // TODO This should be the size of the screen quad = new ScreenSpaceQuad(); quad.Create(); }
public HeightMapNoiseModule(string height_map_filename, OpenTK.Vector3 axial_frequencies, OpenTK.Vector3 projection_offset, ProjectionAxis axis) : base(axial_frequencies) { m_heightmap_data = new HeightMapData("Assets\\Textures\\DeformationHeightMaps\\" + height_map_filename); m_projection_axis = axis; m_projection_offset = projection_offset; }
// No default/parameterless constructor, since you need to specify a filename and projection axis. // We assume for the moment that all heightmaps must be located at Assets/Textures/DeformationHeightMaps. // If that restriction becomes a problem, we can change this behavior to either search the entire Assets tree, // or require the higher-level code to provide a full relative path instead of just a filename. // // The projection axis takes the place of the anti_y/pos_y/neg_y params in the base noise module class, so those base // params are not used for this module. public HeightMapNoiseModule(string height_map_filename, ProjectionAxis axis) : base() { m_heightmap_data = new HeightMapData("Assets\\Textures\\DeformationHeightMaps\\" + height_map_filename); m_projection_axis = axis; m_projection_offset = OpenTK.Vector3.Zero; }