Пример #1
0
        private void Path_OnChanged(object sender, ChangedValueEventArgs e)
        {
            // Apply values
            Utl.MaterialInformation info = new Utl.MaterialInformation();
            info.Load(Path.GetAbsolutePath());

            ApplyMaterial(info);

            if (info.CustomData.Count() > 0)
            {
                rcValues.CustomData1.Name = info.CustomData[0].Summaries[Core.Language];
                rcValues.CustomData1.Desc = info.CustomData[0].Descriptions[Core.Language];
            }
            else
            {
                rcValues.CustomData1.Name = string.Empty;
                rcValues.CustomData1.Desc = string.Empty;
            }

            if (info.CustomData.Count() > 1)
            {
                rcValues.CustomData2.Name = info.CustomData[1].Summaries[Core.Language];
                rcValues.CustomData2.Desc = info.CustomData[1].Descriptions[Core.Language];
            }
            else
            {
                rcValues.CustomData2.Name = string.Empty;
                rcValues.CustomData2.Desc = string.Empty;
            }

            rcValues.CustomData1.Changed();
            rcValues.CustomData2.Changed();
        }
Пример #2
0
        private void Path_OnChanged(object sender, ChangedValueEventArgs e)
        {
            // Apply values
            Utl.MaterialInformation info = new Utl.MaterialInformation();
            info.Load(Path.GetAbsolutePath());

            ApplyMaterial(info);
        }
Пример #3
0
        public Utl.MaterialInformation LoadMaterialInformation(string path)
        {
            path = path.Replace('\\', '/');

            if (materials.ContainsKey(path))
            {
                return(materials[path]);
            }

            var info = new Utl.MaterialInformation();

            if (info.Load(path))
            {
                materials.Add(path, info);
            }

            return(info);
        }
Пример #4
0
        void UpdateInformation()
        {
            if (binding == null || string.IsNullOrEmpty(binding.GetAbsolutePath()))
            {
                matInfo         = null;
                compiledMatInfo = null;
                return;
            }

            matInfo = new Utl.MaterialInformation();
            matInfo.Load(binding.GetAbsolutePath());

            if (System.IO.File.Exists(CreateBinaryFilePath()))
            {
                compiledMatInfo = new Utl.CompiledMaterialInformation();
                compiledMatInfo.Load(CreateBinaryFilePath());
            }
            else
            {
                compiledMatInfo = null;
            }
        }
Пример #5
0
        void UpdateInformation()
        {
            if (binding == null || string.IsNullOrEmpty(binding.GetAbsolutePath()))
            {
                matInfo         = null;
                compiledMatInfo = null;
                return;
            }

            matInfo = new Utl.MaterialInformation();
            matInfo.Load(binding.GetAbsolutePath());

            var binaryPath = IO.MaterialCacheGenerator.CreateBinaryFilePath(binding.GetAbsolutePath());

            if (System.IO.File.Exists(binaryPath))
            {
                compiledMatInfo = new Utl.CompiledMaterialInformation();
                errorCode       = compiledMatInfo.Load(binaryPath);
            }
            else
            {
                compiledMatInfo = null;
            }
        }
Пример #6
0
        public static byte[] GetBytes(Data.RendererCommonValues value, Dictionary <string, int> texture_and_index, Dictionary <string, int> distortionTexture_and_index)
