public override void ExportMaterial(Material material, PrefabContext prefabContext)
        {
            var urhoPath = EvaluateMaterialName(material);

            using (var writer =
                       Engine.TryCreateXml(material.GetKey(), urhoPath, ExportUtils.GetLastWriteTimeUtc(material)))
            {
                if (writer == null)
                {
                    return;
                }

                var urhoMaterial = new UrhoPBRMaterial();
                urhoMaterial.Technique = "Techniques/PBR/PBRWater.xml";
                var metallicGlossinessShaderArguments = new MetallicGlossinessShaderArguments();

                var _SlowWaterNormal = GetTexture(material, "_SlowWaterNormal");
                var _SlowNormalScale = GetFloat(material, "_SlowNormalScale", 1);

                metallicGlossinessShaderArguments.Bump      = _SlowWaterNormal;
                metallicGlossinessShaderArguments.BumpScale = _SlowNormalScale;
                urhoMaterial.NormalTexture = GetScaledNormalTextureName(_SlowWaterNormal, _SlowNormalScale);

                urhoMaterial.ExtraParameters.Add("WaterMetallic", 1);
                urhoMaterial.ExtraParameters.Add("WaterRoughness", 1.0f - 1);
                urhoMaterial.ExtraParameters.Add("WaterFlowSpeed", 0.2);
                urhoMaterial.ExtraParameters.Add("WaterTimeScale", 1);
                urhoMaterial.ExtraParameters.Add("WaterFresnelPower", 4);

                Engine.SchedulePBRTextures(metallicGlossinessShaderArguments, urhoMaterial);

                WriteMaterial(writer, urhoMaterial, prefabContext);
            }
        }
Ejemplo n.º 2
0
        public void Cubemap(Cubemap texture)
        {
            if (!EnsureReadableTexture(texture))
            {
                return;
            }

            var resourceName = EvaluateCubemapName(texture);

            using (var writer =
                       _engine.TryCreateXml(texture.GetKey(), resourceName, ExportUtils.GetLastWriteTimeUtc(texture)))
            {
                if (writer != null)
                {
                    var ddsName = resourceName.Replace(".xml", ".dds");
                    var srgb    = true;
                    DDS.SaveAsRgbaDds(texture, _engine.GetTargetFilePath(ddsName), srgb);
                    writer.WriteStartElement("cubemap");
                    writer.WriteWhitespace(Environment.NewLine);
                    writer.WriteStartElement("srgb");
                    writer.WriteAttributeString("enable", srgb ? "true" : "false");
                    writer.WriteEndElement();
                    writer.WriteStartElement("image");
                    writer.WriteAttributeString("name", Path.GetFileName(ddsName));
                    writer.WriteEndElement();
                    writer.WriteWhitespace(Environment.NewLine);
                    writer.WriteEndElement();
                }
            }
        }
Ejemplo n.º 3
0
        private void CopyTextureAndSaveAs(Texture texture)
        {
            var outputAssetName        = EvaluateTextureName(texture);
            var sourceFileTimestampUtc = ExportUtils.GetLastWriteTimeUtc(texture);
            var assetGuid = texture.GetKey();

            if (_engine.IsUpToDate(assetGuid, outputAssetName, sourceFileTimestampUtc))
            {
                return;
            }

            var tImporter      = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as TextureImporter;
            var texType        = tImporter?.textureType ?? TextureImporterType.Default;
            var textureOptions = ExportUtils.GetTextureOptions(texture);

            switch (texType)
            {
            case TextureImporterType.NormalMap:
                new TextureProcessor().ProcessAndSaveTexture(texture, "Hidden/UnityToCustomEngineExporter/Urho3D/DecodeNormalMap", _engine.GetTargetFilePath(outputAssetName), true);
                break;

            default:
                new TextureProcessor().ProcessAndSaveTexture(texture, "Hidden/UnityToCustomEngineExporter/Urho3D/Copy", _engine.GetTargetFilePath(outputAssetName), textureOptions.textureImporterFormat != TextureImporterFormat.DXT1);
                WriteOptions(assetGuid, outputAssetName, sourceFileTimestampUtc, textureOptions.WithSRGB(true));
                break;
            }
        }
