-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
USD_v01_Core Single, Variant, and SubSOPvariant is working
- Loading branch information
0 parents
commit 7d56f89
Showing
19 changed files
with
1,425 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import sys, os | ||
from PySide2.QtCore import Qt | ||
from PySide2.QtWidgets import QApplication, QPushButton, QListWidget, QVBoxLayout, QHBoxLayout, QWidget, QMessageBox, QLineEdit | ||
|
||
SRC_PATH = "M:\\Notes\\Tools\\USD_Megascan_Importer" | ||
|
||
class ExportPathVarUI(QWidget): | ||
def __init__(self, parentWidget): | ||
super().__init__() | ||
self._parent = parentWidget | ||
self._ui() | ||
|
||
def _ui(self): | ||
self.setWindowTitle("Path Variable") | ||
self.setWindowFlags(Qt.WindowStaysOnTopHint) | ||
# self.setMaximumWidth() | ||
|
||
vbox = QVBoxLayout(self) | ||
self.listWidget = QListWidget() | ||
self.addVarLine = QLineEdit("Add Export Path Here") | ||
RemoveSelected = QPushButton("Remove Selected") | ||
Reset = QPushButton("Reset") | ||
Add = QPushButton("Add") | ||
Save = QPushButton("Save") | ||
|
||
RemoveSelected.clicked.connect(self.Remove_was_clicked) | ||
Reset.clicked.connect(self.Reset_was_clicked) | ||
Save.clicked.connect(self.Save_was_clicked) | ||
Add.clicked.connect(self.Add_was_clicked) | ||
|
||
hbox1 = QHBoxLayout() | ||
hbox2 = QHBoxLayout() | ||
hbox1.addWidget(self.addVarLine) | ||
hbox1.addWidget(Add) | ||
hbox2.addWidget(RemoveSelected) | ||
hbox2.addWidget(Reset) | ||
hbox2.addWidget(Save) | ||
|
||
self.listWidget.addItems(self._getList()) ## Reading all items | ||
|
||
self.listWidget.itemDoubleClicked.connect(self.onClicked) | ||
|
||
vbox.addWidget(self.listWidget) | ||
vbox.addLayout(hbox1) | ||
vbox.addLayout(hbox2) | ||
self.setLayout(vbox) | ||
|
||
def Reset_was_clicked(self): | ||
self.listWidget.clear() | ||
self.listWidget.addItem("$HIP/usd/assets") | ||
|
||
def Save_was_clicked(self, parentWidget): | ||
if self.listWidget.count() == 0: | ||
QMessageBox.critical(self, "Need atleast one Variable", "Export Path Variable list should atleast contain one variable. Reset if you want to continue with default path ($HIP/usd)") | ||
|
||
self._parent.SetPathPrefixCombo.clear() # clearing the combobox | ||
with open(self.exportPathPresetFile, "w") as file: | ||
for i in range(self.listWidget.count()): | ||
file.write((self.listWidget.item(i).text()) + ",") | ||
print(self.listWidget.item(i).text()) | ||
self._parent.SetPathPrefixCombo.addItem(self.listWidget.item(i).text()) | ||
|
||
print (self._parent.SetPathPrefixCombo.itemText(2)) | ||
# # parentWidget.SetPathPrefixSelection.addItems(self._getList()) | ||
|
||
self.close() | ||
|
||
def Remove_was_clicked(self): | ||
for i in self.listWidget.selectedItems(): | ||
self.listWidget.takeItem(self.listWidget.row(i)) | ||
|
||
def Add_was_clicked(self): | ||
if self.addVarLine.text() != "Add Export Path Here" and self.addVarLine.text().rstrip() != "": | ||
self.listWidget.addItem(self.addVarLine.text().strip()) | ||
|
||
def onClicked(self, item): | ||
QMessageBox.information(self, "Info", item.text()) | ||
|
||
def _getList(self): | ||
if not os.path.exists(SRC_PATH + "\\bin"): | ||
os.makedirs(SRC_PATH + "\\bin") | ||
if not os.path.exists(SRC_PATH + "\\bin\\preset"): | ||
os.makedirs(SRC_PATH + "\\bin\\preset") | ||
|
||
## Create a default file if it doesn't exists | ||
self.exportPathPresetFile = SRC_PATH + "\\bin\\preset\\exportpath.csv" | ||
if not os.path.exists(self.exportPathPresetFile): | ||
print("it not exist") | ||
with open(self.exportPathPresetFile, "w") as file: | ||
file.write("$HIP/usd/assets,") | ||
# file.write("$JIP/USD,") | ||
|
||
## Get List | ||
with open(self.exportPathPresetFile, "r") as file: | ||
for line in file: | ||
return line.split(",")[:-1] | ||
|
||
|
||
def main(): | ||
app = QApplication(sys.argv) | ||
ex = ExportPathVarUI() | ||
ex.show() | ||
app.exec_() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import hou | ||
|
||
class USD_Asset_Builder(): | ||
def __init__(self, asset_name, asset_path, export_prefix= "$HIP/usd/assets"): | ||
self.ASSET_NAME = asset_name | ||
self.ASSET_PATH = asset_path | ||
self.EXPORT_PATH = export_prefix | ||
# self.ASSET_NAME = ASSET_NAME | ||
## Check if the asset Stager Exists and use it if it does | ||
if hou.node("/stage/MS_Asset_USD_Processor") == None: | ||
Asset_Stager = hou.node("/stage").createNode("lopnet", "MS_Asset_USD_Processor") | ||
Asset_Stager.setUserData("nodeinfo_boxPos", "0") | ||
self.i = int(Asset_Stager.userData("nodeinfo_boxPos")) | ||
print("i = ", self.i) | ||
else: | ||
print("Asset is being imported in /stage/MS_Asset_USD_Processor") | ||
Asset_Stager = hou.node("/stage/MS_Asset_USD_Processor") | ||
self.i = int(Asset_Stager.userData("nodeinfo_boxPos")) | ||
print("i = ", self.i) | ||
|
||
self.Stager = Asset_Stager | ||
|
||
## Create a basic component builder | ||
self.asset_compGeo = Asset_Stager.createNode("componentgeometry", self.ASSET_NAME + "_cGeo") | ||
self.asset_compMat = Asset_Stager.createNode("componentmaterial", self.ASSET_NAME + "_cMat") | ||
self.asset_matLib = Asset_Stager.createNode("materiallibrary", self.ASSET_NAME + "_cMLib") | ||
self.asset_compOut = Asset_Stager.createNode("componentoutput", self.ASSET_NAME + "_cOut") | ||
|
||
self.asset_compMat.setFirstInput(self.asset_compGeo) | ||
self.asset_compMat.setNextInput(self.asset_matLib) | ||
self.asset_compOut.setNextInput(self.asset_compMat) | ||
self.asset_compMat.setGenericFlag(hou.nodeFlag.Display, True) | ||
# time.sleep(3) | ||
self.asset_compOut.setGenericFlag(hou.nodeFlag.Display, True) | ||
|
||
|
||
# Global Component Output Settings | ||
self.asset_matLib.parm("matpathprefix").set("/ASSET/mtl/") | ||
self.asset_compMat.parm("variantname").set("Default_MS_Mat") | ||
self.asset_compMat.parm("primpattern1").set("*") | ||
self.asset_compOut.parm("thumbnailmode").set(2) | ||
self.asset_compOut.parm("res1").set(256) | ||
self.asset_compOut.parm("res2").set(256) | ||
self.asset_compOut.parm("autothumbnail").set(True) | ||
|
||
self.Stager_nodes = [self.asset_compGeo, self.asset_compMat, self.asset_compOut, self.asset_matLib] | ||
|
||
|
||
|
||
## Set Network Box | ||
def _create_netBox(self, *args): | ||
self.Stager.layoutChildren() | ||
|
||
self.netbox = self.Stager.createNetworkBox(self.ASSET_NAME) | ||
self.netbox.setComment(self.ASSET_NAME) | ||
|
||
for arg in args: | ||
self.netbox.addItem(arg) | ||
|
||
self.netbox.fitAroundContents() | ||
|
||
self.i+=1 | ||
self.netbox.setPosition(hou.Vector2((self.i%5)*8,-(self.i//5)*8)) | ||
self.Stager.setUserData("nodeinfo_boxPos", str(self.i)) | ||
|
||
#-----------------------------------------------------------# | ||
# Set Single Mesh Export | ||
def setMeshExport(self, IndividualVarLayer = False): | ||
"""Class Method sets file paths for exports and runs the export commands | ||
IndividualVarLayer creates individual variant Layers for LAG | ||
""" | ||
if IndividualVarLayer: | ||
self.asset_compOut.parm("variantlayers").set(True) | ||
|
||
# Setting Component Output Parameters | ||
self.asset_compOut.parm("rootprim").set("/" + self.ASSET_NAME) | ||
self.asset_compOut.parm("lopoutput").set(self.EXPORT_PATH + "/" + self.ASSET_NAME + "/" + self.asset_compOut.parm("filename").eval()) | ||
|
||
buttonPath = self.asset_compOut.path() + "/execute" | ||
hou.parm(buttonPath).pressButton() | ||
|
||
buttonPath = self.asset_compOut.path() + "/addtogallery" | ||
hou.parm(buttonPath).pressButton() | ||
self.asset_compOut.parm("loadfromdisk").set(True) | ||
|
||
#-----------------------------------------------------------# | ||
# Sets the Object import into the Component Geometry | ||
def singleGeoImport(self, meshPath = None, asst_comp_geo = None, polyreducepercent = 10, netbox = True): | ||
""" | ||
asst_comp_geo by default is set to Stager compGeo1 | ||
meshPath by default set to self.ASSET_PATH | ||
polyreducepercent = 10 | ||
netBox = True : Creates a netbox by default. | ||
""" | ||
if asst_comp_geo is None: | ||
asst_comp_geo = self.asset_compGeo | ||
|
||
if meshPath is None: | ||
meshPath = self.ASSET_PATH | ||
|
||
# Component Geometry | ||
asset_compGeo_Inner = hou.node(asst_comp_geo.path() + "/sopnet/geo") | ||
|
||
obj_merge = asset_compGeo_Inner.createNode("object_merge") | ||
obj_merge.parm("objpath1").set(meshPath) | ||
hou.node(asst_comp_geo.path() + "/sopnet/geo" + "/default").setNextInput(obj_merge) | ||
polyreduce = obj_merge.createOutputNode("polyreduce::2.0") | ||
polyreduce.parm("percentage").set(polyreducepercent) | ||
hou.node(asst_comp_geo.path() + "/sopnet/geo" + "/proxy").setNextInput(polyreduce) | ||
hou.node(asst_comp_geo.path() + "/sopnet/geo" + "/simproxy").setNextInput(polyreduce) | ||
|
||
asset_compGeo_Inner.layoutChildren() | ||
if netbox: | ||
self._create_netBox(*self.Stager_nodes) | ||
|
||
|
||
def variantSOPsGeoImport(self, iterLength): | ||
"""Mesh with Multiple LOD0 SOP""" | ||
for_start = self.asset_compGeo.createOutputNode("begincontextoptionsblock", self.ASSET_NAME + "_forStart") | ||
asset_compGeo2 = self.Stager.createNode("componentgeometry", self.ASSET_NAME + "_cGeoVarImports") | ||
compGeoVariants = for_start.createOutputNode("componentgeometryvariants", self.ASSET_NAME + "_cGeoVar") | ||
compGeoVariants.setNextInput(asset_compGeo2) | ||
for_end = self.Stager.createNode("foreach", self.ASSET_NAME + "_forEnd") | ||
for_end.setInput(2, compGeoVariants) | ||
setVariant = for_end.createOutputNode("setvariant") | ||
setVariant.setGenericFlag(hou.nodeFlag.Bypass, True) | ||
self.asset_compMat.insertInput(0, setVariant) | ||
|
||
self.asset_compGeo.parm("geovariantname").set("Var1") | ||
asset_compGeo2.parm("geovariantname").set("Var`@ITERATIONVALUE`") | ||
|
||
for_end.parm("iterations").set(100) | ||
for_end.parm("iterrange").set("range") | ||
for_end.parm("firstiteration").set(2) | ||
for_end.parm("lastiteration").set(iterLength) | ||
|
||
self.Stager_nodes.extend([for_start, asset_compGeo2, compGeoVariants, for_end, setVariant]) | ||
|
||
# Setting the compGeo1 | ||
self.singleGeoImport(meshPath = (self.ASSET_PATH + "/Var1_LOD0"), netbox= False) | ||
# Setting the compGeo1 | ||
|
||
self.singleGeoImport((self.ASSET_PATH + "/`chsop(\"../../../geovariantname\")`_LOD0"), asset_compGeo2) | ||
|
||
def variantSub_SOPGeoImport(self, iterLength): | ||
"""Mesh with Multiple LOD0 SOP""" | ||
for_start = self.asset_compGeo.createOutputNode("begincontextoptionsblock", self.ASSET_NAME + "_forStart") | ||
asset_compGeo2 = self.Stager.createNode("componentgeometry", self.ASSET_NAME + "_cGeoVarImports") | ||
compGeoVariants = for_start.createOutputNode("componentgeometryvariants", self.ASSET_NAME + "_cGeoVar") | ||
compGeoVariants.setNextInput(asset_compGeo2) | ||
for_end = self.Stager.createNode("foreach", self.ASSET_NAME + "_forEnd") | ||
for_end.setInput(2, compGeoVariants) | ||
setVariant = for_end.createOutputNode("setvariant") | ||
setVariant.setGenericFlag(hou.nodeFlag.Bypass, True) | ||
self.asset_compMat.insertInput(0, setVariant) | ||
|
||
self.asset_compGeo.parm("geovariantname").set("Var1") | ||
asset_compGeo2.parm("geovariantname").set("Var`@ITERATIONVALUE`") | ||
|
||
for_end.parm("iterations").set(100) | ||
for_end.parm("iterrange").set("range") | ||
for_end.parm("firstiteration").set(0) | ||
for_end.parm("lastiteration").set(iterLength) | ||
|
||
self.Stager_nodes.extend([for_start, asset_compGeo2, compGeoVariants, for_end, setVariant]) | ||
|
||
# Setting the compGeo1 | ||
self.singleGeoImport(meshPath = (self.ASSET_PATH + "/*_00_LOD0"), netbox= False) | ||
# Setting the compGeo1 | ||
|
||
self.singleGeoImport((self.ASSET_PATH + "/*_`padzero(2, @ITERATIONVALUE)`_LOD0"), asset_compGeo2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import hou | ||
|
||
class MS_Asset(): | ||
""" | ||
This Class only returns the path of the MS Asset Geometry(s), MS Asset Material or Number of Variants | ||
""" | ||
def __init__(self): | ||
self.ms_asset = hou.selectedNodes()[0] | ||
|
||
def __str__(self): | ||
return str(self.ms_asset) | ||
|
||
#--------- Asset Name---------# | ||
def get_MS_name(self): | ||
return str(self.ms_asset) | ||
|
||
#--------- Asset Path---------# | ||
def get_MS_Path(self): | ||
return self.ms_asset.path() | ||
|
||
#--------- Get MS Asset Single Geo Node ---------# | ||
def get_SingleMeshAssetGeo(self): | ||
"""Return the Geo Node inside MS asset Subnet""" | ||
for child in self.ms_asset.children(): | ||
if child.name() == "Asset_Geometry": | ||
return child.path() | ||
|
||
#--------- Get MS Asset Mat Node ---------# | ||
def get_AssetMat(self): | ||
"""Return the Mat Node inside MS asset Subnet""" | ||
for child in self.ms_asset.children(): | ||
if child.name() == "Asset_Material": | ||
return child.children()[0].path() | ||
|
||
#--------- Get MS Asset Single Geo Node ---------# | ||
def get_SOPVariantMeshesGeo(self): | ||
"""Return the inside MS asset Subnet's SOP based LOD0 variants""" | ||
|
||
newChildrenList = [] # LOD0 SOPS meshes are added in this list | ||
children = self.ms_asset.children() | ||
|
||
for i in range(len(children)): | ||
if str(children[i]).rfind("_LOD0") != -1: # -1 if not found | ||
newChildrenList.append(children[i]) | ||
|
||
return len(newChildrenList) | ||
|
||
#--------- Get MS Asset Single Geo Node ---------# | ||
def get_SubSOPVariantMeshesGeo(self): | ||
"""Returns the number of subSop LOD0 variants""" | ||
|
||
newChildrenList = [] # _LOD0 nulls from _LOD0 SOP meshes are added in this list | ||
children = hou.node(self.ms_asset.path() + "/lod0").children() | ||
|
||
for i in range(len(children)): | ||
if str(children[i]).rfind("_LOD0") != -1: # -1 if not found | ||
newChildrenList.append(children[i]) | ||
return len(newChildrenList) | ||
|
||
|
||
class MS_Asset_Data(MS_Asset): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
|
||
def Check_is_MS_Asset(self): | ||
if self.get_AssetMat() == None: | ||
check = False | ||
else: | ||
check = True | ||
|
||
return check | ||
|
||
def SingleMeshData(self): | ||
"""Returns (AssetName, Asset_Geo_Path, Asset_Mat_Path)""" | ||
|
||
self.MS_Name = self.get_MS_name() | ||
self.MS_GeoPath = self.get_SingleMeshAssetGeo() | ||
self.MS_MatPath = self.get_AssetMat() | ||
|
||
return(self.MS_Name, self.MS_GeoPath, self.MS_MatPath) | ||
|
||
def SOPvariantsData(self): | ||
"""Returns (AssetName, Asset_Geo_Path, Asset_Mat_Path, IterationRange)""" | ||
|
||
self.MS_Name = self.get_MS_name() | ||
self.MS_GeoPath = self.get_MS_Path() | ||
self.MS_MatPath = self.get_AssetMat() | ||
self.IterationRange = self.get_SOPVariantMeshesGeo() | ||
|
||
return(self.MS_Name, self.MS_GeoPath, self.MS_MatPath, self.IterationRange) | ||
|
||
def SubSOPvariantsData(self): | ||
"""Returns (AssetName, Asset_Geo_Path, Asset_Mat_Path, IterationRange)""" | ||
|
||
self.MS_Name = self.get_MS_name() | ||
self.MS_GeoPath = self.get_MS_Path() + "/lod0" | ||
self.MS_MatPath = self.get_AssetMat() | ||
self.IterationRange = self.get_SubSOPVariantMeshesGeo() | ||
|
||
return(self.MS_Name, self.MS_GeoPath, self.MS_MatPath, self.IterationRange) | ||
|
||
|
||
# print(MS_Asset_Data().Check_is_MS_Asset()) |
Oops, something went wrong.