<commit_before>﻿using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
public class objectExporter : EditorWindow {

    [MenuItem("File/Export Selected/.obj")]
    private static void ExportMesh()
    {
        GameObject gO = Selection.activeGameObject;
        List<Material> mats = new List<Material>();
        string dir = Path.Combine(Application.dataPath, "objExport/" + gO.name);
        Directory.CreateDirectory(dir);
        BuildObj(gO, ref mats, dir);
        BuildMtl(mats, dir, gO.name);
    }

    private static void BuildObj(GameObject gO, ref List<Material> mtls, string dir)
    {
        MeshFilter[] meshFilters = gO.GetComponentsInChildren<MeshFilter>();
        StringBuilder vs = new StringBuilder("mtllib " + gO.name + ".mtl").AppendLine();
        StringBuilder vts = new StringBuilder();
        StringBuilder vns = new StringBuilder();
        StringBuilder fs = new StringBuilder();
        Mesh m;
        MeshFilter mf;
        Material[] mats;
        Material mat;
        Vector3 vW;
        int[] tr;
        int o = 1;
        for (int i = 0; i < meshFilters.Length; i++)
        {
            mf = meshFilters[i];
            m = mf.sharedMesh;
            if (mf.gameObject.GetComponent<Renderer>() == null)
            {
                continue;
            }
            mats = mf.gameObject.GetComponent<Renderer>().sharedMaterials;
            for (int j = 0; j < m.vertexCount; j++) 
            {
                vW = m.vertices[j];
                vW = mf.transform.TransformPoint(vW);
                vs.AppendFormat("v {0} {1} {2}\n", vW.x, vW.y, vW.z).AppendLine();
            }
            foreach (Vector3 v in m.normals)
            {
                vns.AppendFormat("vn {0} {1} {2}\n", v.x, v.y, v.z).AppendLine();
            }
            foreach (Vector3 v in m.uv)
            {
                vts.AppendFormat("vt {0} {1}\n", v.x, v.y).AppendLine();
            }
            for (int u = 0; u < m.subMeshCount; u++)
            {
                mat = mats[u];
                if (!mtls.Contains(mat))
                {
                    mtls.Add(mat);
                }
                fs.AppendFormat("usemtl {0}\n", mat.name).AppendLine();
                tr = m.GetTriangles(u);
                for (int k = 0; k < tr.Length; k += 3)
                {
                    fs.AppendFormat("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n",
                        tr[k] + o, tr[k + 1] + o, tr[k + 2] + o).AppendLine();
                }
            }
            o += m.vertexCount;
        }
        using (StreamWriter sw = new StreamWriter(Path.Combine(dir, gO.name + ".obj"), false))
        {
            sw.Write(vs.ToString() + vns.ToString() + vts.ToString() + fs.ToString());
        }
    }

    private static void BuildMtl(List<Material> mats, string dir, string name)
    {
        StringBuilder mtl = new StringBuilder();
        foreach (Material m in mats)
        {
            mtl.AppendFormat("newmtl {0}", m.name).AppendLine();
            if (m.HasProperty("_Color"))
            {
                Color c = m.GetColor("_Color");
                mtl.AppendFormat("Kd {0} {1} {2}", c.r, c.g, c.b).AppendLine();
            }
            if (m.HasProperty("_MainTex"))
            {
                string assetPath = AssetDatabase.GetAssetPath(m.GetTexture("_MainTex"));<commit_msg>Removed newlines from stringbuilder<commit_after>﻿using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
public class objectExporter : EditorWindow {

    [MenuItem("File/Export Selected/.obj")]
    private static void ExportMesh()
    {
        GameObject gO = Selection.activeGameObject;
        List<Material> mats = new List<Material>();
        string dir = Path.Combine(Application.dataPath, "objExport/" + gO.name);
        Directory.CreateDirectory(dir);
        BuildObj(gO, ref mats, dir);
        BuildMtl(mats, dir, gO.name);
    }

    private static void BuildObj(GameObject gO, ref List<Material> mtls, string dir)
    {
        MeshFilter[] meshFilters = gO.GetComponentsInChildren<MeshFilter>();
        StringBuilder vs = new StringBuilder("mtllib " + gO.name + ".mtl").AppendLine();
        StringBuilder vts = new StringBuilder();
        StringBuilder vns = new StringBuilder();
        StringBuilder fs = new StringBuilder();
        Mesh m;
        MeshFilter mf;
        Material[] mats;
        Material mat;
        Vector3 vW;
        int[] tr;
        int o = 1;
        for (int i = 0; i < meshFilters.Length; i++)
        {
            mf = meshFilters[i];
            m = mf.sharedMesh;
            if (mf.gameObject.GetComponent<Renderer>() == null)
            {
                continue;
            }
            mats = mf.gameObject.GetComponent<Renderer>().sharedMaterials;
            for (int j = 0; j < m.vertexCount; j++) 
            {
                vW = m.vertices[j];
                vW = mf.transform.TransformPoint(vW);
                vs.AppendFormat("v {0} {1} {2}", vW.x, vW.y, vW.z).AppendLine();
            }
            foreach (Vector3 v in m.normals)
            {
                vns.AppendFormat("vn {0} {1} {2}", v.x, v.y, v.z).AppendLine();
            }
            foreach (Vector3 v in m.uv)
            {
                vts.AppendFormat("vt {0} {1}", v.x, v.y).AppendLine();
            }
            for (int u = 0; u < m.subMeshCount; u++)
            {
                mat = mats[u];
                if (!mtls.Contains(mat))
                {
                    mtls.Add(mat);
                }
                fs.AppendFormat("usemtl {0}", mat.name).AppendLine();
                tr = m.GetTriangles(u);
                for (int k = 0; k < tr.Length; k += 3)
                {
                    fs.AppendFormat("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}",
                        tr[k] + o, tr[k + 1] + o, tr[k + 2] + o).AppendLine();
                }
            }
            o += m.vertexCount;
        }
        using (StreamWriter sw = new StreamWriter(Path.Combine(dir, gO.name + ".obj"), false))
        {
            sw.Write(vs.ToString() + vns.ToString() + vts.ToString() + fs.ToString());
        }
    }

    private static void BuildMtl(List<Material> mats, string dir, string name)
    {
        StringBuilder mtl = new StringBuilder();
        foreach (Material m in mats)
        {
            mtl.AppendFormat("newmtl {0}", m.name).AppendLine();
            if (m.HasProperty("_Color"))
            {
                Color c = m.GetColor("_Color");
                mtl.AppendFormat("Kd {0} {1} {2}", c.r, c.g, c.b).AppendLine();
            }
            if (m.HasProperty("_MainTex"))
            {
                string assetPath = AssetDatabase.GetAssetPath(m.GetTexture("_MainTex"));
{'fraction_non_alphanumeric': 0.13993619489559164, 'fraction_numerical': 0.0095707656612529, 'mean_word_length': 1.6234309623430963, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3259055', 'n_tokens_mistral': 2127, 'n_tokens_neox': 2056, 'n_words': 470}