예제 #1
0
 /// <summary>
 /// Clears all file systems.
 /// </summary>
 public void Clear()
 {
     ModelFiles.Clear();
     TextureFiles.Clear();
     EffectFiles.Clear();
     Objects.Clear();
 }
예제 #2
0
        private void PopulateFromProcessorInfo(ProcessorInfo info)
        {
            ModelFiles.files.Clear();
            foreach (string m in info.models)
            {
                ModelFiles.Add(m, false);
            }
            ModelFiles.RefreshList();

            TextureFiles.files.Clear();
            foreach (string t in info.textures)
            {
                TextureFiles.Add(t, false);
            }
            TextureFiles.RefreshList();

            DoMergeModels.IsChecked      = info.mergeModels;
            Padding.Value                = info.padding;
            DoKeepTransparency.IsChecked = info.keepTransparency;

            string[] exportIds = (string[])ExportModelFormats.Tag;
            ExportModelFormats.SelectedIndex   = Array.IndexOf(exportIds, info.modelExportFormatId);
            ExportTextureFormats.SelectedIndex = (int)info.textureOutputType;

            FilesPrefix.Text         = info.outputFilesPrefix;
            ExportDirectory.FullPath = info.outputDir;
        }
예제 #3
0
        private IntPtr HandleDropFiles(IntPtr hDrop)
        {
            const int MAX_PATH = 260;

            uint count = DragQueryFile(hDrop, 0xFFFFFFFF, null, 0);

            for (uint i = 0; i < count; i++)
            {
                int size = (int)DragQueryFile(hDrop, i, null, 0);

                StringBuilder filename = new StringBuilder(size + 1);
                DragQueryFile(hDrop, i, filename, MAX_PATH);

                string droppedFile = filename.ToString();

                if (Path.GetExtension(droppedFile) == ".xml")
                {
                    LoadSettingsFile(droppedFile);
                    break;
                }

                if (Utils.IsModelExtensionSupported(Path.GetExtension(droppedFile)))
                {
                    ModelFiles.Add(droppedFile, false);
                }
                else
                {
                    if (Utils.IsImageSupported(droppedFile))
                    {
                        TextureFiles.Add(droppedFile, false);
                    }
                    else
                    {
                        Log.Line(LogType.Warning, "Dropped file '{0}' is not supported", droppedFile);
                    }
                }
            }

            DragFinish(hDrop);

            ModelFiles.RefreshList();
            TextureFiles.RefreshList();

            return(IntPtr.Zero);
        }
