diff --git a/dcc/maya/MayaCreateNewUSDAssets.py b/dcc/maya/MayaCreateNewUSDAssets.py new file mode 100644 index 0000000..8970379 --- /dev/null +++ b/dcc/maya/MayaCreateNewUSDAssets.py @@ -0,0 +1,141 @@ + +import sys +import os +from pxr import Gf, Kind, Sdf, Usd, UsdGeom, UsdShade +import time + +def create_variant_set(prim: Usd.Prim, variant_set_name: str, variants: list) -> Usd.VariantSet: + variant_set = prim.GetVariantSets().AddVariantSet(variant_set_name) + for variant in variants: + variant_set.AddVariant(variant) + + + return variant_set + +def add_sub_layer(sub_layer_path, root_layer): + sub_layer = Sdf.Layer.CreateNew(sub_layer_path) + # You can use standard python list.insert to add the subLayer to any position in the list + root_layer.subLayerPaths.append(sub_layer.identifier) + return sub_layer + +def CreateNewUSD(a): + + print(sys.version) + print("Creating new USD Assets list .. .. ..") + print(a) + + raw_s = r'{}'.format(a) + last_name = raw_s.split("\\")[-2] + print(last_name) + + + MainName = last_name.split("_")[0]+".usda" + MainName_material = last_name.split("_")[0]+"_material.usda" + MainName_model = last_name.split("_")[0]+"_model.usda" + MainName_lod0 = last_name.split("_")[0]+"_lod0.usda" + MainName_lod1 = last_name.split("_")[0]+"_lod1.usda" + MainName_lod2 = last_name.split("_")[0]+"_lod2.usda" + + MainDir = a+ MainName + MainDir_material = a+MainName_material + MainDir_model = a+ MainName_model + + MainDir_lod0 = a+ MainName_lod0 + MainDir_lod1 = a+ MainName_lod1 + MainDir_lod2 = a+ MainName_lod2 + + + + print(MainDir) + print(MainDir_material) + print(MainDir_model) + #stage_material = Usd.Stage.CreateNew(MainDir_material) + #stage_model = Usd.Stage.CreateNew(MainDir_model) + #stage_material.GetRootLayer().Save() + #stage_model.GetRootLayer().Save() + + + stage_Main = Usd.Stage.CreateNew(MainDir) + default_prim: Usd.Prim = UsdGeom.Xform.Define(stage_Main, Sdf.Path("/World")).GetPrim() + stage_Main.SetDefaultPrim(default_prim) + + + + sub_layer1= add_sub_layer(MainDir_material, stage_Main.GetRootLayer()) + sub_layer2= add_sub_layer(MainDir_model, stage_Main.GetRootLayer()) + + + #stage_Main.GetRootLayer().Save() + + usda = stage_Main.GetRootLayer().ExportToString() + print(usda) + + # Check to see if the sublayer is loaded + loaded_layers = stage_Main.GetRootLayer().GetLoadedLayers() + assert sub_layer1 in loaded_layers + assert sub_layer2 in loaded_layers + + stage_Main.GetRootLayer().Save() + + + # three LODS + + stage_LOD0 = Usd.Stage.CreateNew(MainDir_lod0) + stage_LOD1 = Usd.Stage.CreateNew(MainDir_lod1) + stage_LOD2 = Usd.Stage.CreateNew(MainDir_lod2) + + default_prim_model2 = UsdGeom.Xform.Define(stage_LOD0, Sdf.Path("/World")).GetPrim() + stage_LOD0.SetDefaultPrim(default_prim_model2) + stage_LOD0.GetRootLayer().Save() + + default_prim_lod1= UsdGeom.Xform.Define(stage_LOD1, Sdf.Path("/World")).GetPrim() + default_prim_lod2= UsdGeom.Xform.Define(stage_LOD2, Sdf.Path("/World")).GetPrim() + + + stage_LOD1.SetDefaultPrim(default_prim_lod1) + stage_LOD2.SetDefaultPrim(default_prim_lod2) + + stage_LOD1.GetRootLayer().Save() + stage_LOD2.GetRootLayer().Save() + + + + + stage_model = Usd.Stage.Open(MainDir_model) + + default_prim_model = UsdGeom.Xform.Define(stage_model, Sdf.Path("/World")).GetPrim() + stage_model.SetDefaultPrim(default_prim_model) + stage_model.GetRootLayer().Save() + variants = ["LOD0", "LOD1", "LOD2"] + + model_varset = create_variant_set(default_prim_model, "model", variants) + + model_varset.SetVariantSelection('LOD0') + with model_varset.GetVariantEditContext(): + default_prim_model.GetReferences().AddReference(MainDir_lod0) + + model_varset.SetVariantSelection('LOD1') + with model_varset.GetVariantEditContext(): + default_prim_model.GetReferences().AddReference(MainDir_lod1) + + model_varset.SetVariantSelection('LOD2') + with model_varset.GetVariantEditContext(): + default_prim_model.GetReferences().AddReference(MainDir_lod2) + + + stage_model.GetRootLayer().Save() + + try: + raise KeyboardInterrupt # Simulating a keyboard interrupt + except KeyboardInterrupt: + input("Press Enter to exit...") + + + + + + + +if __name__ == "__main__": + a = sys.argv[1] + CreateNewUSD(a) \ No newline at end of file diff --git a/dcc/maya/MayaMiddleScript.py b/dcc/maya/MayaMiddleScript.py new file mode 100644 index 0000000..86d62e3 --- /dev/null +++ b/dcc/maya/MayaMiddleScript.py @@ -0,0 +1,36 @@ + +import sys +import os +import psutil + +cwd = os.getcwd() + +def writeToDir(a): + cwd = os.getcwd() + newFileDir = cwd+"\\..\\dcc\\maya\\dir.txt" + open(newFileDir, 'w').close() + f = open(newFileDir, "w") + f.write(a) + f.close() + + + + + + +def check_if_process_running(process_name): + for process in psutil.process_iter(['name']): + if process .info['name'] == process_name: + return True + return False + + + +if __name__ == "__main__": + a = sys.argv[1] + check = check_if_process_running("maya.exe") + if not check: + os.system("start maya.exe") + + #print(check) + writeToDir(a) \ No newline at end of file diff --git a/dcc/maya/dir.txt b/dcc/maya/dir.txt new file mode 100644 index 0000000..edb5874 --- /dev/null +++ b/dcc/maya/dir.txt @@ -0,0 +1 @@ +C:\Users\Han Wang\Documents\Griddle\newassets_87146859\ \ No newline at end of file diff --git a/frontend/src/main/lib/local-assets.ts b/frontend/src/main/lib/local-assets.ts index 07e02b3..274cb4a 100644 --- a/frontend/src/main/lib/local-assets.ts +++ b/frontend/src/main/lib/local-assets.ts @@ -10,7 +10,7 @@ import { DownloadedEntry, Version } from '../../types/ipc'; import { getAuthToken } from './authentication'; import fetchClient from './fetch-client'; import store, { griddleFrontendStore } from './store'; - +import { spawn } from 'child_process'; // TODO: clean up error handling here + in message-handlers export function getDownloadFolder() { @@ -78,6 +78,29 @@ export async function openFolder(asset_id: string) { shell.openPath(path.join(getDownloadFolder(), stored.folderName)); } +export async function openMaya(asset_id: string) { + const stored = getDownloadedVersionByID(asset_id); + if (!stored) return; + + const myPath = path.join(getDownloadFolder(), stored.folderName) + const pythonPath = path.join(__dirname,"../../../dcc/maya/MayaMiddleScript.py") + const cmd = `python ${pythonPath} "${myPath}`; + // replace with your command + const childProcess = spawn(cmd, [], { + shell: true, + }); + + childProcess.stdout.on('data', (data) => { + console.log(data.toString()); + }); + + childProcess.stderr.on('data', (data) => { + console.error(data.toString()); + }); + + //shell.openPath(path.join(getDownloadFolder(), stored.folderName)); +} + async function zipFolder(sourceFolder: string, zipFilePath: string): Promise { return new Promise((resolve, reject) => { const output = createWriteStream(zipFilePath); diff --git a/frontend/src/main/message-handlers.ts b/frontend/src/main/message-handlers.ts index 6396f38..95b9ce9 100644 --- a/frontend/src/main/message-handlers.ts +++ b/frontend/src/main/message-handlers.ts @@ -6,6 +6,7 @@ import { downloadVersion, getDownloadedVersions, openFolder, + openMaya, unsyncAsset, } from './lib/local-assets'; @@ -43,6 +44,10 @@ const messageHandlers: MessageHandlers = { await openFolder(asset_id); return { ok: true }; }, + 'assets:open-Maya': async (_, { asset_id}) => { + await openMaya(asset_id); + return { ok: true }; + }, 'auth:get-auth-token': async () => { return { authToken: getAuthToken() }; }, diff --git a/frontend/src/renderer/src/components/metadata.tsx b/frontend/src/renderer/src/components/metadata.tsx index a6a5daa..06f5c8e 100644 --- a/frontend/src/renderer/src/components/metadata.tsx +++ b/frontend/src/renderer/src/components/metadata.tsx @@ -111,6 +111,19 @@ export default function Metadata() { asset_id: asset.id, }); }; + const onOpenMayaClick = async () => { + if (!asset) return; + + const downloaded = downloadedVersions?.find(({ asset_id }) => asset_id === asset.id); + if (!downloaded) return; + + await window.api.ipc('assets:open-Maya', { + asset_id: asset.id, + semver: downloaded.semver, + }); + }; + + if (!asset) { return ( @@ -264,6 +277,15 @@ export default function Metadata() { Open + + +