Ejemplo n.º 4
0
        private void TransformAOTexture(ShaderArguments arguments, string baseColorName)
        {
            if (arguments.Occlusion == null)
            {
                return;
            }
            var sourceFileTimestampUtc = ExportUtils.GetLastWriteTimeUtc(arguments.Occlusion);
            var assetGuid = arguments.Occlusion.GetKey();

            if (_engine.IsUpToDate(assetGuid, baseColorName, sourceFileTimestampUtc))
            {
                return;
            }

            var tmpMaterial = new Material(Shader.Find("Hidden/UnityToCustomEngineExporter/Urho3D/PremultiplyOcclusionStrength"));

            try
            {
                var mainTexture = arguments.Occlusion;
                tmpMaterial.SetTexture("_MainTex", mainTexture);
                tmpMaterial.SetFloat("_OcclusionStrength", arguments.OcclusionStrength);
                new TextureProcessor().ProcessAndSaveTexture(mainTexture, tmpMaterial,
                                                             _engine.GetTargetFilePath(baseColorName));
                WriteOptions(assetGuid, baseColorName, sourceFileTimestampUtc,
                             ExportUtils.GetTextureOptions(mainTexture).WithSRGB(true));
            }
            finally
            {
                Object.DestroyImmediate(tmpMaterial);
            }
        }
Ejemplo n.º 5
0
        private void ExportMetadata(string metadataFileName, AnimationClip clip, PrefabContext prefabContext)
        {
            using (var file = _engine.TryCreateXml(clip.GetKey(), metadataFileName, ExportUtils.GetLastWriteTimeUtc(clip)))
            {
                if (file == null)
                {
                    return;
                }

                file.WriteStartElement("animation");
                file.WriteWhitespace(Environment.NewLine);
                foreach (var clipEvent in clip.events)
                {
                    file.WriteWhitespace("\t");
                    file.WriteStartElement("trigger");
                    file.WriteAttributeString("time", BaseNodeExporter.Format(clipEvent.time));
                    file.WriteAttributeString("type", "String");
                    file.WriteAttributeString("value", clipEvent.functionName);
                    file.WriteEndElement();
                    file.WriteWhitespace(Environment.NewLine);
                }
                file.WriteEndElement();
                file.WriteWhitespace(Environment.NewLine);
            }
        }
Ejemplo n.º 6
0
        public void Cubemap(Cubemap texture)
        {
            var resourceName           = EvaluateCubemapName(texture);
            var assetGuid              = texture.GetKey();
            var sourceFileTimestampUtc = ExportUtils.GetLastWriteTimeUtc(texture);

            if (_engine.IsUpToDate(assetGuid, resourceName, sourceFileTimestampUtc))
            {
                return;
            }

            if (!EnsureReadableTexture(texture))
            {
                return;
            }

            using (var writer =
                       _engine.TryCreateXml(assetGuid, resourceName, sourceFileTimestampUtc))
            {
                if (writer != null)
                {
                    WriteCubemap(texture, resourceName, writer);
                }
            }
        }
Ejemplo n.º 7
0
        public void ExportMesh(Mesh mesh, PrefabContext prefabContext)
        {
            if (!_engine.Options.ExportMeshes)
            {
                return;
            }
            var meshSource           = new MeshSource(mesh);
            var mdlFilePath          = EvaluateMeshName(mesh, prefabContext);
            var assetKey             = mesh.GetKey();
            var lastWriteDateTimeUtc = ExportUtils.GetLastWriteTimeUtc(mesh);

            ExportMeshModel(meshSource, mdlFilePath, assetKey, lastWriteDateTimeUtc);
        }
Ejemplo n.º 8
0
        public void ExportAnimationController(AnimatorController animationController, PrefabContext prefabContext)
        {
            var animationControllerName = EvaluateAnimationControllerName(animationController, prefabContext);
            var controllerJson          = new ControllerJson(animationController, animationControllerName, _engine, prefabContext);
            var assetGuid = animationController.GetKey();
            var sourceFileTimestampUtc = ExportUtils.GetLastWriteTimeUtc(animationController);

            SaveJson(animationControllerName, controllerJson, assetGuid, sourceFileTimestampUtc);
            for (var index = 0; index < controllerJson.layers.Length; index++)
            {
                var layer = animationController.layers[index];

                SaveJson(controllerJson.layers[index].stateMachine, new StateMachineJson(layer.stateMachine, _engine, prefabContext), assetGuid, sourceFileTimestampUtc);
            }
        }
