Skip to content

Commit

Permalink
Merge pull request #339 from asus4/migrade-texture-source
Browse files Browse the repository at this point in the history
Migrate to VirtualTextureSource
  • Loading branch information
asus4 authored Mar 12, 2024
2 parents 8974e62 + 414c2ca commit b7692d1
Show file tree
Hide file tree
Showing 24 changed files with 823 additions and 339 deletions.
31 changes: 21 additions & 10 deletions Assets/Samples/BlazePose/BlazePose.unity
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1453601107}
- component: {fileID: 1453601108}
- component: {fileID: 1453601109}
- component: {fileID: 1453601106}
m_Layer: 0
m_Name: BlazePose
Expand Down Expand Up @@ -859,7 +859,7 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1453601108
--- !u!114 &1453601109
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -868,15 +868,13 @@ MonoBehaviour:
m_GameObject: {fileID: 1453601105}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3f81f0d43e2d14fbbb064a205095507c, type: 3}
m_Script: {fileID: 11500000, guid: be5e5635fba104ec29475e42f3b5a517, type: 3}
m_Name:
m_EditorClassIdentifier:
editorCameraName: FaceTime HD Camera
preferKind: 1
isFrontFacing: 0
requestSize: {x: 1280, y: 720}
requestFps: 60
OnTextureUpdate:
source: {fileID: 11400000, guid: 75e4397da16524bcd9f1325b0f5d51d4, type: 2}
sourceForEditor: {fileID: 11400000, guid: 75e4397da16524bcd9f1325b0f5d51d4, type: 2}
trimToScreenAspect: 0
OnTexture:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 32141218}
Expand All @@ -891,6 +889,9 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
OnAspectChange:
m_PersistentCalls:
m_Calls: []
--- !u!1 &2074584276
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1073,7 +1074,17 @@ PrefabInstance:
type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
objectReference: {fileID: 1453601108}
objectReference: {fileID: 1453601109}
- target: {fileID: 173531016972836179, guid: a20533af9a9a94af494156c17e85a9e8,
type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: NextSource
objectReference: {fileID: 0}
- target: {fileID: 173531016972836179, guid: a20533af9a9a94af494156c17e85a9e8,
type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName
value: TextureSource.VirtualTextureSource, TextureSource
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
Expand Down
18 changes: 11 additions & 7 deletions Assets/Samples/BlazePose/BlazePoseSample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading;
using Cysharp.Threading.Tasks;
using TensorFlowLite;
using TextureSource;
using UnityEngine;
using UnityEngine.UI;

Expand All @@ -9,7 +10,7 @@
/// https://github.com/google/mediapipe
/// https://viz.mediapipe.dev/demo/pose_tracking
/// </summary>
[RequireComponent(typeof(WebCamInput))]
[RequireComponent(typeof(VirtualTextureSource))]
public sealed class BlazePoseSample : MonoBehaviour
{
[SerializeField]
Expand All @@ -36,22 +37,25 @@ public sealed class BlazePoseSample : MonoBehaviour
private BlazePoseDrawer drawer;

private UniTask<bool> task;
private CancellationToken cancellationToken;

private void Start()
{
pose = new BlazePose(options);

drawer = new BlazePoseDrawer(Camera.main, gameObject.layer, containerView);

cancellationToken = this.GetCancellationTokenOnDestroy();

GetComponent<WebCamInput>().OnTextureUpdate.AddListener(OnTextureUpdate);
if (TryGetComponent(out VirtualTextureSource source))
{
source.OnTexture.AddListener(OnTextureUpdate);
}
}

private void OnDestroy()
{
GetComponent<WebCamInput>().OnTextureUpdate.RemoveListener(OnTextureUpdate);
if (TryGetComponent(out VirtualTextureSource source))
{
source.OnTexture.RemoveListener(OnTextureUpdate);
}
pose?.Dispose();
drawer?.Dispose();
}
Expand Down Expand Up @@ -102,7 +106,7 @@ private void Invoke(Texture texture)

private async UniTask<bool> InvokeAsync(Texture texture)
{
landmarkResult = await pose.InvokeAsync(texture, cancellationToken);
landmarkResult = await pose.InvokeAsync(texture, destroyCancellationToken);
poseResult = pose.PoseResult;
if (pose.LandmarkInputTexture != null)
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/Samples/Common/WebCamTextureSource.asset
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ MonoBehaviour:
m_Name: WebCamTextureSource
m_EditorClassIdentifier:
kindFilter: 11
facingFilter: 3
facingFilter: -1
resolution: {x: 1270, y: 720}
frameRate: 60
78 changes: 57 additions & 21 deletions Assets/Samples/DeepLab/DeepLab.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.3708625, g: 0.37838694, b: 0.35726872, a: 1}
m_IndirectSpecularColor: {r: 0.3708708, g: 0.37838137, b: 0.35725543, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -105,7 +105,7 @@ NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
serializedVersion: 3
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
Expand All @@ -118,7 +118,7 @@ NavMeshSettings:
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
buildHeightMesh: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
Expand Down Expand Up @@ -164,9 +164,17 @@ Camera:
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_Iso: 200
m_ShutterSpeed: 0.005
m_Aperture: 16
m_FocusDistance: 10
m_FocalLength: 50
m_BladeCount: 5
m_Curvature: {x: 2, y: 11}
m_BarrelClipping: 0.25
m_Anamorphism: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
Expand Down Expand Up @@ -200,18 +208,20 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 32141214}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &405086514
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 1051232098}
m_Modifications:
- target: {fileID: 7719925103924872094, guid: c3ad31ccc59b04ac782aaabae2b9706b,
Expand Down Expand Up @@ -325,6 +335,9 @@ PrefabInstance:
value: BackToIndexButton
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: c3ad31ccc59b04ac782aaabae2b9706b, type: 3}
--- !u!224 &405086515 stripped
RectTransform:
Expand All @@ -337,6 +350,7 @@ PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 1051232098}
m_Modifications:
- target: {fileID: 173531016972836176, guid: a20533af9a9a94af494156c17e85a9e8,
Expand Down Expand Up @@ -453,13 +467,21 @@ PrefabInstance:
type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target
value:
objectReference: {fileID: 1453601108}
objectReference: {fileID: 1453601109}
- target: {fileID: 173531016972836179, guid: a20533af9a9a94af494156c17e85a9e8,
type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: ToggleCamera
value: NextSource
objectReference: {fileID: 0}
- target: {fileID: 173531016972836179, guid: a20533af9a9a94af494156c17e85a9e8,
type: 3}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName
value: TextureSource.VirtualTextureSource, TextureSource
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a20533af9a9a94af494156c17e85a9e8, type: 3}
--- !u!224 &536083833 stripped
RectTransform:
Expand Down Expand Up @@ -497,6 +519,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SendPointerHoverToParent: 1
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
Expand Down Expand Up @@ -526,12 +549,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 780088502}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1051232094
GameObject:
Expand Down Expand Up @@ -609,7 +633,9 @@ Canvas:
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_VertexColorAlwaysGammaSpace: 0
m_AdditionalShaderChannelsFlag: 0
m_UpdateRectTransformForStandalone: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
Expand All @@ -623,12 +649,12 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 2074584277}
- {fileID: 536083833}
- {fileID: 405086515}
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand All @@ -644,7 +670,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1453601107}
- component: {fileID: 1453601108}
- component: {fileID: 1453601109}
- component: {fileID: 1453601106}
m_Layer: 0
m_Name: DeepLab Sample
Expand Down Expand Up @@ -678,14 +704,15 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1453601105}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1453601108
--- !u!114 &1453601109
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -694,15 +721,13 @@ MonoBehaviour:
m_GameObject: {fileID: 1453601105}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3f81f0d43e2d14fbbb064a205095507c, type: 3}
m_Script: {fileID: 11500000, guid: be5e5635fba104ec29475e42f3b5a517, type: 3}
m_Name:
m_EditorClassIdentifier:
editorCameraName: FaceTime HD Camera
preferKind: 1
isFrontFacing: 0
requestSize: {x: 1280, y: 720}
requestFps: 60
OnTextureUpdate:
source: {fileID: 11400000, guid: 75e4397da16524bcd9f1325b0f5d51d4, type: 2}
sourceForEditor: {fileID: 11400000, guid: 75e4397da16524bcd9f1325b0f5d51d4, type: 2}
trimToScreenAspect: 0
OnTexture:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 2074584278}
Expand All @@ -717,6 +742,9 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
OnAspectChange:
m_PersistentCalls:
m_Calls: []
--- !u!1 &1931683983
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -745,9 +773,9 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 2074584277}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
Expand Down Expand Up @@ -818,10 +846,10 @@ RectTransform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1931683984}
m_Father: {fileID: 1051232098}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
Expand Down Expand Up @@ -877,3 +905,11 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_AspectMode: 3
m_AspectRatio: 1
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
m_Roots:
- {fileID: 32141217}
- {fileID: 1051232098}
- {fileID: 780088505}
- {fileID: 1453601107}
Loading

0 comments on commit b7692d1

Please sign in to comment.