Ejemplo n.º 1
0
        private GameObject CreateMqoObject(string filename)
        {
            var results = mqoImporter.Import(filename, ImportType.Full);

            foreach (var tex in results[0].Textures)
            {
                tex.Load();
            }
            foreach (var mesh in results[0].Meshes)
            {
                mesh.Load();
            }
            foreach (var mat in results[0].Materials)
            {
                mat.Shader = MMW.GetAsset <Shader>("Toon Shadow");
            }

            var obj = new GameObject(results[0].Name, Matrix4.Identity, "mqo");

            for (var i = 0; i < results[0].Meshes.Length; i++)
            {
                var mr = obj.AddComponent <MeshRenderer>();
                mr.Mesh = results[0].Meshes[i];
                for (var m = 0; m < mr.Mesh.SubMeshCount; m++)
                {
                    var matIndex = mr.Mesh.GetMaterialIndex(m);
                    mr.SetMaterial(matIndex, results[0].Materials[matIndex], true);
                }
            }

            return(obj);
        }
Ejemplo n.º 2
0
        private GameObject CreatePmdObject(string filename)
        {
            var results = pmdImporter.Import(filename, ImportType.Full);

            foreach (var tex in results[0].Textures)
            {
                tex.Load();
            }
            foreach (var mesh in results[0].Meshes)
            {
                mesh.Load();
            }
            foreach (var mat in results[0].Materials)
            {
                mat.Shader = MMW.GetAsset <Shader>("Physical");
                mat.AddParam("roughness", "Roughness", 0.7f);
                mat.AddParam("metallic", "Metallic", 0.0f);
            }

            var obj = new GameObject(results[0].Name, Matrix4.Identity, "pmd");

            for (var i = 0; i < results[0].Meshes.Length; i++)
            {
                var mr = obj.AddComponent <MeshRenderer>();
                mr.Mesh = results[0].Meshes[i];
                for (var m = 0; m < mr.Mesh.SubMeshCount; m++)
                {
                    var matIndex = mr.Mesh.GetMaterialIndex(m);
                    mr.SetMaterial(matIndex, results[0].Materials[matIndex], true);
                }
            }

            return(obj);
        }
        public void Load(Mesh mesh, Material[] mats, string shader = "Physical")
        {
            if (!mesh.Loaded)
            {
                mesh.Load();
            }

            sh = MMW.GetAsset <Shader>(shader);
            foreach (var mat in mats)
            {
                mat.Shader = sh;
            }

            go = new GameObject();

            //  mesh renderer
            MeshRenderer      = go.AddComponent <MeshRenderer>();
            MeshRenderer.Mesh = mesh;
            for (var m = 0; m < MeshRenderer.Mesh.SubMeshCount; m++)
            {
                var matIndex = MeshRenderer.Mesh.GetMaterialIndex(m);
                MeshRenderer.SetMaterial(matIndex, mats[matIndex], true);
            }

            light              = new GameObject();
            DirLight           = light.AddComponent <DirectionalLight>();
            DirLight.Intensity = 4.0f;
            DirLight.Direction = Vector3.UnitZ;
        }
Ejemplo n.º 4
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            WindowBorder             = WindowBorder.Fixed;
            MMW.MainCamera.DebugDraw = true;

            var t = MMW.MainCamera.GameObject.Transform;

            t.Position          = new Vector3(0.0f, 2.0f, -5.0f);
            t.Rotate.X          = -0.3f;
            MMW.MainCamera.Near = 0.01f;
            MMW.MainCamera.Far  = 100.0f;

            //MMW.MainCamera.GameObject.AddComponent<Blur>(20.0f, 2);

            var importer = new MqoImporter();
            //var results = importer.Import(@"../../mqo/brick.mqo");
            var results = importer.Import(@"C:\Users\yoship\Downloads\mqo\Old_Station\Old Station\Old_station.mqo", ImportType.Full);

            foreach (var tex in results[0].Textures)
            {
                tex.Load();
            }
            foreach (var mesh in results[0].Meshes)
            {
                mesh.Load();
            }
            foreach (var mat in results[0].Materials)
            {
                mat.Shader = MMW.GetAsset <Shader>("Test");
            }

            var obj = new GameObject(results[0].Name, Matrix4.Identity, "mqo");

            for (var i = 0; i < results[0].Meshes.Length; i++)
            {
                var mr = obj.AddComponent <MeshRenderer>();
                mr.Mesh = results[0].Meshes[i];
                for (var m = 0; m < mr.Mesh.SubMeshCount; m++)
                {
                    var matIndex = mr.Mesh.GetMaterialIndex(m);
                    mr.SetMaterial(matIndex, results[0].Materials[matIndex], true);
                }
            }

            obj.AddComponent <RotateTest>();
            MMW.RegistGameObject(obj);

            var probj = new GameObject("Property Renderer")
            {
                Layer = 31
            };

            probj.AddComponent <PropertyRenderer>();
            MMW.RegistGameObject(probj);
        }
