private NwCharacter ConvertCharacter(ImportedObject obj)
        {
            var c = new NwCharacter();

            {
                c.Name        = obj.Name;
                c.Description = obj.Description;
                c.Version     = obj.Version;
                c.Editor      = obj.Editor;
                c.EditorURL   = obj.EditorURL;

                var texs = new List <NwTexture2D>();
                foreach (var t in obj.Textures)
                {
                    var bm = AssetConverter.ToNwTexture2D(t.SrcBitmap, t.Name);
                    texs.Add(bm);
                }

                var cubes = new List <NwCubemap>();

                var mats = new List <NwMaterial>();
                foreach (var m in obj.Materials)
                {
                    var mat = AssetConverter.ToNwMaterial(m, m.Name, ref texs, ref cubes);
                    mats.Add(mat);
                }
                c.Texture2Ds = texs.ToArray();
                c.Cubemaps   = cubes.ToArray();
                c.Materials  = mats.ToArray();

                var bones = new List <NwBone>();
                foreach (var b in obj.Bones)
                {
                    var bone = AssetConverter.ToNwBone(b);
                    bones.Add(bone);
                }
                c.Bones = bones.ToArray();

                c.Mesh = AssetConverter.ToNwMesh(obj.Meshes[0]);

                c.CollisionShape = new NwCollisionCapsule()
                {
                    Height = 1.6f,
                    Radius = 0.3f,
                };

                c.Mass = 50.0f;
            }
            return(c);
        }
Beispiel #2
0
        public void OnCharacterLoaded(NwCharacter ch)
        {
            var chara = AssetConverter.FromNwCharacter(ch);

            MMW.Invoke(() =>
            {
                chara.Load();

                var go = CreateGameObject(chara, chara.Name, "Deferred Physical");
                go.AddComponent <CollisionRenderer>();
                MMW.RegistGameObject(go);

                gameObj = go;
            });
        }
Beispiel #3
0
        private byte[] ConvertCharacter(ImportedObject obj)
        {
            var ch = new NwCharacter();

            {
                ch.Name = obj.Name;

                var texs = new List <NwTexture2D>();
                foreach (var t in obj.Textures)
                {
                    var bm = AssetConverter.ToNwTexture2D(t.SrcBitmap, t.Name);
                    texs.Add(bm);
                }

                var cubes = new List <NwCubemap>();

                var mats = new List <NwMaterial>();
                foreach (var m in obj.Materials)
                {
                    var mat = AssetConverter.ToNwMaterial(m, m.Name, ref texs, ref cubes);
                    mats.Add(mat);
                }
                ch.Texture2Ds = texs.ToArray();
                ch.Cubemaps   = cubes.ToArray();
                ch.Materials  = mats.ToArray();

                var bones = new List <NwBone>();
                foreach (var b in obj.Bones)
                {
                    var bone = AssetConverter.ToNwBone(b);
                    bones.Add(bone);
                }
                ch.Bones = bones.ToArray();

                ch.Mesh = AssetConverter.ToNwMesh(obj.Meshes[0]);

                //ch.Height = 1.6f;
                //ch.WidthRadius = 0.3f;
                ch.EyePosition = new Vector3f(0.0f, 1.42f, 0.2f);
                ch.Mass        = 50.0f;
            }

            var json = Util.SerializeJson(ch);
            var comp = Util.Compress(Encoding.UTF8.GetBytes(json));

            return(comp);
        }
        private void menu_open_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.Filter = "MWCファイル|*.mwc|すべてのファイル|*.*";

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (Filepath != null)
            {
                var res = MessageBox.Show("すでにデータが読み込まれています。\r\n変更を破棄して新しく読み込みますか?", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (res == DialogResult.No)
                {
                    return;
                }
            }

            Clear();

            Cursor.Current = Cursors.WaitCursor;
            //try
            //{
            var data   = File.ReadAllBytes(ofd.FileName);
            var decomp = Util.Decompress(data);

            chara = Util.DeserializeJson <NwCharacter>(Encoding.UTF8.GetString(decomp));

            game.OnCharacterLoaded(chara);
            while (game.gameObj == null)
            {
                ;
            }
            SetControlParameters(chara);

            Filepath           = ofd.FileName;
            tabControl.Enabled = true;
            //}
            //catch
            //{
            //    MessageBox.Show("ファイルの読み込みに失敗しました。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    Clear();
            //}
            Cursor.Current = Cursors.Default;
        }
        private void menu_model_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.Filter = "対応ファイル|*.pmd;*.pmx;*.mqo|すべてのファイル|*.*";

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (Filepath != null)
            {
                var res = MessageBox.Show("すでにデータが読み込まれています。\r\n変更を破棄して新しく読み込みますか?", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (res == DialogResult.No)
                {
                    return;
                }
            }

            Clear();

            Cursor.Current = Cursors.WaitCursor;
            //try
            //{
            var ext      = Path.GetExtension(ofd.FileName);
            var importer = importers.Find((i) => Array.Exists(i.Extensions, (ex) => ex == ext));

            var o = importer.Import(ofd.FileName, ImportType.Full)[0];

            chara = ConvertCharacter(o);
            SetControlParameters(chara);
            game.OnCharacterLoaded(chara);
            tabControl.Enabled = true;
            //}
            //catch
            //{
            //    MessageBox.Show("ファイルの読み込みに失敗しました。", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            Cursor.Current = Cursors.Default;
        }
        private void SetControlParameters(NwCharacter obj)
        {
            // textures
            textures.AddRange(obj.Texture2Ds);

            // general
            textBox_name.Text    = obj.Name;
            textBox_version.Text = obj.Version;
            textBox_desc.Text    = obj.Description;
            textBox_editor.Text  = obj.Editor;
            textBox_url.Text     = obj.EditorURL;
            textBox_tags.Text    = obj.Tags;

            // materials
            listBox_material.DisplayMember = "Name";
            foreach (var mat in obj.Materials)
            {
                listBox_material.Items.Add(mat);
            }
            listBox_material.SelectedIndex = 0;

            // physics
            if (obj.CollisionShape is NwCollisionCapsule)
            {
                radioButton_capsule.Checked = true;
            }
            else if (obj.CollisionShape is NwCollisionCylinder)
            {
                radioButton_cylinder.Checked = true;
            }
            else if (obj.CollisionShape is NwCollisionBox)
            {
                radioButton_box.Checked = true;
            }
            else if (obj.CollisionShape is NwCollisionSphere)
            {
                radioButton_sphere.Checked = true;
            }

            numericUpDown_mass.Value = (decimal)obj.Mass;

            // motions
            foreach (var m in obj.Motions)
            {
                var i = dataGridView_motion.Rows.Add(m.Key, m.Name);
                dataGridView_motion.Rows[i].Tag = m;
            }

            // morphs

            // sounds
            foreach (var s in obj.Sounds)
            {
                var i   = dataGridView_sound.Rows.Add();
                var row = dataGridView_sound.Rows[i];
                row.Cells[0].Value = s.Name;

                var path = System.Environment.CurrentDirectory + "/tempsound_" + Util.CreateHash();
                File.WriteAllBytes(path, s.Data);
                var afd     = new AudioFileReader(path);
                var waveOut = new WaveOut();
                waveOut.Init(afd);

                row.Tag = new Tuple <AudioFileReader, WaveOut, byte[], string>(afd, waveOut, s.Data, s.Format);
            }

            // scripts
            foreach (var s in obj.Scripts)
            {
                var asm  = Assembly.Load(s.Assembly);
                var type = asm.GetExportedTypes().Where(t => t.IsSubclassOf(typeof(GameObjectScript))).ToArray()[0];
                var inst = asm.CreateInstance(type.FullName) as GameObjectScript;

                listBox_scripts.Items.Add(new ScriptInfo()
                {
                    Assembly = s.Assembly,
                    Script   = inst,
                });
            }

            // property
            var idx = 0;

            foreach (var p in obj.Properties)
            {
                idx = dataGridView_property.Rows.Add(1);
                dataGridView_property[0, idx].Value = p.Key;
                dataGridView_property[1, idx].Value = p.Value;
            }
        }