Ejemplo n.º 9
0
        private void CopyTexture(Texture texture)
        {
            var relPath = ExportUtils.GetRelPathFromAsset(_engine.Options.Subfolder, texture);
            var newName = EvaluateTextureName(texture);

            if (relPath != newName)
            {
                CopyTextureAndSaveAs(texture);
            }
            else
            {
                _engine.TryCopyFile(AssetDatabase.GetAssetPath(texture), newName);
                WriteOptions(texture.GetKey(), newName, ExportUtils.GetLastWriteTimeUtc(texture),
                             ExportUtils.GetTextureOptions(texture));
            }
        }
Ejemplo n.º 10
0
        private void TransformSpecularGlossiness(SpecularGlossinessShaderArguments arguments, string baseColorName)
        {
            var sourceFileTimestampUtc = ExportUtils.GetLastWriteTimeUtc(arguments.Diffuse,
                                                                         arguments.PBRSpecular.Texture, arguments.Smoothness.Texture);
            var assetGuid =
                (arguments.Diffuse ?? arguments.PBRSpecular.Texture ?? arguments.Smoothness.Texture).GetKey();

            if (_engine.IsUpToDate(assetGuid, baseColorName, sourceFileTimestampUtc))
            {
                return;
            }

            var tmpMaterial =
                new Material(
                    Shader.Find("Hidden/UnityToCustomEngineExporter/Urho3D/ConvertSpecularToMetallicRoughness"));
            Texture mainTexture       = null;
            Texture specularTexture   = null;
            Texture smoothnessTexture = null;

            try
            {
                mainTexture        = EnsureTexture(new TextureOrColor(arguments.Diffuse, arguments.DiffuseColor));
                specularTexture    = EnsureTexture(arguments.PBRSpecular);
                smoothnessTexture  = EnsureTexture(arguments.Smoothness);
                var(width, height) = MaxTexutreSize(mainTexture, specularTexture, smoothnessTexture);
                tmpMaterial.SetTexture("_MainTex", mainTexture);
                tmpMaterial.SetTexture("_SpecGlossMap", specularTexture);
                tmpMaterial.SetFloat("_SmoothnessScale",
                                     arguments.GlossinessTextureScale *
                                     (arguments.Smoothness.Texture != null ? 1.0f : arguments.Glossiness));
                tmpMaterial.SetTexture("_Smoothness", smoothnessTexture);
                new TextureProcessor().ProcessAndSaveTexture(mainTexture, width, height, tmpMaterial,
                                                             _engine.GetTargetFilePath(baseColorName));
                WriteOptions(assetGuid, baseColorName, sourceFileTimestampUtc,
                             (ExportUtils.GetTextureOptions(mainTexture) ?? ExportUtils.GetTextureOptions(specularTexture) ??
                              ExportUtils.GetTextureOptions(smoothnessTexture)).WithSRGB(false));
            }
            finally
            {
                Object.DestroyImmediate(tmpMaterial);
                DestroyTmpTexture(arguments.Diffuse, mainTexture);
                DestroyTmpTexture(arguments.PBRSpecular, specularTexture);
                DestroyTmpTexture(arguments.Smoothness, smoothnessTexture);
            }
        }
Ejemplo n.º 11
0
        public void ExportPrefab(AssetKey assetGuid, string assetPath, GameObject gameObject)
        {
            var relativePath = EvaluatePrefabName(assetPath);

            using (var writer = _engine.TryCreateXml(assetGuid, relativePath, ExportUtils.GetLastWriteTimeUtc(assetPath)))
            {
                if (writer == null)
                {
                    return;
                }
                var prefabContext = new PrefabContext()
                {
                    TempFolder = ExportUtils.ReplaceExtension(relativePath, "")
                };

                WriteObject(writer, "", gameObject, new HashSet <Renderer>(), true, prefabContext);
            }
        }
