private void CollectSubAssets(Subassets subassets, OpenVDBStream stream, OpenVDBStreamDescriptor descriptor)
        {
            var     go      = stream.gameObject;
            Texture texture = null;

            if (descriptor.settings.extractTextures)
            {
                texture = descriptor.settings.textures.First();
                AddRemap(new SourceAssetIdentifier(typeof(Texture), texture.name), texture);
            }
            else
            {
                if (stream.texture3D != null)
                {
                    texture = stream.texture3D;
                    subassets.Add(stream.texture3D.name, stream.texture3D);
                }
            }

            var meshFilter = go.GetOrAddComponent <MeshFilter>();

            if (meshFilter != null)
            {
                meshFilter.sharedMesh      = stream.mesh;
                meshFilter.sharedMesh.name = go.name;
                subassets.Add(meshFilter.sharedMesh.name, meshFilter.sharedMesh);
            }
            var renderer = go.GetOrAddComponent <MeshRenderer>();

            if (renderer == null)
            {
                return;
            }
            if (!descriptor.settings.importMaterials)
            {
                return;
            }
            if (descriptor.settings.extractMaterials)
            {
                var material = descriptor.settings.materials.First();
                AddRemap(new SourceAssetIdentifier(typeof(Material), material.name), material);
                renderer.sharedMaterial = material;
            }
            else
            {
                renderer.sharedMaterial = subassets.defaultMaterial;
            }

            if (texture == null)
            {
                return;
            }
            renderer.sharedMaterial.SetTexture("_Volume", texture);
            renderer.sharedMaterial.name = texture.name;
        }
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var shortAssetPath = MakeShortAssetPath(ctx.assetPath);
            var sourcePath     = SourcePath(shortAssetPath);
            var destPath       = Path.Combine(Application.streamingAssetsPath, shortAssetPath);
            var directoryPath  = Path.GetDirectoryName(destPath);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }
            if (File.Exists(destPath))
            {
                File.SetAttributes(destPath, FileAttributes.Normal);
            }
            File.Copy(sourcePath, destPath, true);

            var fileName = Path.GetFileNameWithoutExtension(destPath);
            var go       = new GameObject(fileName);

            var streamDescriptor = ScriptableObject.CreateInstance <OpenVDBStreamDescriptor>();

            streamDescriptor.name      = go.name + "_VDBDesc";
            streamDescriptor.pathToVDB = shortAssetPath;
            streamDescriptor.settings  = streamSettings;

            using (var vdbStream = new OpenVDBStream(go, streamDescriptor))
            {
                if (!vdbStream.Load())
                {
                    return;
                }

                var subassets = new Subassets(ctx);
                subassets.Add(streamDescriptor.name, streamDescriptor);
                GenerateSubAssets(subassets, vdbStream, streamDescriptor);

#if UNITY_2017_3_OR_NEWER
                ctx.AddObjectToAsset(go.name, go);
                ctx.SetMainObject(go);
#else
                ctx.SetMainAsset(go.name, go);
#endif
            }
        }
 private void GenerateSubAssets(Subassets subassets, OpenVDBStream stream, OpenVDBStreamDescriptor descriptor)
 {
     CollectSubAssets(subassets, stream, descriptor);
 }