void GenerateModel(BoctModel model, string modelName, Material mat, string assetDir, GameObject target) { var gen = new BoctMeshGenerator(); gen.BoctMaterial = mat; gen.MaterialList = model.MaterialList; gen.SaveMesh = true; gen.MeshPath = assetDir; gen.BlockScale = _blockScale; gen.GenerateCollider = _generateCollider; if (_useRegion) { foreach (var region in model.Regions) { var go = new GameObject(); go.transform.parent = target.transform; gen.GenerateMesh(region.Value.Head, go, modelName + "_" + region.Value.LUID); } } else { gen.GenerateMesh(model.Head, target, modelName); } }
public override void OnImportAsset(AssetImportContext ctx) { BoctModel model = null; try { model = BoctModelImporter.Import(ctx.assetPath); model.InitRegion(); } catch (Exception e) { Debug.LogException(e); throw; } var go = new GameObject(); var material = Resources.Load("BoctMaterial") as Material; var dir = Path.GetDirectoryName(ctx.assetPath); var modelName = string.IsNullOrEmpty(model.Info.Name) ? "BoctModel" : model.Info.Name; GenerateModel(model, modelName, Resources.Load("BoctMaterial") as Material, dir, go); ctx.AddObjectToAsset("Material", material); ctx.AddObjectToAsset(modelName, go); ctx.SetMainObject(go); }
static BoctModel ImportFtrim(string path) { var model = new BoctModel(); var info = new BoctModelInfo(); info.GUID = Guid.NewGuid(); info.Name = "Import Model(" + info.GUID.ToString().Substring(0, 8) + ")"; info.DataPath = info.GUID + ".db"; info.DataVersion = BoctModelInfo.CurrentVersion; model.Info = info; using (var sr = new StreamReader(path)) { string line; while ((line = sr.ReadLine()) != null) { var arr = line.Split(new char[] { ':' }); if (arr.Length > 1) { var key = arr[0].Trim(); var val = arr[1].Trim(); if (key == "name") { model.Info.Name = val; } else if (key == "boct") { InsertBoctFromBoctPacket30(val, model.Head); } else if (key == "material") { var colors = val.Split(new char[] { ',' }); for (int i = 0; i < colors.Length; i++) { var mat = new BoctMaterial(); mat.GUID = Guid.NewGuid(); mat.LUID = i; mat.Color = colors[i].ToColor(); model.MaterialList.AddMaterial(mat); } } } } } return(model); }
static BoctModel ImportYaml(string path) { var sr = new StreamReader(path); var input = sr.ReadToEnd(); sr.Close(); var deserializer = new DeserializerBuilder().Build(); var data = deserializer.Deserialize <BoctModelData>(input); Debug.Log(data.Regions.Count); var model = new BoctModel(data); model.Info.GUID = Guid.NewGuid(); return(model); }