Ejemplo n.º 1
0
 public View(Scene xiScene, Camera xiCamera, AbstractRenderer xiRenderer)
 {
     mScene = xiScene;
       mCamera = xiCamera;
       mRenderer = xiRenderer;
       xiRenderer.NextFrame += new AbstractRenderer.NextFrameEventHandler(Renderer_NextFrame);
 }
Ejemplo n.º 2
0
 public World(Scene scene)
 {
     mScene = scene;
 }
Ejemplo n.º 3
0
 public MMEdEditorView(ThreeDeeEditor xiViewer, Scene xiScene, Camera xiCamera, AbstractRenderer xiRenderer)
     : base(xiScene, xiCamera, xiRenderer)
 {
     mViewer = xiViewer;
 }
Ejemplo n.º 4
0
            public SceneHolder(Scene xiScene)
            {
                Entities = new List<Entity>();
                Entities.AddRange(xiScene.Entities);

                Textures = new List<TextureHolder>();
                Dictionary<int,bool> lTextureIdsSeen = new Dictionary<int,bool>();
                foreach (Entity e in Entities)
                {
                  foreach (Mesh m in e.Meshes)
                  {
                if (m.RenderMode == RenderMode.Textured)
                {
                  if (!lTextureIdsSeen.ContainsKey(m.Texture))
                  {
                lTextureIdsSeen[m.Texture] = true;
                Textures.Add(new TextureHolder(
                  m.Texture,
                  AbstractRenderer.TextureIdToImage(m.Texture)));
                  }
                }
                  }
                }
            }
Ejemplo n.º 5
0
        private ThreeDeeViewer(MainForm xiMainForm)
            : base(xiMainForm)
        {
            mMainForm.KeyPreview = true;
              mMainForm.KeyPress += new KeyPressEventHandler(this.KeyPressHandle);
              mMainForm.FormClosing += new FormClosingEventHandler(mMainForm_FormClosing);
              mMainForm.Viewer3DRenderingSurface.MouseDown += new MouseEventHandler(Viewer3DRenderingSurface_MouseDown);
              mMainForm.Viewer3DRenderingSurface.MouseUp += new MouseEventHandler(Viewer3DRenderingSurface_MouseUp);
              mMainForm.Viewer3DRenderingSurface.MouseMove += new MouseEventHandler(Viewer3DRenderingSurface_MouseMove);
              mMainForm.ChunkTreeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(ChunkTreeView_NodeMouseClick);

              mRenderer = new ImmediateModeRenderer();
              mRenderer.Attach(mMainForm.Viewer3DRenderingSurface);

              mScene = new Scene();
              mCamera = new Camera(80, 0.1, 1e10);
              mView = new MMEdViewerView(this, mScene, mCamera, mRenderer);
              mLight = new Light();
              mLight.DiffuseIntensity = 0.1;
              mLight.SpecularIntensity = 0.02;

              //add view mode menus:
              mOptionsMenu = new ToolStripMenuItem("3D");
              //
              PropertyController lMoveCtrl = new PropertyController(this, "MovementMode");
              mOptionsMenu.DropDownItems.AddRange(lMoveCtrl.CreateMenuItems());
              mOptionsMenu.DropDownItems.Add(new ToolStripSeparator());
              //
              PropertyController lLightCtrl = new PropertyController(this, "LightingMode");
              mOptionsMenu.DropDownItems.AddRange(lLightCtrl.CreateMenuItems());
              mOptionsMenu.DropDownItems.Add(new ToolStripSeparator());
              //
              PropertyController lNormCtrl = new PropertyController(this, "DrawNormalsMode");
              mOptionsMenu.DropDownItems.AddRange(lNormCtrl.CreateMenuItems());
              mOptionsMenu.DropDownItems.Add(new ToolStripSeparator());
              //
              PropertyController lTexModeCtrl = new PropertyController(this, "TextureMode");
              mOptionsMenu.DropDownItems.AddRange(lTexModeCtrl.CreateMenuItems());
              mOptionsMenu.DropDownItems.Add(new ToolStripSeparator());
              //
              PropertyController lSelMetaCtrl = new PropertyController(this, "SelectedMetadata");
              mOptionsMenu.DropDownItems.Add(lSelMetaCtrl.CreateToolStripComboBox());
              mOptionsMenu.DropDownItems.Add(new ToolStripSeparator());
              //
              mOptionsMenu.DropDownItems.Add(new ToolStripMenuItem("Hide all invisible Flats", null, new EventHandler(this.HideAllFlatsWithoutFlgDClicked)));
              //
              if (DEBUG_ALLOW_LOAD_SAVE_SCENE)
              {
            mOptionsMenu.DropDownItems.Add(new ToolStripSeparator());
            mOptionsMenu.DropDownItems.Add(new ToolStripMenuItem(
              "Save scene to XML...",
              null,
              SaveSceneToXML));
            mOptionsMenu.DropDownItems.Add(new ToolStripMenuItem(
              "Load scene from XML...",
              null,
              LoadSceneFromXML));
              }
              mOptionsMenu.DropDownItems.Add(new ToolStripMenuItem(
            "Export scene to VRML...",
            null,
            ExportSceneToVRML));
              //
              mMainForm.mMenuStrip.Items.Add(mOptionsMenu);
        }
