Beispiel #1
0
        public void ExportAnimation(AnimationClip clip, PrefabContext prefabContext)
        {
            if (!_engine.Options.ExportAnimations)
            {
                return;
            }

            var aniFilePath = EvaluateAnimationName(clip, prefabContext);

            ExportMetadata(ExportUtils.ReplaceExtension(aniFilePath, ".xml"), clip, prefabContext);

            using (var file = _engine.TryCreate(clip.GetKey(), aniFilePath,
                                                ExportUtils.GetLastWriteTimeUtc(clip)))
            {
                if (file == null)
                {
                    return;
                }
                using (var writer = new BinaryWriter(file))
                {
                    writer.Write(new byte[] { 0x55, 0x41, 0x4e, 0x49 });
                    WriteStringSZ(writer, _engine.DecorateName(ExportUtils.GetName(clip)));
                    writer.Write(clip.length);

                    // Legacy animation
                    if (clip.legacy)
                    {
                        WriteTracksAsIs(clip, writer);
                    }
                    else if (clip.isHumanMotion)
                    {
                        WriteHumanoidAnimation(clip, writer);
                    }
                    else
                    {
                        WriteGenericAnimation(clip, writer);
                    }
                }
            }
        }
Beispiel #2
0
        public virtual string EvaluateMaterialName(Material material)
        {
            if (material == null)
            {
                return(null);
            }
            var assetPath = AssetDatabase.GetAssetPath(material);

            if (string.IsNullOrWhiteSpace(assetPath))
            {
                return(null);
            }
            if (assetPath.EndsWith(".mat", StringComparison.InvariantCultureIgnoreCase))
            {
                return(ExportUtils.ReplaceExtension(ExportUtils.GetRelPathFromAssetPath(Engine.Options.Subfolder, assetPath),
                                                    ".xml"));
            }
            var newExt = "/" + ExportUtils.SafeFileName(Engine.DecorateName(ExportUtils.GetName(material))) + ".xml";

            return(ExportUtils.ReplaceExtension(ExportUtils.GetRelPathFromAssetPath(Engine.Options.Subfolder, assetPath),
                                                newExt));
        }
        public string EvaluateMeshName(ProBuilderMesh mesh, PrefabContext prefabContext)
        {
            if (mesh == null)
            {
                return(null);
            }
            if (_dynamicMeshNames.TryGetValue(mesh, out var name))
            {
                return(name);
            }

            var assetUrhoAssetName = ExportUtils.GetRelPathFromAsset(_engine.Options.Subfolder, mesh);

            if (string.IsNullOrWhiteSpace(assetUrhoAssetName))
            {
                name = ExportUtils.Combine(prefabContext.TempFolder, ExportUtils.SafeFileName(_engine.DecorateName(ExportUtils.GetName(mesh))) + "." + _dynamicMeshNames.Count + ".mdl");
                _dynamicMeshNames.Add(mesh, name);
                return(name);
            }

            return(ExportUtils.ReplaceExtension(assetUrhoAssetName, "") + "/" +
                   ExportUtils.SafeFileName(_engine.DecorateName(mesh.name)) + ".mdl");
        }
        public string EvaluateLODGroupName(LODGroup lodGroup, PrefabContext prefabContext)
        {
            if (lodGroup == null)
            {
                return(null);
            }
            var lods = lodGroup.GetLODs();

            if (lods.Length == 0)
            {
                return(null);
            }
            var firstMesh = lods[0].renderers.FirstOrDefault();

            if (firstMesh == null)
            {
                return(null);
            }
            var folder = ExportUtils.ReplaceExtension(ExportUtils.GetRelPathFromAsset(_engine.Options.Subfolder, firstMesh), "");

            if (string.IsNullOrWhiteSpace(folder))
            {
                folder = prefabContext.TempFolder;
            }
            return(ExportUtils.Combine(folder, ExportUtils.SafeFileName(_engine.DecorateName(ExportUtils.GetName(firstMesh))) + ".With" + lods.Length.ToString(CultureInfo.InvariantCulture) + "Lods.mdl"));
        }
        public string EvaluateMeshName(Mesh mesh, PrefabContext prefabContext)
        {
            if (mesh == null)
            {
                return(null);
            }
            var folder = ExportUtils.ReplaceExtension(ExportUtils.GetRelPathFromAsset(_engine.Options.Subfolder, mesh), "");

            if (string.IsNullOrWhiteSpace(folder))
            {
                folder = prefabContext.TempFolder;
            }
            return(ExportUtils.Combine(folder, ExportUtils.SafeFileName(_engine.DecorateName(ExportUtils.GetName(mesh))) + ".mdl"));
        }
Beispiel #6
0
        public string EvaluateAnimationName(AnimationClip clip, PrefabContext prefabContext)
        {
            if (clip == null)
            {
                return(null);
            }
            var relPath = ExportUtils.GetRelPathFromAsset(_engine.Options.Subfolder, clip);

            if (Path.GetExtension(relPath).ToLowerInvariant() == ".anim")
            {
                return(ExportUtils.ReplaceExtension(relPath, ".ani"));
            }
            var folder = ExportUtils.ReplaceExtension(relPath, "");

            if (string.IsNullOrWhiteSpace(folder))
            {
                folder = prefabContext.TempFolder;
            }
            return(ExportUtils.Combine(folder, ExportUtils.SafeFileName(_engine.DecorateName(ExportUtils.GetName(clip))) + ".ani"));
        }