예제 #1
0
        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));
            }
        }
예제 #2
0
        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));
            }
        }