| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # This file uses centimeters as units for non-parametric coordinates. | ||
|
|
||
| g default | ||
| v -0.100000 -0.000000 0.100000 | ||
| v 0.100000 -0.000000 0.100000 | ||
| v -0.100000 0.000000 -0.100000 | ||
| v 0.100000 0.000000 -0.100000 | ||
| vt 0.000000 0.000000 | ||
| vt 1.000000 0.000000 | ||
| vt 0.000000 1.000000 | ||
| vt 1.000000 1.000000 | ||
| vn 0.000000 1.000000 0.000000 | ||
| vn 0.000000 1.000000 0.000000 | ||
| vn 0.000000 1.000000 0.000000 | ||
| vn 0.000000 1.000000 0.000000 | ||
| s off | ||
| g AndyBlobShadow_GEO | ||
| f 4/4/1 3/3/2 1/1/3 2/2/4 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!21 &2100000 | ||
| Material: | ||
| serializedVersion: 6 | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 0} | ||
| m_Name: AndyMaterial | ||
| m_Shader: {fileID: 4800000, guid: c4790e12ed76c486d9fd9d9ccefecb25, type: 3} | ||
| m_ShaderKeywords: | ||
| m_LightmapFlags: 4 | ||
| m_EnableInstancingVariants: 0 | ||
| m_DoubleSidedGI: 0 | ||
| m_CustomRenderQueue: -1 | ||
| stringTagMap: {} | ||
| disabledShaderPasses: [] | ||
| m_SavedProperties: | ||
| serializedVersion: 3 | ||
| m_TexEnvs: | ||
| - _BumpMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailAlbedoMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailMask: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailNormalMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _EmissionMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _MainTex: | ||
| m_Texture: {fileID: 2800000, guid: cc3e4b93718924afa9aae49c0c7fb48f, type: 3} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _MetallicGlossMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _OcclusionMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _ParallaxMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| m_Floats: | ||
| - _BumpScale: 1 | ||
| - _Cutoff: 0.5 | ||
| - _DetailNormalMapScale: 1 | ||
| - _DstBlend: 0 | ||
| - _GlobalLightEstimation: -1.56 | ||
| - _GlossMapScale: 1 | ||
| - _Glossiness: 1 | ||
| - _GlossyReflections: 1 | ||
| - _Metallic: 1 | ||
| - _Mode: 0 | ||
| - _OcclusionStrength: 1 | ||
| - _Parallax: 0.02 | ||
| - _SmoothnessTextureChannel: 0 | ||
| - _SpecularHighlights: 1 | ||
| - _SrcBlend: 1 | ||
| - _UVSec: 0 | ||
| - _ZWrite: 1 | ||
| m_Colors: | ||
| - _Color: {r: 1, g: 1, b: 1, a: 1} | ||
| - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!21 &2100000 | ||
| Material: | ||
| serializedVersion: 6 | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 0} | ||
| m_Name: AndyShadowMaterial | ||
| m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} | ||
| m_ShaderKeywords: _ALPHABLEND_ON _GLOSSYREFLECTIONS_OFF _SPECULARHIGHLIGHTS_OFF | ||
| m_LightmapFlags: 4 | ||
| m_EnableInstancingVariants: 0 | ||
| m_DoubleSidedGI: 0 | ||
| m_CustomRenderQueue: 3000 | ||
| stringTagMap: | ||
| RenderType: Transparent | ||
| disabledShaderPasses: [] | ||
| m_SavedProperties: | ||
| serializedVersion: 3 | ||
| m_TexEnvs: | ||
| - _BumpMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailAlbedoMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailMask: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailNormalMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _EmissionMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _MainTex: | ||
| m_Texture: {fileID: 2800000, guid: 19b4db079e5fe418bb3ace35ae195521, type: 3} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _MetallicGlossMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _OcclusionMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _ParallaxMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| m_Floats: | ||
| - _BumpScale: 1 | ||
| - _Cutoff: 0.5 | ||
| - _DetailNormalMapScale: 1 | ||
| - _DstBlend: 10 | ||
| - _GlossMapScale: 0 | ||
| - _Glossiness: 0 | ||
| - _GlossyReflections: 0 | ||
| - _Metallic: 0 | ||
| - _Mode: 2 | ||
| - _OcclusionStrength: 1 | ||
| - _Parallax: 0.02 | ||
| - _SmoothnessTextureChannel: 0 | ||
| - _SpecularHighlights: 0 | ||
| - _SrcBlend: 5 | ||
| - _UVSec: 0 | ||
| - _ZWrite: 0 | ||
| m_Colors: | ||
| - _Color: {r: 1, g: 1, b: 1, a: 1} | ||
| - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!21 &2100000 | ||
| Material: | ||
| serializedVersion: 6 | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 0} | ||
| m_Name: PlaneGrid | ||
| m_Shader: {fileID: 4800000, guid: f3570630f31ec4223a549b595d8cbb53, type: 3} | ||
| m_ShaderKeywords: _ALPHAPREMULTIPLY_ON | ||
| m_LightmapFlags: 4 | ||
| m_EnableInstancingVariants: 0 | ||
| m_DoubleSidedGI: 0 | ||
| m_CustomRenderQueue: -1 | ||
| stringTagMap: {} | ||
| disabledShaderPasses: [] | ||
| m_SavedProperties: | ||
| serializedVersion: 3 | ||
| m_TexEnvs: | ||
| - _BumpMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailAlbedoMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailMask: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailNormalMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _EmissionMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 10, y: 10} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _MainTex: | ||
| m_Texture: {fileID: 2800000, guid: 881f092f5ba194ed69b1de192fc521ce, type: 3} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _MetallicGlossMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _OcclusionMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _ParallaxMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _SpecGlossMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| m_Floats: | ||
| - _BumpScale: 1 | ||
| - _Cutoff: 0.5 | ||
| - _DetailNormalMapScale: 1 | ||
| - _DstBlend: 10 | ||
| - _GlossMapScale: 1 | ||
| - _Glossiness: 0 | ||
| - _GlossyReflections: 1 | ||
| - _InvFade: 1 | ||
| - _Metallic: 0.323 | ||
| - _Mode: 3 | ||
| - _OcclusionStrength: 1 | ||
| - _Parallax: 0.02 | ||
| - _SmoothnessTextureChannel: 0 | ||
| - _SpecularHighlights: 1 | ||
| - _SrcBlend: 1 | ||
| - _UVSec: 0 | ||
| - _UvRotation: 3.39 | ||
| - _ZWrite: 0 | ||
| m_Colors: | ||
| - _Color: {r: 0, g: 0.3254902, b: 0.34509805, a: 0.716} | ||
| - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} | ||
| - _GridColor: {r: 0.21960786, g: 0.21960786, b: 0.21960786, a: 1} | ||
| - _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1} | ||
| - _TintColor: {r: 0.9264706, g: 0, b: 0, a: 0.5} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!21 &2100000 | ||
| Material: | ||
| serializedVersion: 6 | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 0} | ||
| m_Name: PointCloud | ||
| m_Shader: {fileID: 4800000, guid: 9d889a88b50cc4d65b025d5068d78df6, type: 3} | ||
| m_ShaderKeywords: | ||
| m_LightmapFlags: 4 | ||
| m_EnableInstancingVariants: 0 | ||
| m_DoubleSidedGI: 0 | ||
| m_CustomRenderQueue: -1 | ||
| stringTagMap: {} | ||
| disabledShaderPasses: [] | ||
| m_SavedProperties: | ||
| serializedVersion: 3 | ||
| m_TexEnvs: | ||
| - _BumpMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailAlbedoMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailMask: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailNormalMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _EmissionMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _MainTex: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _MetallicGlossMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _OcclusionMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _ParallaxMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| m_Floats: | ||
| - _BumpScale: 1 | ||
| - _Cutoff: 0.5 | ||
| - _DetailNormalMapScale: 1 | ||
| - _DstBlend: 0 | ||
| - _GlossMapScale: 1 | ||
| - _Glossiness: 0.5 | ||
| - _GlossyReflections: 1 | ||
| - _Metallic: 0 | ||
| - _Mode: 0 | ||
| - _OcclusionStrength: 1 | ||
| - _Parallax: 0.02 | ||
| - _SmoothnessTextureChannel: 0 | ||
| - _SpecularHighlights: 1 | ||
| - _SrcBlend: 1 | ||
| - _UVSec: 0 | ||
| - _ZWrite: 1 | ||
| - point_size: 5 | ||
| m_Colors: | ||
| - _Color: {r: 0.12156863, g: 0.7372549, b: 0.8235294, a: 1} | ||
| - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| Shader "ARCore/DiffuseWithLightEstimateion" | ||
| { | ||
| Properties | ||
| { | ||
| _MainTex ("Base (RGB)", 2D) = "white" {} | ||
| } | ||
|
|
||
| SubShader | ||
| { | ||
| Tags { "RenderType"="Opaque" } | ||
| LOD 150 | ||
|
|
||
| CGPROGRAM | ||
| #pragma surface surf Lambert noforwardadd finalcolor:lightEstimation | ||
|
|
||
| sampler2D _MainTex; | ||
| fixed _GlobalLightEstimation; | ||
|
|
||
| struct Input | ||
| { | ||
| float2 uv_MainTex; | ||
| }; | ||
|
|
||
| void lightEstimation(Input IN, SurfaceOutput o, inout fixed4 color) | ||
| { | ||
| color *= _GlobalLightEstimation; | ||
| } | ||
|
|
||
| void surf (Input IN, inout SurfaceOutput o) | ||
| { | ||
| fixed4 c = tex2D(_MainTex, IN.uv_MainTex); | ||
| o.Albedo = c.rgb; | ||
| o.Alpha = c.a; | ||
| } | ||
| ENDCG | ||
| } | ||
|
|
||
| Fallback "Mobile/VertexLit" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| Shader "ARCore/SpecularWithLightEstimation" | ||
| { | ||
| Properties | ||
| { | ||
| _Shininess ("Shininess", Range (0.03, 1)) = 0.078125 | ||
| _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {} | ||
| [NoScaleOffset] _BumpMap ("Normalmap", 2D) = "bump" {} | ||
| } | ||
| SubShader | ||
| { | ||
| Tags { "RenderType"="Opaque" } | ||
| LOD 250 | ||
|
|
||
| CGPROGRAM | ||
| #pragma surface surf MobileBlinnPhong exclude_path:prepass nolightmap noforwardadd halfasview interpolateview finalcolor:lightEstimation | ||
|
|
||
| inline fixed4 LightingMobileBlinnPhong (SurfaceOutput s, fixed3 lightDir, fixed3 halfDir, fixed atten) | ||
| { | ||
| fixed diff = max (0, dot (s.Normal, lightDir)); | ||
| fixed nh = max (0, dot (s.Normal, halfDir)); | ||
| fixed spec = pow (nh, s.Specular*128) * s.Gloss; | ||
|
|
||
| fixed4 c; | ||
| c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * atten; | ||
| UNITY_OPAQUE_ALPHA(c.a); | ||
| return c; | ||
| } | ||
|
|
||
| sampler2D _MainTex; | ||
| sampler2D _BumpMap; | ||
| half _Shininess; | ||
| fixed _GlobalLightEstimation; | ||
|
|
||
| struct Input | ||
| { | ||
| float2 uv_MainTex; | ||
| }; | ||
|
|
||
| void lightEstimation(Input IN, SurfaceOutput o, inout fixed4 color) | ||
| { | ||
| color *= _GlobalLightEstimation; | ||
| } | ||
|
|
||
| void surf (Input IN, inout SurfaceOutput o) | ||
| { | ||
| fixed4 tex = tex2D(_MainTex, IN.uv_MainTex); | ||
| o.Albedo = tex.rgb; | ||
| o.Gloss = tex.a; | ||
| o.Alpha = tex.a; | ||
| o.Specular = _Shininess; | ||
| o.Normal = UnpackNormal (tex2D(_BumpMap, IN.uv_MainTex)); | ||
| } | ||
| ENDCG | ||
| } | ||
|
|
||
| FallBack "Mobile/VertexLit" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| Shader "ARCore/PlaneGrid" | ||
| { | ||
| Properties | ||
| { | ||
| _MainTex ("Texture", 2D) = "white" {} | ||
| _GridColor ("Grid Color", Color) = (1.0, 1.0, 0.0, 1.0) | ||
| _UvRotation ("UV Rotation", float) = 30 | ||
| } | ||
|
|
||
| SubShader | ||
| { | ||
| Tags { "Queue"="Transparent" "RenderType"="Transparent" } | ||
| Blend SrcAlpha OneMinusSrcAlpha | ||
| ZTest on | ||
| ZWrite off | ||
|
|
||
| Pass | ||
| { | ||
| CGPROGRAM | ||
| #pragma vertex vert | ||
| #pragma fragment frag | ||
|
|
||
| #include "UnityCG.cginc" | ||
|
|
||
| struct appdata | ||
| { | ||
| float4 vertex : POSITION; | ||
| float2 uv : TEXCOORD0; | ||
| fixed4 color : COLOR; | ||
| }; | ||
|
|
||
| struct v2f | ||
| { | ||
| float4 vertex : SV_POSITION; | ||
| float2 uv : TEXCOORD0; | ||
| fixed4 color : COLOR; | ||
| }; | ||
|
|
||
| sampler2D _MainTex; | ||
| float4 _MainTex_ST; | ||
| float4 _GridColor; | ||
| fixed _UvRotation; | ||
|
|
||
| v2f vert (appdata v) | ||
| { | ||
| v2f o; | ||
| o.vertex = UnityObjectToClipPos(v.vertex); | ||
|
|
||
| fixed cosr = cos(_UvRotation); | ||
| fixed sinr = sin(_UvRotation); | ||
| fixed2x2 uvrotation = fixed2x2(cosr, -sinr, sinr, cosr); | ||
|
|
||
| float2 uv = mul(UNITY_MATRIX_M, v.vertex).xz * _MainTex_ST.xy; | ||
| o.uv = mul(uvrotation, uv); | ||
| o.color = v.color; | ||
| return o; | ||
| } | ||
|
|
||
| fixed4 frag (v2f i) : SV_Target | ||
| { | ||
| fixed4 col = tex2D(_MainTex, i.uv); | ||
| return fixed4(_GridColor.rgb, col.r * i.color.a); | ||
| } | ||
| ENDCG | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Don't remove the following line. It is used to bypass Unity | ||
| // upgrader change. This is necessary to make sure the shader | ||
| // continues to compile on Unity 5.2 | ||
| // UNITY_SHADER_NO_UPGRADE | ||
| Shader "ARCore/PointCloud" { | ||
| Properties{ | ||
| _PointSize("Point Size", Float) = 5.0 | ||
| _Color ("PointCloud Color", Color) = (0.121, 0.737, 0.823, 1.0) | ||
| } | ||
| SubShader { | ||
| Pass { | ||
| CGPROGRAM | ||
| #pragma vertex vert | ||
| #pragma fragment frag | ||
|
|
||
| #include "UnityCG.cginc" | ||
|
|
||
| struct appdata | ||
| { | ||
| float4 vertex : POSITION; | ||
| }; | ||
|
|
||
| struct v2f | ||
| { | ||
| float4 vertex : SV_POSITION; | ||
| float size : PSIZE; | ||
| }; | ||
|
|
||
| float _PointSize; | ||
| fixed4 _Color; | ||
|
|
||
| v2f vert (appdata v) | ||
| { | ||
| v2f o; | ||
| o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); | ||
| o.size = _PointSize; | ||
|
|
||
| return o; | ||
| } | ||
|
|
||
| fixed4 frag (v2f i) : SV_Target | ||
| { | ||
| return _Color; | ||
| } | ||
| ENDCG | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,255 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!1001 &100100000 | ||
| Prefab: | ||
| m_ObjectHideFlags: 1 | ||
| serializedVersion: 2 | ||
| m_Modification: | ||
| m_TransformParent: {fileID: 0} | ||
| m_Modifications: [] | ||
| m_RemovedComponents: [] | ||
| m_ParentPrefab: {fileID: 0} | ||
| m_RootGameObject: {fileID: 1190091649889860} | ||
| m_IsPrefabParent: 1 | ||
| --- !u!1 &1190091649889860 | ||
| GameObject: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| serializedVersion: 5 | ||
| m_Component: | ||
| - component: {fileID: 4280309514915974} | ||
| - component: {fileID: 114460997975901862} | ||
| m_Layer: 0 | ||
| m_Name: Andy | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!1 &1224761706696916 | ||
| GameObject: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| serializedVersion: 5 | ||
| m_Component: | ||
| - component: {fileID: 4553087980304550} | ||
| - component: {fileID: 33515778104872740} | ||
| - component: {fileID: 23357309348918826} | ||
| m_Layer: 0 | ||
| m_Name: AndyBlobShadow_GEO | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!1 &1249353966497310 | ||
| GameObject: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| serializedVersion: 5 | ||
| m_Component: | ||
| - component: {fileID: 4053639959727920} | ||
| m_Layer: 0 | ||
| m_Name: Andy | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!1 &1313174400183544 | ||
| GameObject: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| serializedVersion: 5 | ||
| m_Component: | ||
| - component: {fileID: 4579515492020152} | ||
| - component: {fileID: 33800310737437648} | ||
| - component: {fileID: 23808477452200100} | ||
| m_Layer: 0 | ||
| m_Name: Andy_GEO | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!1 &1693177947256918 | ||
| GameObject: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| serializedVersion: 5 | ||
| m_Component: | ||
| - component: {fileID: 4468902080585984} | ||
| m_Layer: 0 | ||
| m_Name: AndyBlobShadow | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!4 &4053639959727920 | ||
| Transform: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1249353966497310} | ||
| 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_Children: | ||
| - {fileID: 4579515492020152} | ||
| m_Father: {fileID: 4280309514915974} | ||
| m_RootOrder: 1 | ||
| m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
| --- !u!4 &4280309514915974 | ||
| Transform: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1190091649889860} | ||
| 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_Children: | ||
| - {fileID: 4468902080585984} | ||
| - {fileID: 4053639959727920} | ||
| m_Father: {fileID: 0} | ||
| m_RootOrder: 0 | ||
| m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
| --- !u!4 &4468902080585984 | ||
| Transform: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1693177947256918} | ||
| 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_Children: | ||
| - {fileID: 4553087980304550} | ||
| m_Father: {fileID: 4280309514915974} | ||
| m_RootOrder: 0 | ||
| m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
| --- !u!4 &4553087980304550 | ||
| Transform: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1224761706696916} | ||
| 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_Children: [] | ||
| m_Father: {fileID: 4468902080585984} | ||
| m_RootOrder: 0 | ||
| m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
| --- !u!4 &4579515492020152 | ||
| Transform: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1313174400183544} | ||
| 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_Children: [] | ||
| m_Father: {fileID: 4053639959727920} | ||
| m_RootOrder: 0 | ||
| m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
| --- !u!23 &23357309348918826 | ||
| MeshRenderer: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1224761706696916} | ||
| m_Enabled: 1 | ||
| m_CastShadows: 1 | ||
| m_ReceiveShadows: 1 | ||
| m_DynamicOccludee: 1 | ||
| m_MotionVectors: 1 | ||
| m_LightProbeUsage: 1 | ||
| m_ReflectionProbeUsage: 1 | ||
| m_Materials: | ||
| - {fileID: 2100000, guid: 0130982ecc98e47e4a78ec2f85196be5, type: 2} | ||
| m_StaticBatchInfo: | ||
| firstSubMesh: 0 | ||
| subMeshCount: 0 | ||
| m_StaticBatchRoot: {fileID: 0} | ||
| m_ProbeAnchor: {fileID: 0} | ||
| m_LightProbeVolumeOverride: {fileID: 0} | ||
| m_ScaleInLightmap: 1 | ||
| m_PreserveUVs: 0 | ||
| m_IgnoreNormalsForChartDetection: 0 | ||
| m_ImportantGI: 0 | ||
| m_StitchLightmapSeams: 0 | ||
| m_SelectedEditorRenderState: 3 | ||
| m_MinimumChartSize: 4 | ||
| m_AutoUVMaxDistance: 0.5 | ||
| m_AutoUVMaxAngle: 89 | ||
| m_LightmapParameters: {fileID: 0} | ||
| m_SortingLayerID: 0 | ||
| m_SortingLayer: 0 | ||
| m_SortingOrder: 0 | ||
| --- !u!23 &23808477452200100 | ||
| MeshRenderer: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1313174400183544} | ||
| m_Enabled: 1 | ||
| m_CastShadows: 1 | ||
| m_ReceiveShadows: 1 | ||
| m_DynamicOccludee: 1 | ||
| m_MotionVectors: 1 | ||
| m_LightProbeUsage: 1 | ||
| m_ReflectionProbeUsage: 1 | ||
| m_Materials: | ||
| - {fileID: 2100000, guid: 572e1e52514434db5a8ce3957db3b3fd, type: 2} | ||
| m_StaticBatchInfo: | ||
| firstSubMesh: 0 | ||
| subMeshCount: 0 | ||
| m_StaticBatchRoot: {fileID: 0} | ||
| m_ProbeAnchor: {fileID: 0} | ||
| m_LightProbeVolumeOverride: {fileID: 0} | ||
| m_ScaleInLightmap: 1 | ||
| m_PreserveUVs: 0 | ||
| m_IgnoreNormalsForChartDetection: 0 | ||
| m_ImportantGI: 0 | ||
| m_StitchLightmapSeams: 0 | ||
| m_SelectedEditorRenderState: 3 | ||
| m_MinimumChartSize: 4 | ||
| m_AutoUVMaxDistance: 0.5 | ||
| m_AutoUVMaxAngle: 89 | ||
| m_LightmapParameters: {fileID: 0} | ||
| m_SortingLayerID: 0 | ||
| m_SortingLayer: 0 | ||
| m_SortingOrder: 0 | ||
| --- !u!33 &33515778104872740 | ||
| MeshFilter: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1224761706696916} | ||
| m_Mesh: {fileID: 4300000, guid: 1d7855df49bfa483e8f1d8478d4b233a, type: 3} | ||
| --- !u!33 &33800310737437648 | ||
| MeshFilter: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1313174400183544} | ||
| m_Mesh: {fileID: 4300000, guid: 0e8c4400e5a274e79b60fa5a300aab17, type: 3} | ||
| --- !u!114 &114460997975901862 | ||
| MonoBehaviour: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1190091649889860} | ||
| m_Enabled: 1 | ||
| m_EditorHideFlags: 0 | ||
| m_Script: {fileID: 11500000, guid: 4f72ee472a4654c10a96aeb3fcf25bcf, type: 3} | ||
| m_Name: | ||
| m_EditorClassIdentifier: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!1001 &100100000 | ||
| Prefab: | ||
| m_ObjectHideFlags: 1 | ||
| serializedVersion: 2 | ||
| m_Modification: | ||
| m_TransformParent: {fileID: 0} | ||
| m_Modifications: [] | ||
| m_RemovedComponents: [] | ||
| m_ParentPrefab: {fileID: 0} | ||
| m_RootGameObject: {fileID: 1654175882956584} | ||
| m_IsPrefabParent: 1 | ||
| --- !u!1 &1654175882956584 | ||
| GameObject: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| serializedVersion: 5 | ||
| m_Component: | ||
| - component: {fileID: 4055847820020234} | ||
| - component: {fileID: 33340294062673050} | ||
| - component: {fileID: 23646549736039258} | ||
| - component: {fileID: 114776205485222536} | ||
| m_Layer: 0 | ||
| m_Name: TrackedPlaneVisualizer | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!4 &4055847820020234 | ||
| Transform: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1654175882956584} | ||
| 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_Children: [] | ||
| m_Father: {fileID: 0} | ||
| m_RootOrder: 0 | ||
| m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
| --- !u!23 &23646549736039258 | ||
| MeshRenderer: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1654175882956584} | ||
| m_Enabled: 1 | ||
| m_CastShadows: 1 | ||
| m_ReceiveShadows: 1 | ||
| m_DynamicOccludee: 1 | ||
| m_MotionVectors: 1 | ||
| m_LightProbeUsage: 1 | ||
| m_ReflectionProbeUsage: 1 | ||
| m_Materials: | ||
| - {fileID: 2100000, guid: 92b1ca249edc047509db2c7bc05789ef, type: 2} | ||
| m_StaticBatchInfo: | ||
| firstSubMesh: 0 | ||
| subMeshCount: 0 | ||
| m_StaticBatchRoot: {fileID: 0} | ||
| m_ProbeAnchor: {fileID: 0} | ||
| m_LightProbeVolumeOverride: {fileID: 0} | ||
| m_ScaleInLightmap: 1 | ||
| m_PreserveUVs: 1 | ||
| m_IgnoreNormalsForChartDetection: 0 | ||
| m_ImportantGI: 0 | ||
| m_StitchLightmapSeams: 0 | ||
| m_SelectedEditorRenderState: 3 | ||
| m_MinimumChartSize: 4 | ||
| m_AutoUVMaxDistance: 0.5 | ||
| m_AutoUVMaxAngle: 89 | ||
| m_LightmapParameters: {fileID: 0} | ||
| m_SortingLayerID: 0 | ||
| m_SortingLayer: 0 | ||
| m_SortingOrder: 0 | ||
| --- !u!33 &33340294062673050 | ||
| MeshFilter: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1654175882956584} | ||
| m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} | ||
| --- !u!114 &114776205485222536 | ||
| MonoBehaviour: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1654175882956584} | ||
| m_Enabled: 1 | ||
| m_EditorHideFlags: 0 | ||
| m_Script: {fileID: 11500000, guid: 23e3f20de6c2e405a93736a38f74b0fb, type: 3} | ||
| m_Name: | ||
| m_EditorClassIdentifier: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="HelloARController.cs" company="Google"> | ||
| // | ||
| // Copyright 2017 Google Inc. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| namespace GoogleARCore.HelloAR | ||
| { | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using UnityEngine.Rendering; | ||
| using GoogleARCore; | ||
|
|
||
| /// <summary> | ||
| /// Controlls the HelloAR example. | ||
| /// </summary> | ||
| public class HelloARController : MonoBehaviour | ||
| { | ||
| /// <summary> | ||
| /// The first-person camera being used to render the passthrough camera. | ||
| /// </summary> | ||
| public Camera m_firstPersonCamera; | ||
|
|
||
| /// <summary> | ||
| /// A prefab for tracking and visualizing detected planes. | ||
| /// </summary> | ||
| public GameObject m_trackedPlanePrefab; | ||
|
|
||
| /// <summary> | ||
| /// A model to place when a raycast from a user touch hits a plane. | ||
| /// </summary> | ||
| public GameObject m_andyAndroidPrefab; | ||
|
|
||
| /// <summary> | ||
| /// A gameobject parenting UI for displaying the "searching for planes" snackbar. | ||
| /// </summary> | ||
| public GameObject m_searchingForPlaneUI; | ||
|
|
||
| private List<TrackedPlane> m_newPlanes = new List<TrackedPlane>(); | ||
|
|
||
| private List<TrackedPlane> m_allPlanes = new List<TrackedPlane>(); | ||
|
|
||
| private Color[] m_planeColors = new Color[] { | ||
| new Color(1.0f, 1.0f, 1.0f), | ||
| new Color(0.956f, 0.262f, 0.211f), | ||
| new Color(0.913f, 0.117f, 0.388f), | ||
| new Color(0.611f, 0.152f, 0.654f), | ||
| new Color(0.403f, 0.227f, 0.717f), | ||
| new Color(0.247f, 0.317f, 0.709f), | ||
| new Color(0.129f, 0.588f, 0.952f), | ||
| new Color(0.011f, 0.662f, 0.956f), | ||
| new Color(0f, 0.737f, 0.831f), | ||
| new Color(0f, 0.588f, 0.533f), | ||
| new Color(0.298f, 0.686f, 0.313f), | ||
| new Color(0.545f, 0.764f, 0.290f), | ||
| new Color(0.803f, 0.862f, 0.223f), | ||
| new Color(1.0f, 0.921f, 0.231f), | ||
| new Color(1.0f, 0.756f, 0.027f) | ||
| }; | ||
|
|
||
| /// <summary> | ||
| /// The Unity Update() method. | ||
| /// </summary> | ||
| public void Update () | ||
| { | ||
| _QuitOnConnectionErrors(); | ||
|
|
||
| // The tracking state must be FrameTrackingState.Tracking in order to access the Frame. | ||
| if (Frame.TrackingState != FrameTrackingState.Tracking) | ||
| { | ||
| const int LOST_TRACKING_SLEEP_TIMEOUT = 15; | ||
| Screen.sleepTimeout = LOST_TRACKING_SLEEP_TIMEOUT; | ||
| return; | ||
| } | ||
|
|
||
| Screen.sleepTimeout = SleepTimeout.NeverSleep; | ||
| Frame.GetNewPlanes(ref m_newPlanes); | ||
|
|
||
| // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them. | ||
| for (int i = 0; i < m_newPlanes.Count; i++) | ||
| { | ||
| // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to | ||
| // the origin with an identity rotation since the mesh for our prefab is updated in Unity World | ||
| // coordinates. | ||
| GameObject planeObject = Instantiate(m_trackedPlanePrefab, Vector3.zero, Quaternion.identity, | ||
| transform); | ||
| planeObject.GetComponent<TrackedPlaneVisualizer>().SetTrackedPlane(m_newPlanes[i]); | ||
|
|
||
| // Apply a random color and grid rotation. | ||
| planeObject.GetComponent<Renderer>().material.SetColor("_GridColor", m_planeColors[Random.Range(0, | ||
| m_planeColors.Length - 1)]); | ||
| planeObject.GetComponent<Renderer>().material.SetFloat("_UvRotation", Random.Range(0.0f, 360.0f)); | ||
| } | ||
|
|
||
| // Disable the snackbar UI when no planes are valid. | ||
| bool showSearchingUI = true; | ||
| Frame.GetAllPlanes(ref m_allPlanes); | ||
| for (int i = 0; i < m_allPlanes.Count; i++) | ||
| { | ||
| if (m_allPlanes[i].IsValid) | ||
| { | ||
| showSearchingUI = false; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| m_searchingForPlaneUI.SetActive(showSearchingUI); | ||
|
|
||
| Touch touch; | ||
| if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| TrackableHit hit; | ||
| TrackableHitFlag raycastFilter = TrackableHitFlag.PlaneWithinBounds | TrackableHitFlag.PlaneWithinPolygon; | ||
|
|
||
| if (Session.Raycast(m_firstPersonCamera.ScreenPointToRay(touch.position), raycastFilter, out hit)) | ||
| { | ||
| // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical | ||
| // world evolves. | ||
| var anchor = Session.CreateAnchor(hit.Point, Quaternion.identity); | ||
|
|
||
| // Intanstiate an Andy Android object as a child of the anchor; it's transform will now benefit | ||
| // from the anchor's tracking. | ||
| var andyObject = Instantiate(m_andyAndroidPrefab, hit.Point, Quaternion.identity, | ||
| anchor.transform); | ||
|
|
||
| // Andy should look at the camera but still be flush with the plane. | ||
| andyObject.transform.LookAt(m_firstPersonCamera.transform); | ||
| andyObject.transform.rotation = Quaternion.Euler(0.0f, | ||
| andyObject.transform.rotation.eulerAngles.y, andyObject.transform.rotation.z); | ||
|
|
||
| // Use a plane attachment component to maintain Andy's y-offset from the plane | ||
| // (occurs after anchor updates). | ||
| andyObject.GetComponent<PlaneAttachment>().Attach(hit.Plane); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Quit the application if there was a connection error for the ARCore session. | ||
| /// </summary> | ||
| private void _QuitOnConnectionErrors() | ||
| { | ||
| // Do not update if ARCore is not tracking. | ||
| if (Session.ConnectionState == SessionConnectionState.DeviceNotSupported) | ||
| { | ||
| _ShowAndroidToastMessage("This device does not support ARCore."); | ||
| Application.Quit(); | ||
| } | ||
| else if (Session.ConnectionState == SessionConnectionState.UserRejectedNeededPermission) | ||
| { | ||
| _ShowAndroidToastMessage("Camera permission is needed to run this application."); | ||
| Application.Quit(); | ||
| } | ||
| else if (Session.ConnectionState == SessionConnectionState.ConnectToServiceFailed) | ||
| { | ||
| _ShowAndroidToastMessage("ARCore encountered a problem connecting. Please start the app again."); | ||
| Application.Quit(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Show an Android toast message. | ||
| /// </summary> | ||
| /// <param name="message">Message string to show in the toast.</param> | ||
| /// <param name="length">Toast message time length.</param> | ||
| private static void _ShowAndroidToastMessage(string message) | ||
| { | ||
| AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); | ||
| AndroidJavaObject unityActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); | ||
|
|
||
| if (unityActivity != null) | ||
| { | ||
| AndroidJavaClass toastClass = new AndroidJavaClass("android.widget.Toast"); | ||
| unityActivity.Call("runOnUiThread", new AndroidJavaRunnable(() => | ||
| { | ||
| AndroidJavaObject toastObject = toastClass.CallStatic<AndroidJavaObject>("makeText", unityActivity, | ||
| message, 0); | ||
| toastObject.Call("show"); | ||
| })); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="PlaneAttachment.cs" company="Google"> | ||
| // | ||
| // Copyright 2017 Google Inc. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| namespace GoogleARCore.HelloAR | ||
| { | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using UnityEngine.Rendering; | ||
| using GoogleARCore; | ||
|
|
||
| public class PlaneAttachment : MonoBehaviour | ||
| { | ||
| private TrackedPlane m_AttachedPlane; | ||
|
|
||
| private float m_planeYOffset; | ||
|
|
||
| private MeshRenderer[] m_meshRenderers; | ||
|
|
||
| private bool m_isVisible = true; | ||
|
|
||
| /// <summary> | ||
| /// Unity start. | ||
| /// </summary> | ||
| public void Start() | ||
| { | ||
| m_meshRenderers = GetComponentsInChildren<MeshRenderer>(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Unity update. | ||
| /// </summary> | ||
| public void Update() | ||
| { | ||
| // If the plane has been subsumed switch attachment to the subsuming plane. | ||
| while (m_AttachedPlane.SubsumedBy != null) | ||
| { | ||
| m_AttachedPlane = m_AttachedPlane.SubsumedBy; | ||
| } | ||
|
|
||
| // Update visibility of the GameObject based on plane validity. | ||
| if (!m_AttachedPlane.IsValid && m_isVisible) | ||
| { | ||
| for (int i = 0; i < m_meshRenderers.Length; i++) | ||
| { | ||
| m_meshRenderers[i].enabled = false; | ||
| } | ||
|
|
||
| m_isVisible = false; | ||
| } | ||
| else if (m_AttachedPlane.IsValid && !m_isVisible) | ||
| { | ||
| for (int i = 0; i < m_meshRenderers.Length; i++) | ||
| { | ||
| m_meshRenderers[i].enabled = true; | ||
| } | ||
|
|
||
| m_isVisible = true; | ||
| } | ||
|
|
||
| transform.position = new Vector3(transform.position.x, m_AttachedPlane.Position.y + m_planeYOffset, | ||
| transform.position.z); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Have the GameObject maintain the y-offset to a plane. | ||
| /// </summary> | ||
| /// <param>The plane to attach to.</param> | ||
| public void Attach(TrackedPlane plane) | ||
| { | ||
| m_AttachedPlane = plane; | ||
| m_planeYOffset = transform.position.y - plane.Position.y; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // <copyright file="PointcloudVisualizer.cs" company="Google"> | ||
| // | ||
| // Copyright 2017 Google Inc. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| namespace GoogleARCore.HelloAR | ||
| { | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using UnityEngine.Profiling; | ||
| using GoogleARCore; | ||
|
|
||
| /// <summary> | ||
| /// Visualize the point cloud. | ||
| /// </summary> | ||
| public class PointcloudVisualizer : MonoBehaviour | ||
| { | ||
| private const int MAX_POINT_COUNT = 61440; | ||
|
|
||
| private Mesh m_mesh; | ||
|
|
||
| private Vector3[] m_points = new Vector3[MAX_POINT_COUNT]; | ||
|
|
||
| private double m_lastPointCloudTimestamp; | ||
|
|
||
| /// <summary> | ||
| /// Unity start. | ||
| /// </summary> | ||
| public void Start() | ||
| { | ||
| m_mesh = GetComponent<MeshFilter>().mesh; | ||
| m_mesh.Clear(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Unity update. | ||
| /// </summary> | ||
| public void Update() | ||
| { | ||
| // Do not update if ARCore is not tracking. | ||
| if (Frame.TrackingState != FrameTrackingState.Tracking) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Fill in the data to draw the point cloud. | ||
| PointCloud pointcloud = Frame.PointCloud; | ||
| if (pointcloud.PointCount > 0 && pointcloud.Timestamp > m_lastPointCloudTimestamp) | ||
| { | ||
| // Copy the point cloud points for mesh verticies. | ||
| for (int i = 0; i < pointcloud.PointCount; i++) | ||
| { | ||
| m_points[i] = pointcloud.GetPoint(i); | ||
| } | ||
|
|
||
| // Update the mesh indicies array. | ||
| int[] indices = new int[pointcloud.PointCount]; | ||
| for (int i = 0; i < pointcloud.PointCount; i++) | ||
| { | ||
| indices[i] = i; | ||
| } | ||
|
|
||
| m_mesh.Clear(); | ||
| m_mesh.vertices = m_points; | ||
| m_mesh.SetIndices(indices, MeshTopology.Points, 0); | ||
| m_lastPointCloudTimestamp = pointcloud.Timestamp; | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="TrackedPlaneComponent.cs" company="Google"> | ||
| // | ||
| // Copyright 2017 Google Inc. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| namespace GoogleARCore.HelloAR | ||
| { | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using GoogleARCoreInternal; | ||
|
|
||
| /// <summary> | ||
| /// Visualizes a TrackedPlane in the Unity scene. | ||
| /// </summary> | ||
| public class TrackedPlaneVisualizer : MonoBehaviour | ||
| { | ||
| /// <summary> | ||
| /// The ARCore tracked plane to represent. | ||
| /// </summary> | ||
| private TrackedPlane m_trackedPlane; | ||
|
|
||
| private List<Vector3> m_meshVertices = new List<Vector3>(); | ||
|
|
||
| private List<Color> m_meshColors = new List<Color>(); | ||
|
|
||
| private List<int> m_meshIndices = new List<int>(); | ||
|
|
||
| private Mesh m_mesh; | ||
|
|
||
| private MeshRenderer m_meshRenderer; | ||
|
|
||
| /// <summary> | ||
| /// The Unity Awake() method. | ||
| /// </summary> | ||
| private void Awake() | ||
| { | ||
| m_mesh = GetComponent<MeshFilter>().mesh; | ||
| m_meshRenderer = GetComponent<UnityEngine.MeshRenderer>(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The Unity Update() method. | ||
| /// </summary> | ||
| private void Update() | ||
| { | ||
| if (m_trackedPlane == null) | ||
| { | ||
| return; | ||
| } | ||
| else if (m_trackedPlane.SubsumedBy != null) | ||
| { | ||
| Destroy(gameObject); | ||
| return; | ||
| } | ||
| else if (!m_trackedPlane.IsValid || Frame.TrackingState != FrameTrackingState.Tracking) | ||
| { | ||
| m_meshRenderer.enabled = false; | ||
| return; | ||
| } | ||
|
|
||
| m_meshRenderer.enabled = true; | ||
| if (m_trackedPlane.IsUpdated) | ||
| { | ||
| _UpdateMeshWithCurrentTrackedPlane(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Update the TrackedPlane reference. | ||
| /// </summary> | ||
| /// <param name="plane">The TrackedPlane reference..</param> | ||
| public void SetTrackedPlane(TrackedPlane plane) | ||
| { | ||
| m_trackedPlane = plane; | ||
| _UpdateMeshWithCurrentTrackedPlane(); | ||
| } | ||
|
|
||
| private void _UpdateMeshWithCurrentTrackedPlane() | ||
| { | ||
| // Note that GetBoundaryPolygon returns points in clockwise order. | ||
| m_trackedPlane.GetBoundaryPolygon(ref m_meshVertices); | ||
|
|
||
| Vector3 planeCenter = m_trackedPlane.Position; | ||
| int planePolygonCount = m_meshVertices.Count; | ||
|
|
||
| // The following code convert a polygon to a mesh with two polygons, inner | ||
| // polygon renders with 100% opacity and fade out to outter polygon with opacity 0%, as shown below. | ||
| // The indices shown in the diagram are used in comments below. | ||
| // _______________ 0_______________1 | ||
| // | | |4___________5| | ||
| // | | | | | | | ||
| // | | => | | | | | ||
| // | | | | | | | ||
| // | | |7-----------6| | ||
| // --------------- 3---------------2 | ||
| m_meshColors.Clear(); | ||
|
|
||
| // Fill transparent color to vertices 1 to 3. | ||
| for (int i = 0; i < planePolygonCount; ++i) | ||
| { | ||
| m_meshColors.Add(new Color(0.0f, 0.0f, 0.0f, 0.0f)); | ||
| } | ||
|
|
||
| // Feather distance 0.2 meters. | ||
| const float FEATHER_LENGTH = 0.2f; | ||
|
|
||
| // Feather scale over the distance between plane center and vertices. | ||
| const float FEATHER_SCALE = 0.2f; | ||
|
|
||
| // Add vertex 4 to 5. | ||
| for (int i = 0; i < planePolygonCount; ++i) | ||
| { | ||
| Vector3 v = m_meshVertices[i]; | ||
|
|
||
| // Vector from plane center to current point | ||
| Vector3 d = v - planeCenter; | ||
|
|
||
| float scale = 1.0f - Mathf.Min((FEATHER_LENGTH / d.magnitude), FEATHER_SCALE); | ||
| m_meshVertices.Add(scale * d + planeCenter); | ||
|
|
||
| m_meshColors.Add(new Color(0.0f, 0.0f, 0.0f, 1.0f)); | ||
| } | ||
|
|
||
| m_meshIndices.Clear(); | ||
| int verticeLength = m_meshVertices.Count; | ||
| int verticeLengthHalf = verticeLength / 2; | ||
| // Generate triangle (4, 5, 6) and (4, 6, 7). | ||
| for (int i = verticeLengthHalf + 1; i < verticeLength - 1; ++i) | ||
| { | ||
| m_meshIndices.Add(verticeLengthHalf); | ||
| m_meshIndices.Add(i); | ||
| m_meshIndices.Add(i + 1); | ||
| } | ||
|
|
||
| // Generate triangle (0, 1, 4), (4, 1, 5), (5, 1, 2), (5, 2, 6), (6, 2, 3), (6, 3, 7) | ||
| // (7, 3, 0), (7, 0, 4) | ||
| for (int i = 0; i < verticeLengthHalf; ++i) | ||
| { | ||
| m_meshIndices.Add(i); | ||
| m_meshIndices.Add((i + 1) % verticeLengthHalf); | ||
| m_meshIndices.Add(i + verticeLengthHalf); | ||
|
|
||
| m_meshIndices.Add(i + verticeLengthHalf); | ||
| m_meshIndices.Add((i + 1) % verticeLengthHalf); | ||
| m_meshIndices.Add((i + verticeLengthHalf + 1) % verticeLengthHalf + verticeLengthHalf); | ||
| } | ||
|
|
||
| m_mesh.Clear(); | ||
| m_mesh.SetVertices(m_meshVertices); | ||
| m_mesh.SetIndices(m_meshIndices.ToArray(), MeshTopology.Triangles, 0); | ||
| m_mesh.SetColors(m_meshColors); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!1001 &100100000 | ||
| Prefab: | ||
| m_ObjectHideFlags: 1 | ||
| serializedVersion: 2 | ||
| m_Modification: | ||
| m_TransformParent: {fileID: 0} | ||
| m_Modifications: [] | ||
| m_RemovedComponents: [] | ||
| m_ParentPrefab: {fileID: 0} | ||
| m_RootGameObject: {fileID: 1905656715913530} | ||
| m_IsPrefabParent: 1 | ||
| --- !u!1 &1905656715913530 | ||
| GameObject: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| serializedVersion: 5 | ||
| m_Component: | ||
| - component: {fileID: 4892153982037908} | ||
| - component: {fileID: 114072643661330778} | ||
| - component: {fileID: 114254441574086558} | ||
| m_Layer: 0 | ||
| m_Name: ARCore Device | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!1 &1960903772876386 | ||
| GameObject: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| serializedVersion: 5 | ||
| m_Component: | ||
| - component: {fileID: 4923070639190690} | ||
| - component: {fileID: 20362215073346118} | ||
| m_Layer: 0 | ||
| m_Name: First Person Camera | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!4 &4892153982037908 | ||
| Transform: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1905656715913530} | ||
| 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_Children: | ||
| - {fileID: 4923070639190690} | ||
| m_Father: {fileID: 0} | ||
| m_RootOrder: 0 | ||
| m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
| --- !u!4 &4923070639190690 | ||
| Transform: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1960903772876386} | ||
| 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_Children: [] | ||
| m_Father: {fileID: 4892153982037908} | ||
| m_RootOrder: 0 | ||
| m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
| --- !u!20 &20362215073346118 | ||
| Camera: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1960903772876386} | ||
| m_Enabled: 1 | ||
| serializedVersion: 2 | ||
| m_ClearFlags: 2 | ||
| m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} | ||
| m_NormalizedViewPortRect: | ||
| serializedVersion: 2 | ||
| x: 0 | ||
| y: 0 | ||
| width: 1 | ||
| height: 1 | ||
| near clip plane: 0.05 | ||
| far clip plane: 200 | ||
| field of view: 60 | ||
| orthographic: 0 | ||
| orthographic size: 5 | ||
| m_Depth: 0 | ||
| m_CullingMask: | ||
| serializedVersion: 2 | ||
| m_Bits: 4294967295 | ||
| m_RenderingPath: -1 | ||
| m_TargetTexture: {fileID: 0} | ||
| m_TargetDisplay: 0 | ||
| m_TargetEye: 3 | ||
| m_HDR: 1 | ||
| m_AllowMSAA: 1 | ||
| m_ForceIntoRT: 0 | ||
| m_OcclusionCulling: 1 | ||
| m_StereoConvergence: 10 | ||
| m_StereoSeparation: 0.022 | ||
| m_StereoMirrorMode: 0 | ||
| --- !u!114 &114072643661330778 | ||
| MonoBehaviour: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1905656715913530} | ||
| m_Enabled: 1 | ||
| m_EditorHideFlags: 0 | ||
| m_Script: {fileID: 1742909100, guid: 3a84de5cd0624681b6b6dcd8921d912a, type: 3} | ||
| m_Name: | ||
| m_EditorClassIdentifier: | ||
| m_Device: 0 | ||
| m_PoseSource: 6 | ||
| m_TrackingType: 0 | ||
| m_UpdateType: 2 | ||
| m_UseRelativeTransform: 1 | ||
| --- !u!114 &114254441574086558 | ||
| MonoBehaviour: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1905656715913530} | ||
| m_Enabled: 1 | ||
| m_EditorHideFlags: 0 | ||
| m_Script: {fileID: 11500000, guid: 7bf3911478e8b449181ac73714fa7424, type: 3} | ||
| m_Name: | ||
| m_EditorClassIdentifier: | ||
| m_arSessionConfig: {fileID: 11400000, guid: ba33c039dd5b24adeb15a423efaf4497, type: 2} | ||
| m_firstPersonCamera: {fileID: 20362215073346118} | ||
| m_connectOnAwake: 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!1001 &100100000 | ||
| Prefab: | ||
| m_ObjectHideFlags: 1 | ||
| serializedVersion: 2 | ||
| m_Modification: | ||
| m_TransformParent: {fileID: 0} | ||
| m_Modifications: [] | ||
| m_RemovedComponents: [] | ||
| m_ParentPrefab: {fileID: 0} | ||
| m_RootGameObject: {fileID: 1248447649449928} | ||
| m_IsPrefabParent: 1 | ||
| --- !u!1 &1248447649449928 | ||
| GameObject: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| serializedVersion: 5 | ||
| m_Component: | ||
| - component: {fileID: 4461716624848968} | ||
| - component: {fileID: 114451930413443482} | ||
| m_Layer: 0 | ||
| m_Name: Evironmental Light | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!4 &4461716624848968 | ||
| Transform: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1248447649449928} | ||
| 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_Children: [] | ||
| m_Father: {fileID: 0} | ||
| m_RootOrder: 0 | ||
| m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
| --- !u!114 &114451930413443482 | ||
| MonoBehaviour: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 1248447649449928} | ||
| m_Enabled: 1 | ||
| m_EditorHideFlags: 0 | ||
| m_Script: {fileID: 11500000, guid: 92a4cf446a0c7334aaceb5457be27894, type: 3} | ||
| m_Name: | ||
| m_EditorClassIdentifier: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!21 &2100000 | ||
| Material: | ||
| serializedVersion: 6 | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 0} | ||
| m_Name: ARBackground | ||
| m_Shader: {fileID: 15401, guid: 0000000000000000f000000000000000, type: 0} | ||
| m_ShaderKeywords: | ||
| m_LightmapFlags: 4 | ||
| m_EnableInstancingVariants: 0 | ||
| m_DoubleSidedGI: 0 | ||
| m_CustomRenderQueue: -1 | ||
| stringTagMap: {} | ||
| disabledShaderPasses: [] | ||
| m_SavedProperties: | ||
| serializedVersion: 3 | ||
| m_TexEnvs: | ||
| - _BumpMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailAlbedoMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailMask: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _DetailNormalMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _EmissionMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _MainTex: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _MetallicGlossMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _OcclusionMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| - _ParallaxMap: | ||
| m_Texture: {fileID: 0} | ||
| m_Scale: {x: 1, y: 1} | ||
| m_Offset: {x: 0, y: 0} | ||
| m_Floats: | ||
| - _BumpScale: 1 | ||
| - _Cutoff: 0.5 | ||
| - _DetailNormalMapScale: 1 | ||
| - _DstBlend: 0 | ||
| - _GlossMapScale: 1 | ||
| - _Glossiness: 0.5 | ||
| - _GlossyReflections: 1 | ||
| - _Metallic: 0 | ||
| - _Mode: 0 | ||
| - _OcclusionStrength: 1 | ||
| - _Parallax: 0.02 | ||
| - _SmoothnessTextureChannel: 0 | ||
| - _SpecularHighlights: 1 | ||
| - _SrcBlend: 1 | ||
| - _UVSec: 0 | ||
| - _ZWrite: 1 | ||
| m_Colors: | ||
| - _Color: {r: 1, g: 1, b: 1, a: 1} | ||
| - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="Anchor.cs" company="Google"> | ||
| // | ||
| // Copyright 2017 Google Inc. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| namespace GoogleARCore | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| /// @cond EXCLUDE_FROM_DOXYGEN | ||
| using UnityTango = GoogleAR.UnityNative; | ||
| /// @endcond | ||
|
|
||
| /// <summary> | ||
| /// Anchors a gameobject to a position/rotation in the Unity world relative to ARCore's understanding of the | ||
| /// physical world; Created using <c>Session.CreateAnchor(Vector3, Quaternion)</c>. | ||
| /// ARCore may periodically perform operations that affect the mapping of Unity world coordinates to the | ||
| /// physical world; an example of such being drift correction. Anchors allow GameObjects to retain their | ||
| /// physical world location when these operations occur. If ARCore is unable to track an anchor for any reason, | ||
| /// the attached GameObject will be set inactive until tracking resumes. | ||
| /// </summary> | ||
| public class Anchor : MonoBehaviour | ||
| { | ||
| private Matrix4x4 m_poseTAnchor; | ||
|
|
||
| private double m_creationTimestamp; | ||
|
|
||
| private ScreenOrientation m_creationScreenOrientation; | ||
|
|
||
| /// <summary> | ||
| /// Gets a unique identifier for the anchor. | ||
| /// </summary> | ||
| public string Id { get; private set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the tracking state of the anchor. | ||
| /// </summary> | ||
| public AnchorTrackingState TrackingState { get; private set; } | ||
|
|
||
| /// @cond EXCLUDE_FROM_DOXYGEN | ||
| /// <summary> | ||
| /// Instantiates a new GameObject with an Anchor component attached. | ||
| /// </summary> | ||
| /// <param name="position">The unity world position to instantiate the anchor GameObject.</param> | ||
| /// <param name="rotation">The unity world rotation to instantiate the anchor GameObject.</param> | ||
| /// <param name="updateTracking">A callback to update the anchor's position based on latest | ||
| /// estimation of the physical world pose from ARCore.</param> | ||
| /// <param name="updateTrackingState">A callback to update the private tracking state of the anchor.</param> | ||
| /// <returns>A GameObject with an Anchor component attached.</returns> | ||
| public static Anchor InstantiateAnchor(Vector3 position, Quaternion rotation, | ||
| out Action<double> updateTracking, out Action<AnchorTrackingState> updateTrackingState) | ||
| { | ||
| Anchor anchor = (new GameObject()).AddComponent<Anchor>(); | ||
| anchor.gameObject.name = "Anchor"; | ||
| anchor.Id = Guid.NewGuid().ToString(); | ||
| anchor.TrackingState = AnchorTrackingState.Tracking; | ||
| anchor.transform.position = position; | ||
| anchor.transform.rotation = rotation; | ||
| var cameraPose = Frame.Pose; | ||
| anchor.m_poseTAnchor = Matrix4x4.TRS(cameraPose.position, cameraPose.rotation, Vector3.one).inverse * | ||
| Matrix4x4.TRS(position, rotation, Vector3.one); | ||
| anchor.m_creationTimestamp = Frame.Timestamp; | ||
| anchor.m_creationScreenOrientation = Screen.orientation; | ||
| updateTracking = anchor._UpdateTracking; | ||
| updateTrackingState = anchor._UpdateTrackingState; | ||
| return anchor; | ||
| } | ||
| /// @endcond | ||
|
|
||
| private void _UpdateTracking(double earliestTimestamp) | ||
| { | ||
| if (m_creationTimestamp < earliestTimestamp) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| UnityTango.PoseData poseData; | ||
| bool getPoseSuccess = UnityTango.InputTracking.TryGetPoseAtTime( | ||
| out poseData, UnityTango.CoordinateFrame.StartOfService, UnityTango.CoordinateFrame.CameraColor, | ||
| m_creationTimestamp, m_creationScreenOrientation); | ||
| if (!getPoseSuccess || poseData.statusCode != UnityTango.PoseStatus.Valid) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var unityWorldAnchor = Matrix4x4.TRS(poseData.position, poseData.rotation, Vector3.one) * m_poseTAnchor; | ||
| transform.position = unityWorldAnchor.GetColumn(3); | ||
| transform.rotation = Quaternion.LookRotation(unityWorldAnchor.GetColumn(2), unityWorldAnchor.GetColumn(1)); | ||
| } | ||
|
|
||
| private void _UpdateTrackingState(AnchorTrackingState trackingState) | ||
| { | ||
| TrackingState = trackingState; | ||
| gameObject.SetActive(TrackingState == AnchorTrackingState.Tracking); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| //----------------------------------------------------------------------- | ||
| // <copyright file="AnchorTrackingState.cs" company="Google"> | ||
| // | ||
| // Copyright 2017 Google Inc. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // </copyright> | ||
| //----------------------------------------------------------------------- | ||
|
|
||
| namespace GoogleARCore | ||
| { | ||
| /// <summary> | ||
| /// The tracking state for an anchor. | ||
| /// </summary> | ||
| public enum AnchorTrackingState | ||
| { | ||
| /// <summary> | ||
| /// ARCore has stopped tracking this Anchor and will never resume tracking it. This typically happens | ||
| /// because the anchor was created when the device's tracking state was diminished and then became further | ||
| /// diminished or lost. | ||
| /// </summary> | ||
| StoppedTracking, | ||
|
|
||
| /// <summary> | ||
| /// The anchor is not currently being tracked but tracking may resume in the future. This can happen | ||
| /// if device tracking is lost or if the user enters a new space. When in this state the anchor GameObject | ||
| /// is disabled since the transform could be very inaccurate. | ||
| /// </summary> | ||
| LostTracking, | ||
|
|
||
| /// <summary> | ||
| /// The Anchor is being tracked and its transform is current. | ||
| /// </summary> | ||
| Tracking, | ||
| } | ||
| } |