Beispiel #1
0
        private static Material ExportThenImport(Material src)
        {
            //
            // export
            //
            GameObject cube     = GameObject.CreatePrimitive(PrimitiveType.Cube);
            var        renderer = cube.GetComponent <Renderer>();

            renderer.sharedMaterial = src;
            var gltf     = new glTF();
            var exporter = new VCIExporter(gltf);

            exporter.Prepare(cube);
            exporter.Export();
            var bytes = gltf.ToGlbBytes();

            //
            // importer
            //
            var importer = new VCIImporter();

            importer.ParseGlb(bytes);
            importer.Load();
            var dst = importer.GetMaterial(0);

            return(dst);
        }
        private static Material ExportThenImport(Material src)
        {
            //
            // export
            //
            var gltf     = new glTF();
            var exporter = new VCIExporter(gltf);

            exporter.Materials = new System.Collections.Generic.List <Material> {
                src
            };
            exporter.Export();
            var bytes = gltf.ToGlbBytes();

            //
            // importer
            //
            var importer = new VCIImporter();

            importer.ParseGlb(bytes);
            importer.Load();
            var dst = importer.GetMaterial(0);

            return(dst);
        }
Beispiel #3
0
        public static void ExportObject()
        {
#if UNITY_STANDALONE_WIN && UNITY_EDITOR
            EditorApplication.isPlaying = false;

            if (!Validate())
            {
                return;
            }

            try
            {
                // save dialog
                var root = Selection.activeObject as GameObject;

                var path = VCI.FileDialogForWindows.SaveDialog("Save " + VCIVersion.EXTENSION,
                                                               root.name + VCIVersion.EXTENSION);

                //var path = EditorUtility.SaveFilePanel(
                //    "Save " + VCIVersion.EXTENSION,
                //    null,
                //    root.name + VCIVersion.EXTENSION,
                //    VCIVersion.EXTENSION.Substring(1));
                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                // export
                var gltf = new glTF();
                using (var exporter = new VCIExporter(gltf))
                {
                    exporter.Prepare(root);
                    exporter.Export();
                }

                var bytes = gltf.ToGlbBytes();
                File.WriteAllBytes(path, bytes);

                if (path.StartsWithUnityAssetPath())
                {
                    AssetDatabase.ImportAsset(path.ToUnityRelativePath());
                    AssetDatabase.Refresh();
                }

                // Show the file in the explorer.
                if (VCIConfig.IsOpenDirectoryAfterExport && Application.platform == RuntimePlatform.WindowsEditor)
                {
                    System.Diagnostics.Process.Start("explorer.exe", " /e,/select," + path.Replace("/", "\\"));
                }
            }
            finally
            {
                GUIUtility.ExitGUI();
            }
#else
            Debug.LogError("this function works only on Windows");
#endif
        }
Beispiel #4
0
        /// <summary>
        /// Export GLB.
        /// </summary>
        public static void ExportGlb()
        {
            EditorApplication.isPlaying = false;

            try
            {
                string errorMessage;

                if (!Validate(out errorMessage))
                {
                    Debug.LogAssertion(errorMessage);

                    EditorUtility.DisplayDialog("Error", errorMessage, "OK");

                    return;
                }

                GameObject root = Selection.activeObject as GameObject;

                string path = EditorUtility.SaveFilePanel(title: "Save File Dialog", directory: "", defaultName: root.name + ".glb", extension: "glb");

                if (string.IsNullOrEmpty(path))
                {
                    return;
                }

                var gltf = new glTF();

                using (var exporter = new gltfExporter(gltf))
                {
                    exporter.Prepare(root);
                    exporter.Export();
                }

                byte[] bytes = gltf.ToGlbBytes();

                File.WriteAllBytes(path, bytes);

                Debug.LogFormat("Export VGO file.\nGameObject: {0}, output: {1}", root.name, path);

                if (path.StartsWithUnityAssetPath())
                {
                    AssetDatabase.ImportAsset(path.ToUnityRelativePath());
                    AssetDatabase.Refresh();
                }
            }
            catch
            {
                throw;
            }
        }
Beispiel #5
0
        public static void ExportObject()
        {
            var errorMessage = "";

            if (!Validate(out errorMessage))
            {
                Debug.LogAssertion(errorMessage);
                EditorUtility.DisplayDialog("Error", errorMessage, "OK");
                return;
            }

            // save dialog
            var root = Selection.activeObject as GameObject;
            var path = EditorUtility.SaveFilePanel(
                "Save " + VCIVersion.EXTENSION,
                null,
                root.name + VCIVersion.EXTENSION,
                VCIVersion.EXTENSION.Substring(1));

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            // export
            var gltf = new glTF();

            using (var exporter = new VCIExporter(gltf))
            {
                exporter.Prepare(root);
                exporter.Export();
            }

            var bytes = gltf.ToGlbBytes();

            File.WriteAllBytes(path, bytes);

            if (path.StartsWithUnityAssetPath())
            {
                AssetDatabase.ImportAsset(path.ToUnityRelativePath());
                AssetDatabase.Refresh();
            }

            // Show the file in the explorer.
            if (Application.platform == RuntimePlatform.WindowsEditor)
            {
                System.Diagnostics.Process.Start("explorer.exe", " /e,/select," + path.Replace("/", "\\"));
            }
        }
