public override void onRightMouseUp(int itemId, string mousePos, SimObject obj)
        {
            MenuBuilder popup;
            GuiCanvas Canvas = "Canvas";

            bool haveObjectEntries = false;
            bool haveLockAndHideEntries = true;

            // Handle multi-selection.
            if (this.getSelectedItemsCount() > 1)
                {
                popup = "ETMultiSelectionContextPopup";
                if (!popup.isObject())
                    {
                    ObjectCreator popCreator = new ObjectCreator("PopupMenu", "ETMultiSelectionContextPopup", typeof (MenuBuilder));
                    popCreator["isPopup"] = true.AsString();

                    popCreator["item[0]"] = "Delete" + '\t' + "" + '\t' + "EditorMenuEditDelete();";
                    popCreator["item[1]"] = "Group" + '\t' + "" + '\t' + "EWorldEditor.addSimGroup( true );";

                    popup = popCreator.Create();
                    }
                }

                // Open context menu if this is a CameraBookmark
            else if (obj.isMemberOfClass("CameraBookmark"))
                {
                popup = "ETCameraBookmarkContextPopup";
                if (!popup.isObject())
                    {
                    ObjectCreator popupCreator = new ObjectCreator("PopupMenu", "ETCameraBookmarkContextPopup", typeof (MenuBuilder));
                    popupCreator["isPopup"] = true.AsString();

                    popupCreator["item[0]"] = "Go To Bookmark" + '\t' + "" + '\t' + "EditorGui.jumpToBookmark( this.bookmark.getInternalName() );";

                    popupCreator["bookmark"] = "-1";

                    popup = popupCreator.Create();
                    }

                ((MenuBuilder) "ETCameraBookmarkContextPopup")["bookmark"] = obj;
                }
   
                // Open context menu if this is set CameraBookmarks group.
            else if (obj.name == "CameraBookmarks")
                {
                popup = "ETCameraBookmarksGroupContextPopup";
                if (!popup.isObject())
                    {
                    popup = new ObjectCreator("PopupMenu", "ETCameraBookmarksGroupContextPopup", typeof (MenuBuilder)).Create();
                    popup.isPopup = true;

                    popup.addItem("0", "Add Camera Bookmark" + '\t' + "" + '\t' + "EditorGui.addCameraBookmarkByGui();");
                    }
                }

                // Open context menu if this is a SimGroup
            else if (obj.isMemberOfClass("SimGroup"))
                {
                popup = "ETSimGroupContextPopup";
                if (!popup.isObject())
                    {
                    ObjectCreator popupCreator = new ObjectCreator("PopupMenu", "ETSimGroupContextPopup", typeof (MenuBuilder));
                    popupCreator["isPopup"] = true.AsString();

                    popupCreator["item[0]"] = "Rename" + '\t' + "" + '\t' + "EditorTree.showItemRenameCtrl( EditorTree.findItemByObjectId( ETSimGroupContextPopup.object ) );";
                    popupCreator["item[1]"] = "Delete" + '\t' + "" + '\t' + "EWorldEditor.deleteMissionObject( ETSimGroupContextPopup.object );";
                    popupCreator["item[2]"] = "Inspect" + '\t' + "" + '\t' + "inspectObject( ETSimGroupContextPopup.object );";
                    popupCreator["item[3]"] = "-";
                    popupCreator["item[4]"] = "Toggle Lock Children" + '\t' + "" + '\t' + "EWorldEditor.toggleLockChildren( ETSimGroupContextPopup.object );";
                    popupCreator["item[5]"] = "Toggle Hide Children" + '\t' + "" + '\t' + "EWorldEditor.toggleHideChildren( ETSimGroupContextPopup.object );";
                    popupCreator["item[6]"] = "-";
                    popupCreator["item[7]"] = "Group" + '\t' + "" + '\t' + "EWorldEditor.addSimGroup( true );";
                    popupCreator["item[8]"] = "-";
                    popupCreator["item[9]"] = "Add New Objects Here" + '\t' + "" + '\t' + "EWCreatorWindow.setNewObjectGroup( ETSimGroupContextPopup.object );";
                    popupCreator["item[10]"] = "Add Children to Selection" + '\t' + "" + '\t' + "EWorldEditor.selectAllObjectsInSet( ETSimGroupContextPopup.object, false );";
                    popupCreator["item[11]"] = "Remove Children from Selection" + '\t' + "" + '\t' + "EWorldEditor.selectAllObjectsInSet( ETSimGroupContextPopup.object, true );";

                    popupCreator["object"] = "-1";

                    popup = popupCreator.Create();
                    }

                popup["object"] = obj;

                bool hasChildren = ((SimGroup) obj).getCount() > 0;
                popup.enableItem(10, hasChildren);
                popup.enableItem(11, hasChildren);

                haveObjectEntries = true;
                haveLockAndHideEntries = false;
                }
   
                // Open generic context menu.
            else
                {
                popup = "ETContextPopup";
                if (!popup.isObject())
                    {
                    ObjectCreator popCreator = new ObjectCreator("PopupMenu", "ETContextPopup", typeof (MenuBuilder));
                    popCreator["isPopup"] = true.AsString();

                    popCreator["item[0]"] = "Rename" + '\t' + "" + '\t' + "EditorTree.showItemRenameCtrl( EditorTree.findItemByObjectId( ETContextPopup.object ) );";
                    popCreator["item[1]"] = "Delete" + '\t' + "" + '\t' + "EWorldEditor.deleteMissionObject( ETContextPopup.object );";
                    popCreator["item[2]"] = "Inspect" + '\t' + "" + '\t' + "inspectObject( ETContextPopup.object );";
                    popCreator["item[3]"] = "-";
                    popCreator["item[4]"] = "Locked" + '\t' + "" + '\t' + "ETContextPopup.object.setLocked( !ETContextPopup.object.locked ); EWorldEditor.syncGui();";
                    popCreator["item[5]"] = "Hidden" + '\t' + "" + '\t' + "EWorldEditor.hideObject( ETContextPopup.object, !ETContextPopup.object.hidden ); EWorldEditor.syncGui();";
                    popCreator["item[6]"] = "-";
                    popCreator["item[7]"] = "Group" + '\t' + "" + '\t' + "EWorldEditor.addSimGroup( true );";

                    popCreator["object"] = "-1";

                    popup = popCreator.Create();
                    }

                // Specialized version for ConvexShapes. 
                if (obj.isMemberOfClass("ConvexShape"))
                    {
                    popup = "ETConvexShapeContextPopup";
                    if (!popup.isObject())
                        {
                        ObjectCreator popCreator = new ObjectCreator("PopupMenu", "ETConvexShapeContextPopup", typeof (MenuBuilder));
                        popCreator["isPopup"] = true.AsString();

                        popCreator["item[8]"] = "-";
                        popCreator["item[9]"] = "Convert to Zone" + '\t' + "" + '\t' + "EWorldEditor.convertSelectionToPolyhedralObjects( \\\"Zone\\\" );";
                        popCreator["item[10]"] = "Convert to Portal" + '\t' + "" + '\t' + "EWorldEditor.convertSelectionToPolyhedralObjects( \\\"Portal\\\" );";
                        popCreator["item[11]"] = "Convert to Occluder" + '\t' + "" + '\t' + "EWorldEditor.convertSelectionToPolyhedralObjects( \\\"OcclusionVolume\\\" );";
                        popCreator["item[12]"] = "Convert to Sound Space" + '\t' + "" + '\t' + "EWorldEditor.convertSelectionToPolyhedralObjects( \\\"SFXSpace\\\" );";

                        popup = popCreator.Create();
                        }
                    }
      
                    // Specialized version for polyhedral objects.
                else if (obj.isMemberOfClass("Zone") || obj.isMemberOfClass("Portal") || obj.isMemberOfClass("OcclusionVolume") || obj.isMemberOfClass("SFXSpace"))
                    {
                    popup = "ETPolyObjectContextPopup";
                    if (!popup.isObject())
                        {
                        ObjectCreator popCreator = new ObjectCreator("PopupMenu", "ETPolyObjectContextPopup", typeof (MenuBuilder));
                        popCreator["isPopup"] = true.AsString();

                        popCreator["item[8]"] = "-";
                        popCreator["item[9]"] = "Convert to ConvexShape" + '\t' + "" + '\t' + "EWorldEditor.convertSelectionToConvexShape();";

                        popup = popCreator.Create();
                        }
                    }

                popup["object"] = obj;
                haveObjectEntries = true;
                }

            if (haveObjectEntries)
                {
                popup.enableItem(0, (obj.isNameChangeAllowed() && obj.getName() != "MissionGroup"));
                popup.enableItem(1, (obj.getName() != "MissionGroup"));
                if (haveLockAndHideEntries)
                    {
                    popup.checkItem(4, obj["locked"].AsBool());
                    popup.checkItem(5, obj.hidden);
                    }
                popup.enableItem(7, this.isItemSelected(itemId));
                }

            popup.showPopup(Canvas);
        }