static private void RecursiveExportGameObject(Utils.ColladaExporter exporter, GameObject go, Matrix4x4 root, XmlNode node, ref int n) { Debug.Log("Exporting " + go.name + "..."); Matrix4x4 local = Matrix4x4.TRS( new Vector3(-go.transform.localPosition.x, go.transform.localPosition.y, go.transform.localPosition.z), new Quaternion(go.transform.localRotation.x, -go.transform.localRotation.y, go.transform.localRotation.z, go.transform.localRotation.w), go.transform.localScale ); local *= root; MeshFilter filter = go.GetComponent <MeshFilter>(); XmlNode parent = node; if (filter != null) { n++; exporter.AddGeometry("geometry_" + n, filter.sharedMesh); parent = exporter.AddGeometryToScene("geometry_" + n, go.name, local, node); } else { n++; parent = exporter.AddEmptyToScene("empty_" + n, go.name, local, node); } foreach (Transform child in go.transform) { RecursiveExportGameObject(exporter, child.gameObject, root, parent, ref n); } //Debug.Log("Exported " + go.name); }
static public void ExportGameObject(string path, GameObject[] gos) { Utils.ColladaExporter exporter; try { exporter = new Utils.ColladaExporter(path); } catch (Exception ex) { Debug.LogError(ex.Message); return; } Matrix4x4 root = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, 1, 1)); int n = 0; for (int a = 0, b = gos.Length; a < b; ++a) { RecursiveExportGameObject(exporter, gos[a], root, null, ref n); } exporter.Save(); }