void ExportMesh(Scene scene, GameObject go, ExportPlan exportPlan) { MeshFilter mf = go.GetComponent <MeshFilter>(); Mesh mesh = mf.mesh; bool unvarying = scene.Time == null; if (unvarying) { // Only export the mesh topology on the first frame. var sample = (MeshSample)exportPlan.sample; sample.transform = GetLocalTransformMatrix(go.transform); // Unity uses a forward vector that matches DirectX, but USD matches OpenGL, so a change of // basis is required. There are shortcuts, but this is fully general. sample.ConvertTransform(); sample.normals = mesh.normals; sample.points = mesh.vertices; sample.tangents = mesh.tangents; sample.extent = mesh.bounds; sample.colors = mesh.colors; if (sample.colors != null && sample.colors.Length != sample.points.Length) { sample.colors = null; } // Set face vertex counts and indices. sample.SetTriangles(mesh.triangles); scene.Write(exportPlan.path, sample); var mr = go.GetComponent <MeshRenderer>(); string usdMaterialPath; if (!m_materialMap.TryGetValue(mr.material, out usdMaterialPath)) { Debug.LogError("Invalid material bound for: " + exportPlan.path); } else { MaterialSample.Bind(scene, exportPlan.path, usdMaterialPath); } } else { var sample = new XformSample(); sample.transform = GetLocalTransformMatrix(go.transform); // Unity uses a forward vector that matches DirectX, but USD matches OpenGL, so a change of // basis is required. There are shortcuts, but this is fully general. sample.ConvertTransform(); scene.Write(exportPlan.path, sample); } // On all other frames, we just export the mesh transform data. // TODO(jcowles): cant currently do this because the USD prim typeName is overwritten. //ExportXform(scene, go, exportPlan, unvarying: false); }
void ExportXform(Scene scene, GameObject go, ExportPlan exportPlan) { XformSample sample = (XformSample)exportPlan.sample; sample.transform = GetLocalTransformMatrix(go.transform); // Unity uses a forward vector that matches DirectX, but USD matches OpenGL, so a change of // basis is required. There are shortcuts, but this is fully general. sample.ConvertTransform(); scene.Write(exportPlan.path, sample); }