#endif
        {
            List <byte[]> data = new List <byte[]>();

            var texInfo    = new TextureInformation();
            var hasTexture = true;

#if MATERIAL_ENABLED
            data.Add(((int)value.Material.Value).GetBytes());


            if (value.Material.Value == Data.RendererCommonValues.MaterialType.Default)
            {
                // テクスチャ番号
                if (value.Distortion.Value)
                {
                    if (value.ColorTexture.RelativePath != string.Empty &&
                        distortionTexture_and_index.ContainsKey(value.ColorTexture.RelativePath) &&
                        texInfo.Load(value.ColorTexture.AbsolutePath))
                    {
                        data.Add(distortionTexture_and_index[value.ColorTexture.RelativePath].GetBytes());
                        hasTexture = true;
                    }
                    else
                    {
                        data.Add((-1).GetBytes());
                        hasTexture = false;
                    }
                }
                else
                {
                    if (value.ColorTexture.RelativePath != string.Empty &&
                        texture_and_index.ContainsKey(value.ColorTexture.RelativePath) &&
                        texInfo.Load(value.ColorTexture.AbsolutePath))
                    {
                        data.Add(texture_and_index[value.ColorTexture.RelativePath].GetBytes());
                        hasTexture = true;
                    }
                    else
                    {
                        data.Add((-1).GetBytes());
                        hasTexture = false;
                    }
                }
            }
            else
            {
                var materialInfo = new Utl.MaterialInformation();
                materialInfo.Load(value.MaterialFile.Path.AbsolutePath);

                var textures = value.MaterialFile.GetTextures(materialInfo);
                var uniforms = value.MaterialFile.GetUniforms(materialInfo);

                if (material_and_index.ContainsKey(value.MaterialFile.Path.RelativePath))
                {
                    data.Add(material_and_index[value.MaterialFile.Path.RelativePath].GetBytes());
                }
                else
                {
                    data.Add((-1).GetBytes());
                }

                data.Add(textures.Count.GetBytes());

                foreach (var texture in textures)
                {
                    if (texture.Item2)
                    {
                        if (texture.Item1.RelativePath != string.Empty &&
                            normalTexture_and_index.ContainsKey(texture.Item1.RelativePath) &&
                            texInfo.Load(texture.Item1.AbsolutePath))
                        {
                            data.Add((1).GetBytes());
                            data.Add(normalTexture_and_index[texture.Item1.RelativePath].GetBytes());
                            hasTexture = true;
                        }
                        else
                        {
                            data.Add((1).GetBytes());
                            data.Add((-1).GetBytes());
                            hasTexture = false;
                        }
                    }
                    else
                    {
                        if (texture.Item1.RelativePath != string.Empty &&
                            texture_and_index.ContainsKey(texture.Item1.RelativePath) &&
                            texInfo.Load(texture.Item1.AbsolutePath))
                        {
                            data.Add((0).GetBytes());
                            data.Add(texture_and_index[texture.Item1.RelativePath].GetBytes());
                            hasTexture = true;
                        }
                        else
                        {
                            data.Add((0).GetBytes());
                            data.Add((-1).GetBytes());
                            hasTexture = false;
                        }
                    }
                }

                data.Add(uniforms.Count.GetBytes());

                foreach (var uniform in uniforms)
                {
                    float[] floats = new float[4];

                    if (uniform is Data.Value.Float)
                    {
                        floats[0] = (uniform as Data.Value.Float).Value;
                    }

                    if (uniform is Data.Value.Vector2D)
                    {
                        floats[0] = (uniform as Data.Value.Vector2D).X.Value;
                        floats[1] = (uniform as Data.Value.Vector2D).Y.Value;
                    }

                    if (uniform is Data.Value.Vector3D)
                    {
                        floats[0] = (uniform as Data.Value.Vector3D).X.Value;
                        floats[1] = (uniform as Data.Value.Vector3D).Y.Value;
                        floats[2] = (uniform as Data.Value.Vector3D).Z.Value;
                    }

                    if (uniform is Data.Value.Vector4D)
                    {
                        floats[0] = (uniform as Data.Value.Vector4D).X.Value;
                        floats[1] = (uniform as Data.Value.Vector4D).Y.Value;
                        floats[2] = (uniform as Data.Value.Vector4D).Z.Value;
                        floats[3] = (uniform as Data.Value.Vector4D).W.Value;
                    }

                    data.Add(floats[0].GetBytes());
                    data.Add(floats[1].GetBytes());
                    data.Add(floats[2].GetBytes());
                    data.Add(floats[3].GetBytes());
                }
            }
#else
            // テクスチャ番号
            if (value.Distortion.Value)
            {
                if (value.ColorTexture.RelativePath != string.Empty &&
                    distortionTexture_and_index.ContainsKey(value.ColorTexture.RelativePath) &&
                    texInfo.Load(value.ColorTexture.AbsolutePath))
                {
                    data.Add(distortionTexture_and_index[value.ColorTexture.RelativePath].GetBytes());
                    hasTexture = true;
                }
                else
                {
                    data.Add((-1).GetBytes());
                    hasTexture = false;
                }
            }
            else
            {
                if (value.ColorTexture.RelativePath != string.Empty &&
                    texture_and_index.ContainsKey(value.ColorTexture.RelativePath) &&
                    texInfo.Load(value.ColorTexture.AbsolutePath))
                {
                    data.Add(texture_and_index[value.ColorTexture.RelativePath].GetBytes());
                    hasTexture = true;
                }
                else
                {
                    data.Add((-1).GetBytes());
                    hasTexture = false;
                }
            }
#endif

            data.Add(value.AlphaBlend);
            data.Add(value.Filter);
            data.Add(value.Wrap);

            if (value.ZTest.GetValue())
            {
                data.Add((1).GetBytes());
            }
            else
            {
                data.Add((0).GetBytes());
            }

            if (value.ZWrite.GetValue())
            {
                data.Add((1).GetBytes());
            }
            else
            {
                data.Add((0).GetBytes());
            }

            data.Add(value.FadeInType);
            if (value.FadeInType.Value == Data.RendererCommonValues.FadeType.Use)
            {
                data.Add(value.FadeIn.Frame.GetBytes());

                var easing = Utl.MathUtl.Easing((float)value.FadeIn.StartSpeed.Value, (float)value.FadeIn.EndSpeed.Value);
                data.Add(BitConverter.GetBytes(easing[0]));
                data.Add(BitConverter.GetBytes(easing[1]));
                data.Add(BitConverter.GetBytes(easing[2]));
            }

            data.Add(value.FadeOutType);
            if (value.FadeOutType.Value == Data.RendererCommonValues.FadeType.Use)
            {
                data.Add(value.FadeOut.Frame.GetBytes());

                var easing = Utl.MathUtl.Easing((float)value.FadeOut.StartSpeed.Value, (float)value.FadeOut.EndSpeed.Value);
                data.Add(BitConverter.GetBytes(easing[0]));
                data.Add(BitConverter.GetBytes(easing[1]));
                data.Add(BitConverter.GetBytes(easing[2]));
            }

            if (hasTexture)
            {
                var width  = (float)texInfo.Width;
                var height = (float)texInfo.Height;

                data.Add(value.UV);
                if (value.UV.Value == Data.RendererCommonValues.UVType.Default)
                {
                }
                else if (value.UV.Value == Data.RendererCommonValues.UVType.Fixed)
                {
                    var value_ = value.UVFixed;
                    data.Add((value_.Start.X / width).GetBytes());
                    data.Add((value_.Start.Y / height).GetBytes());
                    data.Add((value_.Size.X / width).GetBytes());
                    data.Add((value_.Size.Y / height).GetBytes());
                }
                else if (value.UV.Value == Data.RendererCommonValues.UVType.Animation)
                {
                    var value_ = value.UVAnimation;
                    data.Add((value_.Start.X / width).GetBytes());
                    data.Add((value_.Start.Y / height).GetBytes());
                    data.Add((value_.Size.X / width).GetBytes());
                    data.Add((value_.Size.Y / height).GetBytes());

                    if (value_.FrameLength.Infinite)
                    {
                        var inf = int.MaxValue / 100;
                        data.Add(inf.GetBytes());
                    }
                    else
                    {
                        data.Add(value_.FrameLength.Value.Value.GetBytes());
                    }

                    data.Add(value_.FrameCountX.Value.GetBytes());
                    data.Add(value_.FrameCountY.Value.GetBytes());
                    data.Add(value_.LoopType);

                    data.Add(value_.StartSheet.Max.GetBytes());
                    data.Add(value_.StartSheet.Min.GetBytes());
                }
                else if (value.UV.Value == Data.RendererCommonValues.UVType.Scroll)
                {
                    var value_ = value.UVScroll;
                    data.Add((value_.Start.X.Max / width).GetBytes());
                    data.Add((value_.Start.Y.Max / height).GetBytes());
                    data.Add((value_.Start.X.Min / width).GetBytes());
                    data.Add((value_.Start.Y.Min / height).GetBytes());

                    data.Add((value_.Size.X.Max / width).GetBytes());
                    data.Add((value_.Size.Y.Max / height).GetBytes());
                    data.Add((value_.Size.X.Min / width).GetBytes());
                    data.Add((value_.Size.Y.Min / height).GetBytes());

                    data.Add((value_.Speed.X.Max / width).GetBytes());
                    data.Add((value_.Speed.Y.Max / height).GetBytes());
                    data.Add((value_.Speed.X.Min / width).GetBytes());
                    data.Add((value_.Speed.Y.Min / height).GetBytes());
                }
                else if (value.UV.Value == Data.RendererCommonValues.UVType.FCurve)
                {
                    {
                        var           value_ = value.UVFCurve.Start;
                        var           bytes1 = value_.GetBytes(1.0f / width);
                        List <byte[]> _data  = new List <byte[]>();
                        data.Add(bytes1);
                    }

                    {
                        var           value_ = value.UVFCurve.Size;
                        var           bytes1 = value_.GetBytes(1.0f / height);
                        List <byte[]> _data  = new List <byte[]>();
                        data.Add(bytes1);
                    }
                }
            }
            else
            {
                data.Add(((int)Data.RendererCommonValues.UVType.Default).GetBytes());
            }

            // Inheritance
            data.Add(value.ColorInheritType.GetValueAsInt().GetBytes());

            // 歪み
            if (value.Distortion.GetValue())
            {
                data.Add((1).GetBytes());
            }
            else
            {
                data.Add((0).GetBytes());
            }

            data.Add(value.DistortionIntensity.GetBytes());

            return(data.ToArray().ToArray());
        }
