static void Postfix(SectionLayer layer, Vector3 center) { LayerSubMesh mesh = layer.GetSubMesh(MatBases.SunShadowFade); if (mesh.verts.Count > 0) { mesh.uvs.Add(center - PrintPlanePatch.currentThingCenter ?? Vector3.zero); } }
public static bool GetSubMesh(SectionLayer __instance, ref LayerSubMesh __result, Material material) { if (allThreads2.TryGetValue(CurrentThread, out ThreadInfo threadInfo)) { Func <object[], object> safeFunction = parameters => __instance.GetSubMesh((Material)parameters[0]); threadInfo.safeFunctionRequest = new object[] { safeFunction, new object[] { material } }; mainThreadWaitHandle.Set(); threadInfo.eventWaitStart.WaitOne(); __result = (LayerSubMesh)threadInfo.safeFunctionResult; return(false); } return(true); }
public static bool ShouldDraw(SectionLayer __instance) { TerrainDef def = TerrainDef.Named("HardVacuum"); Map map = Find.CurrentMap; // if we aren't in space, abort! if (map.terrainGrid.TerrainAt(IntVec3.Zero).defName != def.defName) { return(true); } if (__instance.GetType().Name == "SectionLayer_SunShadows") { return(false); } if (__instance.GetType().Name == "SectionLayer_LightingOverlay") { oldSkyGlow = map.skyManager.CurSkyGlow; MatBases.LightOverlay.color = new Color(1.0f, 1.0f, 1.0f); map.skyManager.ForceSetCurSkyGlow(1.0f); } if (__instance.GetType().Name == "SectionLayer_Terrain") { float num = (float)UI.screenWidth / (float)UI.screenHeight; Vector3 center = Find.CameraDriver.GetComponent <Camera>().transform.position; float cellsHigh = UI.screenHeight / Find.CameraDriver.CellSizePixels; float cellsWide = cellsHigh * num; //recalculate uvs for planet texture. LayerSubMesh mesh = __instance.GetSubMesh(RenderPlanetBehindMap.PlanetMaterial); if (mesh != null) { mesh.Clear(MeshParts.UVs); for (int i = 0; i < mesh.verts.Count; i++) { float xdiff = mesh.verts[i].x - center.x; float xfromEdge = xdiff + cellsWide / 2f; float zdiff = mesh.verts[i].z - center.z; float zfromEdge = zdiff + cellsHigh / 2f; mesh.uvs.Add(new Vector3(xfromEdge / cellsWide, zfromEdge / cellsHigh, 0.0f)); } mesh.FinalizeMesh(MeshParts.UVs); } } return(true); }
public static bool GetSubMesh(SectionLayer __instance, ref LayerSubMesh __result, Material material) { int tID = Thread.CurrentThread.ManagedThreadId; if (RimThreaded.mainRequestWaits.TryGetValue(tID, out EventWaitHandle eventWaitStart)) { Func <object[], object> safeFunction = p => __instance.GetSubMesh((Material)p[0]); object[] functionAndParameters = new object[] { safeFunction, new object[] { material } }; lock (RimThreaded.safeFunctionRequests) { RimThreaded.safeFunctionRequests[tID] = functionAndParameters; } RimThreaded.mainThreadWaitHandle.Set(); eventWaitStart.WaitOne(); RimThreaded.safeFunctionResults.TryGetValue(tID, out object safeFunctionResult); __result = (LayerSubMesh)safeFunctionResult; return(false); } return(true); }
public override void PostPrintOnto(SectionLayer layer) { if (parent.def.graphicData.shadowData != null) { // shadow offset is not calculated in PrintShadow by default for some reason var shadow = parent.def.graphicData.shadowData; var offset = parent.TrueCenter() + parent.def.graphicData.shadowData.offset; var subMesh = layer.GetSubMesh(MatBases.SunShadowFade); var item = new Color32(255, 0, 0, (byte)(255f * shadow.BaseY)); float num, num2; if (parent.Rotation == Rot4.North || parent.Rotation == Rot4.South) { num = shadow.BaseX/2f; num2 = shadow.BaseZ/2f; } else { num = shadow.BaseZ/2f; num2 = shadow.BaseX/2f; } var x = offset.x; var z = offset.z; var count = subMesh.verts.Count; subMesh.verts.Add(new Vector3(x - num, 1f, z - num2)); subMesh.verts.Add(new Vector3(x - num, 1f, z + num2)); subMesh.verts.Add(new Vector3(x + num, 1f, z + num2)); subMesh.verts.Add(new Vector3(x + num, 1f, z - num2)); subMesh.colors.Add(LowVertexColor); subMesh.colors.Add(LowVertexColor); subMesh.colors.Add(LowVertexColor); subMesh.colors.Add(LowVertexColor); subMesh.tris.Add(count); subMesh.tris.Add(count + 1); subMesh.tris.Add(count + 2); subMesh.tris.Add(count); subMesh.tris.Add(count + 2); subMesh.tris.Add(count + 3); var count2 = subMesh.verts.Count; subMesh.verts.Add(new Vector3(x - num, 1f, z - num2)); subMesh.verts.Add(new Vector3(x - num, 1f, z + num2)); subMesh.colors.Add(item); subMesh.colors.Add(item); subMesh.tris.Add(count); subMesh.tris.Add(count2); subMesh.tris.Add(count2 + 1); subMesh.tris.Add(count); subMesh.tris.Add(count2 + 1); subMesh.tris.Add(count + 1); var count3 = subMesh.verts.Count; subMesh.verts.Add(new Vector3(x + num, 1f, z + num2)); subMesh.verts.Add(new Vector3(x + num, 1f, z - num2)); subMesh.colors.Add(item); subMesh.colors.Add(item); subMesh.tris.Add(count + 2); subMesh.tris.Add(count3); subMesh.tris.Add(count3 + 1); subMesh.tris.Add(count3 + 1); subMesh.tris.Add(count + 3); subMesh.tris.Add(count + 2); var count4 = subMesh.verts.Count; subMesh.verts.Add(new Vector3(x - num, 1f, z - num2)); subMesh.verts.Add(new Vector3(x + num, 1f, z - num2)); subMesh.colors.Add(item); subMesh.colors.Add(item); subMesh.tris.Add(count); subMesh.tris.Add(count + 3); subMesh.tris.Add(count4); subMesh.tris.Add(count + 3); subMesh.tris.Add(count4 + 1); subMesh.tris.Add(count4); } }