private static void FillChildrenRecursive(Transform rootObject, List <object> resChildren) { // rootObject.localToWorldMatrix is not in parent's world space var trs = Matrix4x4.TRS(rootObject.localPosition, rootObject.localRotation, rootObject.localScale); // TODO: slow, need optimization var matrixArray = UnityExporterHelper.MatrixToArray(trs); var filter = rootObject.GetComponent <MeshFilter>(); if (filter) { UnityEngine.Mesh sharedMesh = filter.sharedMesh; var meshObject = new Mesh( Guid.NewGuid().ToString("D"), sharedMesh.name, matrixArray, filter == null ? string.Empty : meshesDictionary[sharedMesh].Uuid ); resChildren.Add(meshObject); } var camera = rootObject.GetComponent <Camera>(); if (camera) { var cameraMatrixArray = GetCameraMatrixArray(matrixArray); var cameraObj = new PerspectiveCamera( Guid.NewGuid().ToString("D"), rootObject.name, cameraMatrixArray, camera.fieldOfView, camera.nearClipPlane, camera.farClipPlane); resChildren.Add(cameraObj); } var newRoot = new Object3D( Guid.NewGuid().ToString("D"), rootObject.name, matrixArray); resChildren.Add(newRoot); for (int i = 0; i < rootObject.childCount; i++) { var child = rootObject.GetChild(i); FillChildrenRecursive(child, newRoot.Children); } }
private static Dictionary <UnityEngine.Mesh, Geometry> PrepareGeometriesMap(UnityScene scene, bool includeInactive) { var meshFilters = UnityExporterHelper.GetComponentsInScene <MeshFilter>(scene, includeInactive); var distinctMeshes = meshFilters.Select(x => x.sharedMesh).Distinct(); var res = new Dictionary <UnityEngine.Mesh, Geometry>(); foreach (var mesh in distinctMeshes) { var geometry = StructuresConverter.ToBufferGeometry(mesh); res.Add(mesh, geometry); } return(res); }