Пример #7
0
        public static byte[] GetBytes(Data.RendererCommonValues value, Dictionary <string, int> texture_and_index, Dictionary <string, int> normalTexture_and_index, Dictionary <string, int> distortionTexture_and_index, Dictionary <string, int> material_and_index)

        {
            List <byte[]> data = new List <byte[]>();

            var texInfo = new TextureInformation();

            data.Add(((int)value.Material.Value).GetBytes());

            Func <Data.Value.PathForImage, int, Dictionary <string, int>, int> getTexIDAndStoreSize = (Data.Value.PathForImage image, int number, Dictionary <string, int> texAndInd) =>
            {
                var tempTexInfo = new TextureInformation();

                if (texAndInd.ContainsKey(image.RelativePath) && tempTexInfo.Load(image.AbsolutePath))
                {
                    if (value.UVTextureReferenceTarget.Value != Data.UVTextureReferenceTargetType.None && number == (int)value.UVTextureReferenceTarget.Value)
                    {
                        texInfo.Load(image.AbsolutePath);
                    }

                    return(texAndInd[image.RelativePath]);
                }
                else
                {
                    return(-1);
                }
            };

            if (value.Material.Value == Data.RendererCommonValues.MaterialType.Default)
            {
                // texture1
                data.Add(getTexIDAndStoreSize(value.ColorTexture, 1, texture_and_index).GetBytes());

                // texture2
                data.Add((-1).GetBytes());
            }
            else if (value.Material.Value == Data.RendererCommonValues.MaterialType.BackDistortion)
            {
                // texture1
                data.Add(getTexIDAndStoreSize(value.ColorTexture, 1, distortionTexture_and_index).GetBytes());

                // texture2
                data.Add((-1).GetBytes());
            }
            else if (value.Material.Value == Data.RendererCommonValues.MaterialType.Lighting)
            {
                // texture1
                data.Add(getTexIDAndStoreSize(value.ColorTexture, 1, texture_and_index).GetBytes());

                // texture2
                data.Add(getTexIDAndStoreSize(value.NormalTexture, 2, normalTexture_and_index).GetBytes());
            }
            else
            {
                var materialInfo = new Utl.MaterialInformation();
                materialInfo.Load(value.MaterialFile.Path.AbsolutePath);

                var textures = value.MaterialFile.GetTextures(materialInfo).Where(_ => _.Item1 != null).ToArray();
                var uniforms = value.MaterialFile.GetUniforms(materialInfo);

                // maximum slot limitation
                if (textures.Length > Constant.UserTextureSlotCount)
                {
                    textures = textures.Take(Constant.UserTextureSlotCount).ToArray();
                }

                if (material_and_index.ContainsKey(value.MaterialFile.Path.RelativePath))
                {
                    data.Add(material_and_index[value.MaterialFile.Path.RelativePath].GetBytes());
                }
                else
                {
                    data.Add((-1).GetBytes());
                }

                data.Add(textures.Length.GetBytes());

                foreach (var texture in textures)
                {
                    var texture_ = texture.Item1.Value as Data.Value.PathForImage;
                    if (texture.Item2.Type == TextureType.Value)
                    {
                        data.Add((1).GetBytes());
                        data.Add(getTexIDAndStoreSize(texture_, texture.Item2.Priority, normalTexture_and_index).GetBytes());
                    }
                    else
                    {
                        data.Add((0).GetBytes());
                        data.Add(getTexIDAndStoreSize(texture_, texture.Item2.Priority, texture_and_index).GetBytes());
                    }
                }

                data.Add(uniforms.Count.GetBytes());

                foreach (var uniform in uniforms)
                {
                    float[] floats = new float[4];

                    if (uniform.Item1 == null)
                    {
                        floats = uniform.Item2.DefaultValues.ToArray();
                    }
                    else if (uniform.Item1.Value is Data.Value.Float)
                    {
                        floats[0] = (uniform.Item1.Value as Data.Value.Float).Value;
                    }
                    else if (uniform.Item1.Value is Data.Value.Vector4D)
                    {
                        floats[0] = (uniform.Item1.Value as Data.Value.Vector4D).X.Value;
                        floats[1] = (uniform.Item1.Value as Data.Value.Vector4D).Y.Value;
                        floats[2] = (uniform.Item1.Value as Data.Value.Vector4D).Z.Value;
                        floats[3] = (uniform.Item1.Value as Data.Value.Vector4D).W.Value;
                    }

                    data.Add(floats[0].GetBytes());
                    data.Add(floats[1].GetBytes());
                    data.Add(floats[2].GetBytes());
                    data.Add(floats[3].GetBytes());
                }
            }

            data.Add(value.AlphaBlend);
            data.Add(value.Filter);
            data.Add(value.Wrap);

            data.Add(value.Filter2);
            data.Add(value.Wrap2);

            if (value.ZTest.GetValue())
            {
                data.Add((1).GetBytes());
            }
            else
            {
                data.Add((0).GetBytes());
            }

            if (value.ZWrite.GetValue())
            {
                data.Add((1).GetBytes());
            }
            else
            {
                data.Add((0).GetBytes());
            }

            data.Add(value.FadeInType);
            if (value.FadeInType.Value == Data.RendererCommonValues.FadeType.Use)
            {
                data.Add(value.FadeIn.Frame.GetBytes());

                var easing = Utl.MathUtl.Easing((float)value.FadeIn.StartSpeed.Value, (float)value.FadeIn.EndSpeed.Value);
                data.Add(BitConverter.GetBytes(easing[0]));
                data.Add(BitConverter.GetBytes(easing[1]));
                data.Add(BitConverter.GetBytes(easing[2]));
            }

            data.Add(value.FadeOutType);
            if (value.FadeOutType.Value == Data.RendererCommonValues.FadeType.Use)
            {
                data.Add(value.FadeOut.Frame.GetBytes());

                var easing = Utl.MathUtl.Easing((float)value.FadeOut.StartSpeed.Value, (float)value.FadeOut.EndSpeed.Value);
                data.Add(BitConverter.GetBytes(easing[0]));
                data.Add(BitConverter.GetBytes(easing[1]));
                data.Add(BitConverter.GetBytes(easing[2]));
            }

            // sprcification change(1.5)
            float width  = 128.0f;
            float height = 128.0f;

            if (texInfo.Width > 0 && texInfo.Height > 0)
            {
                width  = (float)texInfo.Width;
                height = (float)texInfo.Height;
            }

            data.Add(value.UV);
            if (value.UV.Value == Data.RendererCommonValues.UVType.Default)
            {
            }
            else if (value.UV.Value == Data.RendererCommonValues.UVType.Fixed)
            {
                var value_ = value.UVFixed;
                data.Add((value_.Start.X / width).GetBytes());
                data.Add((value_.Start.Y / height).GetBytes());
                data.Add((value_.Size.X / width).GetBytes());
                data.Add((value_.Size.Y / height).GetBytes());
            }
            else if (value.UV.Value == Data.RendererCommonValues.UVType.Animation)
            {
                var value_ = value.UVAnimation;
                data.Add((value_.Start.X / width).GetBytes());
                data.Add((value_.Start.Y / height).GetBytes());
                data.Add((value_.Size.X / width).GetBytes());
                data.Add((value_.Size.Y / height).GetBytes());

                if (value_.FrameLength.Infinite)
                {
                    var inf = int.MaxValue / 100;
                    data.Add(inf.GetBytes());
                }
                else
                {
                    data.Add(value_.FrameLength.Value.Value.GetBytes());
                }

                data.Add(value_.FrameCountX.Value.GetBytes());
                data.Add(value_.FrameCountY.Value.GetBytes());
                data.Add(value_.LoopType);

                data.Add(value_.StartSheet.Max.GetBytes());
                data.Add(value_.StartSheet.Min.GetBytes());
            }
            else if (value.UV.Value == Data.RendererCommonValues.UVType.Scroll)
            {
                var value_ = value.UVScroll;
                data.Add((value_.Start.X.Max / width).GetBytes());
                data.Add((value_.Start.Y.Max / height).GetBytes());
                data.Add((value_.Start.X.Min / width).GetBytes());
                data.Add((value_.Start.Y.Min / height).GetBytes());

                data.Add((value_.Size.X.Max / width).GetBytes());
                data.Add((value_.Size.Y.Max / height).GetBytes());
                data.Add((value_.Size.X.Min / width).GetBytes());
                data.Add((value_.Size.Y.Min / height).GetBytes());

                data.Add((value_.Speed.X.Max / width).GetBytes());
                data.Add((value_.Speed.Y.Max / height).GetBytes());
                data.Add((value_.Speed.X.Min / width).GetBytes());
                data.Add((value_.Speed.Y.Min / height).GetBytes());
            }
            else if (value.UV.Value == Data.RendererCommonValues.UVType.FCurve)
            {
                {
                    var           value_ = value.UVFCurve.Start;
                    var           bytes1 = value_.GetBytes(1.0f / width);
                    List <byte[]> _data  = new List <byte[]>();
                    data.Add(bytes1);
                }

                {
                    var           value_ = value.UVFCurve.Size;
                    var           bytes1 = value_.GetBytes(1.0f / height);
                    List <byte[]> _data  = new List <byte[]>();
                    data.Add(bytes1);
                }
            }


            // Inheritance
            data.Add(value.ColorInheritType.GetValueAsInt().GetBytes());

            // Distortion
            data.Add(value.DistortionIntensity.GetBytes());

            // Custom data1 from 1.5
            data.Add(value.CustomData1.CustomData);
            if (value.CustomData1.CustomData.Value == Data.CustomDataType.Fixed2D)
            {
                data.Add(BitConverter.GetBytes(value.CustomData1.Fixed.X.Value));
                data.Add(BitConverter.GetBytes(value.CustomData1.Fixed.Y.Value));
            }
            else if (value.CustomData1.CustomData.Value == Data.CustomDataType.Easing2D)
            {
                var easing = Utl.MathUtl.Easing((float)value.CustomData1.Easing.StartSpeed.Value, (float)value.CustomData1.Easing.EndSpeed.Value);

                List <byte[]> _data = new List <byte[]>();
                _data.Add(value.CustomData1.Easing.Start.GetBytes(1.0f));
                _data.Add(value.CustomData1.Easing.End.GetBytes(1.0f));
                _data.Add(BitConverter.GetBytes(easing[0]));
                _data.Add(BitConverter.GetBytes(easing[1]));
                _data.Add(BitConverter.GetBytes(easing[2]));
                var __data = _data.ToArray().ToArray();
                data.Add(__data);
            }
            else if (value.CustomData1.CustomData.Value == Data.CustomDataType.FCurve2D)
            {
                var value_ = value.CustomData1.FCurve;
                var bytes1 = value_.GetBytes(1.0f);
                data.Add(bytes1);
            }
            else if (value.CustomData1.CustomData.Value == Data.CustomDataType.Fixed4D)
            {
                data.Add(BitConverter.GetBytes(value.CustomData1.Fixed4.X.Value));
                data.Add(BitConverter.GetBytes(value.CustomData1.Fixed4.Y.Value));
                data.Add(BitConverter.GetBytes(value.CustomData1.Fixed4.Z.Value));
                data.Add(BitConverter.GetBytes(value.CustomData1.Fixed4.W.Value));
            }
            else if (value.CustomData1.CustomData.Value == Data.CustomDataType.FCurveColor)
            {
                var bytes = value.CustomData1.FCurveColor.GetBytes();
                data.Add(bytes);
            }

            // Custom data2 from 1.5
            data.Add(value.CustomData2.CustomData);
            if (value.CustomData2.CustomData.Value == Data.CustomDataType.Fixed2D)
            {
                data.Add(BitConverter.GetBytes(value.CustomData2.Fixed.X.Value));
                data.Add(BitConverter.GetBytes(value.CustomData2.Fixed.Y.Value));
            }
            else if (value.CustomData2.CustomData.Value == Data.CustomDataType.Easing2D)
            {
                var easing = Utl.MathUtl.Easing((float)value.CustomData2.Easing.StartSpeed.Value, (float)value.CustomData2.Easing.EndSpeed.Value);

                List <byte[]> _data = new List <byte[]>();
                _data.Add(value.CustomData2.Easing.Start.GetBytes(1.0f));
                _data.Add(value.CustomData2.Easing.End.GetBytes(1.0f));
                _data.Add(BitConverter.GetBytes(easing[0]));
                _data.Add(BitConverter.GetBytes(easing[1]));
                _data.Add(BitConverter.GetBytes(easing[2]));
                var __data = _data.ToArray().ToArray();
                data.Add(__data);
            }
            else if (value.CustomData2.CustomData.Value == Data.CustomDataType.FCurve2D)
            {
                var value_ = value.CustomData2.FCurve;
                var bytes1 = value_.GetBytes(1.0f);
                data.Add(bytes1);
            }
            else if (value.CustomData2.CustomData.Value == Data.CustomDataType.Fixed4D)
            {
                data.Add(BitConverter.GetBytes(value.CustomData2.Fixed4.X.Value));
                data.Add(BitConverter.GetBytes(value.CustomData2.Fixed4.Y.Value));
                data.Add(BitConverter.GetBytes(value.CustomData2.Fixed4.Z.Value));
                data.Add(BitConverter.GetBytes(value.CustomData2.Fixed4.W.Value));
            }
            else if (value.CustomData2.CustomData.Value == Data.CustomDataType.FCurveColor)
            {
                var bytes = value.CustomData2.FCurveColor.GetBytes();
                data.Add(bytes);
            }

            return(data.ToArray().ToArray());
        }
