示例#1
0
    // Start is called before the first frame update
    void OnEnable()
    {
        var src   = new FileInfo(m_vrmPath);
        var vrm0x = Import(File.ReadAllBytes(m_vrmPath), src);

        // Export 1.0
        var exporter = new UniVRM10.RuntimeVrmConverter();
        var model    = exporter.ToModelFrom10(vrm0x);

        // 右手系に変換
        model.ConvertCoordinate(VrmLib.Coordinates.Vrm1);
        var exportedBytes = model.ToGlb();

        // Import 1.0
        var vrm10 = Import(exportedBytes, src);
        var pos   = vrm10.transform.position;

        pos.x += 1.5f;
        vrm10.transform.position = pos;
        vrm10.name = vrm10.name + "_Imported_v1_0";

        // write
        var path = Path.GetFullPath("vrm10.vrm");

        Debug.Log($"write : {path}");
        File.WriteAllBytes(path, exportedBytes);
    }
示例#2
0
        private Model ToVrmModel(GameObject root)
        {
            var exporter = new UniVRM10.RuntimeVrmConverter();
            var model    = exporter.ToModelFrom10(root, root.GetComponent <VRM10Controller>().Meta);

            model.ConvertCoordinate(VrmLib.Coordinates.Gltf, ignoreVrm: false);
            return(model);
        }
        private Model ToVrmModel(GameObject root)
        {
            var exporter = new UniVRM10.RuntimeVrmConverter();
            var model    = exporter.ToModelFrom10(root);

            model.ConvertCoordinate(VrmLib.Coordinates.Vrm1, ignoreVrm: false);
            return(model);
        }
示例#4
0
        void Export()
        {
            var path = ComDialog.Save("write file", "export.vrm");

            if (string.IsNullOrEmpty(path))
            {
                Debug.Log($"cancel save");
                return;
            }

            Debug.Log($"save to {path}");
            var exporter = new UniVRM10.RuntimeVrmConverter();
            var meta     = ScriptableObject.CreateInstance <UniVRM10.VRMMetaObject>();

            meta.Name       = "";
            meta.Copyrights = "";
            meta.Version    = "";
            meta.Authors    = new[] {
                "PriMan"
            };
            meta.ContactInformation = "";
            meta.Reference          = "";
            meta.OtherPermissionUrl = "";
            meta.OtherLicenseUrl    = "";

            var model = exporter.ToModelFrom10(m_builder.Root.gameObject, meta);

            foreach (var kv in exporter.Nodes)
            {
                kv.Value.HumanoidBone = m_builder.GetHumanBone(kv.Key.transform);
            }

            // normalize
            var modifier = new ModelModifier(model);

            modifier.SkinningBake();

            VrmLib.ModelExtensionsForCoordinates.ConvertCoordinate(model, VrmLib.Coordinates.Gltf);
            var bytes = Vrm10.ModelExtensions.ToGlb(model);

            File.WriteAllBytes(path, bytes);
        }
示例#5
0
 public void Export(GameObject root, Model model, RuntimeVrmConverter converter, ExportArgs option, Func <Texture2D, (byte[], string)> getTextureBytes, VRM10MetaObject metaObject = null)
        public void Export(GameObject root, Model model, RuntimeVrmConverter converter, ExportArgs option, VRM10MetaObject metaObject = null)
        {
            ExportAsset(model);

            ///
            /// 必要な容量を先に確保
            /// (sparseは考慮してないので大きめ)
            ///
            {
                var reserveBytes = 0;
                // mesh
                foreach (var g in model.MeshGroups)
                {
                    foreach (var mesh in g.Meshes)
                    {
                        // 頂点バッファ
                        reserveBytes += mesh.IndexBuffer.ByteLength;
                        foreach (var kv in mesh.VertexBuffer)
                        {
                            reserveBytes += kv.Value.ByteLength;
                        }
                        // morph
                        foreach (var morph in mesh.MorphTargets)
                        {
                            foreach (var kv in morph.VertexBuffer)
                            {
                                reserveBytes += kv.Value.ByteLength;
                            }
                        }
                    }
                }
                Reserve(reserveBytes);
            }

            // mesh
            ExportMeshes(model.MeshGroups, model.Materials, option);

            // node
            ExportNodes(model.Root, model.Nodes, model.MeshGroups, option);

            // material
            var materialExporter = new Vrm10MaterialExporter();

            foreach (Material material in model.Materials)
            {
                var glTFMaterial = materialExporter.ExportMaterial(material, m_textureExporter);
                Storage.Gltf.materials.Add(glTFMaterial);
            }

            var(vrm, vrmSpringBone, thumbnailTextureIndex) = ExportVrm(root, model, converter, metaObject);

            // Extension で Texture が増える場合があるので最後に呼ぶ
            for (int i = 0; i < m_textureExporter.Exported.Count; ++i)
            {
                var unityTexture = m_textureExporter.Exported[i];
                Storage.Gltf.PushGltfTexture(0, unityTexture);
            }

            if (thumbnailTextureIndex.HasValue)
            {
                vrm.Meta.ThumbnailImage = Storage.Gltf.textures[thumbnailTextureIndex.Value].source;
            }

            UniGLTF.Extensions.VRMC_vrm.GltfSerializer.SerializeTo(ref Storage.Gltf.extensions, vrm);

            if (vrmSpringBone != null)
            {
                UniGLTF.Extensions.VRMC_springBone.GltfSerializer.SerializeTo(ref Storage.Gltf.extensions, vrmSpringBone);
            }
        }