예제 #1
0
 void FixedUpdate()
 {
     if (!RoomName.Equals(Config.RoomObject.GameObjectName))
     {
         Config.RoomObject.GameObjectName = RoomName;
         // Make the directory for this room
         string directoryPath = Config.RoomObject.CompileAbsoluteAssetDirectory(Config.RoomObject.GameObjectName);
         AbnormalDirectoryHandler.CreateDirectory(directoryPath);
     }
 }
예제 #2
0
        public static void CreateRoomPrefab(GameObject obj)
        {
#if UNITY_EDITOR
            if (obj != null)
            {
                //AssetDatabase.CreateAsset(obj, "Assets/Room Texture/Resources/Test.obj");
                //AssetDatabase.SaveAssets();
                //AssetDatabase.Refresh();

                //string roomName = Config.RoomObject.GameObjectName;
                string roomName = obj.name ?? Config.RoomObject.GameObjectName;

                if (!Directory.Exists(Config.Prefab.CompileAbsoluteAssetDirectory(roomName)))
                {
                    //Directory.CreateDirectory(Config.Prefab.CompileAbsoluteAssetDirectory());
                    AbnormalDirectoryHandler.CreateDirectory(Config.Prefab.CompileAbsoluteAssetDirectory(roomName));
                    Debug.Log("Prefab folder created: " + Config.Prefab.CompileAbsoluteAssetDirectory(roomName));
                }
                //var emptyPrefab = PrefabUtility.CreateEmptyPrefab(CrossPlatformNames.Prefab.CompileCompatibleOutputFolder() + '/' + CrossPlatformNames.Prefab.Filename);
                //PrefabUtility.ReplacePrefab()
                //PrefabUtility.CreatePrefab(CrossPlatformNames.Prefab.CompileCompatibleOutputFolder() + '/' + CrossPlatformNames.Prefab.Filename, AssetDatabase.Find)

                //PrefabUtility.CreatePrefab(Config.Prefab.CompileUnityAssetDirectory(roomName) + '/' + Config.Prefab.CompileFilename(), obj); // CompileCompatibleOutputFolder
                PrefabUtility.CreatePrefab(Config.Prefab.CompileUnityAssetPath(Config.Prefab.CompileFilename(), roomName), obj);
                //PrefabUtility.CreatePrefab(CrossPlatformNames.Prefab.OutputFilepath, obj);

                Debug.Log("Room prefab generated at " + Config.Prefab.CompileUnityAssetDirectory(roomName));
                //Debug.Log("Room path = " + CrossPlatformNames.Prefab.OutputFilepath);
                //Debug.Log("Room path = " + Config.Prefab.CompileUnityAssetDirectory(roomName) + '/' + Config.Prefab.CompileFilename()); // CompileCompatibleOutputFolder
                Debug.Log("Room path = " + Config.Prefab.CompileUnityAssetPath(Config.Prefab.CompileFilename(), roomName));
            }
            else
            {
                //UnityEngine.Debug.Log(Messages.GameObjectDoesNotExist);

                //string originalRoomName = Config.RoomObject.GameObjectName;

                //Config.RoomObject.GameObjectName = obj.name;
                //BundleHandler.InstantiateRoom(Config.AssetBundle.RawPackage.CompileAbsoluteAssetPath(Config.AssetBundle.RawPackage.CompileFilename(), obj.name));
                BundleHandler.InstantiateRoom(Config.AssetBundle.RawPackage.CompileAbsoluteAssetPath(Config.AssetBundle.RawPackage.CompileFilename(), Config.RoomObject.GameObjectName));

                CreateRoomPrefab(GameObject.Find(Config.RoomObject.GameObjectName));

                BundleHandler.RemoveRoomObject(Config.RoomObject.GameObjectName);

                //Config.RoomObject.GameObjectName = originalRoomName;
            }

            UnityEditor.AssetDatabase.Refresh();
#endif
        }
예제 #3
0
 public static void SaveMesh(Mesh mesh)
 {
     if (mesh != null)
     {
         string roomName     = Config.RoomObject.GameObjectName;
         string meshString   = WriteMeshString(mesh);
         string meshFilePath = Config.CustomMesh.CompileAbsoluteAssetPath(Config.CustomMesh.CompileFilename(), roomName);
         //Directory.CreateDirectory(meshFilePath);
         AbnormalDirectoryHandler.CreateDirectoryFromFile(meshFilePath);
         File.WriteAllText(meshFilePath, meshString);
     }
     else
     {
         Debug.Log(Messages.InvalidMesh);
     }
 }
