Esempio n. 1
0
        /// <summary>
        /// Insert new mesh into the collision data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddCollisionModel(object sender, System.EventArgs e)
        {
            //make sure an actual model has been selected.
            if (openM2T.ShowDialog() != DialogResult.OK)
            {
                MessageBox.Show("Failed to select an M2T model.", "Toolkit", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            M2TStructure colModel = new M2TStructure();

            if (openM2T.FileName.ToLower().EndsWith(".m2t"))
            {
                colModel.ReadFromM2T(new BinaryReader(File.Open(openM2T.FileName, FileMode.Open)));
            }
            else if (openM2T.FileName.ToLower().EndsWith(".fbx"))
            {
                colModel.ReadFromFbx(openM2T.FileName);
            }

            //crash happened/
            if (colModel.Lods[0] == null)
            {
                return;
            }

            Collision.NXSStruct nxsData = new Collision.NXSStruct();
            nxsData.Hash = FNV64.Hash(colModel.Name);
            nxsData.Data.BuildBasicCollision(colModel.Lods[0]);
            nxsData.Sections = new Collision.Section[colModel.Lods[0].Parts.Length];

            int curEdges = 0;

            for (int i = 0; i != nxsData.Sections.Length; i++)
            {
                nxsData.Sections[i]          = new Collision.Section();
                nxsData.Sections[i].Unk1     = (int)Enum.Parse(typeof(CollisionMaterials), colModel.Lods[0].Parts[i].Material) - 2;
                nxsData.Sections[i].Start    = curEdges;
                nxsData.Sections[i].NumEdges = colModel.Lods[0].Parts[i].Indices.Length * 3;
                curEdges += colModel.Lods[0].Parts[i].Indices.Length * 3;
            }

            Collision.Placement placement = new Collision.Placement();
            placement.Hash     = nxsData.Hash;
            placement.Unk5     = 128;
            placement.Unk4     = -1;
            placement.Position = new Vector3(0, 0, 0);
            placement.Rotation = new Vector3(0);


            SceneData.Collisions.NXSData.Add(nxsData.Hash, nxsData);
            SceneData.Collisions.Placements.Add(placement);
            treeView1.Nodes.Clear();
            LoadInCollision();
        }
        public bool PreInit(IntPtr WindowHandle)
        {
            D3D = new DirectX11Class();
            if (!D3D.Init(WindowHandle))
            {
                MessageBox.Show("Failed to initialize DirectX11!");
                return(false);
            }

            Timer = new TimerClass();
            FPS   = new FPSClass();

            Timer.Init();
            FPS.Init();

            RenderStorageSingleton.Instance.Prefabs = new RenderPrefabs();
            if (!RenderStorageSingleton.Instance.ShaderManager.Init(D3D.Device))
            {
                MessageBox.Show("Failed to initialize Shader Manager!");
                return(false);
            }
            //this is backup!
            RenderStorageSingleton.Instance.TextureCache.Add(0, TextureLoader.LoadTexture(D3D.Device, D3D.DeviceContext, "texture.dds"));

            var structure = new M2TStructure();
            //import gizmo
            RenderModel model = new RenderModel();

            structure.ReadFromM2T("Resources/GizmoModel.m2t");
            model.ConvertMTKToRenderModel(structure);
            model.InitBuffers(D3D.Device, D3D.DeviceContext);
            model.DoRender = false;

            RenderModel sky = new RenderModel();

            structure = new M2TStructure();
            structure.ReadFromM2T("Resources/sky_backdrop.m2t");
            sky.ConvertMTKToRenderModel(structure);
            sky.InitBuffers(D3D.Device, D3D.DeviceContext);
            sky.DoRender = false;
            Assets.Add(1, sky);

            RenderModel clouds = new RenderModel();

            structure = new M2TStructure();
            structure.ReadFromM2T("Resources/weather_clouds.m2t");
            clouds.ConvertMTKToRenderModel(structure);
            clouds.InitBuffers(D3D.Device, D3D.DeviceContext);
            clouds.DoRender = false;
            Assets.Add(2, clouds);
            return(true);
        }
Esempio n. 3
0
        public bool PreInit(IntPtr WindowHandle)
        {
            D3D = new DirectX11Class();
            if (!D3D.Init(WindowHandle))
            {
                MessageBox.Show("Failed to initialize DirectX11!");
            }
            Profile.Init();
            if (!RenderStorageSingleton.Instance.IsInitialised())
            {
                bool result    = RenderStorageSingleton.Instance.Initialise(D3D);
                var  structure = new M2TStructure();
                //import gizmo
                RenderModel gizmo = new RenderModel();
                structure.ReadFromM2T("Resources/GizmoModel.m2t");
                gizmo.ConvertMTKToRenderModel(structure);
                gizmo.InitBuffers(D3D.Device, D3D.DeviceContext);
                gizmo.DoRender   = true;
                TranslationGizmo = new GizmoTool(gizmo);

                sky       = new RenderModel();
                structure = new M2TStructure();
                structure.ReadFromM2T("Resources/sky_backdrop.m2t");
                sky.ConvertMTKToRenderModel(structure);
                sky.InitBuffers(D3D.Device, D3D.DeviceContext);

                clouds    = new RenderModel();
                structure = new M2TStructure();
                structure.ReadFromM2T("Resources/weather_clouds.m2t");
                clouds.ConvertMTKToRenderModel(structure);
                clouds.InitBuffers(D3D.Device, D3D.DeviceContext);
                clouds.DoRender = false;
            }

            selectionBox.SetColour(System.Drawing.Color.Red);
            selectionBox.Init(new BoundingBox(new Vector3(0.5f), new Vector3(-0.5f)));
            selectionBox.DoRender = false;
            return(true);
        }