Skip to content

Commit a0fbbef

Browse files
committed
working texture export
1 parent 3f11d99 commit a0fbbef

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Editor/ZOExportOBJ.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static string MaterialToString(Material material) {
9292
}
9393

9494
public class ZOExportOBJ : EditorWindow {
95-
public bool _exportSubMeshes = false;
95+
public bool _exportSubMeshes = true;
9696
public bool _zeroPosition = true;
9797
private string _selectedNames;
9898

@@ -142,7 +142,6 @@ public static void DoExport(bool makeSubmeshes, string fileDirectory, bool zeroP
142142
}
143143

144144
string meshName = gameObject.name;
145-
// string fileName = EditorUtility.SaveFilePanel("Export .obj file", "", meshName, "obj");
146145

147146
ZOObjExporter.Start();
148147

@@ -187,6 +186,15 @@ public static void DoExport(bool makeSubmeshes, string fileDirectory, bool zeroP
187186
string materialString = ZOObjExporter.MaterialToString(material);
188187
mtlFileString.Append(materialString);
189188
materialNames.Add(material.name);
189+
190+
// handle texture
191+
if (material.HasProperty("_MainTex")) {
192+
string assetPath = AssetDatabase.GetAssetPath(material.GetTexture("_MainTex"));
193+
if (string.IsNullOrEmpty(assetPath) == false) {
194+
string texName = Path.GetFileName(assetPath);
195+
File.Copy(assetPath, Path.Combine(fileDirectory, texName));
196+
}
197+
}
190198
}
191199
}
192200
}
@@ -205,6 +213,14 @@ public static void DoExport(bool makeSubmeshes, string fileDirectory, bool zeroP
205213
string materialString = ZOObjExporter.MaterialToString(material);
206214
mtlFileString.Append(materialString);
207215
materialNames.Add(material.name);
216+
// handle texture
217+
if (material.HasProperty("_MainTex")) {
218+
string assetPath = AssetDatabase.GetAssetPath(material.GetTexture("_MainTex"));
219+
if (string.IsNullOrEmpty(assetPath) == false) {
220+
string texName = Path.GetFileName(assetPath);
221+
File.Copy(assetPath, Path.Combine(fileDirectory, texName));
222+
}
223+
}
208224
}
209225
}
210226
}

Samples~/ZeroSimSamples/Scenes/URDF_test.unity

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3532,6 +3532,16 @@ PrefabInstance:
35323532
propertyPath: m_Name
35333533
value: teapot
35343534
objectReference: {fileID: 0}
3535+
- target: {fileID: -890894850248633325, guid: 17be92f99b8fb14eaa65adc226ac3fd4,
3536+
type: 3}
3537+
propertyPath: m_Materials.Array.data[0]
3538+
value:
3539+
objectReference: {fileID: 2100000, guid: ee87d3c7aff907920a745c6fd0164cf6, type: 2}
3540+
- target: {fileID: 7069507564420078126, guid: 17be92f99b8fb14eaa65adc226ac3fd4,
3541+
type: 3}
3542+
propertyPath: m_Materials.Array.data[0]
3543+
value:
3544+
objectReference: {fileID: 2100000, guid: e115d419d8845cbbfb2488170128cdbd, type: 2}
35353545
m_RemovedComponents: []
35363546
m_SourcePrefab: {fileID: 100100000, guid: 17be92f99b8fb14eaa65adc226ac3fd4, type: 3}
35373547
--- !u!4 &1753407360 stripped

0 commit comments

Comments
 (0)