示例#1
0
        public LoadResult Load(Scene scene)
        {
            var result = new LoadResult();

            // Output is World_t we need to iterate m_worldNodes inside it.
            var worldNodes = world.GetWorldNodeNames();

            foreach (var worldNode in worldNodes)
            {
                if (worldNode != null)
                {
                    var newResource = guiContext.LoadFileByAnyMeansNecessary(worldNode + ".vwnod_c");
                    if (newResource == null)
                    {
                        throw new Exception("WTF");
                    }

                    var subloader = new WorldNodeLoader(guiContext, (WorldNode)newResource.DataBlock);
                    subloader.Load(scene);
                }
            }

            foreach (var lumpName in world.GetEntityLumpNames())
            {
                if (lumpName == null)
                {
                    return(result);
                }

                var newResource = guiContext.LoadFileByAnyMeansNecessary(lumpName + "_c");

                if (newResource == null)
                {
                    return(result);
                }

                var entityLump = (EntityLump)newResource.DataBlock;
                LoadEntitiesFromLump(scene, result, entityLump, "world_layer_base"); // TODO
            }

            return(result);
        }
        protected override void LoadScene()
        {
            if (world != null)
            {
                var loader = new WorldLoader(GuiContext, world);
                var result = loader.Load(Scene);

                if (result.Skybox != null)
                {
                    SkyboxScene = new Scene(GuiContext);
                    var skyboxLoader = new WorldLoader(GuiContext, result.Skybox);
                    var skyboxResult = skyboxLoader.Load(SkyboxScene);

                    SkyboxScale  = skyboxResult.SkyboxScale;
                    SkyboxOrigin = skyboxResult.SkyboxOrigin;

                    ViewerControl.AddCheckBox("Show Skybox", ShowSkybox, (v) => ShowSkybox = v);
                }

                var worldLayers = Scene.AllNodes
                                  .Select(r => r.LayerName)
                                  .Distinct();
                SetAvailableLayers(worldLayers);

                if (worldLayers.Any())
                {
                    // TODO: Since the layers are combined, has to be first in each world node?
                    worldLayersComboBox.SetItemCheckState(0, CheckState.Checked);

                    foreach (var worldLayer in result.DefaultEnabledLayers)
                    {
                        worldLayersComboBox.SetItemCheckState(worldLayersComboBox.FindStringExact(worldLayer), CheckState.Checked);
                    }
                }

                if (result.CameraMatrices.Any())
                {
                    if (cameraComboBox == default)
                    {
                        cameraComboBox = ViewerControl.AddSelection("Camera", (cameraName, index) =>
                        {
                            if (index > 0)
                            {
                                if (result.CameraMatrices.TryGetValue(cameraName, out var cameraMatrix))
                                {
                                    Scene.MainCamera.SetFromTransformMatrix(cameraMatrix);
                                }

                                cameraComboBox.SelectedIndex = 0;
                            }
                        });

                        cameraComboBox.Items.Add("Set view to camera...");
                        cameraComboBox.SelectedIndex = 0;
                    }

                    cameraComboBox.Items.AddRange(result.CameraMatrices.Keys.ToArray <object>());
                }

                var physNodes = Scene.AllNodes.OfType <PhysSceneNode>().Distinct();
                triggerNodes  = physNodes.Where(n => n.IsTrigger);
                colliderNodes = physNodes.Where(n => !n.IsTrigger);
            }

            if (worldNode != null)
            {
                var loader = new WorldNodeLoader(GuiContext, worldNode);
                loader.Load(Scene);

                var worldLayers = Scene.AllNodes
                                  .Select(r => r.LayerName)
                                  .Distinct()
                                  .ToList();
                SetAvailableLayers(worldLayers);

                for (var i = 0; i < worldLayersComboBox.Items.Count; i++)
                {
                    worldLayersComboBox.SetItemChecked(i, true);
                }
            }

            ShowBaseGrid = false;

            ViewerControl.Invoke((Action)savedCameraPositionsControl.RefreshSavedPositions);
        }