Skip to content

Commit 1098fed

Browse files
committed
Merge branch 'master' into UNI-41724-sprint50-release
2 parents dbf4c70 + 067acc5 commit 1098fed

File tree

6 files changed

+130
-62
lines changed

6 files changed

+130
-62
lines changed

Assets/FbxExporters/Editor/ConvertToModel.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,7 @@ public static GameObject Convert (
108108
)
109109
{
110110
// Only create the prefab (no FBX export) if we have selected the root of a model prefab instance.
111-
// Children of model prefab instances will also have "model prefab instance"
112-
// as their prefab type, so it is important that it is the root that is selected.
113-
//
114-
// e.g. If I have the following hierarchy:
115-
// Cube
116-
// -- Sphere
117-
//
118-
// Both the Cube and Sphere will have ModelPrefabInstance as their prefab type.
119-
// However, when selecting the Sphere to convert, we don't want to connect it to the
120-
// existing FBX but create a new FBX containing just the sphere.
121-
PrefabType unityPrefabType = PrefabUtility.GetPrefabType(toConvert);
122-
if (unityPrefabType == PrefabType.ModelPrefabInstance && toConvert.Equals(PrefabUtility.FindPrefabRoot(toConvert))) {
111+
if(IsModelInstance(toConvert)){
123112
// don't re-export fbx
124113
// create prefab out of model instance in scene, link to existing fbx
125114
var mainAsset = PrefabUtility.GetPrefabParent(toConvert) as GameObject;
@@ -223,6 +212,26 @@ public static void SetupFbxPrefab(GameObject toConvert, GameObject unityMainAsse
223212
}
224213
}
225214

215+
/// <summary>
216+
/// Determines if the given GameObject is a model instance.
217+
/// </summary>
218+
/// <returns><c>true</c> if go is a model instance; otherwise, <c>false</c>.</returns>
219+
/// <param name="go">Go.</param>
220+
public static bool IsModelInstance(GameObject go){
221+
// Children of model prefab instances will also have "model prefab instance"
222+
// as their prefab type, so it is important that it is the root that is selected.
223+
//
224+
// e.g. If I have the following hierarchy:
225+
// Cube
226+
// -- Sphere
227+
//
228+
// Both the Cube and Sphere will have ModelPrefabInstance as their prefab type.
229+
// However, when selecting the Sphere to convert, we don't want to connect it to the
230+
// existing FBX but create a new FBX containing just the sphere.
231+
PrefabType unityPrefabType = PrefabUtility.GetPrefabType(go);
232+
return unityPrefabType == PrefabType.ModelPrefabInstance && go.Equals (PrefabUtility.FindPrefabRoot (go));
233+
}
234+
226235
/// <summary>
227236
/// Check if the file exists, and if it does, then increment the name.
228237
/// e.g. if filename is Sphere.fbx and it already exists, change it to Sphere 1.fbx.

Assets/FbxExporters/Editor/ConvertToPrefabEditorWindow.cs

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections;
1+
using System.Collections;
22
using System.Collections.Generic;
33
using UnityEngine;
44
using UnityEditor;
@@ -45,12 +45,23 @@ protected void SetGameObjectsToConvert(IEnumerable<GameObject> toConvert){
4545

4646
TransferAnimationSource = null;
4747
TransferAnimationDest = null;
48-
4948
if (ToExport.Length == 1) {
50-
m_prefabFileName = ToExport [0].name;
49+
var go = ModelExporter.GetGameObject (ToExport [0]);
50+
// check if the GameObject is a model instance, use as default filename and path if it is
51+
if(ConvertToModel.IsModelInstance(go)) {
52+
var mainAsset = PrefabUtility.GetPrefabParent (go) as GameObject;
53+
var mainAssetRelPath = AssetDatabase.GetAssetPath (mainAsset);
54+
// remove Assets/ from beginning of path
55+
mainAssetRelPath = mainAssetRelPath.Substring ("Assets".Length);
56+
57+
m_prefabFileName = System.IO.Path.GetFileNameWithoutExtension (mainAssetRelPath);
58+
ExportSettings.AddFbxSavePath (System.IO.Path.GetDirectoryName (mainAssetRelPath));
59+
}
60+
else{
61+
m_prefabFileName = ToExport [0].name;
62+
}
5163

5264
// if only one object selected, set transfer source/dest to this object
53-
var go = ModelExporter.GetGameObject (ToExport [0]);
5465
if (go) {
5566
TransferAnimationSource = go.transform;
5667
TransferAnimationDest = go.transform;
@@ -71,8 +82,18 @@ protected override void OnEnable ()
7182
m_prefabExtLabelWidth = m_fbxExtLabelStyle.CalcSize (new GUIContent (".prefab")).x;
7283
}
7384

74-
protected override void Export ()
85+
protected override bool Export ()
7586
{
87+
if (string.IsNullOrEmpty (m_exportFileName)) {
88+
Debug.LogError ("FbxExporter: Please specify an fbx filename");
89+
return false;
90+
}
91+
92+
if (string.IsNullOrEmpty (m_prefabFileName)) {
93+
Debug.LogError ("FbxExporter: Please specify a prefab filename");
94+
return false;
95+
}
96+
7697
var fbxDirPath = ExportSettings.GetFbxAbsoluteSavePath ();
7798
var fbxPath = System.IO.Path.Combine (fbxDirPath, m_exportFileName + ".fbx");
7899

@@ -81,20 +102,45 @@ protected override void Export ()
81102

82103
// check if file already exists, give a warning if it does
83104
if (!OverwriteExistingFile (fbxPath) || !OverwriteExistingFile (prefabPath)) {
84-
return;
105+
return false;
85106
}
86107

87108
if (ToExport == null) {
88109
Debug.LogError ("FbxExporter: missing object for conversion");
89-
return;
110+
return false;
90111
}
91112

92113
if (ToExport.Length == 1) {
93114
var go = ModelExporter.GetGameObject (ToExport [0]);
115+
116+
if (!OverwriteExistingFile (prefabPath)) {
117+
return false;
118+
}
119+
120+
// Only create the prefab (no FBX export) if we have selected the root of a model prefab instance.
121+
if(ConvertToModel.IsModelInstance(go)) {
122+
// don't re-export fbx
123+
// create prefab out of model instance in scene, link to existing fbx
124+
var mainAsset = PrefabUtility.GetPrefabParent(go) as GameObject;
125+
var mainAssetRelPath = AssetDatabase.GetAssetPath(mainAsset);
126+
var mainAssetAbsPath = System.IO.Directory.GetParent(Application.dataPath) + "/" + mainAssetRelPath;
127+
var relPrefabPath = ExportSettings.GetProjectRelativePath (prefabPath);
128+
129+
if (string.Equals(System.IO.Path.GetFullPath(fbxPath), System.IO.Path.GetFullPath(mainAssetAbsPath))) {
130+
ConvertToModel.SetupFbxPrefab(go, mainAsset, relPrefabPath, mainAssetAbsPath);
131+
return true;
132+
}
133+
}
134+
135+
// check if file already exists, give a warning if it does
136+
if (!OverwriteExistingFile (fbxPath)) {
137+
return false;
138+
}
139+
94140
ConvertToModel.Convert (
95141
go, fbxFullPath: fbxPath, prefabFullPath: prefabPath, exportOptions: ExportSettings.instance.convertToPrefabSettings.info
96142
);
97-
return;
143+
return true;
98144
}
99145

100146
foreach (var obj in ToExport) {
@@ -103,6 +149,7 @@ protected override void Export ()
103149
go, fbxDirectoryFullPath: fbxDirPath, prefabDirectoryFullPath: prefabDirPath, exportOptions: ExportSettings.instance.convertToPrefabSettings.info
104150
);
105151
}
152+
return true;
106153
}
107154

108155
protected override ExportOptionsSettingsSerializeBase SettingsObject

Assets/FbxExporters/Editor/ExportModelEditorWindow.cs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections;
1+
using System.Collections;
22
using System.Collections.Generic;
33
using UnityEngine;
44
using UnityEditor;
@@ -116,7 +116,7 @@ public void OnPresetSelectionChanged()
116116
this.Repaint ();
117117
}
118118

119-
protected abstract void Export ();
119+
protected abstract bool Export ();
120120

121121
/// <summary>
122122
/// Function to be used by derived classes to add custom UI between the file path selector and export options.
@@ -356,8 +356,9 @@ protected void OnGUI ()
356356
}
357357

358358
if (GUILayout.Button (ExportButtonName, GUILayout.Width(ExportButtonWidth))) {
359-
Export ();
360-
this.Close ();
359+
if (Export ()) {
360+
this.Close ();
361+
}
361362
}
362363
GUILayout.EndHorizontal ();
363364

@@ -412,6 +413,7 @@ protected bool IsTimelineAnim {
412413
set{
413414
m_isTimelineAnim = value;
414415
if (m_isTimelineAnim) {
416+
m_previousInclude = ExportSettings.instance.exportModelSettings.info.ModelAnimIncludeOption;
415417
ExportSettings.instance.exportModelSettings.info.SetModelAnimIncludeOption(ExportSettings.Include.Anim);
416418
}
417419
if (m_innerEditor) {
@@ -451,6 +453,8 @@ protected override ExportOptionsSettingsSerializeBase SettingsObject
451453
get { return ExportSettings.instance.exportModelSettings.info; }
452454
}
453455

456+
private ExportSettings.Include m_previousInclude = ExportSettings.Include.ModelAndAnim;
457+
454458
public static void Init (IEnumerable<UnityEngine.Object> toExport, string filename = "", bool isTimelineAnim = false, bool isPlayableDirector = false)
455459
{
456460
ExportModelEditorWindow window = CreateWindow<ExportModelEditorWindow> ();
@@ -509,12 +513,33 @@ protected override void OnEnable ()
509513
}
510514
}
511515

512-
protected override void Export(){
516+
protected void OnDisable()
517+
{
518+
RestoreSettings ();
519+
}
520+
521+
/// <summary>
522+
/// Restore changed export settings after export
523+
/// </summary>
524+
protected virtual void RestoreSettings()
525+
{
526+
if (IsTimelineAnim) {
527+
ExportSettings.instance.exportModelSettings.info.SetModelAnimIncludeOption(m_previousInclude);
528+
SaveExportSettings ();
529+
}
530+
}
531+
532+
533+
protected override bool Export(){
534+
if (string.IsNullOrEmpty (m_exportFileName)) {
535+
Debug.LogError ("FbxExporter: Please specify an fbx filename");
536+
return false;
537+
}
513538
var folderPath = ExportSettings.GetFbxAbsoluteSavePath ();
514539
var filePath = System.IO.Path.Combine (folderPath, m_exportFileName + ".fbx");
515540

516541
if (!OverwriteExistingFile (filePath)) {
517-
return;
542+
return false;
518543
}
519544

520545
if (IsPlayableDirector) {
@@ -528,14 +553,15 @@ protected override void Export(){
528553
// refresh the asset database so that the file appears in the
529554
// asset folder view.
530555
AssetDatabase.Refresh ();
531-
return;
556+
return true;
532557
}
533558

534559
if (ModelExporter.ExportObjects (filePath, ToExport, SettingsObject, timelineAnim: m_isTimelineAnim) != null) {
535560
// refresh the asset database so that the file appears in the
536561
// asset folder view.
537562
AssetDatabase.Refresh ();
538563
}
564+
return true;
539565
}
540566

541567
#if UNITY_2018_1_OR_NEWER

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3780,7 +3780,7 @@ bool ExportMesh (GameObject gameObject, FbxNode fbxNode)
37803780

37813781
// if user doesn't want to export mesh colliders, and this gameobject doesn't have a renderer
37823782
// then don't export it.
3783-
if (!ExportOptions.ExportUnrendered && !gameObject.GetComponent<Renderer>()) {
3783+
if (!ExportOptions.ExportUnrendered && (!gameObject.GetComponent<Renderer>() || !gameObject.GetComponent<Renderer>().enabled)) {
37843784
return false;
37853785
}
37863786

Assets/FbxExporters/LICENSE.txt

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
1-
Unity Companion License 1.0 (“License”)
2-
Copyright © 2017 Unity Technologies ApS (“Unity”)
3-
4-
Unity hereby grants to you a worldwide, non-exclusive, no-charge, and royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the software that is made available with this License (“Software”), subject to the following terms and conditions:
5-
6-
1. Unity Companion Use Only. Exercise of the license granted herein is limited to exercise for the creation, use, and/or distribution of applications, software, or other content pursuant to a valid Unity development engine software license (“Engine License”). That means while use of the Software is not limited to use in the software licensed under the Engine License, the Software may not be used for any purpose other than the creation, use, and/or distribution of Engine License-dependent applications, software, or other content. No other exercise of the license granted herein is permitted.
7-
8-
2. No Modification of Engine License. Neither this License nor any exercise of the license granted herein modifies the Engine License in any way.
9-
10-
3. Ownership & Grant Back to You.
1+
FBX Exporter copyright © 2017 Unity Technologies ApS
112

3+
Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License).
124

13-
3.1 You own your content. In this License, “derivative works” means derivatives of the Software itself--works derived only from the Software by you under this License (for example, modifying the code of the Software itself to improve its efficacy); “derivative works” of the Software do not include, for example, games, apps, or content that you create using the Software. You keep all right, title, and interest to your own content.
14-
15-
16-
3.2 Unity owns its content. While you keep all right, title, and interest to your own content per the above, as between Unity and you, Unity will own all right, title, and interest to all intellectual property rights (including patent, trademark, and copyright) in the Software and derivative works of the Software, and you hereby assign and agree to assign all such rights in those derivative works to Unity.
17-
18-
19-
3.3 You have a license to those derivative works. Subject to this License, Unity grants to you the same worldwide, non-exclusive, no-charge, and royalty-free copyright license to derivative works of the Software you create as is granted to you for the Software under this License.
20-
21-
4. Trademarks. You are not granted any right or license under this License to use any trademarks, service marks, trade names, products names, or branding of Unity or its affiliates (“Trademarks”). Descriptive uses of Trademarks are permitted; see, for example, Unity’s Branding Usage Guidelines at https://unity3d.com/public-relations/brand.
22-
23-
5. Notices & Third-Party Rights. This License, including the copyright notice above, must be provided in all substantial portions of the Software and derivative works thereof (or, if that is impracticable, in any other location where such notices are customarily placed). Further, if the Software is accompanied by a Unity “third-party notices” or similar file, you acknowledge and agree that software identified in that file is governed by those separate license terms.
24-
25-
6. DISCLAIMER, LIMITATION OF LIABILITY. THE SOFTWARE AND ANY DERIVATIVE WORKS THEREOF IS PROVIDED ON AN "AS IS" BASIS, AND IS PROVIDED WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR NONINFRINGEMENT. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES (WHETHER DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL, INCLUDING PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS, AND BUSINESS INTERRUPTION), OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM OR OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR ANY DERIVATIVE WORKS THEREOF OR THE USE OF OR OTHER DEALINGS IN SAME, EVEN WHERE ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26-
27-
7. USE IS ACCEPTANCE and License Versions. Your receipt and use of the Software constitutes your acceptance of this License and its terms and conditions. Software released by Unity under this License may be modified or updated and the License with it; upon any such modification or update, you will comply with the terms of the updated License for any use of any of the Software under the updated License.
28-
29-
8. Use in Compliance with Law and Termination. Your exercise of the license granted herein will at all times be in compliance with applicable law and will not infringe any proprietary rights (including intellectual property rights); this License will terminate immediately on any breach by you of this License.
30-
31-
32-
9. Severability. If any provision of this License is held to be unenforceable or invalid, that provision will be enforced to the maximum extent possible and the other provisions will remain in full force and effect.
33-
34-
35-
10. Governing Law and Venue. This License is governed by and construed in accordance with the laws of Denmark, except for its conflict of laws rules; the United Nations Convention on Contracts for the International Sale of Goods will not apply. If you reside (or your principal place of business is) within the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the state and federal courts located in San Francisco County, California concerning any dispute arising out of this License (“Dispute”). If you reside (or your principal place of business is) outside the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the courts located in Copenhagen, Denmark concerning any Dispute.
5+
Unless expressly provided otherwise, the Software under this license is made available strictly on an "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.

RELEASE_NOTES_EXTERNAL.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@ Error caused by UnityFbxSdk.dll being set as compatible with any platform instea
1616

1717
**Version**: 1.2.0b1
1818

19+
NEW FEATURES
20+
* Added Maya LT one button import/export
21+
* Added Camera export support
22+
1923
**Version**: 1.1.0b1
2024

21-
**Version**: 1.0.0b1
25+
NEW FEATURES
26+
* Added 3ds Max one button import/export
27+
28+
FIXES
29+
* Fix so Object references aren't lost when using Convert to Linked Prefab Instance
30+
* Fix Maya Integration dropdown not appearing in the Export Settings
31+
32+
**Version**: 1.0.0b1
33+
34+
NEW FEATURES
35+
* Ability to export fbx files from Unity
36+
* Convert to linked prefab to create a prefab that auto-updates with the linked fbx
37+
* Maya one button import/export

0 commit comments

Comments
 (0)