Ejemplo n.º 12
0
        private void WriteTerrainMaterial(TerrainData terrain, PrefabContext prefabContext)
        {
            using (var writer =
                       _engine.TryCreateXml(terrain.GetKey(), EvaluateMaterial(terrain),
                                            ExportUtils.GetLastWriteTimeUtc(terrain)))
            {
                if (writer == null)
                {
                    return;
                }

                var layers       = terrain.terrainLayers;
                var layerIndices = GetTerrainLayersByPopularity(terrain).Take(_maxLayers).ToArray();

                var material = new UrhoPBRMaterial();
                material.Technique = "Techniques/PBR/PBRTerrainBlend.xml";
                material.TextureUnits.Add(EvaluateWeightsMap(terrain));
                Vector2 detailTiling = new Vector2(1, 1);
                for (var layerIndex = 0; layerIndex < layerIndices.Length; ++layerIndex)
                {
                    var layer = layers[layerIndices[layerIndex]];
                    detailTiling = new Vector2(terrain.size.x / layer.tileSize.x, terrain.size.z / layer.tileSize.y);
                    if (layer.diffuseTexture != null)
                    {
                        _engine.ScheduleTexture(layer.diffuseTexture);
                        var urhoAssetName = _engine.EvaluateTextrueName(layer.diffuseTexture);
                        material.TextureUnits.Add(urhoAssetName);
                    }
                    else
                    {
                        material.TextureUnits.Add(null);
                    }
                }
                material.MatSpecColor = new Color(0.0f, 0.0f, 0.0f, 1.0f);
                material.Roughness    = 1;
                material.Metallic     = 0;
                material.ExtraParameters.Add("DetailTiling", detailTiling);
                material.PixelShaderDefines.Add("TERRAINLAYERS" + layerIndices.Length.ToString(CultureInfo.InvariantCulture));

                StandardMaterialExporter.WriteMaterial(writer, material, prefabContext);
            }
        }
