Beispiel #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));
            }
        }
        public static glTF_Effekseer_effect glTF_Effekseer_Deserializevci_effects_ITEM(JsonNode parsed)
        {
            var value = new glTF_Effekseer_effect();

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

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

                if (key == "nodeName")
                {
                    value.nodeName = kv.Value.GetString();
                    continue;
                }

                if (key == "effectName")
                {
                    value.effectName = kv.Value.GetString();
                    continue;
                }

                if (key == "body")
                {
                    value.body = glTF_Effekseer_Deserializevci_effects__body(kv.Value);
                    continue;
                }

                if (key == "scale")
                {
                    value.scale = kv.Value.GetSingle();
                    continue;
                }

                if (key == "images")
                {
                    value.images = glTF_Effekseer_Deserializevci_effects__images(kv.Value);
                    continue;
                }

                if (key == "models")
                {
                    value.models = glTF_Effekseer_Deserializevci_effects__models(kv.Value);
                    continue;
                }
            }
            return(value);
        }
        public static void Serialize_vci_effects_ITEM(JsonFormatter f, glTF_Effekseer_effect value)
        {
            f.BeginMap();


            if (true)
            {
                f.Key("nodeIndex");
                f.Value(value.nodeIndex);
            }

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

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

            if (value.body != null)
            {
                f.Key("body");
                Serialize_vci_effects__body(f, value.body);
            }

            if (true)
            {
                f.Key("scale");
                f.Value(value.scale);
            }

            if (value.images != null && value.images.Count >= 1)
            {
                f.Key("images");
                Serialize_vci_effects__images(f, value.images);
            }

            if (value.models != null && value.models.Count >= 1)
            {
                f.Key("models");
                Serialize_vci_effects__models(f, value.models);
            }

            f.EndMap();
        }
Beispiel #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));
            }
        }