Skip to content
This repository has been archived by the owner on Jun 24, 2019. It is now read-only.

Commit

Permalink
Poly Toolkit for Unity v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
anokta committed Jun 27, 2018
1 parent f3a818d commit 143b2b7
Show file tree
Hide file tree
Showing 242 changed files with 5,731 additions and 4,237 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@
# Ignore built unity packages, we don't want to check those in.
*.unitypackage


# Don't commit the Asset Store Tools plugin.
/Assets/AssetStoreTools/
/Assets/AssetStoreTools.meta
2 changes: 1 addition & 1 deletion Assets/Editor/CheckUnityVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace PolyToolkitDev {

[InitializeOnLoad]
public class CheckUnityVersion {
private const string SUPPORTED_UNITY_VERSION = "5.6.3p1";
private const string SUPPORTED_UNITY_VERSION = "5.6.3f1";
static CheckUnityVersion() {
if (Application.unityVersion != SUPPORTED_UNITY_VERSION) {
EditorUtility.DisplayDialog(
Expand Down
13 changes: 11 additions & 2 deletions Assets/Editor/Tests/TestImportGltf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ internal class TestImportGltf {
internal const string kAllBrush14 = "TestData/gltf1/All_Brushes_TB14.gltf";
internal const string kComputer = "TestData/gltf2/computer.gltf";
internal const string kGoblets = "TestData/gltf2/goblets.gltf";
internal const string kShark = "TestData/gltf2-fbx/shark.gltf";

// The root of this git repository
static string RepoRoot { get {
Expand Down Expand Up @@ -188,7 +189,9 @@ private static GameObject DoImport(string gltfPath, PolyImportOptions options, b
var text = File.ReadAllText(gltfPath);

GltfSchemaVersion version;
if (text.Contains("\"version\": \"1")) {
if (gltfPath.EndsWith("gltf2")) {
version = GltfSchemaVersion.GLTF2;
} else if (text.Contains("\"version\": \"1")) {
version = GltfSchemaVersion.GLTF1;
} else if (text.Contains("\"version\": \"2")) {
version = GltfSchemaVersion.GLTF2;
Expand Down Expand Up @@ -265,11 +268,17 @@ public static void TestImportGltf2TargetSizeRecenter() {
}

[Test]
[MenuItem("Poly/Dev/Test/Import only (GLTF2, transparent)")]
[MenuItem("Poly/Dev/Test/Import only/Goblets (GLTF2 transparent)")]
public static void TestImportGltf2Transparent() {
DoImport(Path.Combine(RepoRoot, kGoblets), PolyImportOptions.Default());
}

[Test]
[MenuItem("Poly/Dev/Test/Import only/Shark (GLTF2 generated from FBX)")]
public static void TestImportGltf2FromFbx() {
DoImport(Path.Combine(RepoRoot, kShark), PolyImportOptions.Default());
}

static void AssertNear(float f1, float f2, float eps=1e-4f) {
if (Mathf.Abs(f2-f1) >= eps) {
Assert.Fail("{0} not near {1}", f1, f2);
Expand Down
17 changes: 10 additions & 7 deletions Assets/PolyToolkit/Editor/AssetBrowser/AssetBrowserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,27 +454,30 @@ public void StartDownloadAndImport(PolyAsset asset, string ptAssetLocalPath, Edi
PtDebug.LogFormat("ABM: starting to fetch asset {0} ({1}) -> {2}", asset.name, asset.displayName,
ptAssetLocalPath);

// Prefer glTF2 format.
// Prefer glTF1 to glTF2.
// It used to be that no Poly assets had both formats, so the ordering did not matter.
// Blocks assets now have both glTF1 and glTF2. PT does not understand the glTF2 version,
// so the ordering matters a great deal.
PolyFormat glTF2format = asset.GetFormatIfExists(PolyFormatType.GLTF_2);
PolyFormat glTFformat = asset.GetFormatIfExists(PolyFormatType.GLTF);

PolyMainInternal.FetchProgressCallback progressCallback = (PolyAsset assetBeingFetched, float progress) => {
EditorUtility.DisplayProgressBar(DOWNLOAD_PROGRESS_TITLE, DOWNLOAD_PROGRESS_TEXT, progress);
};

if (glTF2format != null) {
if (glTFformat != null) {
EditorUtility.DisplayProgressBar(DOWNLOAD_PROGRESS_TITLE, DOWNLOAD_PROGRESS_TEXT, 0.0f);
PolyMainInternal.Instance.FetchFormatFiles(asset, PolyFormatType.GLTF_2,
PolyMainInternal.Instance.FetchFormatFiles(asset, PolyFormatType.GLTF,
(PolyAsset resultAsset, PolyStatus status) => {
EditorUtility.ClearProgressBar();
OnFetchFinished(status, resultAsset, /*isGltf2*/ true, ptAssetLocalPath, options);
OnFetchFinished(status, resultAsset, /*isGltf2*/ false, ptAssetLocalPath, options);
}, progressCallback);
} else if (glTFformat != null) {
} else if (glTF2format != null) {
EditorUtility.DisplayProgressBar(DOWNLOAD_PROGRESS_TITLE, DOWNLOAD_PROGRESS_TEXT, 0.0f);
PolyMainInternal.Instance.FetchFormatFiles(asset, PolyFormatType.GLTF,
PolyMainInternal.Instance.FetchFormatFiles(asset, PolyFormatType.GLTF_2,
(PolyAsset resultAsset, PolyStatus status) => {
EditorUtility.ClearProgressBar();
OnFetchFinished(status, resultAsset, /*isGltf2*/ false, ptAssetLocalPath, options);
OnFetchFinished(status, resultAsset, /*isGltf2*/ true, ptAssetLocalPath, options);
}, progressCallback);
} else {
Debug.LogError("Asset not in GLTF_2 or GLTF format. Can't import.");
Expand Down
52 changes: 39 additions & 13 deletions Assets/PolyToolkit/Internal/ImportGltf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,15 @@ static List<MeshPrecursor> CreateMeshPrecursorsFromPrimitive(ImportState state,
// Cap the read range to what's available.
attribRange.max = accessor.count;
}
Array data;
if (!TryGetDataAsArray(accessor, attribRange, semantic, out data)) {
// Unrecognized semantic or format. Skip. Warning was already printed.
continue;
}
// PadArrayToSize() guarantees that, no matter what, the data array will have enough data to cover
// all the vertices, even if (due to the problems described above) the accessor is missing
// some elements. The missing elements will be initialized to zero.
Array data = PadArrayToSize(GetDataAsArray(accessor, attribRange, semantic), subset.vertices.Size);
data = PadArrayToSize(data, subset.vertices.Size);
switch (semantic) {
case "POSITION":
ChangeBasisAndApplyScale(data, Semantic.Position, state.scaleFactor);
Expand Down Expand Up @@ -967,59 +972,80 @@ static Semantic GetTexcoordSemantic(
}
}

/// <summary>
/// Returns the specified range of data from an accessor.
/// The result is a copy and is safe to mutate.
///
/// semantic -
/// Attribute name/semantic, if the accessor is for vertex attributes.
/// May be null. Helps determine the return type.
static unsafe Array GetDataAsArray(GltfAccessorBase accessor, IntRange eltRange, string semantic) {
/// </summary>
/// <param name="accessor">The accessor to read.</param>
/// <param name="eltRange">The range of elements to read.</param>
/// <param name="semantic">The semantic to use when reading.</param>
/// <param name="result">(Out) the result of the read. If this method returns true,
/// then this will be an array of the appropriate type for the accessor type
/// (Vector2[] for VEC2, for example). If this method returns false, this will be null.</param>
/// <returns>True if the data could be fetched; false on failure.</returns>
static unsafe bool TryGetDataAsArray(GltfAccessorBase accessor, IntRange eltRange, string semantic, out Array result) {
const Gltf1Accessor.ComponentType FLOAT = Gltf1Accessor.ComponentType.FLOAT;
if (accessor.type == "VEC2" && accessor.componentType == FLOAT) {
var destination = new Vector2[eltRange.Size];
fixed (void* destPtr = destination) {
ReadAccessorData(accessor, eltRange, sizeof(Vector2), (IntPtr)destPtr);
}
return destination;
result = destination;
return true;
} else if (accessor.type == "VEC3" && accessor.componentType == FLOAT) {
var destination = new Vector3[eltRange.Size];
fixed (void* destPtr = destination) {
ReadAccessorData(accessor, eltRange, sizeof(Vector3), (IntPtr)destPtr);
}
return destination;
result = destination;
return true;
} else if (accessor.type == "VEC4" && accessor.componentType == FLOAT) {
if (semantic.StartsWith("COLOR")) {
var destination = new Color[eltRange.Size];
fixed (void* destPtr = destination) {
ReadAccessorData(accessor, eltRange, sizeof(Color), (IntPtr)destPtr);
}
return destination;
result = destination;
return true;
} else {
var destination = new Vector4[eltRange.Size];
fixed (void* destPtr = destination) {
ReadAccessorData(accessor, eltRange, sizeof(Vector4), (IntPtr)destPtr);
}
return destination;
result = destination;
return true;
}
} else if (accessor.type == "SCALAR" && accessor.componentType == FLOAT) {
var destination = new float[eltRange.Size];
fixed (void* destPtr = destination) {
ReadAccessorData(accessor, eltRange, sizeof(float), (IntPtr)destPtr);
}
return destination;
result = destination;
return true;
} else if (accessor.type == "SCALAR"
&& accessor.componentType == Gltf1Accessor.ComponentType.UNSIGNED_SHORT) {
var destination = new ushort[eltRange.Size];
fixed (void* destPtr = destination) {
ReadAccessorData(accessor, eltRange, sizeof(ushort), (IntPtr)destPtr);
}
return destination;
result = destination;
return true;
} else {
Debug.LogWarningFormat(
"Unknown accessor type {0} componentType {1}",
accessor.type, accessor.componentType);
}
return null;
result = null;
return false;
}

static Array GetDataAsArray(GltfAccessorBase accessor, IntRange eltRange, string semantic) {
Array result;
if (!TryGetDataAsArray(accessor, eltRange, semantic, out result)) {
throw new Exception(string.Format("Failed to get GLTF data as array from accessor type {0} with semantic {1}",
accessor.type, semantic));
}
return result;
}

/// Reads (range.Size * elementLength) bytes from the specified point
Expand Down
2 changes: 1 addition & 1 deletion Assets/PolyToolkit/Internal/PtSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class PtSettings : ScriptableObject {
/// Poly Toolkit version number.
/// </summary>
public static Version Version {
get { return new Version { major = 1, minor = 0 }; }
get { return new Version { major = 1, minor = 1 }; }
}

private static PtSettings instance;
Expand Down
33 changes: 23 additions & 10 deletions Assets/PolyToolkit/Internal/tbt/Brushes/AllBrushes.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,54 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_DefaultManifest: {fileID: 0}
m_Brushes:
- {fileID: 11400000, guid: d6f6de76308b4b05386f187491479d94, type: 2}
- {fileID: 11400000, guid: 71dc5ead67382b75789dd72c8058d553, type: 2}
- {fileID: 11400000, guid: 185ca6407d6d6095e95d6695d994a12b, type: 2}
- {fileID: 11400000, guid: cadc04d18daae874aa63168911a19ba6, type: 2}
- {fileID: 11400000, guid: 94e865ca3b92ee5568334254825adac1, type: 2}
- {fileID: 11400000, guid: 58575cce2727fec449fd95b38f249b39, type: 2}
- {fileID: 11400000, guid: d654adeb77b0e4e57be9d81558a4eab8, type: 2}
- {fileID: 11400000, guid: 07ab675df8bcbd148809e406fcd485fd, type: 2}
- {fileID: 11400000, guid: ac595c6b6de2ec859a96231504448d7c, type: 2}
- {fileID: 11400000, guid: c6fa15292ff30d25f819be478121d74e, type: 2}
- {fileID: 11400000, guid: d4d57e30cdd022945b067d76b7ded1c7, type: 2}
- {fileID: 11400000, guid: 89d06e0e0a68a1c488e9eb9bc2ca3abc, type: 2}
- {fileID: 11400000, guid: 7f2dcdb5c7d9fc94db14b323331d5860, type: 2}
- {fileID: 11400000, guid: f4ed52160dfaf694ea666a6294e38f42, type: 2}
- {fileID: 11400000, guid: c2b9f7e0f4fb54b41b7dbeb23b117551, type: 2}
- {fileID: 11400000, guid: 6d014762200f4014fa8a87bcfaa038fe, type: 2}
- {fileID: 11400000, guid: 1087726a0694716539a6894556a3a557, type: 2}
- {fileID: 11400000, guid: 6d014762200f4014fa8a87bcfaa038fe, type: 2}
- {fileID: 11400000, guid: 6e268406bbadd084a825dda73d24387a, type: 2}
- {fileID: 11400000, guid: 9f45a29bbed9af6479948c03267fe239, type: 2}
- {fileID: 11400000, guid: 3c7ec9f584dd60e4a9308abe95b9f22e, type: 2}
- {fileID: 11400000, guid: a97674f9669261b48a61cfed32378345, type: 2}
- {fileID: 11400000, guid: de779677f45c66b5bb80d8fdc8604238, type: 2}
- {fileID: 11400000, guid: 969b71c814f75e9408602593d4e10e3e, type: 2}
- {fileID: 11400000, guid: a97674f9669261b48a61cfed32378345, type: 2}
- {fileID: 11400000, guid: 0cfb52fb947fb6e4786ed9f2bdc5328c, type: 2}
- {fileID: 11400000, guid: b22741da3567d9353a0ccc88393d8c8e, type: 2}
- {fileID: 11400000, guid: 3251442494b7f6c43aa51c2ede6c409e, type: 2}
- {fileID: 11400000, guid: 88ecf340d7ce92a4bada6eac937e887a, type: 2}
- {fileID: 11400000, guid: 6c27caca67a732d4f9d59b028c4dd9a8, type: 2}
- {fileID: 11400000, guid: 4fcc165667ef68c5780910cc28494a38, type: 2}
- {fileID: 11400000, guid: f83c05f7491995a53af9be352980ef25, type: 2}
- {fileID: 11400000, guid: 6e08a273b7cdf2b50b4db8fcd5d3d9b2, type: 2}
- {fileID: 11400000, guid: 6c27caca67a732d4f9d59b028c4dd9a8, type: 2}
- {fileID: 11400000, guid: 362043fe9dab1704fa0f912c4f1e0d09, type: 2}
- {fileID: 11400000, guid: 54a30b55c2e961643a7701bedc663c88, type: 2}
- {fileID: 11400000, guid: 4f55fba4b64913b419cf4a17ba5d489b, type: 2}
- {fileID: 11400000, guid: 1d8b02cc1233fee5fae7728123e6257d, type: 2}
- {fileID: 11400000, guid: 3fd505f4dc669fe4c86c80d009ec2efd, type: 2}
- {fileID: 11400000, guid: cc8a936db644b835cb1d6ac3836f65f2, type: 2}
- {fileID: 11400000, guid: 71228caab923caf46a89c3275938564a, type: 2}
- {fileID: 11400000, guid: d7ada22e6a436e742910a7553f159550, type: 2}
- {fileID: 11400000, guid: 542d61ce63831da52a2faf8cb6e2d161, type: 2}
- {fileID: 11400000, guid: 9b77a7cd7bb6c0244bca8ab8221af846, type: 2}
- {fileID: 11400000, guid: d7ada22e6a436e742910a7553f159550, type: 2}
- {fileID: 11400000, guid: 4c750113c587a7e5c97a5627a917967e, type: 2}
- {fileID: 11400000, guid: 9b77a7cd7bb6c0244bca8ab8221af846, type: 2}
- {fileID: 11400000, guid: a8f488f387b09e35dba50b6e9904301b, type: 2}
- {fileID: 11400000, guid: 7e6a9b8a0ad82cf4da20e86f1a326040, type: 2}
- {fileID: 11400000, guid: d75833fb286458e468c00cc5b0ac5f4d, type: 2}
- {fileID: 11400000, guid: aaaca97d63dd3d156ad1632b76baaf8d, type: 2}
- {fileID: 11400000, guid: 84e07a49ce756cf44ab7ea2dbdc064c4, type: 2}
- {fileID: 11400000, guid: 7ccf5a61af1914e409b526a98d43354b, type: 2}
- {fileID: 11400000, guid: bf5c0e36bc63d7b418af3ac347cfdcfd, type: 2}
- {fileID: 11400000, guid: 402a078d5db9ad0468dda690396443bc, type: 2}
- {fileID: 11400000, guid: aa162493b08406a5a82822709c50af77, type: 2}
- {fileID: 11400000, guid: 20e65e1c9af17105b8a58d0d04ad41c8, type: 2}
- {fileID: 11400000, guid: 402a078d5db9ad0468dda690396443bc, type: 2}
- {fileID: 11400000, guid: b1626af60ae7a31419a1c40afb39c5ed, type: 2}
- {fileID: 11400000, guid: 12b98790c761f47429559af03b6669d2, type: 2}
- {fileID: 11400000, guid: 38f5be2edab11fa429b090756d26d000, type: 2}
Expand All @@ -66,8 +71,16 @@ MonoBehaviour:
- {fileID: 11400000, guid: de4112b6c3a19ae5bb03397212a78339, type: 2}
- {fileID: 11400000, guid: 94cb84ebeec44c540bb15b32797e5a98, type: 2}
- {fileID: 11400000, guid: b8a2349e67797ea4593639454ef74543, type: 2}
- {fileID: 11400000, guid: e6226d3ece719e15aae431e9b1bacf2d, type: 2}
- {fileID: 11400000, guid: 5398e778cce3fdf469bbfa388aa46d5d, type: 2}
- {fileID: 11400000, guid: ebe8a9d99afbd6b46909ea24a9896258, type: 2}
- {fileID: 11400000, guid: cb620f38d66c44f559d8abd0efa6a295, type: 2}
- {fileID: 11400000, guid: 979dc653ba7d1d358a1a3c25bf5d033f, type: 2}
- {fileID: 11400000, guid: b250a068d80bad858be65c3d4675b50d, type: 2}
- {fileID: 11400000, guid: 34192af8b5bb56258ba49d0cf281f850, type: 2}
- {fileID: 11400000, guid: 3a72bd3c1fe3d784ab8896ec9fdfd058, type: 2}
- {fileID: 11400000, guid: 71dc5ead67382b75789dd72c8058d553, type: 2}
- {fileID: 11400000, guid: 185ca6407d6d6095e95d6695d994a12b, type: 2}
- {fileID: 11400000, guid: d6f6de76308b4b05386f187491479d94, type: 2}
- {fileID: 11400000, guid: 64222159a2860fd5d8a9efd7fac6610a, type: 2}
- {fileID: 11400000, guid: 116cd5bf02ca0345da1f33cc3484c5ec, type: 2}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 143b2b7

Please sign in to comment.