Example #1
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            IUriLoader loader = new BufferedStreamLoader(
                ctx.assetPath, Path.GetDirectoryName(ctx.assetPath));

            ImportGltf.GltfImportResult result = ImportGltf.Import(
                ctx.assetPath, loader, null, 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);
        }
Example #2
0
/*
 * public override void OnImportAsset(AssetImportContext ctx) {
 *  IUriLoader loader = new BufferedStreamLoader(
 *      ctx.assetPath, Path.GetDirectoryName(ctx.assetPath));
 *
 *  ImportGltf.GltfImportResult result = ImportGltf.Import(
 *      ctx.assetPath, loader, null, 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);
 * }
 */


        public static GameObject ImportTiltBrushAsset(string path)
        {
            IUriLoader loader = new BufferedStreamLoader(
                path, Path.GetDirectoryName(path));//Directory.GetParent(path).ToString());


            ImportGltf.GltfImportResult result = ImportGltf.Import(
                path, loader, null, kOptions);

            return(result.root);
        }