Пример #8
0
        /// <summary>
        /// エフェクトデータの出力
        /// </summary>
        /// <returns></returns>
        public byte[] Export(float magnification = 1.0f)
        {
            List <byte[]> data = new List <byte[]>();

            // ヘッダ
            data.Add(Encoding.UTF8.GetBytes("SKFE"));

            // バージョン
            data.Add(BitConverter.GetBytes(Version));

            // reset texture names
            UsedTextures = new HashSet <string>();

            UsedNormalTextures = new HashSet <string>();

            UsedDistortionTextures = new HashSet <string>();

            Sounds = new HashSet <string>();

            Models = new HashSet <string>();

#if MATERIAL_ENABLED
            HashSet <string> materials = new HashSet <string>();
#endif

            Action <Data.NodeBase> get_textures = null;
            get_textures = (node) =>
            {
                if (node is Data.Node)
                {
                    var _node = node as Data.Node;

                    if (!_node.IsRendered)
                    {
                    }
                    else
                    {
#if MATERIAL_ENABLED
                        if (_node.RendererCommonValues.Material.Value == Data.RendererCommonValues.MaterialType.Default)
                        {
                            var relative_path = _node.RendererCommonValues.ColorTexture.RelativePath;
                            if (relative_path != string.Empty)
                            {
                                if (_node.RendererCommonValues.Distortion.Value)
                                {
                                    if (!UsedDistortionTextures.Contains(relative_path))
                                    {
                                        UsedDistortionTextures.Add(relative_path);
                                    }
                                }
                                else
                                {
                                    if (!UsedTextures.Contains(relative_path))
                                    {
                                        UsedTextures.Add(relative_path);
                                    }
                                }
                            }
                        }
                        else if (_node.RendererCommonValues.Material.Value == Data.RendererCommonValues.MaterialType.File)
                        {
                            var materialInfo = new Utl.MaterialInformation();
                            materialInfo.Load(_node.RendererCommonValues.MaterialFile.Path.AbsolutePath);

                            var textures = _node.RendererCommonValues.MaterialFile.GetTextures(materialInfo);

                            foreach (var texture in textures)
                            {
                                var relative_path = texture.Item1.RelativePath;
                                if (relative_path != string.Empty)
                                {
                                    if (texture.Item2)
                                    {
                                        if (!UsedNormalTextures.Contains(relative_path))
                                        {
                                            UsedNormalTextures.Add(relative_path);
                                        }
                                    }
                                    else
                                    {
                                        if (!UsedTextures.Contains(relative_path))
                                        {
                                            UsedTextures.Add(relative_path);
                                        }
                                    }
                                }
                            }
                        }
#else
                        {
                            var relative_path = _node.RendererCommonValues.ColorTexture.RelativePath;
                            if (relative_path != string.Empty)
                            {
                                if (_node.RendererCommonValues.Distortion.Value)
                                {
                                    if (!UsedDistortionTextures.Contains(relative_path))
                                    {
                                        UsedDistortionTextures.Add(relative_path);
                                    }
                                }
                                else
                                {
                                    if (!UsedTextures.Contains(relative_path))
                                    {
                                        UsedTextures.Add(relative_path);
                                    }
                                }
                            }
                        }
#endif
                        {
                            var relative_path = _node.DrawingValues.Model.NormalTexture.RelativePath;
                            if (relative_path != string.Empty)
                            {
                                if (!UsedNormalTextures.Contains(relative_path))
                                {
                                    UsedNormalTextures.Add(relative_path);
                                }
                            }
                        }
                    }
                }

                for (int i = 0; i < node.Children.Count; i++)
                {
                    get_textures(node.Children[i]);
                }
            };

            get_textures(Core.Root);

            Dictionary <string, int> texture_and_index = new Dictionary <string, int>();
            {
                int index = 0;
                foreach (var texture in UsedTextures.ToList().OrderBy(_ => _))
                {
                    texture_and_index.Add(texture, index);
                    index++;
                }
            }

            Dictionary <string, int> normalTexture_and_index = new Dictionary <string, int>();
            {
                int index = 0;
                foreach (var texture in UsedNormalTextures.ToList().OrderBy(_ => _))
                {
                    normalTexture_and_index.Add(texture, index);
                    index++;
                }
            }

            Dictionary <string, int> distortionTexture_and_index = new Dictionary <string, int>();
            {
                int index = 0;
                foreach (var texture in UsedDistortionTextures.ToList().OrderBy(_ => _))
                {
                    distortionTexture_and_index.Add(texture, index);
                    index++;
                }
            }

            Action <Data.NodeBase> get_waves = null;
            get_waves = (node) =>
            {
                if (node is Data.Node)
                {
                    var _node = node as Data.Node;

                    if (_node.SoundValues.Type.GetValue() == Data.SoundValues.ParamaterType.None)
                    {
                    }
                    else if (_node.SoundValues.Type.GetValue() == Data.SoundValues.ParamaterType.Use)
                    {
                        var relative_path = _node.SoundValues.Sound.Wave.RelativePath;
                        if (relative_path != string.Empty)
                        {
                            if (!Sounds.Contains(relative_path))
                            {
                                Sounds.Add(relative_path);
                            }
                        }
                    }
                }

                for (int i = 0; i < node.Children.Count; i++)
                {
                    get_waves(node.Children[i]);
                }
            };

            get_waves(Core.Root);

            Dictionary <string, int> wave_and_index = new Dictionary <string, int>();
            {
                int index = 0;
                foreach (var wave in Sounds.ToList().OrderBy(_ => _))
                {
                    wave_and_index.Add(wave, index);
                    index++;
                }
            }

            Action <Data.NodeBase> get_models = null;
            get_models = (node) =>
            {
                if (node is Data.Node)
                {
                    var _node = node as Data.Node;

                    if (_node.IsRendered && _node.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Model)
                    {
                        var relative_path = _node.DrawingValues.Model.Model.RelativePath;

                        if (!string.IsNullOrEmpty(relative_path))
                        {
                            if (string.IsNullOrEmpty(System.IO.Path.GetDirectoryName(relative_path)))
                            {
                                relative_path = System.IO.Path.GetFileNameWithoutExtension(relative_path) + ".efkmodel";
                            }
                            else
                            {
                                relative_path = System.IO.Path.GetDirectoryName(relative_path) + "/" + System.IO.Path.GetFileNameWithoutExtension(relative_path) + ".efkmodel";
                            }

                            if (relative_path != string.Empty)
                            {
                                if (!Models.Contains(relative_path))
                                {
                                    Models.Add(relative_path);
                                }
                            }
                        }
                    }

                    if (_node.GenerationLocationValues.Type.Value == Data.GenerationLocationValues.ParameterType.Model)
                    {
                        var relative_path = _node.GenerationLocationValues.Model.Model.RelativePath;

                        if (!string.IsNullOrEmpty(relative_path))
                        {
                            if (string.IsNullOrEmpty(System.IO.Path.GetDirectoryName(relative_path)))
                            {
                                relative_path = System.IO.Path.GetFileNameWithoutExtension(relative_path) + ".efkmodel";
                            }
                            else
                            {
                                relative_path = System.IO.Path.GetDirectoryName(relative_path) + "/" + System.IO.Path.GetFileNameWithoutExtension(relative_path) + ".efkmodel";
                            }

                            if (relative_path != string.Empty)
                            {
                                if (!Models.Contains(relative_path))
                                {
                                    Models.Add(relative_path);
                                }
                            }
                        }
                    }
                }

                for (int i = 0; i < node.Children.Count; i++)
                {
                    get_models(node.Children[i]);
                }
            };

            get_models(Core.Root);

            Dictionary <string, int> model_and_index = new Dictionary <string, int>();
            {
                int index = 0;
                foreach (var model in Models.ToList().OrderBy(_ => _))
                {
                    model_and_index.Add(model, index);
                    index++;
                }
            }

#if MATERIAL_ENABLED
            Action <Data.NodeBase> get_materials = null;
            get_materials = (node) =>
            {
                if (node is Data.Node)
                {
                    var _node = node as Data.Node;

                    if (_node.RendererCommonValues.Material.Value == Data.RendererCommonValues.MaterialType.File)
                    {
                        var relative_path = _node.RendererCommonValues.MaterialFile.Path.RelativePath;
                        if (relative_path != string.Empty)
                        {
                            if (!materials.Contains(relative_path))
                            {
                                materials.Add(relative_path);
                            }
                        }
                    }
                }

                for (int i = 0; i < node.Children.Count; i++)
                {
                    get_materials(node.Children[i]);
                }
            };

            get_materials(Core.Root);

            Dictionary <string, int> material_and_index = new Dictionary <string, int>();
            {
                int index = 0;
                foreach (var wave in materials.ToList().OrderBy(_ => _))
                {
                    material_and_index.Add(wave, index);
                    index++;
                }
            }
#endif

            // get all nodes
            var nodes = new List <Data.Node>();

            Action <Data.NodeBase> get_nodes = null;
            get_nodes = (node) =>
            {
                if (node is Data.Node)
                {
                    var _node = node as Data.Node;
                    nodes.Add(_node);
                }

                for (int i = 0; i < node.Children.Count; i++)
                {
                    get_nodes(node.Children[i]);
                }
            };

            get_nodes(Core.Root);

            var snode2ind = nodes.
                            Select((v, i) => Tuple35.Create(v, i)).
                            OrderBy(_ => _.Item1.DepthValues.DrawingPriority.Value * 255 + _.Item2).
                            Select((v, i) => Tuple35.Create(v.Item1, i)).ToList();

            // ファイルにテクスチャ一覧出力
            data.Add(BitConverter.GetBytes(texture_and_index.Count));
            foreach (var texture in texture_and_index)
            {
                var path = Encoding.Unicode.GetBytes(texture.Key);
                data.Add(((path.Count() + 2) / 2).GetBytes());
                data.Add(path);
                data.Add(new byte[] { 0, 0 });
            }

            data.Add(BitConverter.GetBytes(normalTexture_and_index.Count));
            foreach (var texture in normalTexture_and_index)
            {
                var path = Encoding.Unicode.GetBytes(texture.Key);
                data.Add(((path.Count() + 2) / 2).GetBytes());
                data.Add(path);
                data.Add(new byte[] { 0, 0 });
            }

            data.Add(BitConverter.GetBytes(distortionTexture_and_index.Count));
            foreach (var texture in distortionTexture_and_index)
            {
                var path = Encoding.Unicode.GetBytes(texture.Key);
                data.Add(((path.Count() + 2) / 2).GetBytes());
                data.Add(path);
                data.Add(new byte[] { 0, 0 });
            }

            // ファイルにウェーブ一覧出力
            data.Add(BitConverter.GetBytes(wave_and_index.Count));
            foreach (var wave in wave_and_index)
            {
                var path = Encoding.Unicode.GetBytes(wave.Key);
                data.Add(((path.Count() + 2) / 2).GetBytes());
                data.Add(path);
                data.Add(new byte[] { 0, 0 });
            }

            // ファイルにモデル一覧出力
            data.Add(BitConverter.GetBytes(model_and_index.Count));
            foreach (var model in model_and_index)
            {
                var path = Encoding.Unicode.GetBytes(model.Key);
                data.Add(((path.Count() + 2) / 2).GetBytes());
                data.Add(path);
                data.Add(new byte[] { 0, 0 });
            }

#if MATERIAL_ENABLED
            // export materials to a file
            data.Add(BitConverter.GetBytes(material_and_index.Count));
            foreach (var material in material_and_index)
            {
                var path = Encoding.Unicode.GetBytes(material.Key);
                data.Add(((path.Count() + 2) / 2).GetBytes());
                data.Add(path);
                data.Add(new byte[] { 0, 0 });
            }
#endif

            // export dynamic parameters
            data.Add(BitConverter.GetBytes(Core.Dynamic.Inputs.Values.Count));
            foreach (var value in Core.Dynamic.Inputs.Values)
            {
                float value_ = value.Input.Value;
                data.Add(BitConverter.GetBytes(value_));
            }

            data.Add(BitConverter.GetBytes(Core.Dynamic.Equations.Values.Count));

            var compiler = new InternalScript.Compiler();

            foreach (var value in Core.Dynamic.Equations.Values)
            {
                var cx = compiler.Compile(value.Code.Value);

                var cs = new [] { cx };

                foreach (var c in cs)
                {
                    if (c.Bytecode != null)
                    {
                        data.Add(BitConverter.GetBytes((int)c.Bytecode.Length));
                        data.Add(c.Bytecode);
                    }
                    else
                    {
                        data.Add(BitConverter.GetBytes((int)0));
                    }
                }
            }

            // Export the number of nodes
            data.Add(BitConverter.GetBytes(snode2ind.Count));

            var renderPriorityThreshold = snode2ind.Where(_ => _.Item1.DepthValues.DrawingPriority.Value < 0).Count();
            data.Add(BitConverter.GetBytes(renderPriorityThreshold));

            // Export magnification
            data.Add(BitConverter.GetBytes(magnification));

            // Export default seed
            int randomSeed = Core.Global.RandomSeed.Value;
            data.Add(BitConverter.GetBytes(randomSeed));

            // カリングを出力
            data.Add(BitConverter.GetBytes((int)Core.Culling.Type.Value));

            if (Core.Culling.Type.Value == Data.EffectCullingValues.ParamaterType.Sphere)
            {
                data.Add(BitConverter.GetBytes(Core.Culling.Sphere.Radius));
                data.Add(BitConverter.GetBytes(Core.Culling.Sphere.Location.X));
                data.Add(BitConverter.GetBytes(Core.Culling.Sphere.Location.Y));
                data.Add(BitConverter.GetBytes(Core.Culling.Sphere.Location.Z));
            }

            // ノード情報出力
            Action <Data.NodeRoot> outout_rootnode = null;
            Action <Data.Node>     outout_node     = null;

            outout_rootnode = (n) =>
            {
                data.Add(((int)NodeType.Root).GetBytes());
                data.Add(n.Children.Count.GetBytes());
                for (int i = 0; i < n.Children.Count; i++)
                {
                    outout_node(n.Children[i]);
                }
            };

            outout_node = (n) =>
            {
                List <byte[]> node_data = new List <byte[]>();

                var isRenderParamExported = n.IsRendered.GetValue();

                for (int i = 0; i < n.Children.Count; i++)
                {
                    var nc = n.Children[i];
                    var v  = nc.RendererCommonValues.ColorInheritType.GetValue();
                    if (v == Data.ParentEffectType.Already || v == Data.ParentEffectType.WhenCreating)
                    {
                        isRenderParamExported = true;
                        break;
                    }
                }

                if (!isRenderParamExported)
                {
                    data.Add(((int)NodeType.None).GetBytes());
                }
                else if (n.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.None)
                {
                    data.Add(((int)NodeType.None).GetBytes());
                }
                else if (n.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Sprite)
                {
                    data.Add(((int)NodeType.Sprite).GetBytes());
                }
                else if (n.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Ribbon)
                {
                    data.Add(((int)NodeType.Ribbon).GetBytes());
                }
                else if (n.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Ring)
                {
                    data.Add(((int)NodeType.Ring).GetBytes());
                }
                else if (n.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Model)
                {
                    data.Add(((int)NodeType.Model).GetBytes());
                }
                else if (n.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Track)
                {
                    data.Add(((int)NodeType.Track).GetBytes());
                }
                else
                {
                    throw new Exception();
                }

                // Whether to draw the node.
                if (n.IsRendered)
                {
                    int v = 1;
                    node_data.Add(BitConverter.GetBytes(v));
                }
                else
                {
                    int v = 0;
                    node_data.Add(BitConverter.GetBytes(v));
                }

                // render order
                {
                    var s = snode2ind.FirstOrDefault(_ => _.Item1 == n);
                    if (s.Item1 != null)
                    {
                        node_data.Add(BitConverter.GetBytes(s.Item2));
                    }
                    else
                    {
                        node_data.Add(BitConverter.GetBytes(-1));
                    }
                }

                node_data.Add(CommonValues.GetBytes(n.CommonValues));
                node_data.Add(LocationValues.GetBytes(n.LocationValues, n.CommonValues.ScaleEffectType));
                node_data.Add(LocationAbsValues.GetBytes(n.LocationAbsValues, n.CommonValues.ScaleEffectType));
                node_data.Add(RotationValues.GetBytes(n.RotationValues));
                node_data.Add(ScaleValues.GetBytes(n.ScalingValues, n.CommonValues.ScaleEffectType));
                node_data.Add(GenerationLocationValues.GetBytes(n.GenerationLocationValues, n.CommonValues.ScaleEffectType, model_and_index));

                // Export depth
                node_data.Add(n.DepthValues.DepthOffset.Value.GetBytes());
                node_data.Add(BitConverter.GetBytes(n.DepthValues.IsScaleChangedDependingOnDepthOffset.Value ? 1 : 0));
                node_data.Add(BitConverter.GetBytes(n.DepthValues.IsDepthOffsetChangedDependingOnParticleScale.Value ? 1 : 0));
                node_data.Add(((int)n.DepthValues.ZSort.Value).GetBytes());
                node_data.Add(n.DepthValues.DrawingPriority.Value.GetBytes());
                node_data.Add(n.DepthValues.SoftParticle.Value.GetBytes());

#if MATERIAL_ENABLED
                node_data.Add(RendererCommonValues.GetBytes(n.RendererCommonValues, texture_and_index, normalTexture_and_index, distortionTexture_and_index, material_and_index));
#else
                node_data.Add(RendererCommonValues.GetBytes(n.RendererCommonValues, texture_and_index, distortionTexture_and_index));
#endif

                if (isRenderParamExported)
                {
                    node_data.Add(RendererValues.GetBytes(n.DrawingValues, texture_and_index, normalTexture_and_index, model_and_index));
                }
                else
                {
                    node_data.Add(RendererValues.GetBytes(null, texture_and_index, normalTexture_and_index, model_and_index));
                }

                data.Add(node_data.ToArray().ToArray());

                data.Add(SoundValues.GetBytes(n.SoundValues, wave_and_index));

                data.Add(n.Children.Count.GetBytes());
                for (int i = 0; i < n.Children.Count; i++)
                {
                    outout_node(n.Children[i]);
                }
            };

            outout_rootnode(Core.Root);

            return(data.ToArray().ToArray());
        }