forked from googlevr/tilt-brush-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mostly copy/paste from Glb1Importer but it returns a different schema version and uses the standard ".glb" file extension. Change-Id: Id000b01593e8277a7e9cc5b4209aa7ebf8d7bd99
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
using Object = UnityEngine.Object; | ||
#if UNITY_2017_1_OR_NEWER | ||
using System; | ||
using System.IO; | ||
|
||
using UnityEngine; | ||
using UnityEditor; | ||
using UnityEditor.Experimental.AssetImporters; | ||
|
||
namespace TiltBrushToolkit { | ||
|
||
[ScriptedImporter(kVersion, "glb", kImportQueueOffset)] | ||
public class Glb2Importer : ScriptedImporter { | ||
const int kVersion = 2; | ||
// ImportGltf needs to reference meshes and textures, so the glb import | ||
// must come after them. We're assuming that Unity built-in asset types | ||
// import at queue offset = 0. | ||
const int kImportQueueOffset = 1; | ||
|
||
private static readonly PolyImportOptions kOptions = new PolyImportOptions { | ||
rescalingMode = PolyImportOptions.RescalingMode.CONVERT, | ||
scaleFactor = 1, | ||
recenter = false, | ||
}; | ||
|
||
public override void OnImportAsset(AssetImportContext ctx) { | ||
StringReader gltfStream = new StringReader(GlbParser.GetJsonChunkAsString(ctx.assetPath)); | ||
IUriLoader loader = new BufferedStreamLoader( | ||
ctx.assetPath, Path.GetDirectoryName(ctx.assetPath)); | ||
|
||
ImportGltf.GltfImportResult result = ImportGltf.Import( | ||
GltfSchemaVersion.GLTF2, gltfStream, loader, kOptions); | ||
|
||
// The "identifier" param passed here is supposed to be: | ||
// - Unique to this asset | ||
// - Deterministic (if possible) | ||
foreach (var obj in result.textures) { | ||
if (! AssetDatabase.Contains(obj)) { | ||
ctx.AddObjectToAsset("Texture/" + obj.name, obj); | ||
} | ||
} | ||
foreach (var obj in result.materials) { | ||
ctx.AddObjectToAsset("Material/" + obj.name, obj); | ||
} | ||
foreach (var obj in result.meshes) { | ||
ctx.AddObjectToAsset("Mesh/" + obj.name, obj); | ||
} | ||
string objectName = Path.GetFileNameWithoutExtension(ctx.assetPath); | ||
result.root.name = objectName; | ||
ctx.AddObjectToAsset("ROOT", result.root); | ||
ctx.SetMainObject(result.root); | ||
} | ||
} | ||
|
||
} // namespace TiltBrushToolkit | ||
|
||
#endif |
11 changes: 11 additions & 0 deletions
11
UnitySDK/Assets/TiltBrush/Scripts/Editor/Glb2Importer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.