예제 #4
0
        /// <summary>
        /// Loads the file from the specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public override void Load(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream, Encoding.GetEncoding("us-ascii"));

            short modelFileCount = reader.ReadInt16();

            for (int i = 0; i < modelFileCount; i++)
            {
                string modelFile = reader.ReadNullTerminatedString();

                ModelFiles.Add(modelFile);
            }

            short textureFileCount = reader.ReadInt16();

            for (int i = 0; i < textureFileCount; i++)
            {
                TextureFile texture = new TextureFile();
                texture.FilePath          = reader.ReadNullTerminatedString();
                texture.UseSkinShader     = reader.ReadInt16() != 0;
                texture.AlphaEnabled      = reader.ReadInt16() != 0;
                texture.TwoSided          = reader.ReadInt16() != 0;
                texture.AlphaTestEnabled  = reader.ReadInt16() != 0;
                texture.AlphaReference    = reader.ReadInt16();
                texture.DepthTestEnabled  = reader.ReadInt16() != 0;
                texture.DepthWriteEnabled = reader.ReadInt16() != 0;
                texture.BlendType         = (BlendType)reader.ReadInt16();
                texture.UseSpecularShader = reader.ReadInt16() != 0;
                texture.Alpha             = reader.ReadSingle();
                texture.GlowType          = (GlowType)reader.ReadInt16();
                texture.GlowColour        = reader.ReadColour3();

                TextureFiles.Add(texture);
            }

            short effectFileCount = reader.ReadInt16();

            for (int i = 0; i < effectFileCount; i++)
            {
                string effectFile = reader.ReadNullTerminatedString();

                EffectFiles.Add(effectFile);
            }

            short objectCount = reader.ReadInt16();

            for (int i = 0; i < objectCount; i++)
            {
                ModelListObject @object = new ModelListObject();

                int cylinderRadius = reader.ReadInt32();
                @object.BoundingCylinder = new BoundingCylinder(new Vector2(reader.ReadInt32(), reader.ReadInt32()), cylinderRadius);

                int partCount = reader.ReadInt16();

                if (partCount > 0)
                {
                    for (int j = 0; j < partCount; j++)
                    {
                        ModelListPart part = new ModelListPart();
                        part.Model   = reader.ReadInt16();
                        part.Texture = reader.ReadInt16();

                        byte propertyType = 0;

                        while ((propertyType = reader.ReadByte()) != 0)
                        {
                            byte size = reader.ReadByte();

                            switch ((ModelListPropertyType)propertyType)
                            {
                            case ModelListPropertyType.Position:
                                part.Position = reader.ReadVector3();
                                break;

                            case ModelListPropertyType.Rotation:
                                part.Rotation = reader.ReadQuaternion(true);
                                break;

                            case ModelListPropertyType.Scale:
                                part.Scale = reader.ReadVector3();
                                break;

                            case ModelListPropertyType.AxisRotation:
                                part.AxisRotation = reader.ReadQuaternion(true);
                                break;

                            case ModelListPropertyType.Parent:
                                part.Parent = reader.ReadInt16();
                                break;

                            case ModelListPropertyType.Collision:
                                part.Collision = (CollisionType)reader.ReadInt16();
                                break;

                            case ModelListPropertyType.ConstantAnimation:
                                part.AnimationFilePath = reader.ReadString(size);
                                break;

                            case ModelListPropertyType.VisibleRangeSet:
                                part.VisibleRangeSet = reader.ReadInt16();
                                break;

                            case ModelListPropertyType.UseLightmap:
                                part.UseLightmap = reader.ReadInt16() != 0;
                                break;

                            case ModelListPropertyType.BoneIndex:
                                part.BoneIndex = reader.ReadInt16();
                                break;

                            case ModelListPropertyType.DummyIndex:
                                part.DummyIndex = reader.ReadInt16();
                                break;

                            default:
                                if (propertyType >= (int)ModelListPropertyType.Animation && propertyType < (int)ModelListPropertyType.Animation + ModelListPart.ANIMATION_COUNT)
                                {
                                    propertyType -= (int)ModelListPropertyType.Animation;

                                    if (propertyType < ModelListPart.MONSTER_ANIMATION_COUNT)
                                    {
                                        part.MonsterAnimations[propertyType] = reader.ReadString(size);
                                    }
                                    else
                                    {
                                        propertyType -= ModelListPart.MONSTER_ANIMATION_COUNT;
                                        part.AvatarAnimations[propertyType] = reader.ReadString(size);
                                    }
                                }
                                else
                                {
                                    stream.Seek(size, SeekOrigin.Current);
                                }
                                break;
                            }
                        }

                        @object.Parts.Add(part);
                    }

                    int effectCount = reader.ReadInt16();

                    for (int j = 0; j < effectCount; j++)
                    {
                        ModelListEffect effect = new ModelListEffect();
                        effect.EffectType = (EffectType)reader.ReadInt16();
                        effect.Effect     = reader.ReadInt16();

                        byte propertyType = 0;

                        while ((propertyType = reader.ReadByte()) != 0)
                        {
                            byte size = reader.ReadByte();

                            switch ((ModelListPropertyType)propertyType)
                            {
                            case ModelListPropertyType.Position:
                                effect.Position = reader.ReadVector3();
                                break;

                            case ModelListPropertyType.Rotation:
                                effect.Rotation = reader.ReadQuaternion(true);
                                break;

                            case ModelListPropertyType.Scale:
                                effect.Scale = reader.ReadVector3();
                                break;

                            case ModelListPropertyType.Parent:
                                effect.Parent = reader.ReadInt16();
                                break;

                            default:
                                stream.Seek(size, SeekOrigin.Current);
                                break;
                            }
                        }

                        @object.Effects.Add(effect);
                    }

                    @object.BoundingBox = new BoundingBox(reader.ReadVector3(), reader.ReadVector3());
                }

                Objects.Add(@object);
            }
        }
