Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions dcc/maya/MayaCreateNewUSDAssets.py
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 36 additions & 0 deletions dcc/maya/MayaMiddleScript.py
Original file line number Diff line number Diff line change
@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does "maya.exe" work for mac or linux?

if not check:
os.system("start maya.exe")

#print(check)
writeToDir(a)
1 change: 1 addition & 0 deletions dcc/maya/dir.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be set for each user..?

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:\Users\Han Wang\Documents\Griddle\newassets_87146859\
25 changes: 24 additions & 1 deletion frontend/src/main/lib/local-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we know if this works on an actual build? like are the python scripts actually included in the bundle?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the dcc files will be stored under the new folder root/dcc/ so griddle should be able to locate the python scripts.

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<void> {
return new Promise((resolve, reject) => {
const output = createWriteStream(zipFilePath);
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/main/message-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
downloadVersion,
getDownloadedVersions,
openFolder,
openMaya,
unsyncAsset,
} from './lib/local-assets';

Expand Down Expand Up @@ -43,6 +44,10 @@ const messageHandlers: MessageHandlers = {
await openFolder(asset_id);
return { ok: true };
},
'assets:open-Maya': async (_, { asset_id}) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably change casing to "open-maya" to match other call names but not super important

await openMaya(asset_id);
return { ok: true };
},
'auth:get-auth-token': async () => {
return { authToken: getAuthToken() };
},
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/renderer/src/components/metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -264,6 +277,15 @@ export default function Metadata() {
<MdFolderOpen />
Open
</button>

<button
className="btn btn-ghost btn-sm flex w-full flex-row flex-nowrap items-center justify-start gap-2 text-sm font-normal"
onClick={onOpenMayaClick}
>
<MdFolderOpen />
Copy link
Member

@printer83mph printer83mph Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Icon or layout should be different to clarify different actions

Open In Maya
</button>

<Link
className="btn btn-outline btn-primary mt-2 w-full justify-start"
to={{ pathname: `/update-asset`, search: `?id=${asset.id}` }}
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/types/ipc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ type GriddleIpcSchema = {
request: { asset_id: string };
response: { ok: boolean };
};
'assets:open-Maya': {
request: { asset_id: string; semver: string | null };
response: { ok: boolean };
};

'auth:get-auth-token': {
request: null;
response: { authToken: string | null };
Expand Down