Ejemplo n.º 5
0
        public static GameObject CreateStage(string path, string shader = "Deferred Physical")
        {
            var obj = importedObjects.FindValue((i) => i.Path == path);

            if (obj == null)
            {
                var imp = MMW.GetSupportedImporter(path);
                obj = imp.Import(path, Importers.ImportType.Full)[0];

                foreach (var tex in obj.Textures)
                {
                    if (tex != null)
                    {
                        tex.Load();
                    }
                }
                foreach (var mesh in obj.Meshes)
                {
                    mesh.Load();
                }

                importedObjects.Add(path, obj);
            }
            var sh = MMW.GetAsset <Shader>(shader);

            foreach (var mat in obj.Materials)
            {
                mat.Shader = sh;
            }

            var go = new GameObject(obj.Name);

            for (var i = 0; i < obj.Meshes.Length; i++)
            {
                var mr = go.AddComponent <MeshRenderer>();
                mr.ForceRendering = true;
                mr.Mesh           = obj.Meshes[i];
                for (var m = 0; m < mr.Mesh.SubMeshCount; m++)
                {
                    var matIndex = mr.Mesh.GetMaterialIndex(m);
                    mr.SetMaterial(matIndex, obj.Materials[matIndex], false);
                }
            }

            for (var i = 0; i < obj.Meshes.Length; i++)
            {
                go.AddComponent <MeshCollider>(obj.Meshes[i]);
            }

            return(go);
        }
Ejemplo n.º 6
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            WindowBorder             = WindowBorder.Fixed;
            MMW.MainCamera.DebugDraw = true;

            var t = MMW.MainCamera.GameObject.Transform;

            t.Position = new Vector3(1.0f, 2.0f, -20.0f);

            var rand = new Random();

            for (var i = 0; i < 50; i++)
            {
                var x = rand.Next(20) - 10;
                var z = rand.Next(20) - 10;
                var y = rand.Next(3, 10);
                var b = new GameObject("Box" + i, Matrix4.CreateTranslation(x, y, z));
                b.AddComponent <BoxCollider>();
                var r = b.AddComponent <RigidBody>();
                b.AddComponent <PhysicsTest>();
                MMW.RegistGameObject(b);
            }

            {
                var plane     = new GameObject("Plane", Matrix4.CreateTranslation(new Vector3(0.0f, -2.0f, 0.0f)));
                var planeMesh = Mesh.CreateSimplePlaneMesh(30.0f, 30.0f);
                var mr        = plane.AddComponent <MeshRenderer>(planeMesh);
                var mat       = new Material("Test", MMW.GetAsset <Shader>("Test"));
                mat.AddParam("diffuse", Color4.Gray);
                mr.SetMaterial(0, mat, false);
                plane.AddComponent <PlaneCollider>(30.0f, 30.0f);
                MMW.RegistGameObject(plane);
            }

            var probj = new GameObject("Property Renderer")
            {
                Layer = 31
            };

            probj.AddComponent <PropertyRenderer>();
            MMW.RegistGameObject(probj);
        }
