Skip to content

Commit 33a7346

Browse files
authored
Merge pull request #179 from Unity-Technologies/UNI-27977-generalize-DCC-app-selection
Uni 27977 generalize dcc app selection (contains all the max commits)
2 parents 2b44006 + 75af8a0 commit 33a7346

File tree

10 files changed

+649
-204
lines changed

10 files changed

+649
-204
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[Bb]in/
1111
[Dd]ebug/
1212

13-
[Aa]ssets/FbxExporters/unityoneclick_for_maya.zip
13+
[Aa]ssets/FbxExporters/*.zip
1414

1515
# vim temp files
1616
*.swp

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 194 additions & 112 deletions
Large diffs are not rendered by default.

Assets/FbxExporters/Editor/InstallIntegration.cs

Lines changed: 231 additions & 71 deletions
Large diffs are not rendered by default.

Assets/FbxExporters/Editor/ReviewLastSavedModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void OnPostprocessAllAssets(
3333
foreach (var assetPath in importedAssets) {
3434
if (assetPath.StartsWith(tempSavePath) && assetPath.EndsWith(".fbx")) {
3535
// if the instruction file exists, then run the turntable and delete the file
36-
string instructionFile = FbxExporters.Editor.Integrations.GetFullMayaInstructionPath ();
36+
string instructionFile = FbxExporters.Editor.MayaIntegration.GetFullMayaInstructionPath ();
3737
if(System.IO.File.Exists(instructionFile)){
3838
LastSavedModel ();
3939
System.IO.File.Delete (instructionFile);

Assets/FbxExporters/Editor/UnitTests/IntegrationsTest.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ void LogNonEmptyString(string name, string str) {
2727

2828
[Test]
2929
public void BasicTest() {
30-
Assert.IsFalse(Editor.Integrations.IsHeadlessInstall());
30+
Assert.IsFalse(Editor.MayaIntegration.IsHeadlessInstall());
3131

32-
LogNonEmptyString("module path", Editor.Integrations.GetModulePath());
33-
LogNonEmptyString("module template path", Editor.Integrations.GetModuleTemplatePath());
32+
LogNonEmptyString("module path", Editor.MayaIntegration.GetModulePath());
33+
LogNonEmptyString("module template path", Editor.MayaIntegration.GetModuleTemplatePath());
3434

35-
LogNonEmptyString("app path", Editor.Integrations.GetAppPath());
36-
LogNonEmptyString("project path", Editor.Integrations.GetProjectPath());
37-
LogNonEmptyString("package path", Editor.Integrations.GetPackagePath());
38-
LogNonEmptyString("package version", Editor.Integrations.GetPackageVersion());
39-
LogNonEmptyString("temp path", Editor.Integrations.GetTempSavePath());
40-
LogNonEmptyString("export settings path", Editor.Integrations.GetExportSettingsPath ());
41-
LogNonEmptyString ("instruction path", Editor.Integrations.GetMayaInstructionPath ());
42-
LogNonEmptyString ("full instruction path", Editor.Integrations.GetFullMayaInstructionPath ());
35+
LogNonEmptyString("app path", Editor.MayaIntegration.GetAppPath());
36+
LogNonEmptyString("project path", Editor.MayaIntegration.GetProjectPath());
37+
LogNonEmptyString("package path", Editor.MayaIntegration.GetPackagePath());
38+
LogNonEmptyString("package version", Editor.MayaIntegration.GetPackageVersion());
39+
LogNonEmptyString("temp path", Editor.MayaIntegration.GetTempSavePath());
40+
LogNonEmptyString("export settings path", Editor.MayaIntegration.GetExportSettingsPath ());
41+
LogNonEmptyString ("instruction path", Editor.MayaIntegration.GetMayaInstructionPath ());
42+
LogNonEmptyString ("full instruction path", Editor.MayaIntegration.GetFullMayaInstructionPath ());
4343

4444
// test that the paths don't contain backslashes
45-
Assert.IsFalse(Editor.Integrations.GetAppPath().Contains("\\"));
46-
Assert.IsFalse(Editor.Integrations.GetProjectPath().Contains("\\"));
47-
Assert.IsFalse(Editor.Integrations.GetTempSavePath().Contains("\\"));
48-
Assert.IsFalse(Editor.Integrations.GetExportSettingsPath ().Contains("\\"));
45+
Assert.IsFalse(Editor.MayaIntegration.GetAppPath().Contains("\\"));
46+
Assert.IsFalse(Editor.MayaIntegration.GetProjectPath().Contains("\\"));
47+
Assert.IsFalse(Editor.MayaIntegration.GetTempSavePath().Contains("\\"));
48+
Assert.IsFalse(Editor.MayaIntegration.GetExportSettingsPath ().Contains("\\"));
4949
}
5050
}
5151
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
-- MacroScripts that will perform actions
2+
macroScript UnityImport category:"File-Import"
3+
(
4+
origObjects = #()
5+
6+
persistent global unityFbxFilePathAttr
7+
persistent global unityFbxFileNameAttr
8+
9+
global afterImport
10+
fn afterImport = (
11+
unityFbxExportSet = #()
12+
currSet = selectionSets["UnityFbxExportSet"]
13+
if not isdeleted currSet and currSet != undefined then (
14+
unityFbxExportSet = unityFbxExportSet + currSet
15+
)
16+
for obj in objects do(
17+
if findItem origObjects obj == 0 then(
18+
-- add to selection set
19+
append unityFbxExportSet obj
20+
)
21+
)
22+
selectionSets["UnityFbxExportSet"] = unityFbxExportSet
23+
);
24+
25+
-- Make sure the FbxImporter plugin is loaded
26+
pluginManager.loadClass FbxImporter
27+
28+
unityProjectPath = getINISetting (GetMAXIniFile()) "Unity" "UnityProject"
29+
fbxFileName = getOpenFileName caption:"Import FBX from Unity" filename:(unityProjectPath + "/Assets/") types:"FBX (*.fbx)|*.fbx|"
30+
if fbxFileName != undefined then
31+
(
32+
-- reset persistent values, in case import fails
33+
unityFbxFilePathAttr = ""
34+
unityFbxFileNameAttr = ""
35+
36+
-- Get all objects in scene before importAction
37+
origObjects = objects as array
38+
callbacks.addScript #postImport ("afterImport()") id:#unityPlugin
39+
40+
importFile fbxFileName using:FBXIMP
41+
42+
unityFbxFilePathAttr = getFilenamePath fbxFileName
43+
unityFbxFileNameAttr = filenameFromPath fbxFileName
44+
45+
callbacks.removeScripts #postImport id:#unityPlugin
46+
)
47+
)
48+
macroScript UnityExport category:"File-Export"
49+
(
50+
fn loadUnityFbxExportSettings = (
51+
fbxExportSettings = getINISetting (GetMAXIniFile()) "Unity" "UnityFbxExportSettings"
52+
if fbxExportSettings != undefined and doesFileExist fbxExportSettings then(
53+
filein fbxExportSettings
54+
)
55+
)
56+
57+
-- Make sure the FbxExporter plugin is loaded
58+
pluginManager.loadClass FbxExporter
59+
60+
loadUnityFbxExportSettings()
61+
62+
origSelection = getCurrentSelection()
63+
exportSet = selectionSets["UnityFbxExportSet"]
64+
if not isdeleted exportSet and exportSet != undefined then(
65+
select exportSet
66+
)
67+
68+
exportFileName = undefined
69+
if unityFbxFilePathAttr != undefined and unityFbxFileNameAttr != undefined then(
70+
exportFileName = unityFbxFilePathAttr + unityFbxFileNameAttr
71+
)
72+
else(
73+
unityProjectPath = getINISetting (GetMAXIniFile()) "Unity" "UnityProject"
74+
exportFileName = getSaveFileName caption:"Export FBX to Unity" filename:(unityProjectPath + "/Assets/") types:"FBX (*.fbx)|*.fbx|"
75+
)
76+
77+
if exportFileName != undefined then (
78+
exportFile exportFileName #noPrompt selectedOnly:true using:FBXEXP
79+
)
80+
81+
if origSelection != undefined then (
82+
select origSelection
83+
)
84+
)
85+
86+
-- Setup UI
87+
importMenuName = "File-Import"
88+
exportMenuName = "File-Export"
89+
fn setupUnityPluginUI = (
90+
importMenu = menuMan.findMenu importMenuName
91+
exportMenu = menuMan.findMenu exportMenuName
92+
if importMenu != undefined and exportMenu != undefined do
93+
(
94+
unityImportTitle = "Import from Unity"
95+
unityExportTitle = "Export to Unity"
96+
97+
-- check if menu items already exists
98+
foundUnityImport = false
99+
for i=1 to importMenu.numItems() do(
100+
mi = importMenu.getItem i
101+
if mi.getTitle() == unityImportTitle then(
102+
foundUnityImport = true
103+
global unityImportAction = mi
104+
break
105+
)
106+
)
107+
foundUnityExport = false
108+
for i=1 to exportMenu.numItems() do(
109+
mi = exportMenu.getItem i
110+
if mi.getTitle() == unityExportTitle then(
111+
foundUnityExport = true
112+
global unityExportAction = mi
113+
break
114+
)
115+
)
116+
117+
if foundUnityImport == false or foundUnityExport == false then(
118+
id = genClassID returnValue:true
119+
if menuMan.registerMenuContext id[1] then
120+
(
121+
if foundUnityImport == false do (
122+
global unityImportAction = menuMan.createActionItem "UnityImport" importMenuName; --create an ActionItem from the MacroScript
123+
unityImportAction.setTitle unityImportTitle;
124+
unityImportAction.setUseCustomTitle true;
125+
importMenu.addItem unityImportAction -1; --add the ActionItem to the menu
126+
)
127+
if foundUnityExport == false do (
128+
global unityExportAction = menuMan.createActionItem "UnityExport" exportMenuName;
129+
unityExportAction.setTitle unityExportTitle;
130+
unityExportAction.setUseCustomTitle true;
131+
exportMenu.addItem unityExportAction -1;
132+
)
133+
menuMan.updateMenuBar() --update the menu bar
134+
)
135+
)
136+
)
137+
);
138+
setupUnityPluginUI()
139+
140+
-- Make sure that Menu gets removed at shutdown, force menu to reload each time Max is opened
141+
callbacks.addScript #preSavingMenus (
142+
"importMenu = menuMan.findMenu \""+importMenuName+"\"; \
143+
exportMenu = menuMan.findMenu \""+exportMenuName+"\"; \
144+
if importMenu != undefined and unityImportAction != undefined then( \
145+
importMenu.removeItem unityImportAction; \
146+
) \
147+
if exportMenu != undefined and unityExportAction != undefined then( \
148+
exportMenu.removeItem unityExportAction; \
149+
)"
150+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
temp = pathConfig.GetDir(#userStartupScripts) + "/" + UnityPluginScript_Name;
2+
deleteFile temp;
3+
copyFile UnityPluginScript_Source temp;
4+
5+
maxIniFile = (GetMAXIniFile())
6+
unityCategory = "Unity"
7+
setINISetting maxIniFile unityCategory "UnityProject" UnityProject
8+
setINISetting maxIniFile unityCategory "UnityFbxExportSettings" UnityFbxExportSettings
9+
10+
quitMax()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FbxExporterSetParam "ResetExport"
2+
3+
-- FBX file format
4+
FbxExporterSetParam "ASCII" false
5+
FbxExporterSetParam "FileVersion" "FBX201600"
6+
7+
-- Geometry
8+
FbxExporterSetParam "SmoothMeshExport" false
9+
FbxExporterSetParam "Preserveinstances" true
10+
11+
-- Animation
12+
FbxExporterSetParam "Animation" false
13+
14+
FbxExporterSetParam "Cameras" true
15+
FbxExporterSetParam "Lights" true
16+
17+
FbxExporterSetParam "EmbedTextures" false
18+
19+
-- Units
20+
--FbxExporterSetParam "ScaleFactor" 1
21+
FbxExporterSetParam "ConvertUnit" "cm"
22+
23+
-- Axis Conversion
24+
FbxExporterSetParam "UpAxis" "Y"

CMakeLists.txt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,21 @@ add_custom_target(
122122
###########################################################################
123123
# Zip integrations folder
124124
set(MAYA_INTEGRATION_TARGET zip_maya_integration)
125-
set(MAYA_INTEGRATION_ZIP_NAME "unityoneclick_for_maya.zip")
125+
set(MAYA_INTEGRATION_ZIP_NAME "UnityFbxForMaya.zip")
126126

127-
# remove existing zip file
127+
set(MAX_INTEGRATION_TARGET zip_max_integration)
128+
set(MAX_INTEGRATION_ZIP_NAME "UnityFbxForMax.zip")
129+
130+
# remove existing zip files
128131
file(REMOVE "${CMAKE_SOURCE_DIR}/Assets/FbxExporters/${MAYA_INTEGRATION_ZIP_NAME}")
132+
file(REMOVE "${CMAKE_SOURCE_DIR}/Assets/FbxExporters/${MAX_INTEGRATION_ZIP_NAME}")
133+
129134
# remove .pyc files that we don't want to ship
130135
file(GLOB PYC_FILES "${CMAKE_SOURCE_DIR}/Assets/Integrations/Autodesk/maya/scripts/unityOneClick/*.pyc")
131136
IF( PYC_FILES )
132137
file(REMOVE ${PYC_FILES})
133138
ENDIF()
139+
134140
# remove .meta files from Integrations
135141
file(GLOB_RECURSE META_FILES "${CMAKE_SOURCE_DIR}/Assets/Integrations/*.meta")
136142

@@ -139,13 +145,26 @@ add_custom_command(OUTPUT ${MAYA_INTEGRATION_ZIP_NAME}
139145
COMMAND ${CMAKE_COMMAND} -E remove ${META_FILES}
140146
ENDIF
141147
COMMAND ${CMAKE_COMMAND} -E tar "cfv" ${CMAKE_SOURCE_DIR}/Assets/FbxExporters/${MAYA_INTEGRATION_ZIP_NAME} --format=zip
142-
"${CMAKE_SOURCE_DIR}/Assets/Integrations"
148+
"${CMAKE_SOURCE_DIR}/Assets/Integrations/Autodesk/maya"
149+
"${CMAKE_SOURCE_DIR}/Assets/Integrations/.gitignore"
143150
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Assets
144151
COMMENT "Zipping Maya Integration folder"
145152
DEPENDS ${README_TARGET}
146153
)
147154
add_custom_target(${MAYA_INTEGRATION_TARGET} DEPENDS ${MAYA_INTEGRATION_ZIP_NAME})
148155

156+
157+
add_custom_command(OUTPUT ${MAX_INTEGRATION_ZIP_NAME}
158+
IF(META_FILES)
159+
COMMAND ${CMAKE_COMMAND} -E remove ${META_FILES}
160+
ENDIF
161+
COMMAND ${CMAKE_COMMAND} -E tar "cfv" ${CMAKE_SOURCE_DIR}/Assets/FbxExporters/${MAX_INTEGRATION_ZIP_NAME} --format=zip
162+
"${CMAKE_SOURCE_DIR}/Assets/Integrations/Autodesk/max"
163+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Assets
164+
COMMENT "Zipping 3DsMax Integration folder"
165+
)
166+
add_custom_target(${MAX_INTEGRATION_TARGET} DEPENDS ${MAX_INTEGRATION_ZIP_NAME})
167+
149168
###########################################################################
150169
# Compile editor scripts into a multi-platform DLL
151170
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
@@ -218,7 +237,7 @@ add_custom_command(
218237
COMMENT "Creating Unity Package ${PACKAGE_PATH}"
219238
DEPENDS UnityFbxExporterEditorDLL
220239
)
221-
add_custom_target(unitypackage DEPENDS ${PACKAGE_PATH} ${FBXSDK_PACKAGE_TARGET} ${README_TARGET} ${MAYA_INTEGRATION_TARGET})
240+
add_custom_target(unitypackage DEPENDS ${PACKAGE_PATH} ${FBXSDK_PACKAGE_TARGET} ${MAYA_INTEGRATION_TARGET} ${MAX_INTEGRATION_TARGET} ${README_TARGET})
222241

223242
enable_testing()
224243
add_test(NAME run-all COMMAND "${UNITY_EDITOR_PATH}" -batchmode -projectPath ${CMAKE_SOURCE_DIR} runEditorTests -quit)

scripts/file-search-replace.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)