예제 #5
0
        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("us-ascii"));

            writer.Write((short)ModelFiles.Count);

            ModelFiles.ForEach(modelFile => {
                writer.WriteString(modelFile);
                writer.Write((byte)0);
            });

            writer.Write((short)TextureFiles.Count);

            TextureFiles.ForEach(texture => {
                writer.WriteString(texture.FilePath);
                writer.Write((byte)0);
                writer.Write((short)(texture.UseSkinShader ? 1 : 0));
                writer.Write((short)(texture.AlphaEnabled ? 1 : 0));
                writer.Write((short)(texture.TwoSided ? 1 : 0));
                writer.Write((short)(texture.AlphaTestEnabled ? 1 : 0));
                writer.Write(texture.AlphaReference);
                writer.Write((short)(texture.DepthTestEnabled ? 1 : 0));
                writer.Write((short)(texture.DepthWriteEnabled ? 1 : 0));
                writer.Write((short)texture.BlendType);
                writer.Write((short)(texture.UseSpecularShader ? 1 : 0));
                writer.Write(texture.Alpha);
                writer.Write((short)texture.GlowType);
                writer.Write(texture.GlowColour.ToVector3());
            });

            writer.Write((short)EffectFiles.Count);

            EffectFiles.ForEach(effectFile => {
                writer.WriteString(effectFile);
                writer.Write((byte)0);
            });

            writer.Write((short)Objects.Count);

            Objects.ForEach(@object => {
                writer.Write((int)@object.BoundingCylinder.Radius);
                writer.Write((int)@object.BoundingCylinder.Center.X);
                writer.Write((int)@object.BoundingCylinder.Center.Y);

                writer.Write((short)@object.Parts.Count);

                if (@object.Parts.Count > 0)
                {
                    @object.Parts.ForEach(part => {
                        writer.Write(part.Model);
                        writer.Write(part.Texture);

                        if (part.Position != Vector3.Zero)
                        {
                            writer.Write((byte)ModelListPropertyType.Position);
                            writer.Write((byte)(sizeof(float) * 3));
                            writer.Write(part.Position);
                        }

                        if (part.Rotation != Revise.Types.Utils.QuaternionZero)
                        {
                            writer.Write((byte)ModelListPropertyType.Rotation);
                            writer.Write((byte)(sizeof(float) * 4));
                            writer.Write(part.Rotation, true);
                        }

                        if (part.Scale != Vector3.Zero)
                        {
                            writer.Write((byte)ModelListPropertyType.Scale);
                            writer.Write((byte)(sizeof(float) * 3));
                            writer.Write(part.Scale);
                        }

                        if (part.AxisRotation != Revise.Types.Utils.QuaternionZero)
                        {
                            writer.Write((byte)ModelListPropertyType.AxisRotation);
                            writer.Write((byte)(sizeof(float) * 4));
                            writer.Write(part.AxisRotation, true);
                        }

                        if (part.Parent != 0)
                        {
                            writer.Write((byte)ModelListPropertyType.Parent);
                            writer.Write((byte)sizeof(short));
                            writer.Write(part.Parent);
                        }

                        if (part.Collision != 0)
                        {
                            writer.Write((byte)ModelListPropertyType.Collision);
                            writer.Write((byte)sizeof(short));
                            writer.Write((short)part.Collision);
                        }

                        if (string.Compare(part.AnimationFilePath, string.Empty) != 0)
                        {
                            writer.Write((byte)ModelListPropertyType.ConstantAnimation);
                            writer.WriteByteString(part.AnimationFilePath);
                        }

                        if (part.VisibleRangeSet != 0)
                        {
                            writer.Write((byte)ModelListPropertyType.VisibleRangeSet);
                            writer.Write((byte)sizeof(short));
                            writer.Write(part.VisibleRangeSet);
                        }

                        if (!part.UseLightmap)
                        {
                            writer.Write((byte)ModelListPropertyType.UseLightmap);
                            writer.Write((byte)sizeof(short));
                            writer.Write((short)0);
                        }

                        if (part.BoneIndex != 0)
                        {
                            writer.Write((byte)ModelListPropertyType.BoneIndex);
                            writer.Write((byte)sizeof(short));
                            writer.Write(part.BoneIndex);
                        }

                        if (part.DummyIndex != 0)
                        {
                            writer.Write((byte)ModelListPropertyType.DummyIndex);
                            writer.Write((byte)sizeof(short));
                            writer.Write(part.DummyIndex);
                        }

                        for (int i = 0; i < part.MonsterAnimations.Length; i++)
                        {
                            string animationFile = part.MonsterAnimations[i];

                            if (string.Compare(animationFile, string.Empty) != 0)
                            {
                                writer.Write((byte)((byte)ModelListPropertyType.Animation + i));
                                writer.WriteByteString(animationFile);
                            }
                        }

                        for (int i = 0; i < part.AvatarAnimations.Length; i++)
                        {
                            string animationFile = part.AvatarAnimations[i];

                            if (string.Compare(animationFile, string.Empty) != 0)
                            {
                                writer.Write((byte)((byte)ModelListPropertyType.Animation + ModelListPart.MONSTER_ANIMATION_COUNT + i));
                                writer.WriteByteString(animationFile);
                            }
                        }

                        writer.Write((byte)0);
                    });

                    writer.Write((short)@object.Effects.Count);

                    @object.Effects.ForEach(effect => {
                        writer.Write((short)effect.EffectType);
                        writer.Write(effect.Effect);

                        if (effect.Position != Vector3.Zero)
                        {
                            writer.Write((byte)ModelListPropertyType.Position);
                            writer.Write((byte)(sizeof(float) * 3));
                            writer.Write(effect.Position);
                        }

                        if (effect.Rotation != Revise.Types.Utils.QuaternionZero)
                        {
                            writer.Write((byte)ModelListPropertyType.Rotation);
                            writer.Write((byte)(sizeof(float) * 4));
                            writer.Write(effect.Rotation, true);
                        }

                        if (effect.Scale != Vector3.Zero)
                        {
                            writer.Write((byte)ModelListPropertyType.Scale);
                            writer.Write((byte)(sizeof(float) * 3));
                            writer.Write(effect.Scale);
                        }

                        if (effect.Parent != 0)
                        {
                            writer.Write((byte)ModelListPropertyType.Parent);
                            writer.Write((byte)sizeof(short));
                            writer.Write(effect.Parent);
                        }

                        writer.Write((byte)0);
                    });

                    writer.Write(@object.BoundingBox.Minimum);
                    writer.Write(@object.BoundingBox.Maximum);
                }
            });
        }
