Exemple #1
0
        void IGameViewModel.LoadScene(Game game)
        {
            var scene = new Scene();

            _modelEntity = game.ContentManager.Load <Model>(File.FilePath, uploadBatch: null).CreateEntity();
            scene.Entities.Add(_modelEntity);

            //var enclosingBoundingBox = _modelEntity.GetEnclosingBoundingBox();

            //cameraEntity.Components.Add(new ArcballCameraController(
            //    enclosingBoundingBox.GetCenter(),
            //    Vector3.Distance(enclosingBoundingBox.Min, enclosingBoundingBox.Max) / 1.5f));

            game.Scene = scene;

            _animations = new List <AnimationComponent>();
            _animations.AddRange(_modelEntity.Components.OfType <AnimationComponent>());

            // If this is a skin file, load "external" animations.
            _externalAnimations = new List <AnimationComponent>();
            if (_w3dFile.HLod != null && _w3dFile.HLod.Header.Name.EndsWith("_SKN", System.StringComparison.OrdinalIgnoreCase))
            {
                var namePrefix   = _w3dFile.HLod.Header.Name.Substring(0, _w3dFile.HLod.Header.Name.LastIndexOf('_') + 1);
                var parentFolder = Path.GetDirectoryName(_w3dFile.FilePath);
                var pathPrefix   = Path.Combine(parentFolder, namePrefix);
                foreach (var animationFileEntry in File.FileSystem.GetFiles(parentFolder))
                {
                    if (!animationFileEntry.FilePath.StartsWith(pathPrefix, System.StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    var animationModel = game.ContentManager.Load <Model>(animationFileEntry.FilePath, uploadBatch: null);
                    foreach (var animation in animationModel.Animations)
                    {
                        var externalAnimationComponent = new AnimationComponent
                        {
                            Animation = animation
                        };
                        _modelEntity.Components.Add(externalAnimationComponent);
                        _externalAnimations.Add(externalAnimationComponent);
                    }
                }
            }

            SubObjects.Add(new ModelViewModel());

            foreach (var animation in _animations)
            {
                SubObjects.Add(new AnimationViewModel(animation, "Animations"));
            }

            foreach (var animation in _externalAnimations)
            {
                SubObjects.Add(new AnimationViewModel(animation, "External Animations"));
            }

            SelectedSubObject = SubObjects[0];
        }
Exemple #2
0
        public IniFileContentViewModel(FileSystemEntry file)
            : base(file)
        {
            _iniDataContext = new IniDataContext(file.FileSystem);
            _iniDataContext.LoadIniFile(file);

            foreach (var objectDefinition in _iniDataContext.Objects)
            {
                SubObjects.Add(new ObjectDefinitionIniEntryViewModel(objectDefinition));
            }

            foreach (var particleSystem in _iniDataContext.ParticleSystems)
            {
                SubObjects.Add(new ParticleSystemIniEntryViewModel(particleSystem));
            }
        }
        /// <summary>
        /// When null is given, the default SubObject
        /// </summary>
        /// <param name="mat"></param>
        /// <returns></returns>
        public SubObject GetOrCreateSubObject(OBJMaterial mat)
        {
            if (mat == null)
            {
                return(DefaultSubObject);
            }
            for (int i = 0; i < SubObjects.Count; i++)
            {
                if (SubObjects[i].Material == mat)
                {
                    return(SubObjects[i]);
                }
            }

            SubObject obj = new SubObject();

            SubObjects.Add(obj);

            obj.Material = mat;

            return(obj);
        }
Exemple #4
0
        public override void BeforeEdit()
        {
            SubObjects.Clear();
            try
            {
                if (Value != null && Value.Contains($"\"Type\":\"{nameof(MenuItem)}\""))
                {
                    SubObjects.Add(JsonSerializer.Deserialize <MenuItem>(Value));
                }
                else if (Value != null && Value.Contains($"\"Type\":\"{nameof(ModelSetting)}\""))
                {
                    SubObjects.Add(JsonSerializer.Deserialize <ModelSetting>(Value));
                }
                else if (Value != null && Value.Contains($"\"Type\":\"{nameof(DisplaySetting)}\""))
                {
                    SubObjects.Add(JsonSerializer.Deserialize <DisplaySetting>(Value));
                }
                else if (Value != null && Value.Contains($"\"Type\":\"{nameof(DataGridSetting)}\""))
                {
                    SubObjects.Add(JsonSerializer.Deserialize <DataGridSetting>(Value));
                }
                else if (Value != null && Value.Contains($"\"Type\":\"{nameof(DataGridHandlerSetting)}\""))
                {
                    SubObjects.Add(JsonSerializer.Deserialize <DataGridHandlerSetting>(Value));
                }
                else if (Value != null && Value.Contains($"\"Type\":\"{nameof(DialogOptions)}\""))
                {
                    SubObjects.Add(JsonSerializer.Deserialize <DialogOptions>(Value));
                }
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Error in {System.Reflection.MethodBase.GetCurrentMethod().Name}: {ex.Message}");
            }

            base.BeforeEdit();
        }