// Use this for initialization void Start () { GenerateBlockData (); GenerateBlockModels (); // i should save/load all data here GenerateItemsForBlocks (); for (int i = 0; i < BlockStructuresList.Count; i++) { if (!BlockStructuresList[i].HasInitiated) { BlockStructuresList[i].Reset(); BlockStructuresList[i].UpdateBlockStructureWithType(); } // for my models! - create a meshes for them in thread BlockMesher NewTerrain = new BlockMesher(); BlockMeshers.Add (NewTerrain); MyMesh NewMesh = new MyMesh(); MeshesList.Add (NewMesh); NewTerrain.UpdateMeshesOnThread(NewMesh, BlockStructuresList[i].MyBlocks); } for (int i = 0; i < MazeList.Count; i++) { MazeList [i].Reset (); //MazeList [i].GenerateDungeon (); } // only use voxel models from now on lel ModelsList.Clear (); }
// Use this for initialization void Start () { if (IsGetFromDatabase) { LoadModelFromDataBase (); } else { // generate new mesh MyBlockMesher = new BlockMesher(); // MyBlockStructure = GetManager.GetDataManager ().GetBlockStructure(MyBlockStructureName); MyBlockStructure.Reset (); if (IsVaryScale) { float CurrentSize = MyBlockStructure.MyBlocks.Scale.x; float NewSize = CurrentSize * (Random.Range (MinimumVariation, MaximumVariation)); MyBlockStructure.MyBlocks.Scale += new Vector3 (NewSize, NewSize, NewSize); //MyBlockStructure.MyBlockTypes[0] = Random.Range(1,12); } //MyBlockStructure.UpdateBlockStructureWithType(); if (Type == 0) { MyBlockStructure.Sphere (Random.Range (1, 12), SphereSize); // 7 for cores MyBlockStructure.AddNoise (NoiseValue); } else { MyBlockStructure.MyBlocks.Size.y = 8; MyBlockStructure.Reset (); MyBlockStructure.Cylinder (2, SphereSize); } MyMesh = new MyMesh (); MyBlockMesher.UpdateMeshesOnThread (MyMesh, MyBlockStructure.MyBlocks); } }
void OnDestroy() { if (mesher != null) { mesher.Terminate(); mesher = null; } }
// Update is called once per frame void Update () { if (IsGetFromDatabase) { LoadModelFromDataBase (); } else { if (MyBlockMesher != null) if (MyBlockMesher.CanUpdateMesh) { //Debug.LogError ("BlockMesher: " + i + " : Has finished creating a mesh." + Time.time); Mesh NewMesh = MyBlockMesher.CreateMesh (MyMesh); gameObject.GetComponent<MeshFilter> ().mesh = NewMesh; if (gameObject.GetComponent<MeshCollider> () != null) { gameObject.GetComponent<MeshCollider> ().sharedMesh = null; gameObject.GetComponent<MeshCollider> ().sharedMesh = gameObject.GetComponent<MeshFilter> ().mesh; } MyBlockMesher.CanUpdateMesh = false; HasLoaded = true; MyBlockMesher = null; // finished with it! } } AddForceToExplosion (); }
void OnConnectToDF() { Debug.Log("Connected"); enabled = true; mesher = BlockMesher.GetMesher(meshingThreads); // Initialize materials if (materials == null) { materials = new Dictionary <MatPairStruct, RemoteFortressReader.MaterialDefinition>(); } materials.Clear(); foreach (RemoteFortressReader.MaterialDefinition material in DFConnection.Instance.NetMaterialList.material_list) { materials[material.mat_pair] = material; } // Initialize items if (items == null) { items = new Dictionary <MatPairStruct, RemoteFortressReader.MaterialDefinition>(); } items.Clear(); foreach (RemoteFortressReader.MaterialDefinition material in DFConnection.Instance.NetItemList.material_list) { items[material.mat_pair] = material; } SaveTileTypeList(); SaveMaterialList(DFConnection.Instance.NetMaterialList.material_list, "MaterialList.csv"); SaveMaterialList(DFConnection.Instance.NetItemList.material_list, "ItemList.csv"); SaveBuildingList(); UpdateView(); blockListTimer.Start(); cullTimer.Start(); lazyLoadTimer.Start(); InitializeBlocks(); }
void OnConnectToDF() { Debug.Log("Connected"); enabled = true; mesher = BlockMesher.GetMesher(meshingThreads); // Initialize materials if (materials == null) materials = new Dictionary<MatPairStruct, RemoteFortressReader.MaterialDefinition>(); materials.Clear(); foreach (RemoteFortressReader.MaterialDefinition material in DFConnection.Instance.NetMaterialList.material_list) { materials[material.mat_pair] = material; } // Initialize items if (items == null) items = new Dictionary<MatPairStruct, RemoteFortressReader.MaterialDefinition>(); items.Clear(); foreach (RemoteFortressReader.MaterialDefinition material in DFConnection.Instance.NetItemList.material_list) { items[material.mat_pair] = material; } SaveTileTypeList(); SaveMaterialList(DFConnection.Instance.NetMaterialList.material_list, "MaterialList.csv"); SaveMaterialList(DFConnection.Instance.NetItemList.material_list, "ItemList.csv"); SaveBuildingList(); UpdateView(); blockListTimer.Start(); cullTimer.Start(); lazyLoadTimer.Start(); InitializeBlocks(); }
void OnConnectToDF() { Debug.Log("Connected"); enabled = true; mesher = BlockMesher.GetMesher(meshingThreads); // Initialize materials, if available if (DFConnection.Instance.NetMaterialList != null) { if (materials == null) materials = new Dictionary<MatPairStruct, RemoteFortressReader.MaterialDefinition>(); materials.Clear(); foreach (RemoteFortressReader.MaterialDefinition material in DFConnection.Instance.NetMaterialList.material_list) { materials[material.mat_pair] = material; } SaveMaterialList(materials, "MaterialList.csv"); } // Initialize items, if available if (DFConnection.Instance.NetItemList != null) { if (items == null) items = new Dictionary<MatPairStruct, RemoteFortressReader.MaterialDefinition>(); items.Clear(); foreach (MaterialDefinition material in DFConnection.Instance.NetItemList.material_list) { items[material.mat_pair] = material; } SaveMaterialList(items, "ItemList.csv"); } if (DFConnection.Instance.NetBuildingList != null) { if (buildings == null) buildings = new Dictionary<BuildingStruct, BuildingDefinition>(); buildings.Clear(); foreach (BuildingDefinition building in DFConnection.Instance.NetBuildingList.building_list) { buildings[building.building_type] = building; } SaveBuildingList(); } if (DFConnection.Instance.NetCreatureRawList != null) { if (creatures == null) creatures = new Dictionary<MatPairStruct, MaterialDefinition>(); foreach (CreatureRaw creatureRaw in DFConnection.Instance.NetCreatureRawList.creature_raws) { foreach (var caste in creatureRaw.caste) { MatPairStruct creatureCaste = new MatPairStruct(creatureRaw.index, caste.index); MaterialDefinition creatureDef = new MaterialDefinition(); creatureDef.mat_pair = creatureCaste; creatureDef.id = creatureRaw.creature_id + ":" + caste.caste_id; creatureDef.name = caste.caste_name[0]; creatureDef.state_color = creatureRaw.color; creatures[creatureCaste] = creatureDef; } } SaveMaterialList(creatures, "CreatureList.csv"); } SaveTileTypeList(); UpdateView(); blockListTimer.Start(); cullTimer.Start(); lazyLoadTimer.Start(); InitializeBlocks(); }
internal void LoadMeshes(BlockMesher.Result newMeshes, string suffix) { if (newMeshes.tiles != null) { if (blocks == null) { blocks = new Mesh(); blocks.name = string.Format("block_solid_{0}", suffix); } blocks.Clear(); newMeshes.tiles.CopyToMesh(blocks); } if (newMeshes.topTiles != null) { if (topBlocks == null) { topBlocks = new Mesh(); topBlocks.name = string.Format("block_solid_top_{0}", suffix); } topBlocks.Clear(); newMeshes.topTiles.CopyToMesh(topBlocks); } if (newMeshes.stencilTiles != null) { if (stencilBlocks == null) { stencilBlocks = new Mesh(); stencilBlocks.name = string.Format("block_stencil_{0}", suffix); } stencilBlocks.Clear(); newMeshes.stencilTiles.CopyToMesh(stencilBlocks); } if (newMeshes.topStencilTiles != null) { if (topStencilBlocks == null) { topStencilBlocks = new Mesh(); topStencilBlocks.name = string.Format("block_stencil_top_{0}", suffix); } topStencilBlocks.Clear(); newMeshes.topStencilTiles.CopyToMesh(topStencilBlocks); } if (newMeshes.transparentTiles != null) { if (transparentBlocks == null) { transparentBlocks = new Mesh(); transparentBlocks.name = string.Format("block_transparent_{0}", suffix); } transparentBlocks.Clear(); newMeshes.transparentTiles.CopyToMesh(transparentBlocks); } if (newMeshes.topTransparentTiles != null) { if (topTransparentBlocks == null) { topTransparentBlocks = new Mesh(); topTransparentBlocks.name = string.Format("block_transparent_top_{0}", suffix); } topTransparentBlocks.Clear(); newMeshes.topTransparentTiles.CopyToMesh(topTransparentBlocks); } if (newMeshes.terrainMesh != null) { if (voxelBlocks == null) { voxelBlocks = new Mesh(); voxelBlocks.name = string.Format("block_voxel_{0}", suffix); } voxelBlocks.Clear(); newMeshes.terrainMesh.CopyToMesh(voxelBlocks); voxelBlocks.RecalculateNormals(); voxelBlocks.RecalculateTangents(); } if(newMeshes.topTerrainMesh != null) { if(topVoxelBlocks == null) { topVoxelBlocks = new Mesh(); topVoxelBlocks.name = string.Format("block_voxel_top_{0}", suffix); } topVoxelBlocks.Clear(); newMeshes.topTerrainMesh.CopyToMesh(topVoxelBlocks); topVoxelBlocks.RecalculateNormals(); topVoxelBlocks.RecalculateTangents(); } if (newMeshes.water != null) { if (liquidBlocks == null) liquidBlocks = new Mesh[2]; if (liquidBlocks[MapDataStore.WATER_INDEX] == null) { liquidBlocks[MapDataStore.WATER_INDEX] = new Mesh(); liquidBlocks[MapDataStore.WATER_INDEX].name = string.Format("liquid_water_{0}", suffix); } liquidBlocks[MapDataStore.WATER_INDEX].Clear(); newMeshes.water.CopyToMesh(liquidBlocks[MapDataStore.WATER_INDEX]); } if (newMeshes.magma != null) { if (liquidBlocks == null) liquidBlocks = new Mesh[2]; if (liquidBlocks[MapDataStore.MAGMA_INDEX] == null) { liquidBlocks[MapDataStore.MAGMA_INDEX] = new Mesh(); liquidBlocks[MapDataStore.MAGMA_INDEX].name = string.Format("liquid_magma_{0}", suffix); } liquidBlocks[MapDataStore.MAGMA_INDEX].Clear(); newMeshes.magma.CopyToMesh(liquidBlocks[MapDataStore.MAGMA_INDEX]); } }