//Dictionary<string, Texture2D> diffuseTextures = new Dictionary<string, Texture2D>(); //Dictionary<string, Texture2D> specularTextures = new Dictionary<string, Texture2D>(); //Dictionary<string, geometry> geometryLibrary = new Dictionary<string, geometry>(); //List<node> nodeList = new List<node>(); //this is very similar to the blockmesher function. void CollectModel(MapDataStore.Tile tile, MeshLayer layer, DFCoord pos) { if (layer == MeshLayer.Collision) { return; } #region Mesh Selection MeshContent meshContent = null; switch (layer) { case MeshLayer.GrowthMaterial: case MeshLayer.GrowthMaterial1: case MeshLayer.GrowthMaterial2: case MeshLayer.GrowthMaterial3: case MeshLayer.GrowthCutout: case MeshLayer.GrowthCutout1: case MeshLayer.GrowthCutout2: case MeshLayer.GrowthCutout3: case MeshLayer.GrowthTransparent: case MeshLayer.GrowthTransparent1: case MeshLayer.GrowthTransparent2: case MeshLayer.GrowthTransparent3: { switch (tile.tiletypeMaterial) { case TiletypeMaterial.PLANT: case TiletypeMaterial.ROOT: case TiletypeMaterial.TREE_MATERIAL: case TiletypeMaterial.MUSHROOM: if (!ContentLoader.Instance.GrowthMeshConfiguration.GetValue(tile, layer, out meshContent)) { return; } break; default: return; } } break; //case MeshLayer.BuildingMaterial: //case MeshLayer.NoMaterialBuilding: //case MeshLayer.BuildingMaterialCutout: //case MeshLayer.NoMaterialBuildingCutout: //case MeshLayer.BuildingMaterialTransparent: //case MeshLayer.NoMaterialBuildingTransparent: // { // if (tile.buildingType == default(BuildingStruct)) // return; // if (!ContentLoader.Instance.BuildingMeshConfiguration.GetValue(tile, layer, out meshContent)) // return; // } // break; default: { if (!ContentLoader.Instance.TileMeshConfiguration.GetValue(tile, layer, out meshContent)) { return; } } break; } if (!meshContent.MeshData.ContainsKey(layer)) { return; } #endregion node tileNode = new node(); tileNode.id = string.Format("Tile[{0},{1},{2}]_{3}", pos.x, pos.y, pos.z, layer); tileNode.Items = new object[] { COLLADA.ConvertMatrix(Matrix4x4.TRS( GameMap.DFtoUnityCoord(pos), meshContent.GetRotation(tile), Vector3.one)) }; tileNode.ItemsElementName = new ItemsChoiceType2[] { ItemsChoiceType2.matrix }; //string geometryName = "Mesh-" + meshContent.UniqueIndex; //if (!geometryLibrary.ContainsKey(geometryName)) //{ // geometryLibrary[geometryName] = COLLADA.MeshToGeometry(meshContent.MeshData[layer], geometryName); //} //instance_geometry geometryInstance = new instance_geometry(); //geometryInstance.url = "#" + geometryLibrary[geometryName].id; //tileNode.instance_geometry = new instance_geometry[] { geometryInstance }; //nodeList.Add(tileNode); //return; //----------------------------------------------------------- //Put normal map stuff here! Remember! //----------------------------------------------------------- //string patternName = "Tex-"; //Texture2D tiletexture = null; //TextureContent textureContent; //if (ContentLoader.Instance.MaterialTextureConfiguration.GetValue(tile, layer, out textureContent)) //{ // tiletexture = textureContent.Texture; // patternName += textureContent.UniqueIndex; //} //else patternName += "#"; //patternName += "-#"; //Color color = Color.grey; //ColorContent colorContent; //if (ContentLoader.Instance.ColorConfiguration.GetValue(tile, layer, out colorContent)) //{ // color = colorContent.color; //} //patternName += string.Format("{0:X2}{1:X2}{2:X2}", ((Color32)color).r, ((Color32)color).g, ((Color32)color).b); //if (diffuseTextures.ContainsKey(patternName)) // return; //Color neutralSpec = new Color(0.04f, 0.04f, 0.04f); //Texture2D outputDiffuse; //Texture2D outputSpec; //if (tiletexture != null) //{ // outputDiffuse = new Texture2D(tiletexture.width, tiletexture.height); // outputSpec = new Texture2D(tiletexture.width, tiletexture.height); // Color[] colors = tiletexture.GetPixels(); // Color[] specs = new Color[colors.Length]; // for (int i = 0; i < colors.Length; i++) // { // var diffuseColor = OverlayBlend(colors[i], color); // diffuseColor.a = 1; // colors[i] = Color.Lerp(Color.black, diffuseColor, color.a); // specs[i] = Color.Lerp(diffuseColor, neutralSpec, color.a); // } // outputDiffuse.SetPixels(colors); // outputSpec.SetPixels(specs); //} //else //{ // outputDiffuse = ContentLoader.CreateFlatTexture(color); // outputSpec = ContentLoader.CreateFlatTexture(neutralSpec); //} //outputDiffuse.name = patternName + "_Diffuse"; //outputSpec.name = patternName + "_Specular"; //diffuseTextures[patternName] = outputDiffuse; //specularTextures[patternName] = outputSpec; }