public static void Export(string path, BlockGroup blockGroup) { var blockMeshes = new BlockMeshMerger(); foreach (var block in blockGroup.GetAllBlocks()) { block.WriteToMesh(blockGroup, blockMeshes); } string dataName = Path.GetFileNameWithoutExtension(path); var writer = new StringWriter(); writer.WriteLine("#Created by Tsumiki Editor"); writer.WriteLine(""); writer.WriteLine("mtllib " + dataName + ".mtl"); writer.WriteLine(""); // Output Vertices foreach (Vector3 v in blockMeshes.vertexPos) { writer.WriteLine("v " + v.x + " " + v.y + " " + v.z); } writer.WriteLine("# " + blockMeshes.vertexPos.Count + " vertices"); // Output Texture Vertices foreach (Vector2 vt in blockMeshes.vertexUv) { writer.WriteLine("vt " + vt.x + " " + (1.0f - vt.y)); } writer.WriteLine("# " + blockMeshes.vertexUv.Count + " texture vertices"); // Output Faces writer.WriteLine("usemtl mat1"); int facesCount = blockMeshes.triangles.Count / 3; for (int i = 0; i < facesCount; i++) { int i0 = blockMeshes.triangles[i * 3 + 0] + 1; int i1 = blockMeshes.triangles[i * 3 + 1] + 1; int i2 = blockMeshes.triangles[i * 3 + 2] + 1; writer.WriteLine("f " + i0 + "/" + i0 + " " + i1 + "/" + i1 + " " + i2 + "/" + i2); } writer.WriteLine("# " + blockMeshes.vertexUv.Count + " texture vertices"); File.WriteAllText(path, writer.ToString(), Encoding.ASCII); writer.Dispose(); // Output Materials var mtlWriter = new StringWriter(); mtlWriter.WriteLine("newmtl mat1"); mtlWriter.WriteLine("Ka 0.00000 0.00000 0.00000"); mtlWriter.WriteLine("Kd 0.00000 0.00000 0.00000"); mtlWriter.WriteLine("Ks 0.00000 0.00000 0.00000"); mtlWriter.WriteLine("Ns 0.00000"); File.WriteAllText(Path.ChangeExtension(path, ".mtl"), mtlWriter.ToString(), Encoding.ASCII); mtlWriter.Dispose(); }
private static void WriteMetaFile(string path, Vector3 offset, bool toRightHanded) { BlockGroup blockGroup = EditManager.Instance.Layers[0].GetBlockGroup(); ModelGroup modelGroup = EditManager.Instance.Layers[0].GetModelGroup(); Mesh mesh = blockGroup.GetRouteMesh(); Block[] blocks = blockGroup.GetEnterableBlocks(); // モデルを見て移動可能かどうかをチェックする blocks = blocks.Where(block => { var model = modelGroup.GetModel(block.position); return(model == null || model.shape.enterable); }).ToArray(); var fieldPanels = new FieldPanelGroup(mesh, blocks, offset); fieldPanels.ApplyRoutePath(blockGroup, EditManager.Instance.RoutePath); // バウンディングボックス Vector3 minpos = mesh.bounds.min + offset; Vector3 maxpos = mesh.bounds.max + offset; // 座標系反転処理 if (toRightHanded) { fieldPanels.ApplyRightHanded(); minpos = FileUtil.ApplyRightHanded(minpos); maxpos = FileUtil.ApplyRightHanded(maxpos); float z = minpos.z; minpos.z = maxpos.z; maxpos.z = z; } var mem = new MemoryStream(); var writer = new BinaryWriter(mem); writer.Write("E3MT".ToArray()); // Identifier writer.Write(2); // Version // バウンディングボックス writer.Write(minpos); writer.Write(maxpos); // 移動パネル fieldPanels.Write(writer); // 当たり判定ブロック Block[] colliderBlocks = blockGroup.GetAllBlocks(); writer.Write(colliderBlocks.Length); Vector3 colliderOffset = new Vector3(0.5f, 0.25f, 0.5f); foreach (var block in colliderBlocks) { Vector3 position = block.position; if (toRightHanded) { position = FileUtil.ApplyRightHanded(position); } position += colliderOffset; writer.Write(position); } // 3Dモデル配置 Model[] models = modelGroup.GetAllModels(); writer.Write(models.Length); foreach (var model in models) { Vector3 position = model.position; if (toRightHanded) { position = FileUtil.ApplyRightHanded(position); } writer.Write(model.shape.id); writer.Write(position); writer.Write(model.offset); writer.Write((float)model.rotation); writer.Write(model.shape.scale * model.scale); } File.WriteAllBytes(path, mem.ToArray()); }