Ejemplo n.º 13
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(clip.name));
                    writer.Write(clip.length);

                    // Legacy animation
                    if (clip.legacy)
                    {
                        WriteTracksAsIs(clip, writer);
                    }
                    else if (clip.isHumanMotion)
                    {
                        WriteHumanoidAnimation(clip, writer);
                    }
                    else
                    {
                        WriteGenericAnimation(clip, writer);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private void TransformNormal(Texture bump, float bumpScale, string baseColorName)
        {
            if (bump == null)
            {
                return;
            }

            if (bumpScale >= 0.999f)
            {
                CopyTexture(bump);
                return;
            }

            var sourceFileTimestampUtc = ExportUtils.GetLastWriteTimeUtc(bump);
            var assetGuid = bump.GetKey();

            if (_engine.IsUpToDate(assetGuid, baseColorName, sourceFileTimestampUtc))
            {
                return;
            }

            var tmpMaterial = new Material(Shader.Find("Hidden/UnityToCustomEngineExporter/Urho3D/DecodeNormalMap"));

            try
            {
                var mainTexture = bump;
                tmpMaterial.SetTexture("_MainTex", mainTexture);
                tmpMaterial.SetFloat("_BumpScale", bumpScale);
                new TextureProcessor().ProcessAndSaveTexture(mainTexture, tmpMaterial, _engine.GetTargetFilePath(baseColorName));
                WriteOptions(assetGuid, baseColorName, sourceFileTimestampUtc, ExportUtils.GetTextureOptions(mainTexture).WithSRGB(false));
            }
            finally
            {
                Object.DestroyImmediate(tmpMaterial);
            }
        }
        public override void ExportMaterial(Material material, PrefabContext prefabContext)
        {
            var urhoPath = EvaluateMaterialName(material);

            using (var writer =
                       Engine.TryCreateXml(material.GetKey(), urhoPath, ExportUtils.GetLastWriteTimeUtc(material)))
            {
                if (writer == null)
                {
                    return;
                }

                var arguments    = SetupSpecularGlossinessPBR(material);
                var urhoMaterial = FromSpecularGlossiness(arguments);
                WriteMaterial(writer, urhoMaterial, prefabContext);

                //Engine.ScheduleTexture(arguments.Bump, new TextureReference(TextureSemantic.Bump));

                Engine.SchedulePBRTextures(arguments, urhoMaterial);

                Engine.ScheduleTexture(arguments.Emission);
                //Engine.ScheduleTexture(arguments.Occlusion, new TextureReference(TextureSemantic.Occlusion));
            }
        }
Ejemplo n.º 16
0
        public void ExportMesh(GameObject go, PrefabContext prefabContext)
        {
            if (!_engine.Options.ExportMeshes)
            {
                return;
            }
            var proBuilderMesh      = go.GetComponent <ProBuilderMesh>();
            var skinnedMeshRenderer = go.GetComponent <SkinnedMeshRenderer>();
            var meshFilter          = go.GetComponent <MeshFilter>();

            if (proBuilderMesh != null)
            {
                ExportProBuilderMeshModel(proBuilderMesh, prefabContext);
            }
            else
            {
                Mesh mesh = null;
                if (skinnedMeshRenderer != null)
                {
                    mesh = skinnedMeshRenderer.sharedMesh;
                }
                else if (meshFilter != null)
                {
                    mesh = meshFilter.sharedMesh;
                }
                var meshSource = new MeshSource(mesh, skinnedMeshRenderer);
                ExportMeshModel(meshSource, EvaluateMeshName(mesh, prefabContext), mesh.GetKey(),
                                ExportUtils.GetLastWriteTimeUtc(mesh));
            }


            for (var i = 0; i < go.transform.childCount; ++i)
            {
                ExportMesh(go.transform.GetChild(i).gameObject, prefabContext);
            }
        }
Ejemplo n.º 17
0
        protected override void ExportAssetBlock(string assetPath, Type mainType, Object[] assets, PrefabContext prefabContext)
        {
            if (mainType == typeof(GameObject))
            {
                var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath);
                _meshExporter.ExportMesh(prefab, prefabContext);
                _prefabExporter.ExportPrefab(new AssetKey(AssetDatabase.AssetPathToGUID(assetPath), 0),
                                             _prefabExporter.EvaluatePrefabName(assetPath), prefab);
            }
            else
            {
                foreach (var asset in assets)
                {
                    if (asset is Mesh mesh)
                    {
                        EditorTaskScheduler.Default.ScheduleForegroundTask(
                            () => _meshExporter.ExportMeshModel(new MeshSource(mesh), EvaluateMeshName(mesh, prefabContext),
                                                                mesh.GetKey(), ExportUtils.GetLastWriteTimeUtc(mesh)),
                            mesh.name + " from " + assetPath);
                    }
                }
            }

            foreach (var asset in assets)
            {
                if (asset is Mesh mesh)
                {
                    //We already processed all meshes.
                }
                else if (asset is GameObject gameObject)
                {
                    //We already processed prefab.
                }
                else if (asset is Transform transform)
                {
                    //Skip
                }
                else if (asset is MeshRenderer meshRenderer)
                {
                    //Skip
                }
                else if (asset is MeshFilter meshFilter)
                {
                    //Skip
                }
                else if (asset is MeshCollider meshCollider)
                {
                    //Skip
                }
                else if (asset is ProBuilderMesh proBuilderMesh)
                {
                    //Skip
                }
                else if (asset is LODGroup lodGroup)
                {
                    //Skip
                }
                else if (asset is SkinnedMeshRenderer skinnedMeshRenderer)
                {
                    //Skip
                }
                else if (asset is Animation animation)
                {
                    //Skip
                }
                else if (asset is AudioClip audioClip)
                {
                    EditorTaskScheduler.Default.ScheduleForegroundTask(() => _audioExporter.ExportClip(audioClip),
                                                                       audioClip.name + " from " + assetPath);
                }
                else if (asset is Material material)
                {
                    EditorTaskScheduler.Default.ScheduleForegroundTask(() => _materialExporter.ExportMaterial(material, prefabContext),
                                                                       material.name + " from " + assetPath);
                }
                else if (asset is TerrainData terrainData)
                {
                    EditorTaskScheduler.Default.ScheduleForegroundTask(
                        () => _terrainExporter.ExportTerrain(terrainData, prefabContext), terrainData.name + " from " + assetPath);
                }
                else if (asset is Texture2D texture2d)
                {
                    EditorTaskScheduler.Default.ScheduleForegroundTask(
                        () => _textureExporter.ExportTexture(texture2d, new TextureReference(TextureSemantic.Other)),
                        texture2d.name + " from " + assetPath);
                }
                else if (asset is Cubemap cubemap)
                {
                    EditorTaskScheduler.Default.ScheduleForegroundTask(() => _cubemapExporter.Cubemap(cubemap),
                                                                       cubemap.name + " from " + assetPath);
                }
                else if (asset is AnimationClip animationClip)
                {
                    EditorTaskScheduler.Default.ScheduleForegroundTask(
                        () => _animationExporter.ExportAnimation(animationClip, prefabContext), animationClip.name + " from " + assetPath);
                }
                else if (asset is AnimatorController animationController)
                {
                    EditorTaskScheduler.Default.ScheduleForegroundTask(
                        () => _animationControllerExporter.ExportAnimationController(animationController, prefabContext), animationController.name + " from " + assetPath);
                }
            }
        }
