static void SetSmooth(Game g, string v) { g.SmoothLighting = SetBool(v, OptionsKey.SmoothLighting); ChunkMeshBuilder builder = g.MapRenderer.DefaultMeshBuilder(); g.MapRenderer.SetMeshBuilder(builder); g.MapRenderer.Refresh(); }
void SetSmoothLighting(Game g, bool v) { g.SmoothLighting = v; ChunkMeshBuilder builder = g.MapRenderer.DefaultMeshBuilder(); g.MapRenderer.SetMeshBuilder(builder); g.MapRenderer.Refresh(); }
public void SetMeshBuilder(ChunkMeshBuilder newBuilder) { if (builder != null) { builder.Dispose(); } builder = newBuilder; builder.Init(game); builder.OnNewMapLoaded(); }
public void SetMeshBuilder(ChunkMeshBuilder newBuilder) { if (updater.builder != null) { updater.builder.Dispose(); } updater.builder = newBuilder; updater.builder.Init(game); updater.builder.OnNewMapLoaded(); }
public void UpdateSection(ChunkSection section) { if (chunkRenderer.ContainsKey(section.Pos)) { if (section.Meshed) { LoadedData data = new ChunkMeshBuilder(section).BuildChunk(); chunkRenderer[section.Pos].CommitMesh(data); } } }
public ChunkUpdater( Game game, MapRenderer renderer ) { this.game = game; this.renderer = renderer; info = game.BlockInfo; builder = new ChunkMeshBuilder( game ); api = game.Graphics; game.Events.TerrainAtlasChanged += TerrainAtlasChanged; game.WorldEvents.OnNewMap += OnNewMap; game.WorldEvents.OnNewMapLoaded += OnNewMapLoaded; game.WorldEvents.EnvVariableChanged += EnvVariableChanged; game.Events.BlockDefinitionChanged += BlockDefinitionChanged; game.Events.ViewDistanceChanged += ViewDistanceChanged; game.Events.ProjectionChanged += ProjectionChanged; }
public ChunkUpdater(Game game, MapRenderer renderer) { this.game = game; this.renderer = renderer; info = game.BlockInfo; builder = new ChunkMeshBuilder(game); api = game.Graphics; game.Events.TerrainAtlasChanged += TerrainAtlasChanged; game.WorldEvents.OnNewMap += OnNewMap; game.WorldEvents.OnNewMapLoaded += OnNewMapLoaded; game.WorldEvents.EnvVariableChanged += EnvVariableChanged; game.Events.BlockDefinitionChanged += BlockDefinitionChanged; game.Events.ViewDistanceChanged += ViewDistanceChanged; game.Events.ProjectionChanged += ProjectionChanged; }
public void InitPlayScene() { m_EventMng.enabled = true; m_WorldMng.enabled = true; m_PlayerMng.enabled = true; m_InputMng.enabled = true; m_SaveMng.enabled = true; ApplySettings(false); //Load Save File m_SaveMng.InitSaveSystem(); //Provide Event Service m_EventMng.ProvideEventServ(); //Init Game Utility m_Utility.Init(m_SaveMng.WorldSeed); //Spawn World m_WorldMng.ProvideWorldServ(m_SaveMng.WorldSeed); m_WorldMng.BiomeMng.Init(m_Utility.NoiseMaker, m_WorldMng.WorldServ); m_WorldMng.GetComponent <MapMaker>().Init(); m_WorldMng.SpawnWorld(m_SaveMng.PlayerPos, m_PlayerMng.PlayerView); //Init Loading Screen LoadingScreenIns = Instantiate(m_Prefab_LoadingScreen).GetComponent <LoadingScreen>(); LoadingScreenIns.gameObject.SetActive(true); LoadingScreenIns.AddListener(InitPlayer); LoadingScreenIns.AddListener(InitInput); //Init Mesh Builder ChunkMeshBuilder meshBuilder = Locator <IWorld> .GetService().Entity.GetComponent <ChunkMeshBuilder>(); meshBuilder.AddListener(LoadingScreenIns.SetRemainedTask); LoadingScreenIns.SetTotalTask(meshBuilder.RemainedTask); meshBuilder.StartBuildingThread(); }
public void InitMeshBuilder() { if (builder != null) { builder.Dispose(); } if (game.SmoothLighting) { builder = new AdvLightingMeshBuilder(); } else { builder = new NormalMeshBuilder(); } builder.Init(game); builder.OnNewMapLoaded(); }
public ChunkUpdater( Game game, MapRenderer renderer ) { this.game = game; this.renderer = renderer; info = game.BlockInfo; renderer._1DUsed = game.TerrainAtlas1D.CalcMaxUsedRow( game.TerrainAtlas, info ); renderer.totalUsed = new int[game.TerrainAtlas1D.TexIds.Length]; RecalcBooleans( true ); builder = new ChunkMeshBuilder( game ); api = game.Graphics; elementsPerBitmap = game.TerrainAtlas1D.elementsPerBitmap; game.Events.TerrainAtlasChanged += TerrainAtlasChanged; game.WorldEvents.OnNewMap += OnNewMap; game.WorldEvents.OnNewMapLoaded += OnNewMapLoaded; game.WorldEvents.EnvVariableChanged += EnvVariableChanged; game.Events.BlockDefinitionChanged += BlockDefinitionChanged; game.Events.ViewDistanceChanged += ViewDistanceChanged; game.Events.ProjectionChanged += ProjectionChanged; }
public override void Load() { base.Load(); chunkMeshBuilder = new ChunkMeshBuilder(); chunkGenerator = new ChunkGenerator(1975); map.Populate(chunkGenerator, chunkMeshBuilder); shader = Shader.Load("Simple", 2, "Assets/Shaders/simple.vert", "Assets/Shaders/simple.frag"); shader.Use(); vpLoc = GL.GetUniformLocation(shader.ShaderID, "VP"); mLoc = GL.GetUniformLocation(shader.ShaderID, "M"); model = Matrix4.Identity; vp = Matrix4.Identity; ortho = Matrix4.CreateOrthographicOffCenter(0.0f, (float)game.ClientSize.X, 0.0f, (float)game.ClientSize.Y, 0.1f, 1.0f); projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(60.0f), game.ClientSize.X / game.ClientSize.Y, 0.1f, 1000.0f); //cam = new Camera(new Vector3(20.0f, 80.0f, 100.0f), new Vector3(20.0f, 0.0f, 0.0f)); //cam.OrbitMinZoom = 1.5f; //cam.OrbitMaxZoom = 800.0f; //cam.OrbitOffsetDistance = 150.0f; //cam.Yaw = MathHelper.DegreesToRadians(-90.0f); //cam.Pitch = MathHelper.DegreesToRadians(-60.0f); //cam.Behavior = Camera.BehaviorType.ORBIT; //cam.LookAt(new Vector3(20.0f, 0.0f, 0.0f)); // //vp = cam.View * projection; //float textWidth = (float)game.SceneManager.MeasureText("TAB = Toggle Camera Rotation, F3 = Toggle draw chunk borders"); //UI.Label infoText = new UI.Label(0.0f, 100.0f, textWidth, 40.0f, "TAB = Toggle Camera Rotation, F3 = Toggle draw chunk borders"); //game.SceneManager.CurrentScreen.Elements.Add("DebugInfo", infoText); }
IEnumerator buildMesh(Chunk c, Chunk.renderChunkDelegate callback) { /* #region CoroutineObject No Stacking * List<CoroutineObject> others = new List<CoroutineObject> (0); * foreach (GameObject g in GameObject.FindGameObjectsWithTag("CoroutineObject")) { * if (g != this.gameObject) { * others.Add(g.GetComponent<CoroutineObject>()); * } * } * bool needsToWait = true; * while(needsToWait) { * int numRunning = 0; * foreach(CoroutineObject co in others) { * if(co.isRunning) { * numRunning++; * } * } * * if(numRunning > maxNumRunning) { * needsToWait = true; * } else { * needsToWait = false; * } * * if(needsToWait) { * yield return null; * } * } #endregion */ isRunning = true; float time = 0.0f; ChunkMeshObject cmo = null; bool done = false; Thread thread = new Thread(() => { cmo = ChunkMeshBuilder.BuildMesh(c); done = true; }); thread.Start(); while (!done && time < timeout) { yield return(new WaitForEndOfFrame()); time += Time.deltaTime; } if (time >= timeout) { BuildMesh(c, callback); thread.Abort(); print("CoroutineObject timed out building mesh. Retrying..."); yield break; } callback.Invoke(cmo); Destroy(this.gameObject); }
public void UpdateMesh() { if (ChunkData is null) { return; } if (player is null) { Start(); } meshBuilder = new ChunkMeshBuilder(); ChunkData.ForEach((x, y, z) => { if (!ChunkData.Blocks[x, y, z].GetBlockType().Renderable) { return; } Vector3 vector = new Vector3(x, y, z); bool[] renderFace = new bool[6] { false, false, false, false, false, false }; long index = GetChunkIndex(ChunkData.ChunkPos); // Top renderFace[0] = y == ChunkY - 1 || !ChunkData.Blocks[x, y + 1, z].GetBlockType().Solid; // Front if (z != 0) { renderFace[1] = !ChunkData.Blocks[x, y, z - 1].GetBlockType().Solid; } else if (Chunks.ContainsKey(index - MaxChunkCount)) { renderFace[1] = !Chunks[index - MaxChunkCount].Blocks[x, y, ChunkZ - 1].GetBlockType().Solid; } // Left if (x != 0) { renderFace[2] = !ChunkData.Blocks[x - 1, y, z].GetBlockType().Solid; } else if (Chunks.ContainsKey(index - 1)) { renderFace[2] = !Chunks[index - 1].Blocks[ChunkX - 1, y, z].GetBlockType().Solid; } // Right if (x != ChunkX - 1) { renderFace[3] = !ChunkData.Blocks[x + 1, y, z].GetBlockType().Solid; } else if (Chunks.ContainsKey(index + 1)) { renderFace[3] = !Chunks[index + 1].Blocks[0, y, z].GetBlockType().Solid; } // Back if (z != ChunkZ - 1) { renderFace[4] = !ChunkData.Blocks[x, y, z + 1].GetBlockType().Solid; } else if (Chunks.ContainsKey(index + MaxChunkCount)) { renderFace[4] = !Chunks[index + MaxChunkCount].Blocks[x, y, 0].GetBlockType().Solid; } // Bottom renderFace[5] = y == 0 || !ChunkData.Blocks[x, y - 1, z].GetBlockType().Solid; for (int i = 0; i < 6; i++) { if (renderFace[i]) { meshBuilder.AddFace(i, vector, ChunkData.Blocks[x, y, z]); } } }); Mesh mesh = meshBuilder.BuildMesh(); GetComponent <MeshFilter>().mesh = mesh; GetComponent <MeshCollider>().sharedMesh = mesh; GetComponent <MeshRenderer>().material = PackedMaterial; }