Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
Create mtl file for obj?

Hello i really need help. i am using unity and i have this code to export obj. but i also wantmy obj to contain textures. i can export texture as jpg but i do not want it, i need mtl file. i want obj to have that textures with it and not with jpg.so how can i make mtl for my exported obj file?

using System.Collections;
using System.IO;
using System.Text;
using System;

public class ObjExporter
{

public static string MeshToString(MeshFilter mf)
{
    Mesh m = mf.mesh;
    Material[] mats = mf.GetComponent<Renderer>().sharedMaterials;

    StringBuilder sb = new StringBuilder();

    //sb.Append("g ").Append(mf.name).Append("\n");
   
    foreach (Vector3 v in m.vertices)
    {
        sb.Append(string.Format("v {0} {1} {2}\n", v.x, v.y, v.z));
    }
    sb.Append("\n");
    foreach (Vector3 v in m.normals)
    {
        sb.Append(string.Format("vn {0} {1} {2}\n", v.x, v.y, v.z));
    }
    sb.Append("\n");
    foreach (Vector3 v in m.uv)
    {
        sb.Append(string.Format("vt {0} {1}\n", v.x, v.y));
    }
    for (int material = 0; material < m.subMeshCount; material++)
    {
        sb.Append("\n");
        sb.Append("usemtl ").Append(mats[material].name).Append("\n");
        sb.Append("usemap ").Append(mats[material].name).Append("\n");

        int[] triangles = m.GetTriangles(material);
        for (int i = 0; i < triangles.Length; i += 3)
        {
            sb.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n",
                triangles[i] + 1, triangles[i + 1] + 1, triangles[i + 2] + 1));
        }
    }
    return sb.ToString();
}

public static void MeshToFile(MeshFilter mf, string filename)
{
    using (StreamWriter sw = new StreamWriter(filename))
    {
        sw.Write(MeshToString(mf));
      

        string path = Application.dataPath + "/screenshots/" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".png";

    }
}

}

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!