Ejemplo n.º 7
0
        public static GameObject CreateWorld(World world, string name, string shader = "Deferred Physical")
        {
            var sh = MMW.GetAsset <Shader>(shader);

            foreach (var mat in world.Materials)
            {
                mat.Shader = sh;
            }

            var go = new GameObject(name);

            go.Tags.Add("world");
            //go.Layer = GameObject.LayerAfterRender + 1;

            if (world.Meshes != null)
            {
                for (var i = 0; i < world.Meshes.Length; i++)
                {
                    var mr = go.AddComponent <MeshRenderer>();
                    mr.ForceRendering = true;
                    mr.Mesh           = world.Meshes[i];
                    for (var m = 0; m < mr.Mesh.SubMeshCount; m++)
                    {
                        var matIndex = mr.Mesh.GetMaterialIndex(m);
                        mr.SetMaterial(matIndex, world.Materials[matIndex], false);
                    }
                }
            }

            for (var i = 0; i < world.ColliderMeshes.Length; i++)
            {
                var mc = go.AddComponent <MeshCollider>(world.ColliderMeshes[i]);
                mc.CollideGroup = BulletSharp.CollisionFilterGroups.StaticFilter;
                mc.CollideMask  = BulletSharp.CollisionFilterGroups.KinematicFilter | BulletSharp.CollisionFilterGroups.CharacterFilter | BulletSharp.CollisionFilterGroups.DefaultFilter;
            }

            return(go);
        }
Ejemplo n.º 8
0
        private GameObject CreatePmxObject(string filename)
        {
            var results = pmxImporter.Import(filename, ImportType.Full);

            foreach (var tex in results[0].Textures)
            {
                tex.Load();
            }
            foreach (var mesh in results[0].Meshes)
            {
                mesh.Load();
            }
            foreach (var mat in results[0].Materials)
            {
                mat.Shader = MMW.GetAsset <Shader>("Toon Shadow");
                mat.AddParam("limCoeff", "LimCoefficient", 0.0f);
                mat.SetParam("specular", Color4.Black);
            }

            var obj = new GameObject(results[0].Name, Matrix4.Identity, "pmx");

            CreateBoneObject(obj.Transform, new Bone[] { results[0].Bones[0] });

            for (var i = 0; i < results[0].Meshes.Length; i++)
            {
                var mr = obj.AddComponent <MeshRenderer>();
                mr.Mesh = results[0].Meshes[i];
                for (var m = 0; m < mr.Mesh.SubMeshCount; m++)
                {
                    var matIndex = mr.Mesh.GetMaterialIndex(m);
                    mr.SetMaterial(matIndex, results[0].Materials[matIndex], true);
                }
            }

            return(obj);
        }