Ejemplo n.º 6
0
        private void InitialiseThreeDeeView()
        {
            if (mSubject == null)
              {
            return;
              }

              int SCALE = 256;
              int GRIDSIZE = 9; // Should be an odd number so the centre is the middle of a tile.
              mRenderer = new ImmediateModeRenderer();
              mRenderer.Attach(mMainForm.CameraRenderingSurface);

              mScene = new Scene();
              mCamera = new Camera(80, 0.1, 1e10);
              mView = new GLTK.View(mScene, mCamera, mRenderer);

              mScene.Clear();
              if (mMainForm.CurrentLevel != null)
              {
            // Create a surface and fill it with a 10 x 10 grid of squares
            MMEdEntity lSurface = new MMEdEntity(mSubject);

            for (int x = 0; x < GRIDSIZE; x++)
            {
              for (int y = 0; y < GRIDSIZE; y++)
              {
            Mesh lSquare = new OwnedMesh(mSubject, PolygonMode.Quads);
            lSquare.AddFace(
              new Vertex(new GLTK.Point(x, y, 0), 0, 0),
              new Vertex(new GLTK.Point(x + 1, y, 0), 1, 0),
              new Vertex(new GLTK.Point(x + 1, y + 1, 0), 1, 1),
              new Vertex(new GLTK.Point(x, y + 1, 0), 0, 1));
            lSquare.RenderMode = RenderMode.Wireframe;
            lSurface.Meshes.Add(lSquare);
              }
            }

            // Add it to the scene at the origin
            lSurface.Scale(SCALE, SCALE, 1.0);
            short lOffset = (short)(-SCALE * GRIDSIZE / 2);
            GLTK.Point lNewPos = ThreeDeeViewer.Short3CoordToPoint(new Short3Coord(lOffset, lOffset, 0));
            lSurface.Position = new GLTK.Point(lNewPos.x, lNewPos.y, -lNewPos.z);
            mScene.AddRange(new MMEdEntity[] { lSurface });

            // Use a random object from the level for now.
            Level lLevel = mMainForm.CurrentLevel;
            TMDChunk lObject = lLevel.GetObjtById(1);
            mScene.AddRange(lObject.GetEntities(
              mMainForm.CurrentLevel,
              MMEd.Viewers.ThreeDee.eTextureMode.NormalTextures,
              eTexMetaDataEntries.Steering));

            string lExceptionWhen = "opening file";
            try
            {
              ThreeDeeViewer.SceneHolder sh;
              string lFilename = string.Format("{0}{1}..{1}camera-editor-scene.xml",
            Path.GetDirectoryName(
              new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath),
            Path.DirectorySeparatorChar);

              using (FileStream fs = File.OpenRead(lFilename))
              {
            lExceptionWhen = "deserialising the scene";
            XmlSerializer xs = new XmlSerializer(typeof(ThreeDeeViewer.SceneHolder));
            sh = (ThreeDeeViewer.SceneHolder)xs.Deserialize(fs);
              }
              lExceptionWhen = "fixing texture ids";
              Dictionary<int, int> lSavedTexIdsToLiveTexIds = new Dictionary<int, int>();
              foreach (ThreeDeeViewer.TextureHolder th in sh.Textures)
              {
            if (th.Bitmap != null)
            {
              lSavedTexIdsToLiveTexIds[th.ID] = AbstractRenderer.ImageToTextureId(th.Bitmap);
            }
            else
            {
              lSavedTexIdsToLiveTexIds[th.ID] = 0;
            }
              }
              foreach (Entity ent in sh.Entities)
              {
            foreach (Mesh m in ent.Meshes)
            {
              if (m.RenderMode == RenderMode.Textured)
              {
                m.Texture = lSavedTexIdsToLiveTexIds[m.Texture];
              }
            }
              }
              mScene.Objects.Clear();
              mScene.AddRange(sh.Entities);
            }
            catch (Exception err)
            {
              System.Diagnostics.Trace.WriteLine(err);
              MessageBox.Show(string.Format("Exception occurred while {0}: {1}", lExceptionWhen, err.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            UpdateCameraThreeDee();
              }
              else
              {
            System.Windows.Forms.MessageBox.Show("3D view is only available when editing a level");
            mMainForm.CameraRenderingSurface.Visible = false;
              }
        }
Ejemplo n.º 7
0
        void CreateView(RenderingSurface xiSurface, Scene xiScene, Camera xiCamera, RenderMode xiFixedRenderMode)
        {
            xiSurface.MouseDown += new MouseEventHandler(Viewer3DRenderingSurface_MouseDown);
              xiSurface.MouseUp += new MouseEventHandler(Viewer3DRenderingSurface_MouseUp);
              xiSurface.MouseMove += new MouseEventHandler(Viewer3DRenderingSurface_MouseMove);
              xiSurface.MouseWheel += new MouseEventHandler(Viewer3DRenderingSurface_MouseWheel);
              xiSurface.GotFocus += new EventHandler(Viewer3DRenderingSurface_GotFocus);

              ImmediateModeRenderer lRenderer = new ImmediateModeRenderer();
              lRenderer.FixedRenderMode = xiFixedRenderMode;
              lRenderer.Attach(xiSurface);

              MMEdEditorView lView = new MMEdEditorView(this, xiScene, xiCamera, lRenderer);

              mViews.Add(xiSurface, lView);
        }