private static glTF_VCAST_vci_audio FromAudioClip(glTF gltf, AudioClip clip) { #if UNITY_EDITOR if (Application.isPlaying) #endif { var bytes = WaveUtil.GetWaveBinary(clip); var viewIndex = gltf.ExtendBufferAndGetViewIndex(0, bytes); return(new glTF_VCAST_vci_audio { name = clip.name, mimeType = "audio/wav", bufferView = viewIndex, }); } #if UNITY_EDITOR else { var path = UnityPath.FromAsset(clip); if (!path.IsUnderAssetsFolder) { return(null); } if (path.Extension.ToLower() == ".wav") { var bytes = File.ReadAllBytes(path.FullPath); var viewIndex = gltf.ExtendBufferAndGetViewIndex(0, bytes); return(new glTF_VCAST_vci_audio { name = clip.name, mimeType = "audio/wav", bufferView = viewIndex, }); } else if (path.Extension.ToLower() == ".mp3") { var bytes = File.ReadAllBytes(path.FullPath); var viewIndex = gltf.ExtendBufferAndGetViewIndex(0, bytes); return(new glTF_VCAST_vci_audio { name = clip.name, mimeType = "audio/mp3", bufferView = viewIndex, }); } else { // Convert to wav var bytes = WaveUtil.GetWaveBinary(clip); var viewIndex = gltf.ExtendBufferAndGetViewIndex(0, bytes); return(new glTF_VCAST_vci_audio { name = clip.name, mimeType = "audio/wav", bufferView = viewIndex, }); } } #endif }
private static int AddEffekseerEffect(glTF gltf, Effekseer.EffekseerEmitter emitter) { if (gltf.extensions.Effekseer.effects.FirstOrDefault(x => x.effectName == emitter.effectAsset.name) == null) { var viewIndex = gltf.ExtendBufferAndGetViewIndex(0, emitter.effectAsset.efkBytes); // body var effect = new glTF_Effekseer_effect() { nodeIndex = 0, nodeName = "Root", effectName = emitter.effectAsset.name, scale = emitter.effectAsset.Scale, body = new glTF_Effekseer_body() { bufferView = viewIndex }, images = new List <glTF_Effekseer_image>(), models = new List <glTF_Effekseer_model>() }; // texture foreach (var texture in emitter.effectAsset.textureResources) { #if UNITY_EDITOR var texturePath = UnityEditor.AssetDatabase.GetAssetPath(texture.texture); var textureImporter = (UnityEditor.TextureImporter)UnityEditor.TextureImporter.GetAtPath(texturePath); textureImporter.isReadable = true; textureImporter.textureCompression = UnityEditor.TextureImporterCompression.Uncompressed; textureImporter.SaveAndReimport(); #endif var image = new glTF_Effekseer_image() { bufferView = gltf.ExtendBufferAndGetViewIndex(0, texture.texture.EncodeToPNG()), mimeType = "image/png" }; effect.images.Add(image); } // model foreach (var model in emitter.effectAsset.modelResources) { var efkModel = new glTF_Effekseer_model() { bufferView = gltf.ExtendBufferAndGetViewIndex(0, model.asset.bytes) }; effect.models.Add(efkModel); } gltf.extensions.Effekseer.effects.Add(effect); int index = gltf.extensions.Effekseer.effects.Count - 1; return(index); } else { return(gltf.extensions.Effekseer.effects.FindIndex(x => x.effectName == emitter.effectAsset.name)); } }
private int AddEffekseerEffect(glTF gltf, glTF_Effekseer effekseer, Effekseer.EffekseerEmitter emitter) { if (effekseer.effects.FirstOrDefault(x => x.effectName == emitter.effectAsset.name) == null) { var viewIndex = gltf.ExtendBufferAndGetViewIndex(0, emitter.effectAsset.efkBytes); // body var effect = new glTF_Effekseer_effect() { nodeIndex = 0, nodeName = "Root", effectName = emitter.effectAsset.name, scale = emitter.effectAsset.Scale, body = new glTF_Effekseer_body() { bufferView = viewIndex }, images = new List <glTF_Effekseer_image>(), models = new List <glTF_Effekseer_model>() }; // texture foreach (var texture in emitter.effectAsset.textureResources) { if (texture == null || texture.texture == null) { Debug.LogWarning("Effekseer Texture Asset is null. " + texture?.path); continue; } #if UNITY_EDITOR var texturePath = UnityEditor.AssetDatabase.GetAssetPath(texture.texture); var textureImporter = (UnityEditor.TextureImporter)UnityEditor.TextureImporter.GetAtPath(texturePath); if (textureImporter != null) { textureImporter.isReadable = true; textureImporter.textureCompression = UnityEditor.TextureImporterCompression.Uncompressed; textureImporter.SaveAndReimport(); } #endif var textureBytes = TextureExporter.GetBytesWithMime(texture.texture, glTFTextureTypes.Unknown); var image = new glTF_Effekseer_image() { bufferView = gltf.ExtendBufferAndGetViewIndex(0, textureBytes.bytes), mimeType = textureBytes.mine }; effect.images.Add(image); } // model foreach (var model in emitter.effectAsset.modelResources) { if (model == null || model.asset == null) { Debug.LogWarning("Effekseer Model Asset is null. " + model?.path); continue; } var efkModel = new glTF_Effekseer_model() { bufferView = gltf.ExtendBufferAndGetViewIndex(0, model.asset.bytes) }; effect.models.Add(efkModel); } effekseer.effects.Add(effect); int index = effekseer.effects.Count - 1; return(index); } else { return(effekseer.effects.FindIndex(x => x.effectName == emitter.effectAsset.name)); } }