Ejemplo n.º 9
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var gd = new GameData()
            {
                Shader     = "Deferred Physical",
                SkinShader = "Deferred Physical Skin",
            };

            MMW.RegistAsset(gd);

            var ds = new List <UserData>();
            var hs = new List <string>();

            for (var i = 0; i < 3; i++)
            {
                var      str = "d0" + i;
                UserData d   = null;
                try
                {
                    var t = 2;
                    var x = 3;
                    var s = 0;
                    while (x > 1)
                    {
                        t *= 2;
                        x--;
                        s = t;
                    }
                    var p = "fa3daa8aa37e1461a1b5ddf959d28f3b" + str;
                    for (var c = 0; c < s; c++)
                    {
                        p = Util.ComputeHash(Encoding.UTF8.GetBytes(p), 17 + c);
                    }
                    var j = Encrypter.Decrypt(File.ReadAllText(GameData.AppDir + str), p);
                    d = Util.DeserializeJson <UserData>(j, false);
                }
                catch { }

                ds.Add(d);

                if (ds.Last() == null)
                {
                    hs.Add(null);
                }
                else
                {
                    var b = Util.SerializeBson(ds.Last());
                    hs.Add(Util.ComputeHash(b, 8));
                }
            }
            var counts = new int[3];

            for (var i = 0; i < 3; i++)
            {
                counts[i] = hs.Where(h => h == hs[i]).Count();
            }
            var idx = Array.IndexOf(counts, counts.Max());

            if (ds[idx] != null)
            {
                MMW.RegistAsset(ds[idx]);
                foreach (var ach in ds[idx].Achivements.ToArray())
                {
                    if (!ach.Verify())
                    {
                        ds[idx].Achivements.Remove(ach);
                    }
                }
            }
            else
            {
                var data = new UserData()
                {
                    UserID = Util.CreateBase58(20)
                };
                var rew = Reward.CreatePublicReward(0, 0, 0, "Beginner", "Have a nice trip!");
                data.Achivements.Add(rew.Achivement);
                MMW.RegistAsset(data);
            }

            {
                var userData = MMW.GetAsset <UserData>();
                var p        = "fa3daa8aa37e1461a1b5ddf959d28f3b";
                for (var c = 0; c < 8; c++)
                {
                    p = Util.ComputeHash(Encoding.UTF8.GetBytes(p), 17 + c);
                }

                foreach (var f in Directory.EnumerateFiles(GameData.AppDir, "*.mwr"))
                {
                    try
                    {
                        var data = File.ReadAllText(f);
                        var str  = Encrypter.Decrypt(data, p);
                        var rew  = Util.DeserializeJson <Reward>(str, false);

                        if (userData.Achivements.Exists(a => a.Name == rew.Achivement.Name))
                        {
                            continue;
                        }
                        if (!(rew.Verify() && rew.Achivement.Verify()) || rew.Achivement.PublicKey != Achivement.PublicPub)
                        {
                            continue;
                        }

                        userData.Achivements.Add(rew.Achivement);
                        userData.AddCoin(rew.Coin);
                        userData.Exp += rew.Exp;
                    }
                    catch { }
                }



                /*
                 * var r1 = Reward.CreatePublicReward(50, 0, 10, "Little Donor", "Thank you for Donation!");
                 * var r2 = Reward.CreatePublicReward(100, 0, 10, "Common Donor", "Thank you for Donation!");
                 * var r3 = Reward.CreatePublicReward(150, 0, 10, "Big Donor", "Thank you for Donation!");
                 * var r4 = Reward.CreatePublicReward(200, 0, 10, "Super Donor", "Thank you for Donation!");
                 * var r5 = Reward.CreatePublicReward(300, 0, 10, "The Walker", "Messiah of MMW");
                 *
                 * File.WriteAllText(GameData.AppDir + "Little Donor.mwr", Encrypter.Encrypt(Util.SerializeJson(r1, false), p));
                 * File.WriteAllText(GameData.AppDir + "Common Donor.mwr", Encrypter.Encrypt(Util.SerializeJson(r2, false), p));
                 * File.WriteAllText(GameData.AppDir + "Big Donor.mwr", Encrypter.Encrypt(Util.SerializeJson(r3, false), p));
                 * File.WriteAllText(GameData.AppDir + "Super Donor.mwr", Encrypter.Encrypt(Util.SerializeJson(r4, false), p));
                 * File.WriteAllText(GameData.AppDir + "The Walker.mwr", Encrypter.Encrypt(Util.SerializeJson(r5, false), p));
                 */
            }

            MMW.RegistAsset(new Sound(Resources.coin2, "WAV")
            {
                Name = "coin"
            });
            MMW.RegistAsset(new Sound(Resources.select2, "WAV")
            {
                Name = "select"
            });
            MMW.RegistAsset(new Sound(Resources.click7, "WAV")
            {
                Name = "click"
            });
            MMW.RegistAsset(new Sound(Resources.back3, "WAV")
            {
                Name = "back"
            });
            MMW.RegistAsset(new Sound(Resources.button, "WAV")
            {
                Name = "button"
            });

            var effs = MMW.MainCamera.GameObject.GetComponents <ImageEffect>();

            foreach (var eff in effs)
            {
                eff.Enabled = false;
            }

            var hw = new GameObject("Hello World");

            hw.AddComponent <HelloWorld>();
            MMW.RegistGameObject(hw);

            var load = new GameObject("Init Loading", Matrix4.Identity, "title");

            load.AddComponent <InitLoading>();
            load.Enabled = false;
            MMW.RegistGameObject(load);

            var title = new GameObject("Title", Matrix4.Identity, "title");

            MMW.RegistGameObject(title);
            title.AddComponent <BackgroundScript>();
            title.AddComponent <TitleScript>();
            title.Enabled = false;

            var loading = new GameObject("Loading");

            loading.AddComponent <LoadingScript>();
            loading.Enabled = false;
            MMW.RegistGameObject(loading);

            var probj = new GameObject("Property Renderer");

            probj.AddComponent <PropertyRenderer>();
            MMW.RegistGameObject(probj);

            var debugger = new GameObject("Debugger");

            debugger.AddComponent <Debugger>();
            MMW.RegistGameObject(debugger);

            MMW.MainCamera.GameObject.UpdateAction += (s, ev) =>
            {
                var cc = MMW.FindGameComponent <GameComponents.ImageEffects.ColorCollect>();
                cc.Contrast   = MMW.Contrast;
                cc.Saturation = MMW.Saturation;
                cc.Brightness = MMW.Brightness;
            };

            for (var i = 0; i < 200; i++)
            {
                var value = Tables.NextRankExp(i + 1);
                Debug.WriteLine(i + ": " + value);
            }


            /*
             * var g = Drawer.GetGraphics();
             * var font = new Font("Yu Gothic UI Light", 32.0f);
             * var size = g.MeasureString("0 1 2 3 4 5 6 7 8 9", font, 1024, new StringFormat() { FormatFlags = StringFormatFlags.MeasureTrailingSpaces });
             * var bm = new Bitmap((int)size.Width + 1, (int)size.Height + 1);
             * g = Graphics.FromImage(bm);
             * g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
             * g.Clear(Color.FromArgb(0));
             * g.DrawString("0 1 2 3 4 5 6 7 8 9", font, Brushes.White, 0, 0);
             * bm.Save(@"C:\Users\yoshihiro\Pictures\number.png");
             */

            // TODO: Bullet拘束機能
            // TODO: IK足修正
            // TODO: サーバー保存
            // TODO: キャラクタ作成
            // TODO: ワールド作成
            // TODO: アイテム使用の仕方
        }