Beispiel #7
0
        public static Character FromNwCharacter(NwCharacter ch)
        {
            var c = new Character();

            c.nwCharacter = ch;
            c.Name        = ch.Name;
            c.Texture2Ds  = new Texture2D[ch.Texture2Ds.Length];
            for (var i = 0; i < ch.Texture2Ds.Length; i++)
            {
                c.Texture2Ds[i]           = FromNwTexture2D(ch.Texture2Ds[i]);
                c.Texture2Ds[i].UseMipmap = true;
                c.Texture2Ds[i].MinFilter = OpenTK.Graphics.OpenGL4.TextureMinFilter.LinearMipmapLinear;
                c.Texture2Ds[i].MagFilter = OpenTK.Graphics.OpenGL4.TextureMagFilter.Linear;
                c.Texture2Ds[i].WrapMode  = OpenTK.Graphics.OpenGL4.TextureWrapMode.Repeat;
            }

            c.TextureCubes = new TextureCube[ch.Cubemaps.Length];
            for (var i = 0; i < ch.Cubemaps.Length; i++)
            {
                c.TextureCubes[i]           = FromNwTextureCube(ch.Cubemaps[i]);
                c.TextureCubes[i].UseMipmap = true;
                c.TextureCubes[i].MinFilter = OpenTK.Graphics.OpenGL4.TextureMinFilter.LinearMipmapLinear;
                c.TextureCubes[i].MagFilter = OpenTK.Graphics.OpenGL4.TextureMagFilter.Linear;
                c.TextureCubes[i].WrapMode  = OpenTK.Graphics.OpenGL4.TextureWrapMode.Repeat;
            }

            if (ch.Bones != null && ch.Bones.Length > 0)
            {
                c.Bones = FromNwBones(ch.Bones);
            }

            c.Mesh = FromNwMesh(ch.Mesh);

            c.Materials = new Material[ch.Materials.Length];
            for (var i = 0; i < ch.Materials.Length; i++)
            {
                c.Materials[i] = FromNwMaterial(ch.Materials[i], ref ch.Texture2Ds, ref c.Texture2Ds);
            }

            if (ch.EyePosition == null)
            {
                ch.EyePosition = new Vector3f(0.0f, 1.4f, 0.1f);
            }
            c.EyePosition      = new Vector3(ch.EyePosition.X, ch.EyePosition.Y, ch.EyePosition.Z);
            c.PhysicalMaterial = new PhysicalMaterial()
            {
                Mass = ch.Mass,
            };

            c.Sounds = new Sound[ch.Sounds.Length];
            for (var i = 0; i < c.Sounds.Length; i++)
            {
                c.Sounds[i] = FromNwSound(ch.Sounds[i]);
            }

            c.Motions = new Motion[ch.Motions.Length];
            for (var i = 0; i < c.Motions.Length; i++)
            {
                c.Motions[i] = FromNwMotion(ch.Motions[i]);
            }

            var scripts = new List <Assembly>();

            foreach (var s in ch.Scripts)
            {
                try
                {
                    var asm = Assembly.Load(s.Assembly);
                    scripts.Add(asm);
                }
                catch { }
            }
            c.Scripts = scripts.ToArray();

            c.Properties = ch.Properties;

            c.CollisionShape = FromNwCollisionShape(ch.CollisionShape);

            return(c);
        }