예제 #6
0
        private void AddParticlesClickHandler(object Sender, MouseButton eButton)
        {
            Particle2D   NewParticle;
            TextureFiles eTexture = TextureFiles.dirt_01;
            int          nCtr, nParticleCnt;
            Vector2      nHeight, nWidth, nRed, nGreen, nBlue, nLife, nDelay, nXDist, nYDist, nRotate;

            if (Int32.TryParse(cNumParticlesTxt.Text, out nParticleCnt) == false)
            {
                nParticleCnt = 1;
            }

            if ((float.TryParse(cHeightMinTxt.Text, out nHeight.X) == false) || (nHeight.X <= 0))
            {
                nHeight.X = cTextureDict[eTexture].Height / 2;
            }

            if ((float.TryParse(cHeightMaxTxt.Text, out nHeight.Y) == false) || (nHeight.X > nHeight.Y))
            {
                nHeight.Y = nHeight.X;
            }

            if ((float.TryParse(cHeightMinTxt.Text, out nWidth.X) == false) || (nWidth.X <= 0))
            {
                nWidth.X = cTextureDict[eTexture].Height / 2;
            }

            if ((float.TryParse(cHeightMaxTxt.Text, out nWidth.Y) == false) || (nWidth.X > nWidth.Y))
            {
                nWidth.Y = nWidth.X;
            }

            if ((float.TryParse(cRedMinTxt.Text, out nRed.X) == false) || (nRed.X < 0) || (nRed.X > 255))
            {
                nRed.X = 0;
            }

            if ((float.TryParse(cRedMaxTxt.Text, out nRed.Y) == false) || (nRed.X > nRed.Y) || (nRed.Y > 255))
            {
                nRed.Y = nRed.X;
            }

            if ((float.TryParse(cGreenMinTxt.Text, out nGreen.X) == false) || (nGreen.X < 0) || (nGreen.X > 255))
            {
                nGreen.X = 0;
            }

            if ((float.TryParse(cGreenMaxTxt.Text, out nGreen.Y) == false) || (nGreen.X > nGreen.Y) || (nGreen.Y > 255))
            {
                nGreen.Y = nGreen.X;
            }

            if ((float.TryParse(cBlueMinTxt.Text, out nBlue.X) == false) || (nBlue.X < 0) || (nBlue.X > 255))
            {
                nBlue.X = 0;
            }

            if ((float.TryParse(cBlueMaxTxt.Text, out nBlue.Y) == false) || (nBlue.X > nBlue.Y) || (nBlue.Y > 255))
            {
                nBlue.Y = nBlue.X;
            }

            if ((float.TryParse(cLifeMinTxt.Text, out nLife.X) == false) || (nLife.X < 0))
            {
                nLife.X = 1;
            }

            if ((float.TryParse(cLifeMaxTxt.Text, out nLife.Y) == false) || (nLife.X > nLife.Y))
            {
                nLife.Y = nLife.X;
            }

            if ((float.TryParse(cDelayMinTxt.Text, out nDelay.X) == false) || (nDelay.X < 0))
            {
                nDelay.X = 0;
            }

            if ((float.TryParse(cDelayMaxTxt.Text, out nDelay.Y) == false) || (nDelay.X > nDelay.Y))
            {
                nDelay.Y = nDelay.X;
            }

            if (float.TryParse(cXDistMinTxt.Text, out nXDist.X) == false)
            {
                nXDist.X = GraphicsDevice.Viewport.Width / -2;
            }

            if ((float.TryParse(cXDistMaxTxt.Text, out nXDist.Y) == false) || (nXDist.X > nXDist.Y))
            {
                nXDist.Y = nXDist.X;
            }

            if (float.TryParse(cYDistMinTxt.Text, out nYDist.X) == false)
            {
                nYDist.X = GraphicsDevice.Viewport.Height / -2;
            }

            if ((float.TryParse(cYDistMaxTxt.Text, out nYDist.Y) == false) || (nYDist.X > nYDist.Y))
            {
                nYDist.Y = nYDist.X;
            }

            if (float.TryParse(cRotateMinTxt.Text, out nRotate.X) == false)
            {
                nRotate.X = GraphicsDevice.Viewport.Height / -2;
            }

            if ((float.TryParse(cRotateMaxTxt.Text, out nRotate.Y) == false) || (nRotate.X > nRotate.Y))
            {
                nRotate.Y = nRotate.X;
            }

            if (eButton == MouseButton.Left)
            {
                for (nCtr = 0; nCtr < nParticleCnt; nCtr++)
                {
                    NewParticle = new Particle2D(GraphicsDevice);
                    //Particle images should be grayscale, allowing this tint value to color them
                    NewParticle.Tint  = new Color(cRand.Next((int)nRed.X, (int)nRed.Y), cRand.Next((int)nGreen.X, (int)nGreen.Y), cRand.Next((int)nBlue.X, (int)nBlue.Y));
                    NewParticle.Image = cTextureDict[eTexture];

                    //Set the dimensions of the image on screen
                    NewParticle.Height = cRand.Next((int)nHeight.X, (int)nHeight.Y);
                    NewParticle.Width  = cRand.Next((int)nWidth.X, (int)nWidth.Y);
                    //Set the position of the image
                    NewParticle.TopLeft.X = (GraphicsDevice.Viewport.Width / 2) - (NewParticle.Width / 2);
                    NewParticle.TopLeft.Y = (GraphicsDevice.Viewport.Height / 2) - (NewParticle.Height / 2);
                    NewParticle.Rotation  = (float)((cRand.Next(0, 360) * (2 * Math.PI)) / 360);

                    //Set the total movement the particle will travel
                    NewParticle.TotalDistance.X = cRand.Next((int)nXDist.X, (int)nXDist.Y);
                    NewParticle.TotalDistance.Y = cRand.Next((int)nYDist.X, (int)nYDist.Y);
                    NewParticle.TotalRotate     = (float)(cRand.Next((int)nRotate.X, (int)nRotate.Y) * 2 * Math.PI);

                    //Set how long the particle will live in milliseconds
                    NewParticle.TimeToLive   = cRand.Next((int)nLife.X, (int)nLife.Y);
                    NewParticle.tCreateDelay = cRand.Next((int)nDelay.X, (int)nDelay.Y);

                    NewParticle.AlphaFade   = cbAlphaFade;
                    NewParticle.bSpiralPath = cbRotateAfter;

                    cSparkles.AddParticle(NewParticle);
                }
            }

            return;
        }
