Пример #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
        public static void Serialize_vci_effects__images_ITEM(JsonFormatter f, glTF_Effekseer_image value)
        {
            f.BeginMap();


            if (value.bufferView >= 0)
            {
                f.Key("bufferView");
                f.Value(value.bufferView);
            }

            if (!string.IsNullOrEmpty(value.mimeType))
            {
                f.Key("mimeType");
                f.Value(value.mimeType);
            }

            f.EndMap();
        }
Пример #3
0
        public static glTF_Effekseer_image glTF_Effekseer_Deserializevci_effects__images_ITEM(JsonNode parsed)
        {
            var value = new glTF_Effekseer_image();

            foreach (var kv in parsed.ObjectItems())
            {
                var key = kv.Key.GetString();

                if (key == "bufferView")
                {
                    value.bufferView = kv.Value.GetInt32();
                    continue;
                }

                if (key == "mimeType")
                {
                    value.mimeType = kv.Value.GetString();
                    continue;
                }
            }
            return(value);
        }
Пример #4
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));
            }
        }