// // Model List Box Handlers // private void OnModelListDoubleClick(object sender, EventArgs e) { String modelName = (String)modelListBox.SelectedItem; // TODO: Not really sure how to handle errors // if either of these functions fail. LOLModel model = reader.GetModel(modelName); if (model != null) { bool result = renderer.LoadModel(model, logger); currentAnimationComboBox.Items.Clear(); foreach (String name in renderer.GetAnimations()) { currentAnimationComboBox.Items.Add(name); } currentAnimationComboBox.Text = ""; if (currentAnimationComboBox.Items.Count > 0) { currentAnimationComboBox.SelectedIndex = 0; } animationController.DisableAnimation(); // Update status bar text. mainWindowStatusLabel.Text = "Viewing " + modelName + ". Left mouse rotates, right mouse pans, and mouse wheel zooms."; } OnResetCameraButtonClick(sender, e); GLControlMainOnUpdateFrame(sender, e); }
/// <summary> /// Loads a model into the renderer. /// </summary> /// <param name="model">The model to load.</param> /// <param name="logger"></param> /// <returns></returns> public bool LoadModel(LOLModel model, Logger logger) { bool result = true; DestroyModel(); // // Create model geometry // // If the model definition does not contain .skl files, // then it's a static model. if (model.skl == null && result == true) { result = CreateStaticModel(model, logger); } // It's a rigged model else { result = CreateRiggedModel(model, logger); } return(result); }
private bool CreateStaticModel(LOLModel model, Logger logger) { bool result = true; logger.Event("Creating static model."); SKNFile file = new SKNFile(); if (result == true) { // Model is stored in a RAF. result = SKNReader.Read(model.skn, ref file, logger); } staticModel = new GLStaticModel(); if (result == true) { result = staticModel.Create(file, logger); } // // Create Model Texture. // if (result == true) { // Texture stored in RAF file. result = CreateTexture(model.texture, TextureTarget.Texture2D, GLTexture.SupportedImageEncodings.DDS, logger); // Store it in our new model file. if (result == true) { String name = model.texture.FileName; int pos = name.LastIndexOf("/"); name = name.Substring(pos + 1); staticModel.TextureName = name; } } if (result == false) { logger.Error("Failed to create static model."); } return(result); }
private bool CreateRiggedModel(LOLModel model, Logger logger) { bool result = true; logger.Event("Creating rigged model."); // Open the skn file. SKNFile sknFile = new SKNFile(); if (result == true) { result = SKNReader.Read(model.skn, ref sknFile, logger); } // Open the skl file. SKLFile sklFile = new SKLFile(); if (result == true) { result = SKLReader.Read(model.skl, ref sklFile, logger); } // Open the anm files. Dictionary <String, ANMFile> anmFiles = new Dictionary <String, ANMFile>(); if (result == true) { foreach (var a in model.animations) { ANMFile anmFile = new ANMFile(); bool anmResult = ANMReader.Read(a.Value, ref anmFile, logger); if (anmResult == true) { anmFiles.Add(a.Key, anmFile); } } } // Create the model. riggedModel = new GLRiggedModel(); if (result == true) { result = riggedModel.Create(sknFile, sklFile, anmFiles, logger); } // Set up an initial animation. if (result == true) { if (anmFiles.Count > 0) { riggedModel.SetCurrentAnimation(anmFiles.First().Key); riggedModel.SetCurrentFrame(0, 0); } } // // Create Model Texture. // if (result == true) { // Texture stored in RAF file. result = CreateTexture(model.texture, TextureTarget.Texture2D, GLTexture.SupportedImageEncodings.DDS, logger); // Store it in our new model file. if (result == true) { String name = model.texture.FileName; int pos = name.LastIndexOf("/"); name = name.Substring(pos + 1); riggedModel.TextureName = name; } } if (result == false) { logger.Error("Failed to create rigged model."); } return(result); }