예제 #7
0
        void OnAddCollection()
        {
            var textureSet = SelectedItem switch
            {
                TextureSetFile s => s,
                TileTextureCollection c => c.Parent,
                TextureGrid g => g.Parent?.Parent,
                TextureTile t => t.Parent?.Parent?.Parent,
           _ => null
            };

            textureSet?.Collections.Add(new TileTextureCollection()
            {
                Id = "New Collection"
            }.WithTextureGrid(new TextureGrid()

            {
                Name = "New Texture Grid"
            }));
        }

        void OnAddGrid()
        {
            var textureCollection = SelectedItem switch
            {
                TileTextureCollection c => c,
                TextureGrid g => g.Parent,
                TextureTile t => t.Parent?.Parent,
                _ => null
            };

            textureCollection?.Grids.Add(new TextureGrid()
            {
                Name = "New Texture Grid"
            });
        }

        void OnAddTile()
        {
            var textureGrid = SelectedItem switch
            {
                TextureGrid g => g,
                TextureTile t => t.Parent,
                _ => null
            };

            textureGrid?.Tiles.Add(new TextureTile());
        }

        bool HasAnySelection(object?selectedItem) => selectedItem != null;

        bool CanAddGrid(object?selectedItem) => selectedItem switch
        {
            TileTextureCollection => true,
            TextureGrid => true,
            TextureTile => true,
            _ => false
        };

        bool CanAddTile(object?selectedItem) => selectedItem switch
        {
            TextureGrid => true,
            TextureTile => true,
            _ => false
        };

        public Task OpenFile(string fileName)
        {
            try
            {
                var x = TextureSetFileLoader.Read(fileName);
                TextureFiles.Add(x);
                return(Task.CompletedTask);
            }
            catch (Exception e)
            {
                return(Task.FromException(e));
            }
        }