main
henrique 2 months ago
parent 9aa3acc3b4
commit 00a789c410

@ -1,68 +1,56 @@
import os import os
from pymxs import runtime as rt from pymxs import runtime as rt
def install_vr4life_babylon_final(): def install_vr4life_2026_fixed():
try: try:
# 1. DEFINIR CAMINHOS # 1. CAMINHOS
plugin_dir = os.path.dirname(os.path.realpath(__file__)).replace("\\", "/") plugin_dir = os.path.dirname(os.path.realpath(__file__)).replace("\\", "/")
startup_dir = rt.getDir(rt.name("userStartupScripts"))
loader_path = os.path.join(startup_dir, "CreateVr4LifeMenus.ms")
# 2. O CONTEÚDO DO SCRIPT (Fiel ao repositório BabylonJS 2026)
# O segredo do 2026: usar interfaces dinâmicas e registrar no CUI
ms_content = f"""
(
-- Função principal de criação (Abordagem Babylon)
fn CreateVr4LifeMenu = (
local menuMgr = maxUtils.getMainMenuManager()
if menuMgr == undefined do menuMgr = menuMan
if menuMgr != undefined then ( # Onde o MNX foi copiado pelo seu instalador
local mainMenuBar = menuMgr.getMainMenuBar() pasta_macros = rt.getDir(rt.name("userMacros"))
pasta_enu = os.path.dirname(pasta_macros)
-- Remove duplicados para evitar poluição caminho_mnx = os.path.join(pasta_enu, "en-US", "UI", "vr4life.mnx").replace("\\", "/")
local existingMenu = menuMgr.findMenu "Vr4Life"
if existingMenu != undefined do menuMgr.unRegisterMenu existingMenu
-- Cria o menu "Vr4Life"
local newMenu = menuMgr.createMenu "Vr4Life"
-- Cria os itens (Actions) - Usando a categoria Immerse Games do seu MNX
local actionLauncher = menuMgr.createActionItem "VR4Life_Launcher" "Immerse Games"
local actionUpdate = menuMgr.createActionItem "VR4Life_Update" "Immerse Games"
newMenu.addItem actionLauncher -1
newMenu.addItem actionUpdate -1
-- Adiciona à barra principal (Posição final)
local subMenuItem = menuMgr.createSubMenuItem "Vr4Life" newMenu
mainMenuBar.addItem subMenuItem (mainMenuBar.numItems())
menuMgr.updateMenuBar()
format ">> VR4Life: Menu injetado via %\\n" (getSourceFileName())
)
)
-- Registro das Macros (O motor por trás dos botões) # 2. REGISTRAR AS MACROS (Obrigatorio para o MNX funcionar)
macroScript VR4Life_Launcher category:"Immerse Games" tooltip:"Abrir VR4Life" ( on execute do python.executeFile "{plugin_dir}/run_vr4life.py" ) # Usamos exatamente a categoria "Immerse Games" que está no seu MNX
macroScript VR4Life_Update category:"Immerse Games" tooltip:"Atualizar VR4Life" ( on execute do python.executeFile "{plugin_dir}/vr4life_updater.py" ) macro_cmd = f"""
macroScript VR4Life_Launcher
category:"Immerse Games"
tooltip:"Abrir VR4Life"
(
on execute do python.executeFile "{plugin_dir}/run_vr4life.py"
)
-- Gatilhos de execução (O Babylon usa múltiplos para garantir) macroScript VR4Life_Update
CreateVr4LifeMenu() category:"Immerse Games"
callbacks.removeScripts id:#VR4LifeMenuSetup tooltip:"Atualizar VR4Life"
callbacks.addScript #cuiRegisterMenus "CreateVr4LifeMenu()" id:#VR4LifeMenuSetup (
callbacks.addScript #filePostOpen "CreateVr4LifeMenu()" id:#VR4LifeMenuSetup on execute do python.executeFile "{plugin_dir}/vr4life_updater.py"
) )
""" """
# 3. GRAVAR O ARQUIVO NO DISCO (Persistência estilo Babylon) rt.execute(macro_cmd)
with open(loader_path, "w", encoding="utf-8") as f:
f.write(ms_content)
# 4. EXECUTAR O ARQUIVO CRIADO # 3. CARREGAR O MNX VIA INTERFACE DE CONTEXTO (Abordagem Babylon 2026)
rt.fileIn(loader_path) # Se o menuMan é undefined, usamos o carregamento de arquivo de configuração
setup_script = f"""
(
local mnxPath = "{caminho_mnx}"
if (doesFileExist mnxPath) then (
-- No 2026, tentamos carregar o arquivo de menus diretamente
-- sem passar pelas propriedades de "getMainMenuBar"
try (
menuMan.loadMenuFile mnxPath
menuMan.updateMenuBar()
) catch (
-- Se falhar aqui, o Max carregará no próximo boot
-- pois o arquivo está na pasta oficial de UI
)
)
)
"""
rt.execute(setup_script)
print(f">> Arquivo gerado em: {loader_path}") print(">> VR4Life: Macros registradas e MNX vinculado.")
print(">> Se o menu não aparecer agora, ele aparecerá ao abrir qualquer arquivo ou reiniciar.")
return True return True
except Exception as e: except Exception as e:
@ -70,4 +58,4 @@ def install_vr4life_babylon_final():
return False return False
if __name__ == "__main__": if __name__ == "__main__":
install_vr4life_babylon_final() install_vr4life_2026_fixed()
Loading…
Cancel
Save