Exemplo n.º 1
0
        private void loadMqoButton_Click(object sender, EventArgs e)
        {
            using (var fileDialog = new OpenFileDialog {
                Filter = "Metasequoia Files|*.mqo", Title = "Select .mqo file"
            })
            {
                if (fileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                mqoModel = MqoModel.Load(fileDialog.FileName);

                var modelName = Path.GetFileNameWithoutExtension(fileDialog.SafeFileName);
                modelNameTextBox.Text = modelName.Length > 8 ? modelName.Substring(0, 8) : modelName;

                mqoModel.TextureNames.ForEach(texture =>
                                              textureDataGrid.Rows.Add(new object[] { texture, "Stone", 512, 512, false }));

                namePanel.Visible = true;
                placeholderContentLabel.Visible = false;
                texturePanel.Visible            = true;
                addCollisionButton.Enabled      = true;
                save3diButton.Enabled           = true;
                placeholderLabel.Visible        = false;
                vertexCountLabel.Visible        = true;
                faceCountLabel.Visible          = true;

                var mqoObject = mqoModel.Objects[0];
                vertexCountLabel.Text = $"Vertices: {mqoObject.Vertices.Count}";
                faceCountLabel.Text   = $"Faces: {mqoObject.Faces.Count}";
            }
        }
        private Model Convert()
        {
            var mqo       = MqoModel.Load("Resources/box-object.mqo");
            var collision = MqoModel.Load("Resources/box-collision.mqo");

            return(MqoTo3diConverter.Convert("box", mqo, new List <Texture> {
                new Texture("box", 0, 512, 512)
            }, collision));
        }
        public void CollisionPlanesTest()
        {
            var mqo       = MqoModel.Load("Resources/box-object.mqo");
            var collision = MqoModel.Load("Resources/box-collision.mqo");
            var df2       = MqoTo3diConverter.Convert("box", mqo, new List <Texture> {
                new Texture("box", 0, 512, 512)
            }, collision);
            var expected = File.ReadAllBytes("Resources/collision-planes.3di");
            var actual   = df2.Lods[0].CollisionPlaneVectors.SelectMany(collisionPlane => TestUtils.SerializeToBytes(collisionPlane)).ToArray();

            Assert.True(expected.SequenceEqual(actual));
        }
Exemplo n.º 4
0
        private void addCollisionButton_Click(object sender, EventArgs e)
        {
            using (var fileDialog = new OpenFileDialog {
                Filter = "Metasequoia Files|*.mqo", Title = "Select collision .mqo file"
            })
            {
                if (fileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                collision = MqoModel.Load(fileDialog.FileName);

                collisionPlaneCountLabel.Visible = true;
                collisionVolumeLabel.Visible     = true;

                collisionPlaneCountLabel.Text = $"CPs: {collision.Objects.SelectMany(obj => obj.Faces).Count()}";
                collisionVolumeLabel.Text     = $"CVs: {collision.Objects.Count}";
            }
        }
Exemplo n.º 5
0
        public void LoadTest()
        {
            var model     = MqoModel.Load("Resources/box-object.mqo");
            var mqoObject = model.Objects[0];

            Assert.Equal(8, mqoObject.Vertices.Count);
            Assert.Equal(12, mqoObject.Faces.Count);

            var vertex = mqoObject.Vertices[0];

            Assert.Equal(0, vertex.X);
            Assert.Equal(1, vertex.Y);
            Assert.Equal(-1, vertex.Z);

            var face = mqoObject.Faces[0];

            Assert.Equal(0, face.MaterialIndex);
            Assert.True(new List <int> {
                5, 4, 6
            }.SequenceEqual(face.VertexIndices));

            var expectedUVCoordinates = new List <Tuple <double, double> >
            {
                Tuple.Create(1.0, 1.0),
                Tuple.Create(0.0, 1.0),
                Tuple.Create(1.0, 0.0)
            };

            Assert.True(expectedUVCoordinates.SequenceEqual(face.UVCoordinates));

            var expectedTextures = new List <string> {
                "Box.bmp"
            };

            Assert.True(expectedTextures.SequenceEqual(model.TextureNames));
        }
Exemplo n.º 6
0
        public void init(StreamWriter st)
        {
            st.WriteLine("初期化開始");

            pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);

            st.WriteLine("デバイス作成の開始");
            device = new Device(new Direct3D(), 0, DeviceType.Hardware, this.pictureBox1.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters()
            {
                BackBufferWidth = this.pictureBox1.ClientSize.Width,
                BackBufferHeight = this.pictureBox1.ClientSize.Height,
                Windowed = true,
            });
            st.WriteLine("デバイス作成の終了");
            Capabilities caps = device.Capabilities;
            st.WriteLine("adapterOrdinal:" + caps.AdapterOrdinal);
            st.WriteLine("DeviceType:" + caps.DeviceType);
            if (caps.VertexShaderVersion.Major < 3)
            {
                MessageBox.Show("VertexShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion);
                device.Dispose();
                Environment.Exit(0);
            }
            else if (caps.PixelShaderVersion.Major < 3)
            {
                MessageBox.Show("PixelShader3.0 以上がサポートされていません。\n現バージョン:" + caps.VertexShaderVersion);
                device.Dispose();
                Environment.Exit(0);
            }

            st.WriteLine("DeviceContextの初期化");
            DeviceContext.init(device);

            st.WriteLine("ZEnableの初期化");
            device.SetRenderState(RenderState.ZEnable, true);

            st.WriteLine("cameraの初期化");
            camera = new Camera(device);

            st.WriteLine("Floorの初期化");
            floorMap = new FloorMap(device);

            //            teapot = Mesh.CreateTeapot(device);
            //            device.SetRenderState(RenderState.ShadeMode, ShadeMode.Flat);

            st.WriteLine("照明の初期化");
            device.SetRenderState(RenderState.Lighting, true);
            device.SetLight(0, new Light() {
                Type = LightType.Directional,
                Diffuse = Color.White,
                Ambient = Color.Gray,
                Direction = new Vector3(1.0f, 1.0f, 0.0f),
            });
            device.EnableLight(0,true);
            standardLine = new StandardLine(device);
            //射影変換
            device.SetTransform(TransformState.Projection,
                                 Matrix.PerspectiveFovLH((float)(Math.PI / 4),
                                                         (float)this.pictureBox1.ClientSize.Width / (float)this.pictureBox1.ClientSize.Height,
                                                         0.1f, 1500.0f));
            //ビュー
            device.SetTransform(TransformState.View,
                                 camera.getLookAtLh());

            device.SetTransform(TransformState.World, Matrix.Identity);

            st.WriteLine("FloorModelの初期化");
            floorModel = new FloorModel(new MqoParser(device).parse(".\\projects\\sample\\model\\floor.mqo", new MqoModel()));

            st.WriteLine("初期化終了");
        }
Exemplo n.º 7
0
 public FloorModel(MqoModel model)
 {
     this.model = model;
     effect = EffectRepository.getInstance().getEffect(".\\resources\\fx\\selectedObj.fx");
 }