|
@@ -1,4 +1,6 @@
|
|
|
-function AssetBrowser::createMaterialAsset(%this)
|
|
|
+AssetBrowser::registerAssetType("MaterialAsset", "Materials");
|
|
|
+
|
|
|
+function MaterialAsset::createMaterialAsset(%this)
|
|
|
{
|
|
|
%assetName = AssetBrowser.newAssetSettings.assetName;
|
|
|
|
|
@@ -33,15 +35,15 @@ function AssetBrowser::createMaterialAsset(%this)
|
|
|
return %tamlpath;
|
|
|
}
|
|
|
|
|
|
-function AssetBrowser::editMaterialAsset(%this, %assetDef)
|
|
|
+function MaterialAsset::onEdit(%this)
|
|
|
{
|
|
|
- %assetDef.materialDefinitionName.reload();
|
|
|
+ %this.materialDefinitionName.reload();
|
|
|
|
|
|
EditorGui.setEditor(MaterialEditorPlugin);
|
|
|
|
|
|
- MaterialEditorGui.currentMaterialAsset = %assetDef.getAssetId();
|
|
|
- MaterialEditorGui.currentMaterial = %assetDef.materialDefinitionName;
|
|
|
- MaterialEditorGui.setActiveMaterial( %assetDef.materialDefinitionName );
|
|
|
+ MaterialEditorGui.currentMaterialAsset = %this.getAssetId();
|
|
|
+ MaterialEditorGui.currentMaterial = %this.materialDefinitionName;
|
|
|
+ MaterialEditorGui.setActiveMaterial( %this.materialDefinitionName );
|
|
|
|
|
|
AssetBrowser.hideDialog();
|
|
|
}
|
|
@@ -60,451 +62,82 @@ function AssetBrowser::renameMaterialAsset(%this, %assetDef, %newAssetName)
|
|
|
renameAssetFile(%assetDef, %newAssetName);
|
|
|
}
|
|
|
|
|
|
-//Deletes the asset
|
|
|
-function AssetBrowser::deleteMaterialAsset(%this, %assetDef)
|
|
|
-{
|
|
|
- AssetDatabase.deleteAsset(%assetDef.getAssetId(), true);
|
|
|
-}
|
|
|
-
|
|
|
-//Moves the asset to a new path/module
|
|
|
-function AssetBrowser::moveMaterialAsset(%this, %assetDef, %destination)
|
|
|
-{
|
|
|
- %currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
|
|
|
- %targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
|
|
|
-
|
|
|
- %newAssetPath = moveAssetFile(%assetDef, %destination);
|
|
|
-
|
|
|
- if(%newAssetPath $= "")
|
|
|
- return false;
|
|
|
-
|
|
|
- moveAssetLooseFile(%assetDef.getScriptPath(), %destination);
|
|
|
-
|
|
|
- AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
|
|
|
- AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
|
|
|
-}
|
|
|
-
|
|
|
-function AssetBrowser::prepareImportMaterialAsset(%this, %assetItem)
|
|
|
-{
|
|
|
- ImportActivityLog.add("Preparing Material for Import: " @ %assetItem.assetName);
|
|
|
-
|
|
|
- //Iterate over to find appropriate images for
|
|
|
-
|
|
|
- //Fetch just the fileBase name
|
|
|
- %fileDir = filePath(%assetItem.filePath);
|
|
|
- %fileName = fileBase(%assetItem.filePath);
|
|
|
- %fileExt = fileExt(%assetItem.filePath);
|
|
|
-
|
|
|
- %assetItem.generatedAsset = true;
|
|
|
-
|
|
|
- //Check if we need to filter this material out or not
|
|
|
- if(getAssetImportConfigValue("Materials/IgnoreMaterials", "") !$= "")
|
|
|
- {
|
|
|
- %ignoredMatNamesCount = getTokenCount(getAssetImportConfigValue("Materials/IgnoreMaterials", ""), ",;");
|
|
|
- for(%i=0; %i < %ignoredMatNamesCount; %i++)
|
|
|
- {
|
|
|
- %ignoreName = getToken(getAssetImportConfigValue("Materials/IgnoreMaterials", ""), ",;", %i);
|
|
|
-
|
|
|
- if(strIsMatchExpr(%ignoreName, %fileName))
|
|
|
- {
|
|
|
- //We fit the bill, ignore this material and skip it
|
|
|
- %assetItem.skip = true;
|
|
|
-
|
|
|
- ImportActivityLog.add(%assetItem.assetName @ " has been ignored due to config Materials/IgnoreMaterials settings");
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(getAssetImportConfigValue("Materials/PopulateMaterialMaps", "1") == 1)
|
|
|
- {
|
|
|
- ImportActivityLog.add("Attempting to Auto-Populate Material Maps");
|
|
|
-
|
|
|
- for(%i=0; %i < %assetItem.childAssetItems.count(); %i++)
|
|
|
- {
|
|
|
- %childAssetItem = %assetItem.childAssetItems.getKey(%i);
|
|
|
-
|
|
|
- if(!isObject(%childAssetItem) || %childAssetItem.skip || %childAssetItem.processed == true || %childAssetItem.assetType !$= "ImageAsset")
|
|
|
- return;
|
|
|
-
|
|
|
- if(%childAssetItem.imageType $= "Albedo")
|
|
|
- {
|
|
|
- %assetItem.diffuseImageAsset = %childAssetItem;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*%materialItemId = ImportAssetTree.findItemByObjectId(%assetItem);
|
|
|
-
|
|
|
- if(%assetItem.diffuseImageAsset $= "")
|
|
|
- {
|
|
|
- %diffuseTypeSuffixes = getAssetImportConfigValue("Images/DiffuseTypeSuffixes", "");
|
|
|
-
|
|
|
- %targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %diffuseTypeSuffixes);
|
|
|
-
|
|
|
- if(%targetFilePath !$= "")
|
|
|
- {
|
|
|
- ImportActivityLog.add("Auto-Populated Diffuse Map Image Asset via file: " @ %targetFilePath);
|
|
|
-
|
|
|
- %diffuseAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
|
|
|
- %assetItem.diffuseImageAsset = %diffuseAsset;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //Now, iterate over our comma-delimited suffixes to see if we have any matches. We'll use the first match in each case, if any.
|
|
|
- if(%assetItem.normalImageAsset $= "")
|
|
|
- {
|
|
|
- %normalTypeSuffixes = getAssetImportConfigValue("Images/NormalTypeSuffixes", "");
|
|
|
-
|
|
|
- //First, normal map
|
|
|
- %targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %normalTypeSuffixes);
|
|
|
-
|
|
|
- if(%targetFilePath !$= "")
|
|
|
- {
|
|
|
- ImportActivityLog.add("Auto-Populated Normal Map Image Asset via file: " @ %targetFilePath);
|
|
|
-
|
|
|
- %normalAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
|
|
|
- %assetItem.normalImageAsset = %normalAsset;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(%assetItem.metalImageAsset $= "")
|
|
|
- {
|
|
|
- %metalnessTypeSuffixes = getAssetImportConfigValue("Images/MetalnessTypeSuffixes", "");
|
|
|
-
|
|
|
- %targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %metalnessTypeSuffixes);
|
|
|
-
|
|
|
- if(%targetFilePath !$= "")
|
|
|
- {
|
|
|
- ImportActivityLog.add("Auto-Populated Metalness Map Image Asset via file: " @ %targetFilePath);
|
|
|
-
|
|
|
- %metalAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
|
|
|
- %assetItem.metalImageAsset = %metalAsset;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(%assetItem.roughnessImageAsset $= "")
|
|
|
- {
|
|
|
- %roughnessTypeSuffixes = getAssetImportConfigValue("Images/RoughnessTypeSuffixes", "");
|
|
|
-
|
|
|
- %targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %roughnessTypeSuffixes);
|
|
|
-
|
|
|
- if(%targetFilePath !$= "")
|
|
|
- {
|
|
|
- ImportActivityLog.add("Auto-Populated Roughness Map Image Asset via file: " @ %targetFilePath);
|
|
|
-
|
|
|
- %roughnessAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
|
|
|
- %assetItem.roughnessImageAsset = %roughnessAsset;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(%assetItem.smoothnessImageAsset $= "")
|
|
|
- {
|
|
|
- %smoothnessTypeSuffixes = getAssetImportConfigValue("Images/SmoothnessTypeSuffixes", "");
|
|
|
-
|
|
|
- %targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %smoothnessTypeSuffixes);
|
|
|
-
|
|
|
- if(%targetFilePath !$= "")
|
|
|
- {
|
|
|
- ImportActivityLog.add("Auto-Populated Smoothness Map Image Asset via file: " @ %targetFilePath);
|
|
|
-
|
|
|
- %smoothnessAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
|
|
|
- %assetItem.SmoothnessImageAsset = %smoothnessAsset;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(%assetItem.AOImageAsset $= "")
|
|
|
- {
|
|
|
- %aoTypeSuffixes = getAssetImportConfigValue("Images/AOTypeSuffixes", "");
|
|
|
-
|
|
|
- %targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %aoTypeSuffixes);
|
|
|
-
|
|
|
- if(%targetFilePath !$= "")
|
|
|
- {
|
|
|
- ImportActivityLog.add("Auto-Populated AO Map Image Asset via file: " @ %targetFilePath);
|
|
|
-
|
|
|
- %AOAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
|
|
|
- %assetItem.AOImageAsset = %AOAsset;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(%assetItem.compositeImageAsset $= "")
|
|
|
- {
|
|
|
- %compositeTypeSuffixes = getAssetImportConfigValue("Images/CompositeTypeSuffixes", "");
|
|
|
-
|
|
|
- %targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %compositeTypeSuffixes);
|
|
|
-
|
|
|
- if(%targetFilePath !$= "")
|
|
|
- {
|
|
|
- ImportActivityLog.add("Auto-Populated Composite Map Image Asset via file: " @ %targetFilePath);
|
|
|
-
|
|
|
- %compositeAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
|
|
|
- %assetItem.compositeImageAsset = %compositeAsset;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //If after the above we didn't find any, check to see if we should be generating one
|
|
|
- if(%assetItem.compositeImageAsset $= "" &&
|
|
|
- (%assetItem.roughnessImageAsset !$= "" || %assetItem.AOImageAsset !$= "" || %assetItem.metalnessImageAsset !$= "") &&
|
|
|
- getAssetImportConfigValue("Materials/CreateComposites", "1") == 1)
|
|
|
- {
|
|
|
- %assetItem.roughnessImageAsset.skip = true;
|
|
|
- %assetItem.AOImageAsset.skip = true;
|
|
|
- %assetItem.metalnessImageAsset.skip = true;
|
|
|
-
|
|
|
- %compositeAssetPath = AssetBrowser.dirHandler.currentAddress @ "/";
|
|
|
- %saveAsPath = %compositeAssetPath @ "/" @ %assetItem.assetName @ "_composite.png";
|
|
|
-
|
|
|
- ImportActivityLog.add("Auto-Generated Composite Map from ORM maps");
|
|
|
-
|
|
|
- %compositeAsset = AssetBrowser.addImportingAsset("ImageAsset", "", %assetItem, %assetItem.assetName @ "_composite");
|
|
|
- %compositeAsset.generatedAsset = true;
|
|
|
- %compositeAsset.filePath = %saveAsPath;
|
|
|
-
|
|
|
- %assetItem.compositeImageAsset = %compositeAsset;
|
|
|
- }*/
|
|
|
- }
|
|
|
-
|
|
|
- %assetItem.processed = true;
|
|
|
-
|
|
|
- refreshImportAssetWindow();
|
|
|
-}
|
|
|
-
|
|
|
-function AssetBrowser::findMaterialMapFileWSuffix(%this, %fileDir, %filename, %fileExt, %suffixesList)
|
|
|
-{
|
|
|
- %listCount = getTokenCount(%suffixesList, ",;");
|
|
|
-
|
|
|
- %foundFile = 0;
|
|
|
- %filePath = "";
|
|
|
- for(%i=0; %i < %listCount; %i++)
|
|
|
- {
|
|
|
- %entryText = getToken(%suffixesList, ",;", %i);
|
|
|
-
|
|
|
- if(%fileExt $= "")
|
|
|
- {
|
|
|
- %filePath = findFirstFile(%fileDir @ "/" @ %filename @ %entryText @ ".*");
|
|
|
- %foundFile = isFile(%filePath);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- %filePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt;
|
|
|
- %foundFile = isFile(%filePath);
|
|
|
- }
|
|
|
-
|
|
|
- if(%foundFile)
|
|
|
- {
|
|
|
- return %filePath;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return "";
|
|
|
-}
|
|
|
-
|
|
|
-function AssetBrowser::importMaterialAsset(%this, %assetItem)
|
|
|
-{
|
|
|
- %moduleName = AssetImportTargetModule.getText();
|
|
|
-
|
|
|
- %assetType = %assetItem.AssetType;
|
|
|
- %filePath = %assetItem.filePath;
|
|
|
- %assetName = %assetItem.assetName;
|
|
|
- %assetImportSuccessful = false;
|
|
|
- %assetId = %moduleName@":"@%assetName;
|
|
|
-
|
|
|
- %assetPath = NewAssetTargetAddress.getText() @ "/";
|
|
|
- %tamlpath = %assetPath @ %assetName @ ".asset.taml";
|
|
|
- %sgfPath = %assetPath @ %assetName @ ".sgf";
|
|
|
- %scriptPath = %assetPath @ %assetName @ "." @ $TorqueScriptFileExtension;
|
|
|
-
|
|
|
- %newAsset = new MaterialAsset()
|
|
|
- {
|
|
|
- assetName = %assetName;
|
|
|
- versionId = 1;
|
|
|
- shaderGraph = %sgfPath;
|
|
|
- scriptFile = %assetName @ "." @ $TorqueScriptFileExtension;
|
|
|
- materialDefinitionName = %assetName;
|
|
|
- };
|
|
|
-
|
|
|
- //No point in indicating the original path data if it was imported in-place
|
|
|
- %mainPath = getMainDotCsDir();
|
|
|
- if(!startsWith(makeFullPath(%filePath), getMainDotCsDir()))
|
|
|
- {
|
|
|
- %newAsset.originalFilePath = %filePath;
|
|
|
- }
|
|
|
-
|
|
|
- //check dependencies
|
|
|
- %dependencySlotId = 0;
|
|
|
- for(%i=0; %i < %assetItem.childAssetItems.count(); %i++)
|
|
|
- {
|
|
|
- %childAssetItem = %assetItem.childAssetItems.getKey(%i);
|
|
|
-
|
|
|
- if(!isObject(%childAssetItem) || %childAssetItem.skip || %childAssetItem.processed == false)
|
|
|
- continue;
|
|
|
-
|
|
|
- %depAssetType = %childAssetItem.assetType;
|
|
|
- if(%depAssetType $= "ImageAsset")
|
|
|
- {
|
|
|
- %matSet = "%newAsset.imageMap"@%dependencySlotId@"=\"@asset="@%moduleName@":"@%childAssetItem.assetName@"\";";
|
|
|
- eval(%matSet);
|
|
|
- %dependencySlotId++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- %assetImportSuccessful = TamlWrite(%newAsset, %tamlpath);
|
|
|
-
|
|
|
- //if we're set to save a composite image, we do that first
|
|
|
- if(getAssetImportConfigValue("Materials/CreateComposites", "1") == 1)
|
|
|
- {
|
|
|
- //don't save a composite if we've already got one bound
|
|
|
- if(%assetItem.compositeImageAsset !$= "" && %assetItem.compositeImageAsset.generatedAsset)
|
|
|
- {
|
|
|
- if(%assetItem.roughnessImageAsset !$= "" || %assetItem.AOImageAsset !$= "" || %assetItem.metalnessImageAsset !$= "")
|
|
|
- {
|
|
|
- %channelKey = "0 1 2 3";
|
|
|
-
|
|
|
- saveCompositeTexture(%assetItem.AOImageAsset.filePath,
|
|
|
- %assetItem.roughnessImageAsset.filePath,
|
|
|
- %assetItem.metalnessImageAsset.filePath,"",
|
|
|
- %channelKey,
|
|
|
- %assetItem.compositeImageAsset.filePath);
|
|
|
-
|
|
|
- %compositeAssetId = %moduleName @ ":" @ assetItem.compositeImageAsset.assetName;
|
|
|
- AssetDatabase.refreshAsset(%compositeAssetId);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- %file = new FileObject();
|
|
|
-
|
|
|
- if(%file.openForWrite(%scriptPath))
|
|
|
- {
|
|
|
- %file.writeline("//--- OBJECT WRITE BEGIN ---");
|
|
|
- %file.writeline("singleton Material(" @ %assetName @ ") {");
|
|
|
-
|
|
|
- //TODO: pass along the shape's target material for this just to be sure
|
|
|
- %file.writeLine(" mapTo = \"" @ %assetName @ "\";");
|
|
|
-
|
|
|
- //now we re-iterate back over our child items so we can map them correctly
|
|
|
- for(%i=0; %i < %assetItem.childAssetItems.count(); %i++)
|
|
|
- {
|
|
|
- %childAssetItem = %assetItem.childAssetItems.getKey(%i);
|
|
|
-
|
|
|
- if(!isObject(%childAssetItem) || %childAssetItem.skip || %childAssetItem.processed == false)
|
|
|
- continue;
|
|
|
-
|
|
|
- if(%childAssetItem.assetType $= "ImageAsset")
|
|
|
- {
|
|
|
- %mapFieldName = "";
|
|
|
- if(%childAssetItem.imageType $= "Albedo")
|
|
|
- %mapFieldName = "DiffuseMap";
|
|
|
- else if(%childAssetItem.imageType $= "Normal")
|
|
|
- %mapFieldName = "NormalMap";
|
|
|
- else if(%childAssetItem.imageType $= "Metalness")
|
|
|
- %mapFieldName = "MetalMap";
|
|
|
- else if(%childAssetItem.imageType $= "Roughness")
|
|
|
- %mapFieldName = "RoughnessMap";
|
|
|
- else if(%childAssetItem.imageType $= "AO")
|
|
|
- %mapFieldName = "AOMap";
|
|
|
- else if(%childAssetItem.imageType $= "Composite")
|
|
|
- %mapFieldName = "ORMConfigMap";
|
|
|
-
|
|
|
- %path = fileName(%childAssetItem.filePath);
|
|
|
- %file.writeline(" "@ %mapFieldName @ "[0] = \"" @ %path @"\";");
|
|
|
- %file.writeline(" "@ %mapFieldName @ "Asset[0] = \"" @ %moduleName @ ":" @ %childAssetItem.assetName @"\";");
|
|
|
- }
|
|
|
- }
|
|
|
- %file.writeline("};");
|
|
|
- %file.writeline("//--- OBJECT WRITE END ---");
|
|
|
-
|
|
|
- %file.close();
|
|
|
- }
|
|
|
-
|
|
|
- %moduleDef = ModuleDatabase.findModule(%moduleName,1);
|
|
|
-
|
|
|
- if(!AssetBrowser.isAssetReImport)
|
|
|
- AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
|
|
|
- else
|
|
|
- AssetDatabase.refreshAsset(%assetId);
|
|
|
-}
|
|
|
-
|
|
|
-function AssetBrowser::buildMaterialAssetPreview(%this, %assetDef, %previewData, %forcePreviewRegenerate)
|
|
|
+function MaterialAsset::buildBrowserElement(%this, %previewData)
|
|
|
{
|
|
|
%previewData.previewImage = "ToolsModule:genericAssetIcon_image";
|
|
|
%previewData.previewLoaded = false; //this marks it for loading progressively later
|
|
|
|
|
|
- %previewData.assetName = %assetDef.assetName;
|
|
|
- %previewData.assetPath = %assetDef.scriptFile;
|
|
|
+ %previewData.assetName = %this.assetName;
|
|
|
+ %previewData.assetPath = %this.scriptFile;
|
|
|
|
|
|
- %previewData.assetFriendlyName = %assetDef.assetName;
|
|
|
- %previewData.assetDesc = %assetDef.description;
|
|
|
+ %previewData.assetFriendlyName = %this.assetName;
|
|
|
+ %previewData.assetDesc = %this.description;
|
|
|
|
|
|
if(%this.selectMode)
|
|
|
- %previewData.doubleClickCommand = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );";
|
|
|
+ %previewData.doubleClickCommand = $CurrentAssetBrowser @ ".selectAsset( " @ $CurrentAssetBrowser @ ".selectedAsset );";
|
|
|
else
|
|
|
- %previewData.doubleClickCommand = "AssetBrowser.editAsset( "@%assetDef@" );";
|
|
|
+ %previewData.doubleClickCommand = $CurrentAssetBrowser @ ".editAsset( "@%this@" );";
|
|
|
|
|
|
- %definitionPath = %assetDef.getScriptPath();
|
|
|
+ %definitionPath = %this.getScriptPath();
|
|
|
if(%definitionPath $= "")
|
|
|
- %definitionPath = %assetDef.getFilename();
|
|
|
+ %definitionPath = %this.getFilename();
|
|
|
|
|
|
- %previewData.tooltip = "Asset Name: " @ %assetDef.assetName @
|
|
|
+ %previewData.tooltip = "Asset Name: " @ %this.assetName @
|
|
|
"\nAsset Type: Material Asset" @
|
|
|
- "\nAsset Definition ID: " @ %assetDef @
|
|
|
+ "\nAsset Definition ID: " @ %this @
|
|
|
"\nDefinition Path: " @ %definitionPath;
|
|
|
|
|
|
- if(!%this.selectMode)
|
|
|
+ if(!$CurrentAssetBrowser.selectMode)
|
|
|
{
|
|
|
- %previewData.doubleClickCommand = "AssetBrowser.editAsset( "@%assetDef@" );";
|
|
|
+ %previewData.doubleClickCommand = $CurrentAssetBrowser @ ".editAsset( "@%this@" );";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function AssetBrowser::generateMaterialAssetPreviewImage(%this, %previewButton, %forceRegenerate)
|
|
|
+function MaterialAsset::generatePreviewImage(%this, %previewButton, %forceRegenerate)
|
|
|
{
|
|
|
if(%forceRegenerate $= "")
|
|
|
%forceRegenerate = false;
|
|
|
|
|
|
- %assetId = %previewButton.moduleName @ ":" @ %previewButton.assetName;
|
|
|
-
|
|
|
- %assetDef = AssetDatabase.acquireAsset(%assetId);
|
|
|
-
|
|
|
- %module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(AssetDatabase.getAssetFilePath(%assetDef.getAssetId()))));
|
|
|
+ %module = $CurrentAssetBrowser.dirHandler.getModuleFromAddress(makeRelativePath(filePath(AssetDatabase.getAssetFilePath(%this.getAssetId()))));
|
|
|
%previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/";
|
|
|
|
|
|
if(!IsDirectory(%previewPath))
|
|
|
{
|
|
|
- %this.dirHandler.createFolder(%previewPath);
|
|
|
+ $CurrentAssetBrowser.dirHandler.createFolder(%previewPath);
|
|
|
}
|
|
|
|
|
|
%generatePreview = false;
|
|
|
|
|
|
- %previewFilePath = %previewPath @ %assetDef.assetName @ "_Preview.dds";
|
|
|
+ %previewFilePath = %previewPath @ %this.assetName @ "_Preview.dds";
|
|
|
if(!isFile(%previewFilePath))
|
|
|
{
|
|
|
%generatePreview = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if(isObject(%assetDef.materialDefinitionName))
|
|
|
+ if(isObject(%this.materialDefinitionName))
|
|
|
{
|
|
|
- if(compareFileTimes(%assetDef.materialDefinitionName.getDiffuseMap(0), %previewFilePath) == 1 ||
|
|
|
- compareFileTimes(%assetDef.materialDefinitionName.getFilename(), %previewFilePath) == 1)
|
|
|
+ if(compareFileTimes(%this.materialDefinitionName.getDiffuseMap(0), %previewFilePath) == 1 ||
|
|
|
+ compareFileTimes(%this.materialDefinitionName.getFilename(), %previewFilePath) == 1)
|
|
|
%generatePreview = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- %previewAssetName = %module.moduleId @ "_" @ %assetDef.assetName @ "_PreviewImage";
|
|
|
+ %previewAssetName = %module.moduleId @ "_" @ %this.assetName @ "_PreviewImage";
|
|
|
|
|
|
if(%generatePreview || %forceRegenerate)
|
|
|
{
|
|
|
- if(isObject(%assetDef.materialDefinitionName))
|
|
|
+ if(isObject(%this.materialDefinitionName))
|
|
|
{
|
|
|
//real fast, we'll be 100% sure that the image resource we need is loaded
|
|
|
- %diffuseMapAssetId = %assetDef.materialDefinitionName.getDiffuseMapAsset(0);
|
|
|
+ %diffuseMapAssetId = %this.materialDefinitionName.getDiffuseMapAsset(0);
|
|
|
if(AssetDatabase.isDeclaredAsset(%diffuseMapAssetId))
|
|
|
{
|
|
|
%diffuseMapAsset = AssetDatabase.acquireAsset(%diffuseMapAssetId);
|
|
|
AssetDatabase.releaseAsset(%diffuseMapAssetId);
|
|
|
}
|
|
|
%previewShapeDef = AssetDatabase.acquireAsset("ToolsModule:previewSphereShape");
|
|
|
- %generatedFilePath = %previewShapeDef.generateCachedPreviewImage(256, %assetDef.materialDefinitionName);
|
|
|
+ %generatedFilePath = %previewShapeDef.generateCachedPreviewImage(256, %this.materialDefinitionName);
|
|
|
|
|
|
pathCopy(%generatedFilePath, %previewFilePath, false);
|
|
|
fileDelete(%generatedFilePath);
|
|
@@ -548,7 +181,7 @@ function AssetBrowser::generateMaterialAssetPreviewImage(%this, %previewButton,
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-function AssetBrowser::onMaterialAssetEditorDropped(%this, %assetDef, %position)
|
|
|
+function MaterialAsset::onWorldEditorDropped(%this, %position)
|
|
|
{
|
|
|
//echo("DROPPED A SHAPE ON THE EDITOR WINDOW!");
|
|
|
//first, see if we hit a static shape
|
|
@@ -558,26 +191,24 @@ function AssetBrowser::onMaterialAssetEditorDropped(%this, %assetDef, %position)
|
|
|
%camPos = LocalClientConnection.camera.getPosition();
|
|
|
%rayResult = materialRayCast(%camPos, %targetPosition, -1, 0, false);
|
|
|
|
|
|
- %validTarget = false;
|
|
|
if(%rayResult != 0)
|
|
|
{
|
|
|
%obj = getWord(%rayResult, 0);
|
|
|
if(%obj.isMemberOfClass("TSStatic"))
|
|
|
{
|
|
|
//oh, cool a valid target!
|
|
|
- %obj.materialSlot0 = %assetDef.getAssetId();
|
|
|
- echo("MaterialSlot0 set to " @ %assetDef.getAssetId());
|
|
|
+ %obj.materialSlot0 = %this.getAssetId();
|
|
|
+ //echo("MaterialSlot0 set to " @ %this.getAssetId());
|
|
|
}
|
|
|
else if(%obj.isField("materialAsset"))
|
|
|
{
|
|
|
- %obj.materialAsset = %assetDef.getAssetId();
|
|
|
- echo("materialAsset set to " @ %assetDef.getAssetId());
|
|
|
+ %obj.materialAsset = %this.getAssetId();
|
|
|
+ //echo("materialAsset set to " @ %this.getAssetId());
|
|
|
}
|
|
|
%obj.inspectPostApply();
|
|
|
+
|
|
|
+ EWorldEditor.isDirty = true;
|
|
|
}
|
|
|
-
|
|
|
- EWorldEditor.isDirty = true;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
function GuiInspectorTypeMaterialAssetPtr::onControlDropped( %this, %payload, %position )
|