Ejemplo n.º 10
0
 protected override void OnClosing(CancelEventArgs e)
 {
     MMW.GetAsset <UserData>().Save();
     base.OnClosing(e);
 }
Ejemplo n.º 11
0
        public static GameObject CreateItem(NwWalkerGameObject wgo, WorldObject obj, WalkerPlayer player, string name, string shader = "Deferred Physical Skin")
        {
            if (!obj.Loaded)
            {
                obj.Load();
            }

            var sh = MMW.GetAsset <Shader>(shader);

            foreach (var mat in obj.Materials)
            {
                mat.Shader = sh;
            }

            var go = new GameObject(name);

            go.Tags.Add("item");
            //go.Layer = GameObject.LayerAfterRender + 1;

            if (obj.Tags != null)
            {
                foreach (var t in obj.Tags)
                {
                    go.Tags.Add(t);
                }
            }

            //  mesh renderer
            var mr = go.AddComponent <MeshRenderer>();

            mr.Mesh  = obj.Mesh;
            mr.Bones = obj.Bones;
            for (var m = 0; m < mr.Mesh.SubMeshCount; m++)
            {
                var matIndex = mr.Mesh.GetMaterialIndex(m);
                mr.SetMaterial(matIndex, obj.Materials[matIndex], false);
            }

            // motion
            if (obj.Bones != null)
            {
                var animator = go.AddComponent <ComputeAnimator>();
                animator.Bones = mr.Bones;

                if (obj.Motions != null)
                {
                    foreach (var m in obj.Motions)
                    {
                        animator.AddMotion(m.Name, m);
                    }
                }

                var ac = go.AddComponent <AnimationController>();
                ac.Play("idle");
            }

            // morph
            if (obj.Morphs != null)
            {
                var morpher = go.AddComponent <Morpher>();

                foreach (var m in obj.Morphs)
                {
                    if (m == null)
                    {
                        continue;
                    }
                    morpher.AddMorph(m.Name, m);
                }
            }

            // physics

            /*
             * var center = Vector3.Zero;
             * if (obj.CollisionShape != null)
             * {
             *  Collider c = null;
             *  if (obj.CollisionShape is CollisionCapsule)
             *  {
             *      var s = obj.CollisionShape as CollisionCapsule;
             *      c = go.AddComponent<CapsuleCollider>(s.Radius, s.Height - s.Radius * 2.0f);
             *      if (!obj.PhysicalMaterial.IsRigidBody) c.Position.Y = s.Height * 0.5f;
             *      center = new Vector3(0.0f, s.Height * 0.5f, 0.0f);
             *  }
             *  else if (obj.CollisionShape is CollisionCylinder)
             *  {
             *      //var s = obj.CollisionShape as CollisionCylinder;
             *      //c = go.AddComponent<CylinderCollider>(s.Radius, s.Height - s.Radius * 2.0f);
             *      //c.Position.Y = s.Height * 0.5f;
             *  }
             *  else if (obj.CollisionShape is CollisionBox)
             *  {
             *      var s = obj.CollisionShape as CollisionBox;
             *      c = go.AddComponent<BoxCollider>(s.HalfExtents);
             *      if (!obj.PhysicalMaterial.IsRigidBody) c.Position.Y = s.HalfExtents.Y;
             *      center = new Vector3(0, s.HalfExtents.Y, 0);
             *  }
             *  else if (obj.CollisionShape is CollisionSphere)
             *  {
             *      var s = obj.CollisionShape as CollisionSphere;
             *      c = go.AddComponent<SphereCollider>(s.Radius);
             *      if (!obj.PhysicalMaterial.IsRigidBody) c.Position.Y = s.Radius;
             *      center = new Vector3(0, s.Radius, 0);
             *  }
             *
             *  c.CollideGroup = BulletSharp.CollisionFilterGroups.DefaultFilter;
             *  c.CollideMask = BulletSharp.CollisionFilterGroups.SensorTrigger;
             * }
             */
            /*
             * if (obj.PhysicalMaterial.IsRigidBody)
             * {
             *  var rb = go.AddComponent<RigidBody>();
             *
             *  rb.CollideGroup = BulletSharp.CollisionFilterGroups.DefaultFilter;
             *  rb.CollideMask = BulletSharp.CollisionFilterGroups.SensorTrigger;
             *  rb.Mass = obj.PhysicalMaterial.Mass;
             *  rb.Friction = obj.PhysicalMaterial.Friction;
             *  rb.RollingFriction = obj.PhysicalMaterial.RollingFriction;
             *  rb.AnisotropicFriction = obj.PhysicalMaterial.AnisotropicFriction;
             *  rb.Restitution = obj.PhysicalMaterial.Restitution;
             *  rb.LinearDamping = obj.PhysicalMaterial.LinearDamping;
             *  rb.AngulerDamping = obj.PhysicalMaterial.AngulerDamping;
             *
             *  rb.FreezePosition = obj.PhysicalMaterial.FreezePosition;
             *  rb.FreezeRotation = obj.PhysicalMaterial.FreezeRotation;
             *  rb.DisableDeactivation = obj.PhysicalMaterial.DisableDeactivation;
             *  rb.Kinematic = obj.PhysicalMaterial.Kinematic;
             *
             *  rb.CenterOfMass = center;
             *
             *  go.Transform.Position = center;
             * }
             */

            // sound
            if (obj.Sounds != null)
            {
                var sc = go.AddComponent <SoundController>();
                foreach (var s in obj.Sounds)
                {
                    sc.Sounds.Add(s.Name, s.Clone());
                }
            }

            go.AddComponent <WalkerObjectInfo>(obj);

            // scripts
            if (obj.Scripts != null)
            {
                var pl = MMW.FindGameComponent <WalkerScript>().Players.Find(p => (string)p.Properties["userID"] == player.UserID);
                var ws = pl.GetComponent <WalkerGameObjectScript>().Script;
                var wr = MMW.GetAsset <WorldResources>();
                foreach (var asm in obj.Scripts)
                {
                    var scr = WorldResources.CreateScript(asm);
                    scr.ParentScript = ws;
                    scr.ScriptHash   = wr.GetHash(asm);
                    scr.HostUserID   = wgo.UserID;
                    scr.IsHost       = MMW.GetAsset <UserData>().UserID == wgo.UserID;
                    go.AddComponent <WalkerGameObjectScript>(go, scr, null);
                }
            }

            return(go);
        }
