Exemplo n.º 1
0
        protected override void ExportPath(string path)
        {
            m_logLabel = "";

            m_logLabel += $"export...\n";

            var root = State.ExportRoot;

            try
            {
                var converter = new UniVRM10.RuntimeVrmConverter();
                var model     = converter.ToModelFrom10(root);

                if (HumanoidValidator.HasRotationOrScale(root))
                {
                    // 正規化
                    m_logLabel += $"normalize...\n";
                    var modifier = new ModelModifier(model);
                    modifier.SkinningBake();
                }

                // 右手系に変換
                m_logLabel += $"convert to right handed coordinate...\n";
                model.ConvertCoordinate(VrmLib.Coordinates.Vrm1, ignoreVrm: false);

                // export vrm-1.0
                var exporter = new UniVRM10.Vrm10Exporter(AssetTextureUtil.IsTextureEditorAsset);
                var option   = new VrmLib.ExportArgs();
                exporter.Export(root, model, converter, option, AssetTextureUtil.GetTextureBytesWithMime, Meta ? Meta : m_tmpMeta);

                var exportedBytes = exporter.Storage.ToBytes();

                m_logLabel += $"write to {path}...\n";
                File.WriteAllBytes(path, exportedBytes);
                Debug.Log("exportedBytes: " + exportedBytes.Length);

                var assetPath = UniGLTF.UnityPath.FromFullpath(path);
                if (assetPath.IsUnderAssetsFolder)
                {
                    // asset folder 内。import を発動
                    assetPath.ImportAsset();
                }
            }
            catch (Exception ex)
            {
                m_logLabel += ex.ToString();
                // rethrow
                throw;
            }
        }
Exemplo n.º 2
0
        static byte[] GetGlb(VrmLib.Model model)
        {
            // export vrm-1.0
            var exporter = new UniVRM10.Vrm10Exporter();
            var option   = new VrmLib.ExportArgs
            {
                // vrm = false
            };
            var glbBytes10 = exporter.Export(model, option);
            // ?
            var glb10 = VrmLib.Glb.Parse(glbBytes10);

            return(glb10.ToBytes());
        }
Exemplo n.º 3
0
        protected override void ExportPath(string path)
        {
            m_logLabel = "";

            m_logLabel += $"export...\n";

            var root = State.ExportRoot;

            try
            {
                using (var arrayManager = new NativeArrayManager())
                {
                    var converter = new UniVRM10.ModelExporter();
                    var model     = converter.Export(arrayManager, root);

                    // 右手系に変換
                    m_logLabel += $"convert to right handed coordinate...\n";
                    model.ConvertCoordinate(VrmLib.Coordinates.Vrm1, ignoreVrm: false);

                    // export vrm-1.0
                    var exporter = new UniVRM10.Vrm10Exporter(new EditorTextureSerializer(), new GltfExportSettings());
                    var option   = new VrmLib.ExportArgs();
                    exporter.Export(root, model, converter, option, Vrm ? Vrm.Meta : m_tmpObject.Meta);

                    var exportedBytes = exporter.Storage.ToGlbBytes();

                    m_logLabel += $"write to {path}...\n";
                    File.WriteAllBytes(path, exportedBytes);
                    Debug.Log("exportedBytes: " + exportedBytes.Length);

                    var assetPath = UniGLTF.UnityPath.FromFullpath(path);
                    if (assetPath.IsUnderAssetsFolder)
                    {
                        // asset folder 内。import を発動
                        assetPath.ImportAsset();
                    }
                }
            }
            catch (Exception ex)
            {
                m_logLabel += ex.ToString();
                // rethrow
                throw;
            }
        }
        void OnExportClicked(GameObject root)
        {
            m_logLabel = "";

            string directory;

            if (string.IsNullOrEmpty(m_lastExportDir))
            {
                directory = Directory.GetParent(Application.dataPath).ToString();
            }
            else
            {
                directory = m_lastExportDir;
            }

            // save dialog
            var path = EditorUtility.SaveFilePanel(
                "Save vrm",
                directory,
                root.name + EXTENSION,
                EXTENSION.Substring(1));

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            m_lastExportDir = Path.GetDirectoryName(path).Replace("\\", "/");

            m_logLabel += $"export...\n";

            try
            {
                var converter = new UniVRM10.RuntimeVrmConverter();
                var model     = converter.ToModelFrom10(root);

                // if (MeshUtility.Validators.HumanoidValidator.HasRotationOrScale(root))
                // {
                //     // 正規化
                //     m_logLabel += $"normalize...\n";
                //     var modifier = new ModelModifier(model);
                //     modifier.SkinningBake();
                // }

                // 右手系に変換
                m_logLabel += $"convert to right handed coordinate...\n";
                model.ConvertCoordinate(VrmLib.Coordinates.Vrm1, ignoreVrm: false);

                // export vrm-1.0
                var exporter = new UniVRM10.Vrm10Exporter(AssetTextureUtil.IsTextureEditorAsset);
                var option   = new VrmLib.ExportArgs();
                exporter.Export(root, model, converter, option, Meta ? Meta : m_tmpMeta);

                var exportedBytes = exporter.Storage.ToBytes();

                m_logLabel += $"write to {path}...\n";
                File.WriteAllBytes(path, exportedBytes);
                Debug.Log("exportedBytes: " + exportedBytes.Length);

                var assetPath = ToAssetPath(path);
                if (!string.IsNullOrEmpty(assetPath))
                {
                    AssetDatabase.ImportAsset(assetPath);
                }
            }
            catch (Exception ex)
            {
                m_logLabel += ex.ToString();
                // rethrow
                throw;
            }
        }