예제 #4
0
//        /// <summary>
//        /// Generates array of room materials to be assigned to room mesh objects.
//        /// Each material will be associated with a specific mesh, since each mesh
//        /// has its own localToWorld matrix.
//        /// </summary>
//        /// <param name="roomMaterials">
//        /// Material array to hold the generated room mesh materials.
//        /// </param>
//        /// <param name="texArray">
//        /// Texture2DArray to apply to each material.
//        /// </param>
//        /// <param name="worldToCameraMatrixArray">
//        /// Array of matrices describing translation of vertices to change
//        /// vertex world space coordinates to camera/view space.
//        /// </param>
//        /// <param name="projectionMatrixArray">
//        /// Array of matrices describing translation of camera/view space
//        /// vertex coordinates to clip space.
//        /// </param>
//        /// <param name="localToWorldMatrixArray">
//        /// Array of matrices describing translation of vertices from
//        /// local space to world space. Each array is specific to a
//        /// single generated mesh and cannot be applied to meshes in general.
//        /// </param>
//        public static void GenerateRoomMaterials(out Material[] roomMaterials, Texture2DArray texArray, Matrix4x4[] worldToCameraMatrixArray, Matrix4x4[] projectionMatrixArray, Matrix4x4[] localToWorldMatrixArray, bool saveAsAssets)
//        {
//            roomMaterials = new Material[localToWorldMatrixArray.Length];
//            for(int i = 0; i < roomMaterials.Length; i++)
//            {
//                string materialNameSuffix = "_" + i;
//                roomMaterials[i] = GenerateRoomMaterial(texArray, worldToCameraMatrixArray, projectionMatrixArray, localToWorldMatrixArray[i]);
//                roomMaterials[i].name = roomMaterials[i].name + materialNameSuffix;

//#if UNITY_EDITOR
//                // Save as assets if applicable
//                if (saveAsAssets)
//                {
//                    AssetDatabase.CreateAsset(roomMaterials[i], CrossPlatformNames.Material.CompileAssetPath(roomMaterials[i].name));
//                    AssetDatabase.SaveAssets();
//                }
//#endif
//            }

//#if UNITY_EDITOR
//            AssetDatabase.Refresh();
//#endif
//        }

        public static void GenerateRoomMaterials(Texture2DArray texArray, Matrix4x4[] worldToCameraMatrixArray, Matrix4x4[] projectionMatrixArray, Matrix4x4[] localToWorldMatrixArray)
        {
            string roomName             = Config.RoomObject.GameObjectName;
            string destinationDirectory = Config.Material.CompileAbsoluteAssetDirectory(roomName);

            //if (!Directory.Exists(Config.Material.CompileAbsoluteAssetDirectory(roomName)))
            if (!Directory.Exists(destinationDirectory))
            {
                //Directory.CreateDirectory(Config.Material.CompileAbsoluteAssetDirectory());
                //AbnormalDirectoryHandler.CreateDirectory(Config.Material.CompileAbsoluteAssetDirectory(roomName));
                AbnormalDirectoryHandler.CreateDirectory(destinationDirectory);
            }

            int numMaterials = localToWorldMatrixArray.Length;

            Debug.Log("Num of materials = " + numMaterials);
            for (int i = 0; i < numMaterials; i++)
            {
                Material roomMat = GenerateRoomMaterial(i, texArray, worldToCameraMatrixArray, projectionMatrixArray, localToWorldMatrixArray[i]);

                Debug.Log("Material created!");

#if UNITY_EDITOR
                //AssetDatabase.CreateAsset(roomMat, Config.Material.CompileUnityAssetPath(Config.Material.CompileFilename(i), roomName));
                string baseDirectory = Config_Base.AbsoluteAssetRootFolder;

                Debug.Log("Asset root folder = " + baseDirectory);

                string destinationDirectory_Unity = destinationDirectory.Remove(0, baseDirectory.Length - 6);
                //AssetDatabase.CreateAsset(roomMat, Path.Combine(destinationDirectory_Unity, Config.Material.CompileFilename(i)));
                AssetDatabase.CreateAsset(roomMat, Path.Combine(destinationDirectory_Unity, Config.Material.CompileFilename(i)));
                AssetDatabase.SaveAssets();
                Debug.Log("Material generated in project folder!");
#endif
            }

#if UNITY_EDITOR
            AssetDatabase.Refresh();
#endif
        }