Ejemplo n.º 12
0
        public static GameObject CreateMeshObject(string path, string shader = "Physical")
        {
            var obj = importedObjects.FindValue((i) => i.Path == path);

            if (obj == null)
            {
                var imp = MMW.GetSupportedImporter(path);
                obj = imp.Import(path, Importers.ImportType.Full)[0];

                if (obj.Textures != null)
                {
                    foreach (var tex in obj.Textures)
                    {
                        if (tex != null)
                        {
                            tex.Load();
                        }
                    }
                }
                if (obj.Meshes != null)
                {
                    foreach (var mesh in obj.Meshes)
                    {
                        if (mesh != null)
                        {
                            mesh.Load();
                        }
                    }
                }

                importedObjects.Add(path, obj);
            }
            var sh = MMW.GetAsset <Shader>(shader);

            if (sh == null)
            {
                sh = MMW.GetAsset <Shader>("Error");
            }
            foreach (var mat in obj.Materials)
            {
                mat.Shader = sh;
            }

            var go = new GameObject(obj.Name);

            // bone
            if (obj.Bones != null && obj.Bones.Length > 0)
            {
                CreateBoneObject(go.Transform, new Bone[] { obj.Bones[0] });
            }

            if (obj.Meshes != null)
            {
                for (var i = 0; i < obj.Meshes.Length; i++)
                {
                    var mr = go.AddComponent <MeshRenderer>();
                    mr.Bones = obj.Bones;
                    mr.Mesh  = obj.Meshes[i];
                    for (var m = 0; m < mr.Mesh.SubMeshCount; m++)
                    {
                        var matIndex = mr.Mesh.GetMaterialIndex(m);
                        mr.SetMaterial(matIndex, obj.Materials[matIndex], false);
                    }
                }
            }

            if (obj.Morphs != null)
            {
                var morpher = go.AddComponent <ComputeMorpher>();

                foreach (var m in obj.Morphs)
                {
                    if (m == null)
                    {
                        continue;
                    }
                    morpher.AddMorph(m.Name, m);
                }
            }

            return(go);
        }
