Пример #1
0
        void GenerateColorMapAsset()
        {
            ColorBasedModelDefinition baseModel = QubicleBinaryToColorBasedModelDefinition();

            if (baseModel.colors == null)
            {
                return;
            }
            ColorToVoxelMap colorMap = VoxelPlayConverter.GetColorToVoxelMapDefinition(baseModel);

            if (!string.IsNullOrEmpty(baseModel.name))
            {
                colorMap.name = baseModel.name;
            }

            colorMap.name += " ColorMap";

            // Create a suitable file path
            string path = GetPathForNewAsset();

            AssetDatabase.CreateAsset(colorMap, path + "/" + GetFilenameForNewModel(colorMap.name) + ".asset");
            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = colorMap;
            EditorGUIUtility.PingObject(colorMap);
        }
Пример #2
0
        void GeneratePrefab()
        {
            ColorBasedModelDefinition baseModel = QubicleBinaryToColorBasedModelDefinition();

            if (baseModel.colors == null)
            {
                return;
            }

            // Generate a cuboid per visible voxel
            int   sizeX = baseModel.sizeX;
            int   sizeY = baseModel.sizeY;
            int   sizeZ = baseModel.sizeZ;
            float offsetX = 0, offsetY = 0, offsetZ = 0;

            if (!importIgnoreOffset)
            {
                offsetX += baseModel.offsetX;
                offsetY += baseModel.offsetY;
                offsetZ += baseModel.offsetZ;
            }
            Color32[] colors = baseModel.colors;

            GameObject obj = VoxelPlayConverter.GenerateVoxelObject(colors, sizeX, sizeY, sizeZ, new Vector3(offsetX, offsetY, offsetZ), scale);

            string path = GetPathForNewAsset();

            path += "/" + GetFilenameForNewModel(baseModel.name) + ".prefab";
#if UNITY_2018_3_OR_NEWER
            GameObject prefab = PrefabUtility.SaveAsPrefabAsset(obj, path);
#else
            GameObject prefab = PrefabUtility.CreatePrefab(path, obj);
#endif
            // Store the mesh inside the prefab
            Mesh mesh = obj.GetComponent <MeshFilter>().sharedMesh;
            AssetDatabase.AddObjectToAsset(mesh, prefab);
            prefab.GetComponent <MeshFilter> ().sharedMesh = mesh;
            Material mat = obj.GetComponent <MeshRenderer> ().sharedMaterial;
            AssetDatabase.AddObjectToAsset(mat, prefab);
            prefab.GetComponent <MeshRenderer> ().sharedMaterial = mat;
            MeshCollider mc = prefab.AddComponent <MeshCollider> ();
            mc.sharedMesh = mesh;
            mc.convex     = true;
            Rigidbody rb = prefab.AddComponent <Rigidbody> ();
            rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            AssetDatabase.SaveAssets();
            DestroyImmediate(obj);

            EditorUtility.FocusProjectWindow();
            Selection.activeObject = prefab;
            EditorGUIUtility.PingObject(prefab);
        }
Пример #3
0
        GameObject GeneratePrefab()
        {
            ColorBasedModelDefinition baseModel = TextureToColorBasedModelDefinition(texture);

            if (baseModel.colors == null)
            {
                return(null);
            }

            // Generate a cuboid per visible voxel
            int sizeX = baseModel.sizeX;
            int sizeY = baseModel.sizeY;
            int sizeZ = baseModel.sizeZ;

            Color32[] colors = baseModel.colors;

            Vector3    scale  = new Vector3(size.x / texture.width, size.y / texture.height, size.z);
            Vector3    offset = new Vector3(0, -0.5f, 0);
            GameObject obj    = VoxelPlayConverter.GenerateVoxelObject(colors, sizeX, sizeY, sizeZ, offset, scale);

            string path = GetPathForNewAsset();

            path += "/" + GetFilenameForNewModel(baseModel.name) + ".prefab";
#if UNITY_2018_3_OR_NEWER
            GameObject prefab = PrefabUtility.SaveAsPrefabAsset(obj, path);
#else
            GameObject prefab = PrefabUtility.CreatePrefab(path, obj);
#endif
            // Store the mesh inside the prefab
            Mesh mesh = obj.GetComponent <MeshFilter> ().sharedMesh;
            AssetDatabase.AddObjectToAsset(mesh, prefab);
            prefab.GetComponent <MeshFilter> ().sharedMesh = mesh;
            Material mat = obj.GetComponent <MeshRenderer> ().sharedMaterial;
            AssetDatabase.AddObjectToAsset(mat, prefab);
            prefab.GetComponent <MeshRenderer> ().sharedMaterial = mat;
            MeshCollider mc = prefab.AddComponent <MeshCollider> ();
            mc.sharedMesh = mesh;
            mc.convex     = true;
            Rigidbody rb = prefab.AddComponent <Rigidbody> ();
            rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
            AssetDatabase.SaveAssets();
            DestroyImmediate(obj);

            EditorUtility.FocusProjectWindow();
            Selection.activeObject = prefab;
            EditorGUIUtility.PingObject(prefab);

            return(prefab);
        }
Пример #4
0
        void GenerateModelAsset()
        {
            ColorBasedModelDefinition baseModel = QubicleBinaryToColorBasedModelDefinition();

            if (baseModel.colors == null)
            {
                return;
            }
            ModelDefinition newModel = VoxelPlayConverter.GetModelDefinition(null, baseModel, importIgnoreOffset, mapping);

            if (!string.IsNullOrEmpty(baseModel.name))
            {
                newModel.name = baseModel.name;
            }

            // Create a suitable file path
            string path = GetPathForNewAsset();

            AssetDatabase.CreateAsset(newModel, path + "/" + GetFilenameForNewModel(newModel.name) + ".asset");
            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = newModel;
            EditorGUIUtility.PingObject(newModel);
        }