public void push_back(DLODGroup dlod, int version) { if (dlods == null) { dlods = new List<DLODVersion>(); } DLODVersion dlod_version = new DLODVersion(); dlod_version.dlod = dlod; dlod_version.version = version; dlods.Add(dlod_version); }
private void _create_dlod_objects() { // Go through each scene object (mesh filter). for (int i = 0; i < _scene_objects.Count; ++i) { // Get parent game object to LOD0. Transform parent = _scene_objects[i].mesh_filter.transform.parent; if (parent) { DLODGroup group = parent.GetComponent <DLODGroup>(); if (group) { // Get the shared mesh hash code. string mesh_hash_code = _scene_objects[i].mesh_filter.sharedMesh.GetHashCode().ToString(); string mesh_path = "Assets/Meshes/Mesh" + mesh_hash_code + "/"; // Go through each LOD. for (int j = 1; j < lod_levels; ++j) { // Create new child game object. GameObject obj = new GameObject(parent.name + "_lod" + j.ToString()); obj.transform.parent = parent.transform; obj.transform.localPosition = Vector3.zero; obj.transform.localScale = Vector3.one; obj.transform.localRotation = Quaternion.identity; // Give child game object mesh filter and mesh renderer. MeshFilter newMeshFilter = obj.AddComponent <MeshFilter>(); MeshRenderer newMeshRenderer = obj.AddComponent <MeshRenderer>(); string mesh_asset_path = mesh_path + mesh_hash_code + "_" + j.ToString() + ".asset"; string material_asset_path = "Assets/Meshes/DefaultMaterial.mat"; Mesh lod_mesh = (Mesh)AssetDatabase.LoadAssetAtPath(mesh_asset_path, typeof(Mesh)); Material lod_material = (Material)AssetDatabase.LoadAssetAtPath(material_asset_path, typeof(Material)); // Was the mesh successfully loaded? if (lod_mesh) { // Set mesh filter mesh to corresponding saved mesh. newMeshFilter.mesh = lod_mesh; } else { Debug.Log("Coult not find mesh at: " + mesh_asset_path); } // Was the material successfully loaded? if (lod_material) { // Set mesh filter mesh to corresponding saved mesh. newMeshRenderer.material = lod_material; } else { Debug.Log("Coult not find material at: " + material_asset_path); } group.dlods.Add(obj); } } } } }