Beispiel #6
0
    public void Export()
    {
        var title     = Title.text;
        var version   = Version.text;
        var author    = Author.text;
        var contact   = Contact.text;
        var reference = Reference.text;
        var license   = License.value;

        if (title == "" || author == "")
        {
            ExportVCI_Text.text = "必須の項目を入力してください";
            return;
        }
        else
        {
            ExportVCI_Text.text = "Export VCI";
        }

        // VCI基本設定
        VRM.name = title;
        var vci = VRM.AddComponent <VCIObject>();

        vci.Meta.title                = title;
        vci.Meta.version              = version;
        vci.Meta.author               = author;
        vci.Meta.contactInformation   = contact;
        vci.Meta.reference            = reference;
        vci.Meta.modelDataLicenseType = (glTF_VCAST_vci_meta.LicenseType)license;

        // luaスクリプト
        var script = new VCIObject.Script
        {
            mimeType     = ScriptMimeType.X_APPLICATION_LUA,
            targetEngine = TargetEngine.MoonSharp,
            source       = lua
        };

        vci.Scripts.Add(script);

        // 不要部位の削除
        DestroyImmediate(VRM.transform.Find("Face").gameObject);
        DestroyImmediate(VRM.transform.Find("Hairs").gameObject);
        DestroyImmediate(VRM.transform.Find("secondary").gameObject);

        // 不要メッシュの透過
        var renderer  = VRM.transform.Find("Body").gameObject.GetComponent <Renderer>();
        var materials = renderer.materials;

        for (int i = 0; i < renderer.materials.Length; i++)
        {
            if (!materials[i].name.Contains("CLOTH"))
            {
                materials[i] = Mat;
            }
        }
        renderer.materials = materials;

        // バージョン差吸収
        string hips = "Root/J_Bip_C_Hips/";

        if (VRM.transform.Find(hips) == null)
        {
            hips = "Root/Global/Position/J_Bip_C_Hips/";
        }

        // 足
        SetAtt(hips + "J_Bip_L_UpperLeg/J_Bip_L_LowerLeg/J_Bip_L_Foot", HumanBodyBones.LeftFoot);
        SetAtt(hips + "J_Bip_R_UpperLeg/J_Bip_R_LowerLeg/J_Bip_R_Foot", HumanBodyBones.RightFoot);
        SetAtt(hips + "J_Bip_L_UpperLeg/J_Bip_L_LowerLeg", HumanBodyBones.LeftLowerLeg);
        SetAtt(hips + "J_Bip_R_UpperLeg/J_Bip_R_LowerLeg", HumanBodyBones.RightLowerLeg);
        SetAtt(hips + "J_Bip_L_UpperLeg", HumanBodyBones.LeftUpperLeg);
        SetAtt(hips + "J_Bip_R_UpperLeg", HumanBodyBones.RightUpperLeg);

        // 腕
        string arm = hips + "J_Bip_C_Spine/J_Bip_C_Chest/J_Bip_C_UpperChest/";

        SetAtt(arm + "J_Bip_L_Shoulder/J_Bip_L_UpperArm/J_Bip_L_LowerArm/J_Bip_L_Hand", HumanBodyBones.LeftHand);
        SetAtt(arm + "J_Bip_R_Shoulder/J_Bip_R_UpperArm/J_Bip_R_LowerArm/J_Bip_R_Hand", HumanBodyBones.RightHand);
        SetAtt(arm + "J_Bip_L_Shoulder/J_Bip_L_UpperArm/J_Bip_L_LowerArm", HumanBodyBones.LeftLowerArm);
        SetAtt(arm + "J_Bip_R_Shoulder/J_Bip_R_UpperArm/J_Bip_R_LowerArm", HumanBodyBones.RightLowerArm);
        SetAtt(arm + "J_Bip_L_Shoulder/J_Bip_L_UpperArm", HumanBodyBones.LeftUpperArm);
        SetAtt(arm + "J_Bip_R_Shoulder/J_Bip_R_UpperArm", HumanBodyBones.RightUpperArm);

        // 体幹
        SetAtt(hips + "J_Bip_C_Spine/J_Bip_C_Chest", HumanBodyBones.Chest);
        SetAtt(hips + "J_Bip_C_Spine", HumanBodyBones.Spine);
        SetAtt(hips, HumanBodyBones.Hips);

        var gltf     = new glTF();
        var exporter = new VCIExporter(gltf);

        exporter.Prepare(VRM);
        exporter.Export();
        var bytes = gltf.ToGlbBytes();
        var path  = Application.dataPath + "/../" + title + ".vci";

        File.WriteAllBytes(path, bytes);

        Destroy(exporter.Copy);
        Destroy(VRM);
    }