com.github.asus4.texture-source 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -57,7 +57,7 @@ Add the following setting to `Packages/manifest.json`
57
57
  }
58
58
  ],
59
59
  "dependencies": {
60
- "com.github.asus4.texture-source": "0.2.2",
60
+ "com.github.asus4.texture-source": "0.3.0",
61
61
  ...// other dependencies
62
62
  }
63
63
  }
@@ -87,6 +87,14 @@ Useful when using test videos only in the Editor.
87
87
 
88
88
  ![video-texture-source](https://github.com/asus4/TextureSource/assets/357497/8e38ed1a-d2d8-4e16-9fc4-e5d4c6d0a888)
89
89
 
90
+ ### Image Texture Source
91
+
92
+ Test with static images.
93
+
94
+ `OnTexture` event is invoked every frame if the `sendContinuousUpdate` is enabled.
95
+
96
+ ![image-texture-source](https://github.com/asus4/TextureSource/assets/357497/3d7eef4b-40c5-40b4-8403-b70f394ce938)
97
+
90
98
  ### AR Foundation Texture Source
91
99
 
92
100
  Provides AR camera texture access. It supports both ARCore/ARKit.
@@ -6,6 +6,9 @@ namespace TextureSource
6
6
  using UnityEngine;
7
7
  using UnityEngine.XR.ARFoundation;
8
8
 
9
+ /// <summary>
10
+ /// Source from ARFoundation
11
+ /// </summary>
9
12
  [CreateAssetMenu(menuName = "ScriptableObject/Texture Source/ARFoundation", fileName = "ARFoundationTextureSource")]
10
13
  public sealed class ARFoundationTextureSource : BaseTextureSource
11
14
  {
@@ -2,6 +2,9 @@ namespace TextureSource
2
2
  {
3
3
  using UnityEngine;
4
4
 
5
+ /// <summary>
6
+ /// Abstract class for the source.
7
+ /// </summary>
5
8
  public abstract class BaseTextureSource : ScriptableObject, ITextureSource
6
9
  {
7
10
  public abstract bool DidUpdateThisFrame { get; }
@@ -2,6 +2,9 @@ namespace TextureSource
2
2
  {
3
3
  using UnityEngine;
4
4
 
5
+ /// <summary>
6
+ /// Interface for the source
7
+ /// </summary>
5
8
  public interface ITextureSource
6
9
  {
7
10
  bool DidUpdateThisFrame { get; }
@@ -0,0 +1,58 @@
1
+ namespace TextureSource
2
+ {
3
+ using UnityEngine;
4
+
5
+ /// <summary>
6
+ /// Source from image texture
7
+ /// </summary>
8
+ [CreateAssetMenu(menuName = "ScriptableObject/Texture Source/Image", fileName = "ImageTextureSource")]
9
+ public class ImageTextureSource : BaseTextureSource
10
+ {
11
+ [SerializeField]
12
+ private Texture[] textures = default;
13
+
14
+ [SerializeField]
15
+ private bool sendContinuousUpdate = false;
16
+
17
+ public override bool DidUpdateThisFrame
18
+ {
19
+ get
20
+ {
21
+ if (sendContinuousUpdate)
22
+ {
23
+ return true;
24
+ }
25
+
26
+ bool updated = isUpdated;
27
+ isUpdated = false;
28
+ return updated;
29
+ }
30
+ }
31
+
32
+ public override Texture Texture => textures[currentIndex];
33
+
34
+ private int currentIndex = 0;
35
+ private bool isUpdated = false;
36
+
37
+ public override void Start()
38
+ {
39
+ if (textures.Length == 0)
40
+ {
41
+ Debug.LogError("No texture is set");
42
+ return;
43
+ }
44
+ isUpdated = true;
45
+ }
46
+
47
+ public override void Stop()
48
+ {
49
+ isUpdated = false;
50
+ }
51
+
52
+ public override void Next()
53
+ {
54
+ currentIndex = (currentIndex + 1) % textures.Length;
55
+ isUpdated = true;
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: b51cafa6a901147349bf2af15e41f6a5
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -3,6 +3,9 @@ namespace TextureSource
3
3
  using System;
4
4
  using UnityEngine;
5
5
 
6
+ /// <summary>
7
+ /// Transforms 2D texture with any arbitrary matrix
8
+ /// </summary>
6
9
  public class TextureTransformer : IDisposable
7
10
  {
8
11
  private static readonly int _InputTex = Shader.PropertyToID("_InputTex");
package/Runtime/Utils.cs CHANGED
@@ -2,6 +2,9 @@ namespace TextureSource
2
2
  {
3
3
  using UnityEngine;
4
4
 
5
+ /// <summary>
6
+ /// Internal utility functions
7
+ /// </summary>
5
8
  internal static class Utils
6
9
  {
7
10
  public static void GetTargetSizeScale(
@@ -4,6 +4,9 @@ namespace TextureSource
4
4
  using UnityEngine;
5
5
  using UnityEngine.Video;
6
6
 
7
+ /// <summary>
8
+ /// Source from video player
9
+ /// </summary>
7
10
  [CreateAssetMenu(menuName = "ScriptableObject/Texture Source/Video", fileName = "VideoTextureSource")]
8
11
  public class VideoTextureSource : BaseTextureSource
9
12
  {
@@ -5,7 +5,7 @@ namespace TextureSource
5
5
  using UnityEngine.Scripting;
6
6
 
7
7
  /// <summary>
8
- /// Virtual Texture Source
8
+ /// Invokes texture update event from the provided texture source ScriptableObject asset.
9
9
  /// </summary>
10
10
  public class VirtualTextureSource : MonoBehaviour
11
11
  {
@@ -4,30 +4,32 @@ namespace TextureSource
4
4
  using System.Linq;
5
5
  using UnityEngine;
6
6
 
7
+ /// <summary>
8
+ /// Source from WebCamTexture
9
+ /// </summary>
7
10
  [CreateAssetMenu(menuName = "ScriptableObject/Texture Source/WebCam", fileName = "WebCamTextureSource")]
8
11
  public sealed class WebCamTextureSource : BaseTextureSource
9
12
  {
10
- [Flags]
11
- public enum WebCamKindFlag
13
+ /// <summary>
14
+ /// Facing direction of the camera
15
+ /// </summary>
16
+ public enum CameraFacing
12
17
  {
13
- WideAngle = 1 << 0,
14
- Telephoto = 1 << 1,
15
- ColorAndDepth = 1 << 2,
16
- UltraWideAngle = 1 << 3,
17
- }
18
-
19
- [Flags]
20
- public enum FacingFlag
21
- {
22
- Front = 1 << 0,
23
- Back = 1 << 1,
18
+ Front,
19
+ Back,
24
20
  }
25
21
 
26
22
  [SerializeField]
27
- private WebCamKindFlag kindFilter = WebCamKindFlag.WideAngle | WebCamKindFlag.Telephoto | WebCamKindFlag.UltraWideAngle;
23
+ [Tooltip("Priorities of Camera Facing Direction")]
24
+ private CameraFacing[] facingPriorities = new CameraFacing[] {
25
+ CameraFacing.Back, CameraFacing.Front
26
+ };
28
27
 
29
28
  [SerializeField]
30
- private FacingFlag facingFilter = FacingFlag.Front | FacingFlag.Back;
29
+ [Tooltip("Priorities of WebCamKind")]
30
+ private WebCamKind[] kindPriority = new WebCamKind[] {
31
+ WebCamKind.WideAngle, WebCamKind.Telephoto, WebCamKind.UltraWideAngle,
32
+ };
31
33
 
32
34
  [SerializeField]
33
35
  private Vector2Int resolution = new Vector2Int(1270, 720);
@@ -57,16 +59,16 @@ namespace TextureSource
57
59
  private int lastUpdatedFrame = -1;
58
60
  private bool isFrontFacing;
59
61
 
60
- public WebCamKindFlag KindFilter
62
+ public CameraFacing[] FacingPriorities
61
63
  {
62
- get => kindFilter;
63
- set => kindFilter = value;
64
+ get => facingPriorities;
65
+ set => facingPriorities = value;
64
66
  }
65
67
 
66
- public FacingFlag FacingFilter
68
+ public WebCamKind[] KindPriorities
67
69
  {
68
- get => facingFilter;
69
- set => facingFilter = value;
70
+ get => kindPriority;
71
+ set => kindPriority = value;
70
72
  }
71
73
 
72
74
  public Vector2Int Resolution
@@ -85,7 +87,24 @@ namespace TextureSource
85
87
 
86
88
  public override void Start()
87
89
  {
88
- devices = WebCamTexture.devices.Where(IsMatchFilter).ToArray();
90
+ static CameraFacing GetFacing(WebCamDevice device)
91
+ {
92
+ return device.isFrontFacing ? CameraFacing.Front : CameraFacing.Back;
93
+ }
94
+
95
+ // Sort with facing, then kind
96
+ devices = WebCamTexture.devices
97
+ .Where(d => facingPriorities.Contains(GetFacing(d)) && kindPriority.Contains(d.kind))
98
+ .OrderBy(d => Array.IndexOf(facingPriorities, GetFacing(d)))
99
+ .ThenBy(d => Array.IndexOf(kindPriority, d.kind))
100
+ .ToArray();
101
+
102
+ if (devices.Length == 0)
103
+ {
104
+ Debug.LogError("No available camera found for the given priorities. Falling back to the default.");
105
+ devices = WebCamTexture.devices;
106
+ }
107
+
89
108
  StartCamera(currentIndex);
90
109
  }
91
110
 
@@ -159,23 +178,5 @@ namespace TextureSource
159
178
  lastUpdatedFrame = Time.frameCount;
160
179
  return transformer.Texture;
161
180
  }
162
-
163
- private bool IsMatchFilter(WebCamDevice device)
164
- {
165
- WebCamKindFlag kind = device.kind switch
166
- {
167
- WebCamKind.WideAngle => WebCamKindFlag.WideAngle,
168
- WebCamKind.Telephoto => WebCamKindFlag.Telephoto,
169
- WebCamKind.ColorAndDepth => WebCamKindFlag.ColorAndDepth,
170
- WebCamKind.UltraWideAngle => WebCamKindFlag.UltraWideAngle,
171
- _ => throw new NotImplementedException($"Unknown WebCamKind: {device.kind}"),
172
- };
173
- FacingFlag facing = device.isFrontFacing
174
- ? FacingFlag.Front
175
- : FacingFlag.Back;
176
-
177
- return kindFilter.HasFlag(kind)
178
- && facingFilter.HasFlag(facing);
179
- }
180
181
  }
181
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.github.asus4.texture-source",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "displayName": "TextureSource",
5
5
  "description": "Simplify WebCamera and test video handling for using Computer Vision in Unity",
6
6
  "unity": "2020.3",
@@ -11,6 +11,7 @@
11
11
  ],
12
12
  "documentationUrl": "https://github.com/asus4/TextureSource/tree/main",
13
13
  "changelogUrl": "https://github.com/asus4/TextureSource/releases",
14
+ "license": "MIT",
14
15
  "licensesUrl": "https://github.com/asus4/TextureSource/blob/main/Packages/com.github.asus4.texture-source/LICENSE",
15
16
  "author": {
16
17
  "name": "Koki Ibukuro",