public void GetSectorIdAt(Vector3 localPosition, out MyPlanetSectorId id) { id = new MyPlanetSectorId(); Vector3D local = localPosition; MyCubemapHelpers.ProjectToNearestFace(ref local, out localPosition); MyCubemapHelpers.GetCubeFaceDirection(ref localPosition, out id.Direction); id.Direction = -id.Direction; localPosition = (localPosition + 1f) * .5f; id.Position = new Vector3S(localPosition.X * m_numSectors, localPosition.Y * m_numSectors, localPosition.Z * m_numSectors); if (id.Position.X == m_numSectors) { id.Position.X = (short)(m_numSectors - 1); } if (id.Position.Y == m_numSectors) { id.Position.Y = (short)(m_numSectors - 1); } if (id.Position.Z == m_numSectors) { id.Position.Z = (short)(m_numSectors - 1); } }
public void CopyRange(Vector2I start, Vector2I end, MyHeightmapFace other, Vector2I oStart, Vector2I oEnd) { Vector2I myStep = MyCubemapHelpers.GetStep(ref start, ref end); Vector2I oStep = MyCubemapHelpers.GetStep(ref oStart, ref oEnd); ushort val; for (; start != end; start += myStep, oStart += oStep) { other.GetValue(oStart.X, oStart.Y, out val); SetValue(start.X, start.Y, val); } other.GetValue(oStart.X, oStart.Y, out val); SetValue(start.X, start.Y, val); }
public void CopyRange(Vector2I start, Vector2I end, MyHeightmapFace other, Vector2I oStart, Vector2I oEnd) { ushort num; Vector2I step = MyCubemapHelpers.GetStep(ref start, ref end); Vector2I vectori2 = MyCubemapHelpers.GetStep(ref oStart, ref oEnd); while (start != end) { other.GetValue(oStart.X, oStart.Y, out num); this.SetValue(start.X, start.Y, num); start += step; oStart += vectori2; } other.GetValue(oStart.X, oStart.Y, out num); this.SetValue(start.X, start.Y, num); }
public MyHeightCubemap GetHeightMap(string folderName, MyModContext context) { string modId = context.ModId; string name = $"{modId ?? "BaseGame"}:{folderName}"; bool flag = false; MyHeightmapFace[] faces = new MyHeightmapFace[6]; int resolution = 0; for (int i = 0; i < 6; i++) { faces[i] = this.GetHeightMap(folderName, MyCubemapHelpers.GetNameForFace(i), context); if (faces[i] == null) { flag = true; } else if ((faces[i].Resolution == resolution) || (resolution == 0)) { resolution = faces[i].Resolution; } else { flag = true; MyLog.Default.Error("Cubemap faces must be all the same size!", Array.Empty <object>()); } if (flag) { break; } } if (flag) { MyLog.Default.WriteLine($"Error loading heightmap {folderName}, using fallback instead. See rest of log for details."); for (int j = 0; j < 6; j++) { faces[j] = MyHeightmapFace.Default; resolution = faces[j].Resolution; } } return(new MyHeightCubemap(name, faces, resolution)); }
// Compute the position in the sector cube from planet space coordinates. private void LocalPositionToSectorCube(Vector3D localCoords, out Vector3 sectorCoords) { Vector3 textcoord; MyCubemapHelpers.ProjectToNearestFace(ref localCoords, out textcoord); // bring textcoords into 0-1 space. textcoord = (textcoord + 1f) * .5f; sectorCoords = new Vector3(textcoord.X * m_numSectors, textcoord.Y * m_numSectors, textcoord.Z * m_numSectors); if (sectorCoords.X == m_numSectors) { sectorCoords.X = (m_numSectors - 1); } if (sectorCoords.Y == m_numSectors) { sectorCoords.Y = (m_numSectors - 1); } if (sectorCoords.Z == m_numSectors) { sectorCoords.Z = (m_numSectors - 1); } }
public MyHeightCubemap(string folderName, MyModContext context) { m_faces = new MyHeightmapFace[6]; var useDefault = false; for (int i = 0; i < MyCubemapHelpers.NUM_MAPS; ++i) { m_faces[i] = MyHeightMapLoadingSystem.Static.GetHeightMap(folderName, MyCubemapHelpers.GetNameForFace(i), context); if (m_faces[i] == null) { useDefault = true; } else if (m_faces[i].Resolution != m_resolution && m_resolution != 0) { useDefault = true; MyLog.Default.WriteLine("Error: Cubemap faces must be all the same size!"); } else { m_resolution = m_faces[i].Resolution; } if (useDefault) { break; } } Name = folderName; if (useDefault) { MyLog.Default.WriteLine(String.Format("Error loading heightmap {0}, using fallback instead. See rest of log for details.", folderName)); for (int i = 0; i < MyCubemapHelpers.NUM_MAPS; ++i) { m_faces[i] = MyHeightmapFace.Default; m_resolution = m_faces[i].Resolution; } } ProfilerShort.Begin("MyHeightCubemap::PrepareSides()"); PrepareSides(); ProfilerShort.End(); }
public override void Draw() { base.Draw(); if (MySession.Static == null) { return; } if (m_comp.CameraPlanet != null) { var provider = m_comp.CameraPlanet.Provider; if (provider == null) { return; } Vector3 camPos = MySector.MainCamera.Position; float instantSpeed = 0; float averageSpeed = 0; if (m_lastCameraPosition.IsValid()) { instantSpeed = (camPos - m_lastCameraPosition).Length() * VRage.Game.MyEngineConstants.UPDATE_STEPS_PER_SECOND; if (m_speeds.Count == 60) { m_speeds.Dequeue(); } m_speeds.Enqueue(instantSpeed); foreach (var s in m_speeds) { averageSpeed += s; } averageSpeed /= m_speeds.Count; } m_lastCameraPosition = camPos; Vector3 pos = camPos; pos -= m_comp.CameraPlanet.PositionLeftBottomCorner; MyPlanetStorageProvider.SurfacePropertiesExtended properties; provider.ComputeCombinedMaterialAndSurfaceExtended(pos, out properties); Section("Position"); Text("Position: {0}", properties.Position); Text("Speed: {0:F2}ms -- {1:F2}m/s", instantSpeed, averageSpeed); Text("Latitude: {0}", MathHelper.ToDegrees(Math.Asin(properties.Latitude))); Text("Longitude: {0}", MathHelper.ToDegrees(MathHelper.MonotonicAcos(properties.Longitude))); Text("Altitude: {0}", properties.Altitude); VSpace(5f); Text("Height: {0}", properties.Depth); Text("HeightRatio: {0}", properties.HeightRatio); Text("Slope: {0}", MathHelper.ToDegrees(Math.Acos(properties.Slope))); Text("Air Density: {0}", m_comp.CameraPlanet.GetAirDensity(camPos)); Text("Oxygen: {0}", m_comp.CameraPlanet.GetOxygenForPosition(camPos)); Section("Cube Position"); Text("Face: {0}", MyCubemapHelpers.GetNameForFace(properties.Face)); Text("Texcoord: {0}", properties.Texcoord); Text("Texcoord Position: {0}", (Vector2I)(properties.Texcoord * 2048)); Section("Material"); Text("Material: {0}", properties.Material != null ? properties.Material.Id.SubtypeName : "null"); Text("Material Origin: {0}", properties.Origin); Text("Biome: {0}", properties.Biome != null ? properties.Biome.Name : ""); MultilineText("EffectiveRule: {0}", properties.EffectiveRule); Text("Ore: {0}", properties.Ore); Section("Map values"); Text("BiomeValue: {0}", properties.BiomeValue); Text("MaterialValue: {0}", properties.MaterialValue); Text("OcclusionValue: {0}", properties.OcclusionValue); Text("OreValue: {0}", properties.OreValue); } }
public void GetPlanetMaps(string folder, MyModContext context, MyPlanetMaps mapsToUse, out MyCubemap[] maps) { if (m_planetMaps.ContainsKey(folder)) { maps = m_planetMaps[folder]; return; } maps = new MyCubemap[4]; MyCubemapData <byte>[] tmpMaps = new MyCubemapData <byte> [4 * 6]; byte[][] streams = new byte[4][]; string fullPath; ProfilerShort.Begin("MyHeightmapLoadingSystem::GetPlanetMaps()"); ProfilerShort.Begin("Load _mat"); // Round one: material, ore, biome if (mapsToUse.Material || mapsToUse.Biome || mapsToUse.Ores) { for (int i = 0; i < 6; ++i) { string name = Path.Combine(folder, MyCubemapHelpers.GetNameForFace(i)); using (var texture = TryGetPlanetTexture(name, context, "_mat", out fullPath)) { if (texture == null) { ClearMatValues(tmpMaps); break; } PixelBuffer buffer = texture.GetPixelBuffer(0, 0, 0); if (buffer.Format != Format.B8G8R8A8_UNorm && buffer.Format != Format.R8G8B8A8_UNorm) { MyDebug.FailRelease("While loading maps from {1}: Unsupported planet map format: {0}.", buffer.Format, fullPath); break; } if (buffer.Width != buffer.Height) { MyDebug.FailRelease("While loading maps from {0}: Width and height must be the same.", fullPath); break; } if (mapsToUse.Material) { tmpMaps[i * 4] = new MyCubemapData <byte>(buffer.Width); streams[0] = tmpMaps[i * 4].Data; } if (mapsToUse.Biome) { tmpMaps[i * 4 + 1] = new MyCubemapData <byte>(buffer.Width); streams[1] = tmpMaps[i * 4 + 1].Data; } if (mapsToUse.Ores) { tmpMaps[i * 4 + 2] = new MyCubemapData <byte>(buffer.Width); streams[2] = tmpMaps[i * 4 + 2].Data; } // Invert channels for BGRA if (buffer.Format == Format.B8G8R8A8_UNorm) { var tmp = streams[2]; streams[2] = streams[0]; streams[0] = tmp; } ReadChannelsFromImage(streams, buffer); } } } ProfilerShort.BeginNextBlock("Load _add"); // round two: add map if (mapsToUse.Occlusion) { for (int i = 0; i < 6; ++i) { string name = Path.Combine(folder, MyCubemapHelpers.GetNameForFace(i)); using (var texture = TryGetPlanetTexture(name, context, "_add", out fullPath)) { if (texture == null) { ClearAddValues(tmpMaps); break; } PixelBuffer buffer = texture.GetPixelBuffer(0, 0, 0); if (buffer.Format != Format.B8G8R8A8_UNorm && buffer.Format != Format.R8G8B8A8_UNorm) { MyDebug.FailRelease("While loading maps from {1}: Unsupported planet map format: {0}.", buffer.Format, fullPath); break; } if (buffer.Width != buffer.Height) { MyDebug.FailRelease("While loading maps from {0}: Width and height must be the same.", fullPath); break; } if (mapsToUse.Occlusion) { tmpMaps[i * 4 + 3] = new MyCubemapData <byte>(buffer.Width); streams[0] = tmpMaps[i * 4 + 3].Data; } streams[1] = streams[2] = null; // Invert channels for BGRA if (buffer.Format == Format.B8G8R8A8_UNorm) { var tmp = streams[2]; streams[2] = streams[0]; streams[0] = tmp; } ReadChannelsFromImage(streams, buffer); } } } ProfilerShort.BeginNextBlock("Finish"); for (int i = 0; i < 4; ++i) { if (tmpMaps[i] != null) { var cmaps = new MyCubemapData <byte> [6]; for (int j = 0; j < 6; j++) { cmaps[j] = tmpMaps[i + j * 4]; } maps[i] = new MyCubemap(cmaps); } } m_planetMaps[folder] = maps; ProfilerShort.End(); ProfilerShort.End(); }
public void GetPlanetMaps(string folder, MyModContext context, MyPlanetMapTypeSet mapsToUse, out MyCubemap[] maps) { int num; int num2; maps = new MyCubemap[4]; MyCubemapData <byte>[] dataArray = new MyCubemapData <byte> [0x18]; byte[][] streams = new byte[4][]; if (mapsToUse == 0) { goto TR_000A; } else { num = 0; } goto TR_0026; TR_000A: num2 = 0; while (num2 < 4) { if (dataArray[num2] != null) { MyCubemapData <byte>[] faces = new MyCubemapData <byte> [6]; int index = 0; while (true) { if (index >= 6) { maps[num2] = new MyCubemap(faces); break; } faces[index] = dataArray[num2 + (index * 4)]; index++; } } num2++; } return; TR_000D: num++; TR_0026: while (true) { if (num >= 6) { break; } string name = Path.Combine(folder, MyCubemapHelpers.GetNameForFace(num)); try { string str; Image image = this.TryGetPlanetTexture(name, context, "_mat", out str); if (image == null) { this.ClearMatValues(dataArray); break; } using (image) { PixelBuffer buffer = image.GetPixelBuffer(0, 0, 0); if ((buffer.Format != Format.B8G8R8A8_UNorm) && (buffer.Format != Format.R8G8B8A8_UNorm)) { object[] args = new object[] { buffer.Format, str }; MyLog.Default.Error("While loading maps from {1}: Unsupported planet map format: {0}.", args); break; } if (buffer.Width == buffer.Height) { if (mapsToUse.HasFlag(MyPlanetMapTypeSet.Material)) { dataArray[num * 4] = new MyCubemapData <byte>(buffer.Width, null); streams[0] = dataArray[num * 4].Data; } if (mapsToUse.HasFlag(MyPlanetMapTypeSet.Biome)) { dataArray[(num * 4) + 1] = new MyCubemapData <byte>(buffer.Width, null); streams[1] = dataArray[(num * 4) + 1].Data; } if (mapsToUse.HasFlag(MyPlanetMapTypeSet.Ore)) { dataArray[(num * 4) + 2] = new MyCubemapData <byte>(buffer.Width, null); streams[2] = dataArray[(num * 4) + 2].Data; } if (buffer.Format == Format.B8G8R8A8_UNorm) { streams[2] = streams[0]; streams[0] = streams[2]; } this.ReadChannelsFromImage(streams, buffer); image.Dispose(); goto TR_000D; } else { object[] args = new object[] { str }; MyLog.Default.Error("While loading maps from {0}: Width and height must be the same.", args); } break; } } catch (Exception exception) { MyLog.Default.Error(exception.ToString(), Array.Empty <object>()); break; } goto TR_000D; } goto TR_000A; }