Skip to content

Commit e28e7d1

Browse files
authored
Merge pull request #39 from Unity-Technologies/Uni-21365-maya2017-integration
Uni-21365 maya2017 integration with installer
2 parents 50aa8fd + c41a5f5 commit e28e7d1

File tree

15 files changed

+1083
-1
lines changed

15 files changed

+1083
-1
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
*.swp
1414
*.swo
1515

16+
## PyCharm ##
17+
**/.idea/
18+
1619
## Unity ##
1720
*.meta
1821
[Pp]rojectSettings/*.asset
@@ -43,7 +46,6 @@ ExportedObj/
4346
*.pidb
4447
*.booproj
4548
*.svd
46-
*.pdb
4749

4850
# Unity3D generated meta files
4951
*.pidb.meta
Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using System;
4+
using System.Collections.Generic;
5+
6+
namespace FbxExporters
7+
{
8+
class Integrations
9+
{
10+
private const string MAYA_VERSION = "2017";
11+
private const string MODULE_FILENAME = "unityoneclick.mod";
12+
private const string PACKAGE_NAME = "FbxExporters";
13+
private const string VERSION_FILENAME = "README.txt";
14+
private const string VERSION_FIELD = "**Version**";
15+
private const string VERSION_TAG = "{Version}";
16+
private const string PROJECT_TAG = "{UnityProject}";
17+
18+
private static Char[] FIELD_SEPARATORS = new Char[] {':'};
19+
20+
private const string MODULE_TEMPLATE_PATH = "Integrations/Autodesk/maya"+VERSION_TAG+"/unityoneclick.mod";
21+
22+
#if UNITY_EDITOR_OSX
23+
private const string REL_MAYA_MODULES_PATH = "Library/Preferences/Autodesk/Maya/"+VERSION_TAG+"/modules";
24+
#elif UNITY_EDITOR_LINUX
25+
private const string REL_MAYA_MODULES_PATH = "Maya/"+VERSION_TAG+"/modules";
26+
#else
27+
private const string REL_MAYA_MODULES_PATH = "maya/"+VERSION_TAG+"/modules";
28+
#endif
29+
30+
private static string GetUserFolder()
31+
{
32+
#if UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX
33+
return System.Environment.GetEnvironmentVariable("HOME");
34+
#else
35+
return System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
36+
#endif
37+
}
38+
39+
private static string GetModulePath(string version)
40+
{
41+
string result = System.IO.Path.Combine(GetUserFolder(), REL_MAYA_MODULES_PATH);
42+
43+
return result.Replace(VERSION_TAG,version);
44+
}
45+
46+
private static string GetModuleTemplatePath(string version)
47+
{
48+
string result = System.IO.Path.Combine(Application.dataPath, MODULE_TEMPLATE_PATH);
49+
50+
return result.Replace(VERSION_TAG,version);
51+
}
52+
53+
private static string GetProjectPath()
54+
{
55+
return System.IO.Directory.GetParent(Application.dataPath).FullName;
56+
}
57+
58+
private static string GetPackagePath()
59+
{
60+
return System.IO.Path.Combine(Application.dataPath, PACKAGE_NAME);
61+
}
62+
63+
private static string GetPackageVersion()
64+
{
65+
string result = null;
66+
67+
try {
68+
string FileName = System.IO.Path.Combine(GetPackagePath(), VERSION_FILENAME);
69+
70+
System.IO.StreamReader sr = new System.IO.StreamReader(FileName);
71+
72+
// Read the first line of text
73+
string line = sr.ReadLine();
74+
75+
// Continue to read until you reach end of file
76+
while (line != null)
77+
{
78+
if (line.StartsWith(VERSION_FIELD))
79+
{
80+
string[] fields = line.Split(FIELD_SEPARATORS);
81+
82+
if (fields.Length>1)
83+
{
84+
result = fields[1];
85+
}
86+
break;
87+
}
88+
line = sr.ReadLine();
89+
}
90+
}
91+
catch(Exception e)
92+
{
93+
Debug.LogError(string.Format("Exception failed to read file containing package version ({0})", e.Message));
94+
}
95+
96+
return result;
97+
}
98+
99+
private static List<string> ParseTemplateFile(string FileName, Dictionary<string,string> Tokens )
100+
{
101+
List<string> lines = new List<string>();
102+
103+
try
104+
{
105+
// Pass the file path and file name to the StreamReader constructor
106+
System.IO.StreamReader sr = new System.IO.StreamReader(FileName);
107+
108+
// Read the first line of text
109+
string line = sr.ReadLine();
110+
111+
// Continue to read until you reach end of file
112+
while (line != null)
113+
{
114+
foreach(KeyValuePair<string, string> entry in Tokens)
115+
{
116+
line = line.Replace(entry.Key, entry.Value);
117+
}
118+
lines.Add(line);
119+
120+
//Read the next line
121+
line = sr.ReadLine();
122+
}
123+
124+
//close the file
125+
sr.Close();
126+
}
127+
catch(Exception e)
128+
{
129+
Debug.LogError(string.Format("Exception reading module file template ({0})", e.Message));
130+
}
131+
132+
return lines;
133+
}
134+
135+
private static void WriteFile(string FileName, List<string> Lines )
136+
{
137+
try
138+
{
139+
//Pass the filepath and filename to the StreamWriter Constructor
140+
System.IO.StreamWriter sw = new System.IO.StreamWriter(FileName);
141+
142+
foreach (string line in Lines)
143+
{
144+
//Write a line of text
145+
sw.WriteLine(line);
146+
}
147+
148+
//Close the file
149+
sw.Close();
150+
}
151+
catch(Exception e)
152+
{
153+
Debug.LogError(string.Format("Exception while writing module file ({0})", e.Message));
154+
}
155+
}
156+
157+
private static void _InstallMaya2017(bool verbose=true, bool commandsOnly=false)
158+
{
159+
// check if package installed
160+
string moduleTemplatePath = GetModuleTemplatePath(MAYA_VERSION);
161+
162+
if (!System.IO.File.Exists(moduleTemplatePath))
163+
{
164+
Debug.LogError(string.Format("FbxExporters package not installed, please install first"));
165+
return;
166+
}
167+
168+
// TODO: detect maya2017 installation
169+
170+
// TODO: if not maya2017 installed warn user
171+
172+
// check for {USER} modules folder
173+
string modulePath = GetModulePath(MAYA_VERSION);
174+
175+
string moduleFilePath = System.IO.Path.Combine( modulePath, MODULE_FILENAME);
176+
177+
bool installed = false;
178+
179+
if (!System.IO.Directory.Exists(modulePath))
180+
{
181+
if (verbose) Debug.Log(string.Format("Creating Maya Modules Folder {0}", modulePath));
182+
183+
try
184+
{
185+
System.IO.Directory.CreateDirectory(modulePath);
186+
}
187+
catch
188+
{
189+
Debug.LogError(string.Format("Failed to create Maya Modules Folder {0}", modulePath));
190+
return;
191+
}
192+
193+
if (!System.IO.Directory.Exists(modulePath)) {
194+
Debug.LogError(string.Format("Failed to create Maya Modules Folder {0}", modulePath));
195+
return;
196+
}
197+
198+
installed = false;
199+
}
200+
else
201+
{
202+
// detect if unityoneclick.mod is installed
203+
installed = System.IO.File.Exists(moduleFilePath);
204+
205+
if (installed)
206+
{
207+
// FIXME: remove this when we support parsing existing .mod files
208+
try {
209+
System.IO.File.Delete(moduleFilePath);
210+
installed = false;
211+
}
212+
catch
213+
{
214+
Debug.LogWarning(string.Format ("Failed to delete plugin module file {0}", moduleFilePath));
215+
}
216+
}
217+
}
218+
219+
// if not installed
220+
if (!installed)
221+
{
222+
Dictionary<string,string> Tokens = new Dictionary<string,string>()
223+
{
224+
{VERSION_TAG, GetPackageVersion() },
225+
{PROJECT_TAG, GetProjectPath() }
226+
};
227+
228+
// parse template, replace "{UnityProject}" with project path
229+
List<string> lines = ParseTemplateFile(moduleTemplatePath, Tokens);
230+
231+
if (verbose) Debug.Log(string.Format("Copying plugin module file to {0}",moduleFilePath));
232+
233+
// write out .mod file
234+
WriteFile(moduleFilePath, lines);
235+
}
236+
else
237+
{
238+
throw new NotImplementedException();
239+
240+
// TODO: parse installed .mod file
241+
242+
// TODO: if maya version not installed add
243+
244+
// TODO: else check installation path
245+
246+
// TODO: if installation path different
247+
248+
// TODO: print message package already installed else where
249+
}
250+
251+
if (commandsOnly)
252+
throw new NotImplementedException();
253+
254+
// TODO: configure maya to auto-load plugin on next startup
255+
256+
}
257+
258+
public static void InstallMaya2017()
259+
{
260+
bool verbose=true;
261+
262+
Debug.Log(string.Format("Installing Maya {0} Integration",MAYA_VERSION));
263+
264+
_InstallMaya2017(verbose);
265+
266+
if (verbose) Debug.Log(string.Format("Finished installing Maya {0} Integration.",MAYA_VERSION));
267+
}
268+
269+
public static void InstallMaya2017CommandsOnly()
270+
{
271+
bool verbose=true;
272+
273+
Debug.Log(string.Format("Installing Maya {0} Integration Commands Only",MAYA_VERSION));
274+
275+
_InstallMaya2017(verbose, true);
276+
277+
if (verbose) Debug.Log(string.Format("Finished installing Maya {0} Integration Commands Only.",MAYA_VERSION));
278+
}
279+
}
280+
281+
namespace Editors
282+
{
283+
class IntegrationsUI
284+
{
285+
const string MenuItemName = "FbxExporters/Install Maya2017 Integration";
286+
287+
[MenuItem (MenuItemName, false, 0)]
288+
public static void OnMenuItem ()
289+
{
290+
Integrations.InstallMaya2017();
291+
}
292+
}
293+
}
294+
}

Assets/FbxExporters/README.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,33 @@ Requirements
1111
------------
1212

1313
* [FBX SDK C# Bindings v0.0.4a or higher](https://github.com/Unity-Technologies/FbxSharp)
14+
15+
Command-line Installing Maya2017 Integration
16+
--------------------------------------------
17+
18+
You can install the package and integrations from the command-line using the following script:
19+
20+
MacOS:
21+
22+
export UNITY3D_PATH=/Applications/Unity\ 2017.1.0f3/Unity.app/Contents/MacOS/Unity
23+
24+
export PROJECT_PATH=~/Development/FbxExporters
25+
export PACKAGE_NAME=FbxExporters
26+
export PACKAGE_VERSION={CurrentVersion}
27+
export FBXEXPORTERS_PACKAGE_PATH=${PROJECT_PATH}/${PACKAGE_NAME}_${PACKAGE_VERSION}.unitypackage
28+
29+
# must be non-batch to import correctly
30+
"${UNITY3D_PATH}" -projectPath "${PROJECT_PATH}" -importPackage ${FBXEXPORTERS_PACKAGE_PATH} -quit
31+
32+
# Use "InstallMaya2017CommandsOnly" to install without UI
33+
"${UNITY3D_PATH}" -batchMode -projectPath "${PROJECT_PATH}" -executeMethod FbxExporters.Integrations.InstallMaya2017 -quit
34+
35+
Configuring Auto-loading of plugin in Maya2017
36+
----------------------------------------------
37+
38+
MacOS:
39+
40+
export MAYA_PATH=/Applications/Autodesk/maya2017/Maya.app/Contents/bin/maya
41+
42+
"${MAYA_PATH}" -command "loadPlugin unityOneClickPlugin; pluginInfo -edit -autoload true unityOneClickPlugin;quit;"
43+

Assets/Integrations/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pyc
2+
.DS_Store
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
########################################################################
2+
# Copyright (c) 2017 Unity Technologies. All rights reserved.
3+
# NOTICE: All information contained herein is, and remains
4+
# the property of Unity Technologies Aps. and its suppliers,
5+
# if any. The intellectual and technical concepts contained
6+
# herein are proprietary to Unity Technologies Aps. and its
7+
# suppliers and may be covered by Canadian, U.S. and/or
8+
# Foreign Patents, patents in process, and are protected
9+
# by trade secret or copyright law. Dissemination of this
10+
# information or reproduction of this material is strictly
11+
# forbidden unless prior written permission is obtained from
12+
# Unity Technologies Aps.
13+
#
14+
########################################################################
15+
16+
Manual Installation
17+
===================
18+
19+
Instructions for installing if you don't use the unity package installer
20+
and your installing in a none-default location.
21+
22+
1. copy unityoneclick.mod to user folder
23+
24+
MacOS & Ubuntu: ~/MayaProjects/modules
25+
Windows: C:\Program Files\Autodesk\Maya2017\modules
26+
27+
2. configure path within unityoneclick.mod to point to integration installation folder
28+
29+
{UnityProject}/Assets/Integrations/Autodesk/maya2017
30+
31+
32+
Running Unit Tests
33+
==================
34+
35+
MacOS
36+
37+
export MAYAPY_PATH=/Applications/Autodesk/maya2017/Maya.app/Contents/bin/mayapy
38+
export MAYA_INTEGRATION_PATH=${UNITY_PROJECT_PATH}/Assets/Integrations/Autodesk/maya2017
39+
export PYTHONPATH=${MAYA_INTEGRATION_PATH}/scripts
40+
41+
# run all tests
42+
${MAYAPY_PATH} ${MAYA_INTEGRATION_PATH}/scripts/run_all_tests.py
43+
44+
# run one test
45+
${MAYAPY_PATH} ${MAYA_INTEGRATION_PATH}/scripts/unityOneClick/commands.py

0 commit comments

Comments
 (0)