Ejemplo n.º 18
0
        public override void ExportMaterial(Material material, PrefabContext prefabContext)
        {
            var urhoPath = EvaluateMaterialName(material);

            using (var writer =
                       Engine.TryCreateXml(material.GetKey(), urhoPath, ExportUtils.GetLastWriteTimeUtc(material)))
            {
                if (writer == null)
                {
                    return;
                }

                var arguments = CreateShaderArguments(material);
                SetupFlags(material, arguments);
                var shader = material.shader;

                for (var i = 0; i < ShaderUtil.GetPropertyCount(shader); i++)
                {
                    var propertyName = ShaderUtil.GetPropertyName(shader, i);
                    var propertyType = ShaderUtil.GetPropertyType(shader, i);
                    switch (propertyType)
                    {
                    case ShaderUtil.ShaderPropertyType.Color:
                    {
                        ParseColor(propertyName, material.GetColor(propertyName), arguments);
                        break;
                    }

                    case ShaderUtil.ShaderPropertyType.Float:
                    {
                        ParseFloatOrRange(propertyName, material.GetFloat(propertyName), arguments);
                        break;
                    }

                    case ShaderUtil.ShaderPropertyType.Range:
                    {
                        ParseFloatOrRange(propertyName, material.GetFloat(propertyName), arguments);
                        break;
                    }

                    case ShaderUtil.ShaderPropertyType.TexEnv:
                    {
                        ParseTexture(propertyName, material.GetTexture(propertyName), arguments);
                        break;
                    }
                    }
                }

                var urhoMaterial = FromMetallicGlossiness(material, arguments);
                WriteMaterial(writer, urhoMaterial, prefabContext);

                Engine.ScheduleTexture(arguments.BaseColor, new TextureReference(TextureSemantic.PBRBaseColor));
                //Engine.ScheduleTexture(arguments.Bump, new TextureReference(TextureSemantic.Bump));
                Engine.ScheduleTexture(arguments.DetailBaseColor, new TextureReference(TextureSemantic.Detail));

                Engine.SchedulePBRTextures(arguments, urhoMaterial);

                Engine.ScheduleTexture(arguments.Emission, new TextureReference(TextureSemantic.Emission));
                //Engine.ScheduleTexture(arguments.Occlusion, new TextureReference(TextureSemantic.Occlusion));
            }
        }
