Example #1
0
        private void LoadNif(string path)
        {
            nifPath = path;
            try {
                NifFile f = BSAArchive.LoadMesh(path);
                if (f == null)
                {
                    throw new ApplicationException("Failed to load nif: " + path);
                }
                nif = f;
            } catch (ApplicationException ex) {
                MessageBox.Show("An error occured while loading the nif: " + ex.Message, "Error");
                return;
            }

            //Change camera radius
            lightControl.Radius = nif.Radius;
            camera.SetRadius(nif.Radius * 3.0f, 0, nif.Radius * 4.9f);
            float aspect = (float)sampleFramework.BackBufferSurfaceDescription.Width / (float)sampleFramework.BackBufferSurfaceDescription.Height;

            camera.SetProjectionParameters((float)Math.PI / 4, aspect, nif.Radius / 80, nif.Radius * 5);

            //Change the subset control box
            ComboBox cb = sampleUi.GetComboBox(SubsetControl);

            cb.Clear();
            cb.AddItem("Whole mesh", (int)-1);
            for (int i = 0; i < nif.Subsets; i++)
            {
                cb.AddItem("Subset " + i, i);
            }
        }
Example #2
0
 /// <summary>
 /// This event will be fired immediately after the Direct3D device has
 /// been destroyed, which generally happens as a result of application termination or
 /// windowed/full screen toggles. Resources created in the OnCreateDevice event
 /// should be released here, which generally includes all Pool.Managed resources.
 /// </summary>
 private void OnDestroyDevice(object sender, EventArgs e)
 {
     // Update the direction widget
     DirectionWidget.OnDestroyDevice();
     if (nif != null)
     {
         nif.Dispose();
         nif           = null;
         nifPath       = null;
         currentSubset = -1;
     }
 }
Example #3
0
        void shaderPicker_Changed(object sender, EventArgs e)
        {
            string tech = (string)((ComboBox)sender).GetSelectedData();

            if (tech == null)
            {
                NifFile.SetAutoTechnique(true);
            }
            else
            {
                NifFile.SetAutoTechnique(false);
                effect.Technique = tech;
            }
        }
Example #4
0
        /// <summary>
        /// This event will be fired immediately after the Direct3D device has been
        /// created, which will happen during application initialization and windowed/full screen
        /// toggles. This is the best location to create Pool.Managed resources since these
        /// resources need to be reloaded whenever the device is destroyed. Resources created
        /// here should be released in the Disposing event.
        /// </summary>
        private void OnCreateDevice(object sender, DeviceEventArgs e)
        {
            // Setup direction widget
            DirectionWidget.OnCreateDevice(e.Device);

            // Initialize the stats font
            statsFont = ResourceCache.GetGlobalInstance().CreateFont(e.Device, 15, 0, FontWeight.Bold, 1, false, CharacterSet.Default,
                                                                     Precision.Default, FontQuality.Default, PitchAndFamily.FamilyDoNotCare | PitchAndFamily.DefaultPitch
                                                                     , "Arial");

            // Read the D3DX effect file
            string path = "NifViewer.fx";
            string errors;

            effect = ResourceCache.GetGlobalInstance().CreateEffectFromFile(e.Device, path, null, null, ShaderFlags.NotCloneable, null, out errors);

            if (effect == null)
            {
                MessageBox.Show("Effects.fx Shader compilation failed.\n" + errors, "Error");
            }

            ehLightDir = effect.GetParameter(null, "g_LightDir");
            ehLightCol = effect.GetParameter(null, "g_LightDiffuse");
            egAmbCol   = effect.GetParameter(null, "g_LightAmbient");
            ehViewProj = effect.GetParameter(null, "viewProjection");
            ehEyePos   = effect.GetParameter(null, "eyePos");
            ehEyeVec   = effect.GetParameter(null, "eyeVec");
            ehHalfVec  = effect.GetParameter(null, "g_LightHalfVec");

            NifFile.SetEffect(effect);

            // Setup the camera's view parameters
            camera.SetViewParameters(new Vector3(0.0f, 0.0f, -15.0f), Vector3.Empty);
            camera.IsPositionMovementEnabled = true;

            NifFile.SetCamera(camera);

            lightControl.Radius = 10;
            camera.SetRadius(30.0f, 0, 100.0f);
        }
Example #5
0
        private void LoadNif(string path) {
            nifPath=path;
            try {
                NifFile f=BSAArchive.LoadMesh(path);
                if(f==null) throw new ApplicationException("Failed to load nif: "+path);
                nif=f;
            } catch(ApplicationException ex) {
                MessageBox.Show("An error occured while loading the nif: "+ex.Message, "Error");
                return;
            }

            //Change camera radius
            lightControl.Radius = nif.Radius;
            camera.SetRadius(nif.Radius * 3.0f, 0, nif.Radius * 4.9f);
            float aspect=(float)sampleFramework.BackBufferSurfaceDescription.Width/(float)sampleFramework.BackBufferSurfaceDescription.Height;
            camera.SetProjectionParameters((float)Math.PI / 4, aspect, nif.Radius/80, nif.Radius*5);

            //Change the subset control box
            ComboBox cb=sampleUi.GetComboBox(SubsetControl);
            cb.Clear();
            cb.AddItem("Whole mesh", (int)-1);
            for(int i=0;i<nif.Subsets;i++) cb.AddItem("Subset "+i, i);
        }
Example #6
0
 /// <summary>
 /// This event will be fired immediately after the Direct3D device has 
 /// been destroyed, which generally happens as a result of application termination or 
 /// windowed/full screen toggles. Resources created in the OnCreateDevice event 
 /// should be released here, which generally includes all Pool.Managed resources. 
 /// </summary>
 private void OnDestroyDevice(object sender, EventArgs e) {
     // Update the direction widget
     DirectionWidget.OnDestroyDevice();
     if(nif != null) {
         nif.Dispose();
         nif=null;
         nifPath=null;
         currentSubset=-1;
     }
 }
Example #7
0
 void parallaxCheckbox_Changed(object sender, EventArgs e)
 {
     NifFile.SetParallax(((Checkbox)sender).IsChecked);
 }