예제 #5
0
        public static GameObject BuildRoomObject(string[] orientationFileLines)
        {
            string roomName = Config.RoomObject.GameObjectName;

            Debug.Log("Building room");
            Debug.Log("Room name = " + roomName);
            //Debug.Log("Unity meshes relative directory = " + unityMeshesRelativeDirectory);
            //Debug.Log("Materials relative directory = " + materialsRelativeDirectory);
            Debug.Log("Previous directory = " + Config.UnityMeshes.AssetSubFolder);

            if (!Directory.Exists(Config.CustomMesh.CompileAbsoluteAssetDirectory(roomName)))
            {
                //Directory.CreateDirectory(Config.CustomMesh.CompileAbsoluteAssetDirectory());
                AbnormalDirectoryHandler.CreateDirectory(Config.CustomMesh.CompileAbsoluteAssetDirectory(roomName));
            }

            Vector3[]    positionArray;
            Quaternion[] rotationArray;

            // Load up the information stored from mesh supplementary information
            // to correct for Hololens mesh translation and orientation.
            CustomOrientation.Load(orientationFileLines, out positionArray, out rotationArray);

            GameObject roomObject = new GameObject();

            //roomObject.name = Config.RoomObject.GameObjectName;
            roomObject.name = roomName;
            for (int i = 0; i < positionArray.Length; i++)
            {
                GameObject child = new GameObject();

                Debug.Log("Mesh resource load path = " + Config.UnityMeshes.CompileResourcesLoadPath(Config.UnityMeshes.CompileMeshName(i), roomName));
                //Debug.Log("mesh resource load path = " + Config.UnityMeshes.CompileResourcesLoadPath(unityMeshesRelativeDirectory, Config.UnityMeshes.CompileMeshName(i)));

                // Set mesh
                Mesh childMesh = Resources.Load(Config.UnityMeshes.CompileResourcesLoadPath(Config.UnityMeshes.CompileMeshName(i), roomName)) as Mesh;
                //Mesh childMesh = Resources.Load(Config.UnityMeshes.CompileResourcesLoadPath(unityMeshesRelativeDirectory, Config.UnityMeshes.CompileMeshName(i))) as Mesh;
                MeshFilter mf = child.AddComponent <MeshFilter>();
                mf.sharedMesh = childMesh;

                // Set material
                MeshRenderer mr = child.AddComponent <MeshRenderer>();
                mr.sharedMaterial = Resources.Load <Material>(Config.Material.CompileResourcesLoadPath(Config.Material.CompileMaterialName(i), roomName));
                //mr.sharedMaterial = Resources.Load<Material>(Config.Material.CompileResourcesLoadPath(materialsRelativeDirectory, Config.Material.CompileMaterialName(i)));

                //Debug.Log("Meshes relative directory = " + unityMeshesRelativeDirectory);
                //Debug.Log("Meshes path = " + Config.UnityMeshes.CompileResourcesLoadPath(unityMeshesRelativeDirectory, Config.UnityMeshes.CompileMeshName(i)));
                //Debug.Log("Materials relative directory = " + materialsRelativeDirectory);
                //Debug.Log("Materials path = " + Config.Material.CompileResourcesLoadPath(materialsRelativeDirectory, Config.Material.CompileMaterialName(i)));

                // Set position and rotation
                child.transform.position = positionArray[i];
                child.transform.rotation = rotationArray[i];

                // Set name
                child.name             = childMesh.name;
                child.transform.parent = roomObject.transform;

                // Add mesh collider
                MeshCollider mc = child.AddComponent <MeshCollider>();
                mc.sharedMesh = childMesh;
            }
            roomObject.AddComponent <RoomModel>();

            //// Integrate it into the UWB Network
            //roomObject.AddComponent<UWBPhotonTransformView>();

            return(roomObject);
        }