Ejemplo n.º 19
0
        public override void ExportMaterial(Material material, PrefabContext prefabContext)
        {
            var assetGuid = material.GetKey();
            var urhoPath  = EvaluateMaterialName(material);
            var arguments = SetupSkybox(material);

            using (var writer = Engine.TryCreateXml(assetGuid, urhoPath, ExportUtils.GetLastWriteTimeUtc(material)))
            {
                if (writer == null)
                {
                    return;
                }
                //writer.WriteStartDocument();
                //writer.WriteWhitespace(Environment.NewLine);
                writer.WriteStartElement("material");
                writer.WriteWhitespace(Environment.NewLine);
                var technique = "Techniques/DiffSkyboxHDRScale.xml";

                var anyFace = arguments.BackTex ?? arguments.DownTex ?? arguments.FrontTex ??
                              arguments.LeftTex ?? arguments.RightTex ?? arguments.UpTex;
                if (arguments.Skybox != null)
                {
                    Engine.ScheduleAssetExport(arguments.Skybox, prefabContext);
                    string name;
                    if (arguments.Skybox is Cubemap cubemap)
                    {
                        name = Engine.EvaluateCubemapName(cubemap);
                    }
                    else
                    {
                        name      = Engine.EvaluateTextrueName(arguments.Skybox);
                        technique = "Techniques/DiffSkydome.xml";
                    }

                    if (!string.IsNullOrWhiteSpace(name))
                    {
                        WriteTexture(name, writer, "diffuse", prefabContext);
                    }
                }
                else if (anyFace != null)
                {
                    var cubemapName = ExportUtils.ReplaceExtension(urhoPath, ".Cubemap.xml");
                    using (var cubemapWriter = Engine.TryCreateXml(assetGuid, cubemapName, DateTime.MaxValue))
                    {
                        if (cubemapWriter != null)
                        {
                            cubemapWriter.WriteStartElement("cubemap");
                            foreach (var tex in new[]
                            {
                                arguments.RightTex, arguments.LeftTex, arguments.UpTex, arguments.DownTex,
                                arguments.FrontTex, arguments.BackTex
                            })
                            {
                                cubemapWriter.WriteWhitespace(Environment.NewLine);
                                cubemapWriter.WriteStartElement("face");
                                cubemapWriter.WriteAttributeString("name", Engine.EvaluateTextrueName(tex ?? anyFace));
                                cubemapWriter.WriteEndElement();
                                Engine.ScheduleTexture(tex);
                            }

                            cubemapWriter.WriteWhitespace(Environment.NewLine);
                            cubemapWriter.WriteStartElement("address");
                            cubemapWriter.WriteAttributeString("coord", "uv");
                            cubemapWriter.WriteAttributeString("mode", "clamp");
                            cubemapWriter.WriteEndElement();
                            cubemapWriter.WriteWhitespace(Environment.NewLine);
                            cubemapWriter.WriteStartElement("mipmap");
                            cubemapWriter.WriteAttributeString("enable", "true");
                            cubemapWriter.WriteEndElement();
                            cubemapWriter.WriteWhitespace(Environment.NewLine);
                            cubemapWriter.WriteStartElement("filter");
                            cubemapWriter.WriteAttributeString("mode", "trilinear");
                            cubemapWriter.WriteEndElement();
                            cubemapWriter.WriteWhitespace(Environment.NewLine);
                            cubemapWriter.WriteEndElement();
                        }
                    }

                    WriteTexture(cubemapName, writer, "diffuse", prefabContext);
                }
                else
                {
                    WriteTexture("Resources/unity_builtin_extra/Default-Skybox-Map.xml", writer, "diffuse", prefabContext);
                }

                WriteTechnique(writer, technique);

                {
                    writer.WriteWhitespace("\t");
                    writer.WriteStartElement("cull");
                    writer.WriteAttributeString("value", "none");
                    writer.WriteEndElement();
                    writer.WriteWhitespace(Environment.NewLine);

                    writer.WriteWhitespace("\t");
                    writer.WriteStartElement("shadowcull");
                    writer.WriteAttributeString("value", "ccw");
                    writer.WriteEndElement();
                    writer.WriteWhitespace(Environment.NewLine);

                    writer.WriteWhitespace("\t");
                    writer.WriteStartElement("shader");
                    writer.WriteAttributeString("vsdefines", "IGNORENODETRANSFORM");
                    writer.WriteEndElement();
                    writer.WriteWhitespace(Environment.NewLine);
                }

                writer.WriteEndElement();
            }
        }
Ejemplo n.º 20
0
 private void ExportProBuilderMeshModel(ProBuilderMesh proBuilderMesh, PrefabContext prefabContext)
 {
     ExportMeshModel(new ProBuilderMeshSource(proBuilderMesh), EvaluateMeshName(proBuilderMesh, prefabContext),
                     proBuilderMesh.GetKey(), ExportUtils.GetLastWriteTimeUtc(proBuilderMesh));
 }