Ejemplo n.º 13
0
        public static GameObject CreatePlayer(Character ch, string name, string shader = "Deferred Physical Skin")
        {
            var sh = MMW.GetAsset <Shader>(shader);

            foreach (var mat in ch.Materials)
            {
                mat.Shader = sh;
            }

            var go = new GameObject(name);

            go.AddComponent <WalkerGameObjectScript>(go, new DummyGameObjectScript(), null);
            go.Tags.Add("player");
            //go.Layer = GameObject.LayerAfterRender + 1;

            var mr = go.AddComponent <MeshRenderer>();

            mr.Mesh  = ch.Mesh;
            mr.Bones = ch.Bones;
            for (var m = 0; m < mr.Mesh.SubMeshCount; m++)
            {
                var matIndex = mr.Mesh.GetMaterialIndex(m);
                mr.SetMaterial(matIndex, ch.Materials[matIndex], false);
            }

            // motion
            if (ch.Bones != null)
            {
                var animator = go.AddComponent <ComputeAnimator>();
                animator.Bones = mr.Bones;

                if (ch.Motions != null)
                {
                    foreach (var m in ch.Motions)
                    {
                        animator.AddMotion(m.Name, m);
                    }
                }

                var ac = go.AddComponent <AnimationController>();
                ac.Play("idle");
            }

            if (ch.Morphs != null)
            {
                var morpher = go.AddComponent <Morpher>();

                foreach (var m in ch.Morphs)
                {
                    if (m == null)
                    {
                        continue;
                    }
                    morpher.AddMorph(m.Name, m);
                }
            }

            if (ch.CollisionShape != null)
            {
                Collider c = null;
                if (ch.CollisionShape is CollisionCapsule)
                {
                    var s = ch.CollisionShape as CollisionCapsule;
                    c            = go.AddComponent <CapsuleCollider>(s.Radius, s.Height - s.Radius * 2.0f);
                    c.Position.Y = s.Height * 0.5f;
                }
                else if (ch.CollisionShape is CollisionCylinder)
                {
                    //var s = obj.CollisionShape as CollisionCylinder;
                    //c = go.AddComponent<CylinderCollider>(s.Radius, s.Height - s.Radius * 2.0f);
                    //c.Position.Y = s.Height * 0.5f;
                }
                else if (ch.CollisionShape is CollisionBox)
                {
                    var s = ch.CollisionShape as CollisionBox;
                    c            = go.AddComponent <BoxCollider>(s.HalfExtents);
                    c.Position.Y = s.HalfExtents.Y;
                }
                else if (ch.CollisionShape is CollisionSphere)
                {
                    var s = ch.CollisionShape as CollisionSphere;
                    c            = go.AddComponent <SphereCollider>(s.Radius);
                    c.Position.Y = s.Radius;
                }

                c.CollideGroup = BulletSharp.CollisionFilterGroups.CharacterFilter;
                c.CollideMask  = BulletSharp.CollisionFilterGroups.AllFilter;
            }

            var rb = go.AddComponent <RigidBody>();

            rb.CollideGroup          = BulletSharp.CollisionFilterGroups.CharacterFilter;
            rb.CollideMask           = BulletSharp.CollisionFilterGroups.AllFilter;
            rb.Mass                  = ch.PhysicalMaterial.Mass;
            rb.FreezeRotation        = true;
            rb.DisableDeactivation   = true;
            rb.LinearDamping         = 0.2f;
            rb.LinearVelocityLimitXZ = 3.0f;
            rb.Friction              = 0.95f;

            return(go);
        }
