/// <summary>
        /// Loads the reward on model.
        /// </summary>
        /// <param name="rewardPackUnlockData">The identifier.</param>
        /// <returns></returns>
        private GameObject LoadRewardPropOnAntura(RewardPack rewardPack)
        {
            RewardProp prop = rewardPack.RewardBase as RewardProp;

            if (prop == null)
            {
                Debug.LogFormat("Prop {0} not found!", rewardPack.BaseId);
                return(null);
            }

            // Check if we already loaded a reward of this category
            LoadedModel loadedModel = LoadedModels.Find(lm => lm.RewardPack.Category == prop.Category);

            if (loadedModel != null)
            {
                Destroy(loadedModel.GO);
                LoadedModels.Remove(loadedModel);
            }

            // Load Model
            string     boneParent  = prop.BoneAttach;
            GameObject rewardModel = null;

            switch (boneParent)
            {
            case "dog_head":
                rewardModel = ModelsManager.MountModel(prop.ID, Dog_head);
                break;

            case "dog_spine01":
                rewardModel = ModelsManager.MountModel(prop.ID, Dog_spine01);
                break;

            case "dog_jaw":
                rewardModel = ModelsManager.MountModel(prop.ID, Dog_jaw);
                break;

            case "dog_Tail4":
                rewardModel = ModelsManager.MountModel(prop.ID, Dog_Tail3);
                break;

            case "dog_R_ear04":
                rewardModel = ModelsManager.MountModel(prop.ID, Dog_R_ear04);
                break;

            case "dog_L_ear04":
                rewardModel = ModelsManager.MountModel(prop.ID, Dog_L_ear04);
                break;
            }

            // Set materials
            ModelsManager.SwitchMaterial(rewardModel, rewardPack.GetMaterialPair());

            // Save on LoadedModel List
            LoadedModels.Add(new LoadedModel()
            {
                RewardPack = rewardPack, GO = rewardModel
            });
            return(rewardModel);
        }
        private LoadedModel LoadModelOfd()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (ofd.CheckFileExists)
                {
                    string dirName = Path.GetDirectoryName(ofd.FileName);
                    try
                    {
                        using (Assimp.AssimpContext importer = new Assimp.AssimpContext())
                        {
                            importer.SetConfig(new NormalSmoothingAngleConfig(66.0f));
                            Assimp.Scene model       = importer.ImportFile(ofd.FileName, Assimp.PostProcessPreset.TargetRealTimeMaximumQuality);
                            LoadedModel  loadedModel = new LoadedModel(model, dirName);
                            loadedModel.Name = Path.GetFileName(ofd.FileName);
                            return(loadedModel);
                        }
                    }
                    catch
                    {
                        System.Windows.MessageBox.Show("Unsupported file type.", "Error");
                    }
                }
            }
            return(null);
        }
 private void AutoCenterButton_Click(object sender, RoutedEventArgs e)
 {
     if (viewModel.SelectedModel != null)
     {
         LoadedModel selectedModel = viewModel.SelectedModel;
         //scale adjusting
         float   maxSize  = 3;
         Vector3 delta    = selectedModel.MaximumPosition - selectedModel.MinimumPosition;
         float   maxDelta = delta.X;
         if (delta.Y > maxDelta)
         {
             maxDelta = delta.Y;
         }
         if (delta.Z > maxDelta)
         {
             maxDelta = delta.Z;
         }
         float   scale       = maxSize / maxDelta;
         Matrix4 scaleMatrix = Matrix4.CreateScale(scale);
         selectedModel.UserTransform.ScaleMatrix = scaleMatrix;
         viewModel.ScaleFactor = scale.ToString("N8");
         //centering
         Vector3 centerOffset = (selectedModel.MaximumPosition + selectedModel.MinimumPosition) / 2;
         centerOffset = new Vector3(scaleMatrix * (new Vector4(centerOffset, 1f)));
         Matrix4 translateBeforeMatrix = Matrix4.CreateTranslation(-centerOffset.X, -centerOffset.Y, -centerOffset.Z);
         selectedModel.UserTransform.TranslateBeforeMatrix = translateBeforeMatrix;
         viewModel.TranslateXBefore = (-centerOffset.X).ToString("N4");
         viewModel.TranslateYBefore = (-centerOffset.Y).ToString("N4");
         viewModel.TranslateZBefore = (-centerOffset.Z).ToString("N4");
     }
 }
        /// <summary>
        /// Clears the loaded reward in category.
        /// </summary>
        /// <param name="_categoryId">The category identifier.</param>
        public void ClearLoadedRewardInCategory(string _categoryId)
        {
            LoadedModel lm = LoadedModels.Find(m => m.RewardPack.Category == _categoryId);

            if (lm != null)
            {
                Destroy(lm.GO);
                LoadedModels.Remove(lm);
            }
        }
 private void RemoveModelButton_Click(object sender, RoutedEventArgs e)
 {
     if (viewModel.SelectedModel != null)
     {
         LoadedModel toDelete = viewModel.SelectedModel;
         viewModel.LoadedModels.Remove(toDelete);
         viewModel.SelectedModel = viewModel.LoadedModels.LastOrDefault();
         scene.LoadedModels.Remove(toDelete);
         toDelete.Dispose();
     }
 }
        private void AddModelButton_Click(object sender, RoutedEventArgs e)
        {
            LoadedModel model = LoadModelOfd();

            if (model != null)
            {
                viewModel.LoadedModels.Add(model);
                viewModel.ModelTransforms.Add(model, new ModelTransform());
                viewModel.SelectedModel = model;
                scene.LoadedModels.Add(model);
            }
        }
