public ModelGroupImportSettings(ModelGroupImportSettings importSettings) { colliders = importSettings.colliders; connectivity = importSettings.connectivity; isStatic = importSettings.isStatic; lightmapped = importSettings.lightmapped; randomizeRotation = importSettings.randomizeRotation; lod = importSettings.lod; }
public static void ReimportModelGroup(LXFMLDoc lxfml, ModelGroup group, ModelGroupImportSettings importSettings, bool detectConnectivity = false) { // Assign the new group import settings to the group. group.importSettings = importSettings; // We assume that the group can be found, so reimport it. if (group.processed) { // Remove all processed meshes. var renderers = group.GetComponentsInChildren <MeshRenderer>(); foreach (var renderer in renderers) { // FIXME Destroy the mesh? Prevents undo.. var filter = renderer.GetComponent <MeshFilter>(); //Undo.DestroyObjectImmediate(filter.sharedMesh); if (renderer.GetComponent <ModelGroup>() == null) { // Destroy submesh game objects entirely. Undo.DestroyObjectImmediate(renderer.gameObject); } else { // Destroy mesh related components on group game object. Object.DestroyImmediate(filter); Object.DestroyImmediate(renderer); } } } // FIXME Check if bricks are referenced. // FIXME Check if bricks have custom components attached. // Remove group bricks. var existingBricks = group.GetComponentsInChildren <Brick>(); foreach (var brick in existingBricks) { Undo.DestroyObjectImmediate(brick.gameObject); } var groupLightMapped = group.importSettings.isStatic && group.importSettings.lightmapped; SetStaticAndGIParams(group.gameObject, group.importSettings.isStatic, groupLightMapped); // Move group to origo to ensure that bricks are instantiated in the correct positions. var originalGroupLocalPosition = group.transform.localPosition; var originalGroupLocalRotation = group.transform.localRotation; var originalGroupLocalScale = group.transform.localScale; var originalGroupParent = group.transform.parent; var originalGroupSiblingIndex = group.transform.GetSiblingIndex(); group.transform.SetParent(null); group.transform.localPosition = Vector3.zero; group.transform.localRotation = Quaternion.identity; group.transform.localScale = Vector3.one; // Create dictionary with just this group. var modelGroupImportSettingsDictionary = new DictionaryIntToModelGroupImportSettings(); modelGroupImportSettingsDictionary.Add(group.number, group.importSettings); // Instantiate group bricks. var resultBricks = new Dictionary <int, Brick>(lxfml.bricks.Count); InstantiateModelBricks(lxfml, modelGroupImportSettingsDictionary, ref resultBricks, group.number); // Assign bricks to group. foreach (var brick in resultBricks.Values) { brick.transform.SetParent(group.transform); } ModelGroupUtility.RecomputePivot(group, false, ModelGroupUtility.UndoBehavior.withoutUndo); // Move group back to original location. group.transform.SetParent(originalGroupParent); group.transform.SetSiblingIndex(originalGroupSiblingIndex); group.transform.localPosition = originalGroupLocalPosition; group.transform.localRotation = originalGroupLocalRotation; group.transform.localScale = originalGroupLocalScale; /*if (group.processed) * { * // Process the group again. * // FIXME Is this even a good idea? * if (group.type == GroupType.Environment || group.type == GroupType.Static) * { * Vector2Int vertCount = Vector2Int.zero; * Vector2Int triCount = Vector2Int.zero; * Vector2Int meshCount = Vector2Int.zero; * Vector2Int colliderCount = Vector2Int.zero; * ModelProcessor.ProcessModelGroup(group, ref vertCount, ref triCount, ref meshCount, ref colliderCount); * * Debug.Log($"Process result (before/after):\nVerts {vertCount.x}/{vertCount.y}, tris {triCount.x}/{triCount.y}, meshes {meshCount.x}/{meshCount.y}, colliders {colliderCount.x}/{colliderCount.y}"); * } * }*/ if (detectConnectivity && group.importSettings.connectivity) { var sceneBricks = new HashSet <Brick>(StageUtility.GetCurrentStageHandle().FindComponentsOfType <Brick>()); DetectConnectivity(new HashSet <Brick>(resultBricks.Values), sceneBricks); } EditorUtility.ClearProgressBar(); }
//private static readonly string decorationMaterialsPath = "Assets/LEGOIntegrationHub/Internal/LXFML/Resources/Materials"; //public static Material decoCutoutMaterial = Resources.Load<Material>("LXFMLMaterials/transpcutoutMinifigure"); /// <summary> /// Translate the bricks in a given LXFML-group to interactable objects /// </summary> /// <param name="group">The LXFML-group</param> /// <param name="index">Index of the group</param> /// <param name="parent">The imported asset</param> /// <param name="absoluteFilePath">Path of the imported asset</param> /// <param name="relativeFilePath">Path of the imported asset</param> /// <param name="resultBricks">Dictionary containing the simple bricks</param> /// <param name="isSubGroup">Whether it is a subgroup or not</param> /// <param name="lightmapped">Whether it is lightmapped or not</param> /// <param name="missingGroups">List of groups containing missing elements</param> public static GameObject InstantiateModelGroup(LXFMLDoc.BrickGroup group, int index, GameObject parent, string absoluteFilePath, string relativeFilePath, ref Dictionary <int, Brick> resultBricks, bool isSubGroup, ModelGroupImportSettings importSettings) { ModelGroup groupComp; GameObject groupParent; if (isSubGroup) { groupParent = new GameObject("SubGroup " + index + " - " + group.name); } else { groupParent = new GameObject(group.name); } // FIXME Handle subgroups properly. //Recursively check subgroups if (group.children != null) { foreach (var subGroup in group.children) { foreach (var part in group.brickRefs) { //Apparently supergroups contain elements from subgroups. Duplicates are removed from supergroups. if (subGroup.brickRefs.Contains(part)) { group.brickRefs[Array.IndexOf(group.brickRefs, part)] = -1; } } InstantiateModelGroup(subGroup, Array.IndexOf(group.children, subGroup), groupParent, absoluteFilePath, relativeFilePath, ref resultBricks, true, importSettings); } } importSettings.lightmapped &= importSettings.isStatic; SetStaticAndGIParams(groupParent, importSettings.isStatic, importSettings.lightmapped); groupParent.transform.parent = parent.transform; groupParent.transform.SetSiblingIndex(index); if (!isSubGroup) { groupComp = groupParent.AddComponent <ModelGroup>(); groupComp.absoluteFilePath = absoluteFilePath; groupComp.relativeFilePath = relativeFilePath; groupComp.importSettings = importSettings; groupComp.groupName = group.name; groupComp.number = index; groupComp.parentName = parent.name; groupComp.optimizations = ModelGroup.Optimizations.Everything; // Add LEGOModelGroupAsset component. groupParent.AddComponent <LEGOModelGroupAsset>(); } var groupBricks = new HashSet <Brick>(); foreach (int id in group.brickRefs) { if (id == -1) { continue; } if (resultBricks.ContainsKey(id)) { groupBricks.Add(resultBricks[id]); resultBricks[id].transform.SetParent(groupParent.transform); } } return(groupParent); }
public static void ReimportModelGroup(LXFMLDoc lxfml, ModelGroup group, ModelGroupImportSettings importSettings, bool detectConnectivity = false) { // Assign the new group import settings to the group. group.importSettings = importSettings; // We assume that the group can be found, so reimport it. if (group.processed) { // Remove all processed meshes. var renderers = group.GetComponentsInChildren <MeshRenderer>(); foreach (var renderer in renderers) { // FIXME Destroy the mesh? Prevents undo.. var filter = renderer.GetComponent <MeshFilter>(); //Undo.DestroyObjectImmediate(filter.sharedMesh); if (renderer.GetComponent <ModelGroup>() == null) { // Destroy submesh game objects entirely. Undo.DestroyObjectImmediate(renderer.gameObject); } else { // Destroy mesh related components on group game object. Object.DestroyImmediate(filter); Object.DestroyImmediate(renderer); } } } // FIXME Check if bricks are referenced. // FIXME Check if bricks have custom components attached. // Remove group bricks. var existingBricks = group.GetComponentsInChildren <Brick>(); foreach (var brick in existingBricks) { Undo.DestroyObjectImmediate(brick.gameObject); } var groupLightMapped = group.importSettings.isStatic && group.importSettings.lightmapped; SetStaticAndGIParams(group.gameObject, group.importSettings.isStatic, groupLightMapped); // Move group to origo to ensure that bricks are instantiated in the correct positions. var originalGroupParent = group.transform.parent; var originalGroupSiblingIndex = group.transform.GetSiblingIndex(); group.transform.parent = null; group.transform.localPosition = Vector3.zero; group.transform.localRotation = Quaternion.identity; group.transform.localScale = Vector3.one; // Create dictionary with just this group. var modelGroupImportSettingsDictionary = new DictionaryIntToModelGroupImportSettings(); modelGroupImportSettingsDictionary.Add(group.number, group.importSettings); // Instantiate group bricks. var resultBricks = new Dictionary <int, Brick>(lxfml.bricks.Count); InstantiateModelBricks(lxfml, modelGroupImportSettingsDictionary, ref resultBricks, group.number); // Assign bricks to group. foreach (var brick in resultBricks.Values) { brick.transform.SetParent(group.transform); } // Set parent of group back to original. group.transform.parent = originalGroupParent; group.transform.SetSiblingIndex(originalGroupSiblingIndex); if (detectConnectivity && group.importSettings.connectivity) { var sceneBricks = new HashSet <Brick>(StageUtility.GetCurrentStageHandle().FindComponentsOfType <Brick>()); DetectConnectivity(new HashSet <Brick>(resultBricks.Values), sceneBricks); } EditorUtility.ClearProgressBar(); }