Ejemplo n.º 14
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // play offline
            // play online

            WindowBorder  = WindowBorder.Fixed;
            CursorVisible = false;

            MMW.MainCamera.GameObject.Transform.Position = new Vector3(0.0f, 1.5f, -4.0f);
            MMW.MainCamera.GameObject.Transform.Rotate   = new Vector3(0.2f, 0.0f, 0.0f);
            MMW.MainCamera.GameObject.AddComponent <GlobalParamChange>();
            MMW.MainCamera.ClearSkyBox = MMW.GetAsset <TextureCube>("DefaultSkyBox");

            MMW.DirectionalLight.Intensity           = 1.0f;
            MMW.DirectionalLight.Transform.Rotate.X *= -1.0f;
            MMW.DirectionalLight.Color = Color4.White;

            mqoImporter = new MqoImporter();
            pmdImporter = new PmdImporter();
            pmxImporter = new PmxImporter();

            var sphere = Mesh.CreateSimpleSphereMesh(0.36f, 24, 20);
            var mat    = new Material("pbr", MMW.GetAsset <Shader>("Physical"));

            mat.AddParam("diffuse", Color4.White);
            mat.AddParam("roughness", 0.5f);
            mat.AddParam("metallic", 0.0f);
            mat.AddParam("f0", new Color4(0.8f, 0.8f, 0.8f, 1.0f));

            var roughnesses = new float[]
            {
                0.9f,
                0.6f,
                0.4f,
                0.25f,
                0.1f
            };

            var metallics = new float[]
            {
                0.0f,
                0.0f,
                1.0f,
                1.0f,
                1.0f,
            };

            var diffuses = new Color4[]
            {
                new Color4(1.0f, 1.0f, 0.9f, 1.0f),
                Material.IronColor,
                Material.CopperColor,
                Material.SilverColor,
                Material.GoldColor,
            };

            var f0s = new Color4[]
            {
                Material.WaterF0Color,
                Material.PlasticF0Color,
                Material.CopperF0Color,
                Material.SilverF0Color,
                Material.GoldF0Color,
            };

            for (var x = 0; x < 5; x++)
            {
                var obj = new GameObject("Sphere", Matrix4.CreateTranslation(new Vector3(x - 2, 0, 0)));
                var mr  = obj.AddComponent <MeshRenderer>(sphere);
                mat.SetParam("roughness", roughnesses[x]);
                mat.SetParam("metallic", metallics[x]);
                mat.SetParam("diffuse", diffuses[x]);
                mat.SetParam("f0", f0s[x]);

                mr.SetMaterial(0, mat, false);
                MMW.RegistGameObject(obj);
            }

            var plane = new GameObject("plane", Matrix4.CreateTranslation(new Vector3(0.0f, -0.36f, 0.0f)));
            var pmr   = plane.AddComponent <MeshRenderer>(Mesh.CreateSimplePlaneMesh(5.0f, 5.0f));

            pmr.SetMaterial(0, mat, false);
            MMW.RegistGameObject(plane);

            var pl = new GameObject();

            pl.AddComponent <PointLight>();
            pl.UpdateAction += (s, ev) =>
            {
                pl.Transform.Position = new Vector3((float)Math.Sin(MMW.TotalElapsedTime) * 2.0f, 2.0f, 0.0f);
            };
            MMW.RegistGameObject(pl);

            //var miku = CreatePmxObject(@"C:\Users\yoship\Downloads\mmd\Models\MikuV4X_Digitrevx\MikuV4X.pmx");
            //var miku = CreatePmdObject(@"C:\Users\yoship\Downloads\mmd\Models\vocaloid\頭の悪い人.pmd");
            //var miku = CreatePmdObject(@"C:\Users\yoship\Downloads\mmd\Models\ドイツ邸001\ドイツ邸セット.pmd");
            //miku.AddComponent<ParamChangeTest>();
            //MMW.RegistGameObject(miku);


            var probj = new GameObject("Property Renderer")
            {
                Layer = GameObject.LayerUI
            };
            var pr = probj.AddComponent <PropertyRenderer>();

            //pr.pct = miku.GetComponent<ParamChangeTest>();
            //pr.light = point.GetComponent<PointLight>();
            MMW.RegistGameObject(probj);
        }