Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the functionality to import Gltf and Glb files #302

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/Prefabs/UI/Layers/AddLayerPanel.prefab

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

2 changes: 1 addition & 1 deletion Assets/Scenes/Main.unity

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

34 changes: 34 additions & 0 deletions Assets/Scriptables/DataTypeImportAdapters/FileTypeAdapter.asset

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

1 change: 1 addition & 0 deletions Assets/Scriptables/PrefabLibrary.asset

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

3 changes: 3 additions & 0 deletions Assets/_Functionalities/GltfImporter.meta

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

30 changes: 30 additions & 0 deletions Assets/_Functionalities/GltfImporter/GltfImporter.asset

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

8 changes: 8 additions & 0 deletions Assets/_Functionalities/GltfImporter/GltfImporter.asset.meta

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

8 changes: 8 additions & 0 deletions Assets/_Functionalities/GltfImporter/Prefabs.meta

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

131 changes: 131 additions & 0 deletions Assets/_Functionalities/GltfImporter/Prefabs/GltfLayer.prefab

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

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

8 changes: 8 additions & 0 deletions Assets/_Functionalities/GltfImporter/ScriptableObjects.meta

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

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

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

3 changes: 3 additions & 0 deletions Assets/_Functionalities/GltfImporter/Scripts.meta

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

30 changes: 30 additions & 0 deletions Assets/_Functionalities/GltfImporter/Scripts/GltfImportAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.IO;
using Netherlands3D.Twin.Layers.Properties;
using Netherlands3D.Twin.Projects;
using UnityEngine;

namespace Netherlands3D.Twin.Functionalities.GltfImporter
{
[CreateAssetMenu(menuName = "Netherlands3D/Adapters/GltfImportAdapter", fileName = "GltfImportAdapter", order = 0)]
public class GltfImportAdapter : ScriptableObject, IDataTypeAdapter
{
[SerializeField] private GltfSpawner layerPrefab;

public bool Supports(LocalFile localFile)
{
return localFile.LocalFilePath.EndsWith(".glb")
|| localFile.LocalFilePath.EndsWith(".gltf");
}

public void Execute(LocalFile localFile)
{
var fullPath = localFile.LocalFilePath;
var fileName = Path.GetFileName(fullPath);
GltfSpawner newLayer = Instantiate(layerPrefab);
newLayer.gameObject.name = fileName;

var propertyData = newLayer.PropertyData as GltfPropertyData;
propertyData.Uri = AssetUriFactory.CreateProjectAssetUri(fullPath);
}
}
}

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

38 changes: 38 additions & 0 deletions Assets/_Functionalities/GltfImporter/Scripts/GltfPropertyData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Netherlands3D.Twin.Layers;
using Netherlands3D.Twin.Layers.Properties;
using Newtonsoft.Json;
using UnityEngine.Events;

namespace Netherlands3D.Twin.Functionalities.GltfImporter
{
[DataContract(Namespace = "https://netherlands3d.eu/schemas/projects/layers/properties", Name = "Gltf")]
public class GltfPropertyData : LayerPropertyData, ILayerPropertyDataWithAssets
{
[DataMember] private Uri uri;

[JsonIgnore] public readonly UnityEvent<Uri> OnUriChanged = new();

[JsonIgnore]
public Uri Uri
{
get => uri;
set
{
uri = value;
OnUriChanged.Invoke(value);
}
}

public IEnumerable<LayerAsset> GetAssets()
{
return new List<LayerAsset>
{
new (this, uri)
};
}
}
}

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

Loading
Loading