Ejemplo n.º 21
0
        public override void ExportMaterial(Material material, PrefabContext prefabContext)
        {
            var urhoPath = EvaluateMaterialName(material);

            using (var writer =
                       Engine.TryCreateXml(material.GetKey(), urhoPath, ExportUtils.GetLastWriteTimeUtc(material)))
            {
                if (writer == null)
                {
                    return;
                }
                var arguments = SetupLegacy(material);
                var flags     = new LegacyTechniqueFlags();
                flags.hasAlpha    = arguments.Transparent;
                flags.hasDiffuse  = arguments.Diffuse != null;
                flags.hasEmissive = arguments.Emission != null;
                flags.hasNormal   = arguments.Bump != null;
                flags.hasSpecular = arguments.Specular != null;
                writer.WriteStartElement("material");
                writer.WriteWhitespace(Environment.NewLine);
                {
                    var bestTechnique         = Techniques[0];
                    var bestTechniqueDistance = bestTechnique.Material - flags;
                    foreach (var technique in Techniques)
                    {
                        if (technique.Material.Fits(flags))
                        {
                            var d = technique.Material - flags;
                            if (d < bestTechniqueDistance)
                            {
                                bestTechnique         = technique;
                                bestTechniqueDistance = d;
                            }
                        }
                    }

                    WriteTechnique(writer, "Techniques/" + bestTechnique.Name);
                }
                if (arguments.Diffuse != null)
                {
                    WriteTexture(arguments.Diffuse, writer, "diffuse", prefabContext);
                }
                if (arguments.Specular != null)
                {
                    WriteTexture(arguments.Specular, writer, "specular", prefabContext);
                }
                if (arguments.Bump != null)
                {
                    WriteTexture(arguments.Bump, writer, "normal", prefabContext);
                }
                if (arguments.Emission != null)
                {
                    WriteTexture(arguments.Bump, writer, "emissive", prefabContext);
                }
                writer.WriteParameter("MatDiffColor", arguments.DiffColor);
                if (arguments.HasEmission)
                {
                    writer.WriteParameter("MatEmissiveColor", BaseNodeExporter.FormatRGB(arguments.EmissiveColor));
                }
                WriteCommonParameters(writer, arguments);

                writer.WriteEndElement();
            }
        }
Ejemplo n.º 22
0
        public void ExportAnimation(AnimationClip clipAnimation, PrefabContext prefabContext)
        {
            if (!_engine.Options.ExportAnimations)
            {
                return;
            }

            var name = GetSafeFileName(_engine.DecorateName(clipAnimation.name));

            //_assetCollection.AddAnimationPath(clipAnimation, fileName);

            var aniFilePath = EvaluateAnimationName(clipAnimation, prefabContext);

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

                    if (clipAnimation.legacy)
                    {
                        WriteTracksAsIs(clipAnimation, writer);
                    }
                    else
                    {
                        var allBindings = AnimationUtility.GetCurveBindings(clipAnimation);
                        var rootBones   =
                            new HashSet <string>(allBindings.Select(_ => GetRootBoneName(_)).Where(_ => _ != null));
                        if (rootBones.Count != 1)
                        {
                            Debug.LogWarning(aniFilePath + ": Multiple root bones found (" +
                                             string.Join(", ", rootBones.ToArray()) +
                                             "), falling back to curve export");
                            WriteTracksAsIs(clipAnimation, writer);
                        }
                        else
                        {
                            var rootBoneName = rootBones.First();
                            var rootGOs      = _skeletons
                                               .Select(_ => _.name == rootBoneName ? _.transform : _.transform.Find(rootBoneName))
                                               .Where(_ => _ != null).ToList();
                            if (rootGOs.Count == 1)
                            {
                                WriteSkelAnimation(clipAnimation, rootGOs.First().gameObject, writer);
                            }
                            else
                            {
                                Debug.LogWarning(aniFilePath +
                                                 ": Multiple game objects found that match root bone name, falling back to curve export");
                                WriteTracksAsIs(clipAnimation, writer);
                            }
                        }
                    }
                }
            }
        }