Exemple #7
0
        private void AddBillboardModels(List <Vector3> modelsPositions)
        {
            var billboard = Content.Load <Model>("billboard_a_2012");

            for (var i = 2; i < 4; i++)
            {
                var advertModel = new LoadedModel(billboard, modelsPositions[i],
                                                  Matrix.CreateRotationX(MathHelper.ToRadians(90f)) * Matrix.CreateRotationZ(MathHelper.ToRadians(180f)),
                                                  Matrix.CreateScale(0.9f), GraphicsDevice);
                advertModel.SetModelEffect(effect, true);
                advertModel.Material = mat;
                loadedModels.Add(advertModel);
            }
        }
        /// <summary>
        /// Ladowanie wszystkich modeli. Inicjalizacja wywolywana z konstruktora
        /// </summary>
        private void LoadModels()
        {
            foreach (string name in GameObjectStatsReader.GetStatsReader().GetObjectsToLoad())
            {
                //odczytaj id obiektu na podstawie nazwy z xmla
                GameObjectID currentObjectId =
                    (from ids in GameObjectNames where ids.Value == name select ids.Key).First();

                //Utworz nowy model "ladowania"
                LoadedModel loadedModel = new LoadedModel();

                //Zaladuj odpowiedni model 3d
                loadedModel.model = contentManager.Load<Model>("Model/" + name);

                //Przepisz tesktury do modelu ladowania
                foreach (ModelMesh mesh in loadedModel.model.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        loadedModel.textures.Add(effect.Texture);
                    }
                }

                //Przepisz shadery w modelu
                foreach (ModelMesh mesh in loadedModel.model.Meshes)
                {
                    foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    {
                        meshPart.Effect = TechniqueProvider.GetEffect("TexturedShaded").Clone();
                    }
                }

                loadedModels.Add(currentObjectId,loadedModel);
            }
        }
Exemple #9
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Version version = new Version(GL.GetString(StringName.Version).Substring(0, 3));
            Version target  = new Version(3, 0);

            if (version < target)
            {
                throw new NotSupportedException(String.Format("OpenGL {0} is required (you only have {1}).", target, version));
            }

            Vector <float> camera_pos     = new Vector <float>(0, 0, -20);
            Vector <float> camera_forward = new Vector <float>(0, 0, 1);
            Vector <float> camera_up      = new Vector <float>(0, 1, 0);

            camera = new Camera(camera_pos, camera_forward, camera_up);

            string xml_file_contents;
            var    assembly  = Assembly.GetExecutingAssembly();
            var    modelFile = "GraphicsWindow.Resources.model.dae";

            using (Stream stream = assembly.GetManifestResourceStream(modelFile))
                using (StreamReader reader = new StreamReader(stream))
                {
                    xml_file_contents = reader.ReadToEnd();
                }

            Model model = Collada.Parse(xml_file_contents);

            #region Debugging

            //Collada_OLD.AnimatedModelData data = Collada_OLD.Collada.LoadModel(xml_file_contents, 3);
            //Collada_OLD.AnimationData animdata = Collada_OLD.Collada.LoadAnimation(xml_file_contents);

            //if (!model._positions.ValuesAreEqual(data.mesh.vertices))
            //    throw new Exception("positions");
            //if (!model._normals.ValuesAreEqual(data.mesh.normals))
            //    throw new Exception("normals");
            //if (!model._indices.ValuesAreEqual(data.mesh.indices))
            //    throw new Exception("indices");
            //if (!model._textureCoordinates.ValuesAreEqual(data.mesh.textureCoords))
            //    throw new Exception("textureCoordinates");

            //if (!Collada.EFFECTORJOINTCOUNTS.ValuesAreEqual(Collada_OLD.EFFECTORJOINTCOUNTS))
            //    throw new Exception("EFFECTORJOINTCOUNTS");
            //if (!Collada.WEIGHTS.ValuesAreEqual(Collada_OLD.WEIGHTS))
            //    throw new Exception("WEIGHTS");
            //if (!Collada.JOINTIDSDATA.ValuesAreEqual(Collada_OLD.JOINTIDSDATA))
            //    throw new Exception("JOINTIDSDATA");
            //if (!Collada.JOINTWEIGHTSDATA.ValuesAreEqual(Collada_OLD.JOINTWEIGHTSDATA))
            //    throw new Exception("JOINTWEIGHTSDATA");

            //if (!model._jointWeights.ValuesAreEqual(data.mesh.vertexWeights))
            //    throw new Exception("jointWeights");
            //if (!model._jointIds.ValuesAreEqual(data.mesh.jointIds))
            //    throw new Exception("jointIds");

            ////model._jointIds = data.mesh.jointIds;
            ////model._jointWeights = data.mesh.vertexWeights;

            #endregion

            var    textureFile = "GraphicsWindow.Resources.diffuse.png";
            Bitmap texture     = new Bitmap(assembly.GetManifestResourceStream(textureFile));
            model._texture = texture;

            loadedModel = Theta.Graphics.OpenGL.Load.Model(model);
            loadedModel.ActivateAnimation("base animation");

            animatedModelShader = new Render.AnimatedModelShader();

            lightDirection = new Vector <float>(0.2f, -0.3f, -0.8f);
        }
        /// <summary>
        /// Loads the reward on model.
        /// </summary>
        /// <param name="_id">The identifier.</param>
        /// <returns></returns>
        public GameObject LoadRewardOnAntura(RewardPack _rewardPack)
        {
            Reward reward = RewardSystemManager.GetConfig().Rewards.Find(r => r.ID == _rewardPack.ItemID);

            if (reward == null)
            {
                Debug.LogFormat("Reward {0} not found!", _rewardPack.ItemID);
                return(null);
            }
            // Check if already charged reward of this category
            LoadedModel loadedModel = LoadedModels.Find(lm => lm.Reward.GetRewardCategory() == reward.Category);

            if (loadedModel != null)
            {
                Destroy(loadedModel.GO);
                LoadedModels.Remove(loadedModel);
            }

            // Load Model
            string     boneParent      = reward.BoneAttach;
            Transform  transformParent = transform;
            GameObject rewardModel     = null;

            switch (boneParent)
            {
            case "dog_head":
                transformParent = Dog_head;
                //if (Dog_head_pointer)
                //    Destroy(Dog_head_pointer.gameObject);
                //Dog_head_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            case "dog_spine01":
                transformParent = Dog_spine01;
                //if (Dog_spine01_pointer)
                //    Destroy(Dog_spine01_pointer.gameObject);
                //Dog_spine01_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            case "dog_jaw":
                transformParent = Dog_jaw;
                //if (Dog_jaw_pointer)
                //    Destroy(Dog_jaw_pointer.gameObject);
                //Dog_jaw_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            case "dog_Tail4":
                transformParent = Dog_Tail3;
                //if (Dog_Tail3_pointer)
                //    Destroy(Dog_Tail3_pointer.gameObject);
                //Dog_Tail3_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            case "dog_R_ear04":
                transformParent = Dog_R_ear04;
                //if (dog_R_ear04_pointer)
                //    Destroy(dog_R_ear04_pointer.gameObject);
                //dog_R_ear04_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            case "dog_L_ear04":
                transformParent = Dog_L_ear04;
                //if (dog_L_ear04_pointer)
                //    Destroy(dog_L_ear04_pointer.gameObject);
                //dog_L_ear04_pointer = ModelsManager.MountModel(reward.ID, transformParent).transform;
                rewardModel = ModelsManager.MountModel(reward.ID, transformParent);
                break;

            default:
                break;
            }

            // Set materials
            ModelsManager.SwitchMaterial(rewardModel, _rewardPack.GetMaterialPair());

            // Save on LoadedModel List
            LoadedModels.Add(new LoadedModel()
            {
                Reward = _rewardPack, GO = rewardModel
            });
            return(rewardModel);
        }