зеркало из https://github.com/xamarin/ios-samples.git
[ios11] ARKit basic sample
This commit is contained in:
Родитель
1ff587b329
Коммит
4523919c03
|
@ -0,0 +1,23 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ARKitSample", "ARKitSample\ARKitSample.csproj", "{91E6A3D9-178A-430C-A6D6-83FF98B69AF9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|iPhoneSimulator = Debug|iPhoneSimulator
|
||||
Release|iPhone = Release|iPhone
|
||||
Release|iPhoneSimulator = Release|iPhoneSimulator
|
||||
Debug|iPhone = Debug|iPhone
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{91E6A3D9-178A-430C-A6D6-83FF98B69AF9}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
|
||||
{91E6A3D9-178A-430C-A6D6-83FF98B69AF9}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
|
||||
{91E6A3D9-178A-430C-A6D6-83FF98B69AF9}.Release|iPhone.ActiveCfg = Release|iPhone
|
||||
{91E6A3D9-178A-430C-A6D6-83FF98B69AF9}.Release|iPhone.Build.0 = Release|iPhone
|
||||
{91E6A3D9-178A-430C-A6D6-83FF98B69AF9}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
|
||||
{91E6A3D9-178A-430C-A6D6-83FF98B69AF9}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
|
||||
{91E6A3D9-178A-430C-A6D6-83FF98B69AF9}.Debug|iPhone.ActiveCfg = Debug|iPhone
|
||||
{91E6A3D9-178A-430C-A6D6-83FF98B69AF9}.Debug|iPhone.Build.0 = Debug|iPhone
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,119 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
|
||||
<ProjectGuid>{91E6A3D9-178A-430C-A6D6-83FF98B69AF9}</ProjectGuid>
|
||||
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>ARKitSample</RootNamespace>
|
||||
<AssemblyName>ARKitSample</AssemblyName>
|
||||
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
|
||||
<MtouchFastDev>true</MtouchFastDev>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
<IOSDebuggerPort>32979</IOSDebuggerPort>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchArch>i386, x86_64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhone\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<MtouchLink>SdkOnly</MtouchLink>
|
||||
<MtouchArch>ARMv7, ARM64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
|
||||
<MtouchLink>None</MtouchLink>
|
||||
<MtouchArch>i386, x86_64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\iPhone\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;ENABLE_TEST_CLOUD;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodesignKey>iPhone Developer</CodesignKey>
|
||||
<DeviceSpecificBuild>true</DeviceSpecificBuild>
|
||||
<MtouchDebug>true</MtouchDebug>
|
||||
<MtouchNoSymbolStrip>true</MtouchNoSymbolStrip>
|
||||
<MtouchFastDev>true</MtouchFastDev>
|
||||
<MtouchProfiling>true</MtouchProfiling>
|
||||
<MtouchFloat32>true</MtouchFloat32>
|
||||
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
|
||||
<IOSDebuggerPort>61205</IOSDebuggerPort>
|
||||
<MtouchLink>SdkOnly</MtouchLink>
|
||||
<MtouchArch>ARM64</MtouchArch>
|
||||
<MtouchHttpClientHandler>HttpClientHandler</MtouchHttpClientHandler>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Xamarin.iOS" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Contents.json" />
|
||||
<ImageAsset Include="Assets.xcassets\Contents.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InterfaceDefinition Include="LaunchScreen.storyboard" />
|
||||
<InterfaceDefinition Include="Main.storyboard" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<SceneKitAsset Include="art.scnassets\ship.dae" />
|
||||
<SceneKitAsset Include="art.scnassets\texture.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
<Folder Include="ClassExtensions\" />
|
||||
<Folder Include="Classes\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Info.plist" />
|
||||
<None Include="Entitlements.plist" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="AppDelegate.cs" />
|
||||
<Compile Include="GameViewController.cs" />
|
||||
<Compile Include="GameViewController.designer.cs">
|
||||
<DependentUpon>GameViewController.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ClassExtensions\Matrix4Extensions.cs" />
|
||||
<Compile Include="Classes\SessionDelegate.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,59 @@
|
|||
using Foundation;
|
||||
using UIKit;
|
||||
|
||||
namespace ARKitSample
|
||||
{
|
||||
// The UIApplicationDelegate for the application. This class is responsible for launching the
|
||||
// User Interface of the application, as well as listening (and optionally responding) to application events from iOS.
|
||||
[Register("AppDelegate")]
|
||||
public class AppDelegate : UIApplicationDelegate
|
||||
{
|
||||
// class-level declarations
|
||||
|
||||
public override UIWindow Window
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
|
||||
{
|
||||
// Override point for customization after application launch.
|
||||
// If not required for your application you can safely delete this method
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void OnResignActivation(UIApplication application)
|
||||
{
|
||||
// Invoked when the application is about to move from active to inactive state.
|
||||
// This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message)
|
||||
// or when the user quits the application and it begins the transition to the background state.
|
||||
// Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
public override void DidEnterBackground(UIApplication application)
|
||||
{
|
||||
// Use this method to release shared resources, save user data, invalidate timers and store the application state.
|
||||
// If your application supports background exection this method is called instead of WillTerminate when the user quits.
|
||||
}
|
||||
|
||||
public override void WillEnterForeground(UIApplication application)
|
||||
{
|
||||
// Called as part of the transiton from background to active state.
|
||||
// Here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
public override void OnActivated(UIApplication application)
|
||||
{
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive.
|
||||
// If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
public override void WillTerminate(UIApplication application)
|
||||
{
|
||||
// Called when the application is about to terminate. Save data, if needed. See also DidEnterBackground.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
{
|
||||
"images": [
|
||||
{
|
||||
"idiom": "iphone",
|
||||
"size": "29x29",
|
||||
"scale": "1x"
|
||||
},
|
||||
{
|
||||
"idiom": "iphone",
|
||||
"size": "29x29",
|
||||
"scale": "2x"
|
||||
},
|
||||
{
|
||||
"idiom": "iphone",
|
||||
"size": "29x29",
|
||||
"scale": "3x"
|
||||
},
|
||||
{
|
||||
"idiom": "iphone",
|
||||
"size": "40x40",
|
||||
"scale": "2x"
|
||||
},
|
||||
{
|
||||
"idiom": "iphone",
|
||||
"size": "40x40",
|
||||
"scale": "3x"
|
||||
},
|
||||
{
|
||||
"idiom": "iphone",
|
||||
"size": "57x57",
|
||||
"scale": "1x"
|
||||
},
|
||||
{
|
||||
"idiom": "iphone",
|
||||
"size": "57x57",
|
||||
"scale": "2x"
|
||||
},
|
||||
{
|
||||
"idiom": "iphone",
|
||||
"size": "60x60",
|
||||
"scale": "2x"
|
||||
},
|
||||
{
|
||||
"idiom": "iphone",
|
||||
"size": "60x60",
|
||||
"scale": "3x"
|
||||
},
|
||||
{
|
||||
"idiom": "ipad",
|
||||
"size": "29x29",
|
||||
"scale": "1x"
|
||||
},
|
||||
{
|
||||
"idiom": "ipad",
|
||||
"size": "29x29",
|
||||
"scale": "2x"
|
||||
},
|
||||
{
|
||||
"idiom": "ipad",
|
||||
"size": "40x40",
|
||||
"scale": "1x"
|
||||
},
|
||||
{
|
||||
"idiom": "ipad",
|
||||
"size": "40x40",
|
||||
"scale": "2x"
|
||||
},
|
||||
{
|
||||
"idiom": "ipad",
|
||||
"size": "50x50",
|
||||
"scale": "1x"
|
||||
},
|
||||
{
|
||||
"idiom": "ipad",
|
||||
"size": "50x50",
|
||||
"scale": "2x"
|
||||
},
|
||||
{
|
||||
"idiom": "ipad",
|
||||
"size": "72x72",
|
||||
"scale": "1x"
|
||||
},
|
||||
{
|
||||
"idiom": "ipad",
|
||||
"size": "72x72",
|
||||
"scale": "2x"
|
||||
},
|
||||
{
|
||||
"idiom": "ipad",
|
||||
"size": "76x76",
|
||||
"scale": "1x"
|
||||
},
|
||||
{
|
||||
"idiom": "ipad",
|
||||
"size": "76x76",
|
||||
"scale": "2x"
|
||||
},
|
||||
{
|
||||
"size": "24x24",
|
||||
"idiom": "watch",
|
||||
"scale": "2x",
|
||||
"role": "notificationCenter",
|
||||
"subtype": "38mm"
|
||||
},
|
||||
{
|
||||
"size": "27.5x27.5",
|
||||
"idiom": "watch",
|
||||
"scale": "2x",
|
||||
"role": "notificationCenter",
|
||||
"subtype": "42mm"
|
||||
},
|
||||
{
|
||||
"size": "29x29",
|
||||
"idiom": "watch",
|
||||
"role": "companionSettings",
|
||||
"scale": "2x"
|
||||
},
|
||||
{
|
||||
"size": "29x29",
|
||||
"idiom": "watch",
|
||||
"role": "companionSettings",
|
||||
"scale": "3x"
|
||||
},
|
||||
{
|
||||
"size": "40x40",
|
||||
"idiom": "watch",
|
||||
"scale": "2x",
|
||||
"role": "appLauncher",
|
||||
"subtype": "38mm"
|
||||
},
|
||||
{
|
||||
"size": "44x44",
|
||||
"idiom": "watch",
|
||||
"scale": "2x",
|
||||
"role": "longLook",
|
||||
"subtype": "42mm"
|
||||
},
|
||||
{
|
||||
"size": "86x86",
|
||||
"idiom": "watch",
|
||||
"scale": "2x",
|
||||
"role": "quickLook",
|
||||
"subtype": "38mm"
|
||||
},
|
||||
{
|
||||
"size": "98x98",
|
||||
"idiom": "watch",
|
||||
"scale": "2x",
|
||||
"role": "quickLook",
|
||||
"subtype": "42mm"
|
||||
}
|
||||
],
|
||||
"info": {
|
||||
"version": 1,
|
||||
"author": "xcode"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using Foundation;
|
||||
using SceneKit;
|
||||
using ARKit;
|
||||
using OpenTK;
|
||||
|
||||
namespace ARKitSample
|
||||
{
|
||||
public static class Matrix4Extensions
|
||||
{
|
||||
public static SCNMatrix4 ToSCNMatrix4(this Matrix4 matrix) {
|
||||
return new SCNMatrix4(matrix.Row0, matrix.Row1, matrix.Row2, matrix.Row3);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using SceneKit;
|
||||
using UIKit;
|
||||
using ARKit;
|
||||
namespace ARKitSample
|
||||
{
|
||||
public class SessionDelegate : ARSessionDelegate
|
||||
{
|
||||
#region Constructors
|
||||
public SessionDelegate()
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Override Methods
|
||||
public override void CameraDidChangeTrackingState(ARSession session, ARCamera camera)
|
||||
{
|
||||
var state = "";
|
||||
var reason = "";
|
||||
|
||||
switch(camera.TrackingState) {
|
||||
case ARTrackingState.NotAvailable:
|
||||
state = "Tracking Not Available";
|
||||
break;
|
||||
case ARTrackingState.Normal:
|
||||
state = "Tracking Normal";
|
||||
break;
|
||||
case ARTrackingState.Limited:
|
||||
state = "Tracking Limited";
|
||||
switch(camera.TrackingStateReason) {
|
||||
case ARTrackingStateReason.ExcessiveMotion:
|
||||
reason = "because of excessive motion";
|
||||
break;
|
||||
case ARTrackingStateReason.Initializing:
|
||||
reason = "because tracking is initializing";
|
||||
break;
|
||||
case ARTrackingStateReason.InsufficientFeatures:
|
||||
reason = "because of insufficient features in the environment";
|
||||
break;
|
||||
case ARTrackingStateReason.None:
|
||||
reason = "because of an unknown reason";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Inform user
|
||||
Console.WriteLine("{0} {1}", state, reason);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,150 @@
|
|||
using System;
|
||||
using SceneKit;
|
||||
using UIKit;
|
||||
using ARKit;
|
||||
using CoreGraphics;
|
||||
|
||||
namespace ARKitSample
|
||||
{
|
||||
public partial class GameViewController : UIViewController, IARSCNViewDelegate
|
||||
{
|
||||
#region Computed Properties
|
||||
public ARSCNView SceneView {
|
||||
get { return View as ARSCNView; }
|
||||
}
|
||||
|
||||
public float AmbientIntensity {
|
||||
get {
|
||||
// Get the current frame
|
||||
var frame = SceneView.Session.CurrentFrame;
|
||||
if (frame == null) return 1000;
|
||||
|
||||
// Return ambient intensity
|
||||
if (frame.LightEstimate == null) {
|
||||
return 1000;
|
||||
} else {
|
||||
return (float)frame.LightEstimate.AmbientIntensity;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
protected GameViewController(IntPtr handle) : base(handle)
|
||||
{
|
||||
// Note: this .ctor should not contain any initialization logic.
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Override Methods
|
||||
public override void ViewDidLoad()
|
||||
{
|
||||
base.ViewDidLoad();
|
||||
|
||||
// Set self as the Scene View's delegate
|
||||
SceneView.Delegate = this;
|
||||
|
||||
// Track changes to the session
|
||||
SceneView.Session.Delegate = new SessionDelegate();
|
||||
|
||||
// Create a new scene
|
||||
var scene = SCNScene.FromFile("art.scnassets/ship");
|
||||
|
||||
// Set the scene to the view
|
||||
SceneView.Scene = scene;
|
||||
|
||||
|
||||
// Add a tap gesture recognizer
|
||||
var tapGesture = new UITapGestureRecognizer(HandleTap);
|
||||
View.AddGestureRecognizer(tapGesture);
|
||||
|
||||
}
|
||||
|
||||
public override void ViewWillAppear(bool animated)
|
||||
{
|
||||
base.ViewWillAppear(animated);
|
||||
|
||||
// Create a session configuration
|
||||
var configuration = new ARWorldTrackingSessionConfiguration(){
|
||||
PlaneDetection = ARPlaneDetection.Horizontal,
|
||||
LightEstimationEnabled = true
|
||||
};
|
||||
|
||||
// Run the view's session
|
||||
SceneView.Session.Run(configuration);
|
||||
|
||||
|
||||
// Find the ship and position it just in front of the camera
|
||||
var ship = SceneView.Scene.RootNode.FindChildNode("ship", true);
|
||||
ship.Position = new SCNVector3(2f, -2f, -9f);
|
||||
|
||||
}
|
||||
|
||||
public override void ViewWillDisappear(bool animated)
|
||||
{
|
||||
base.ViewWillDisappear(animated);
|
||||
|
||||
// Pause the view's session
|
||||
SceneView.Session.Pause();
|
||||
}
|
||||
|
||||
public override bool ShouldAutorotate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
|
||||
{
|
||||
return UIInterfaceOrientationMask.All;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
private void HandleTap(UIGestureRecognizer gestureRecognize)
|
||||
{
|
||||
// Get current frame
|
||||
var currentFrame = SceneView.Session.CurrentFrame;
|
||||
if (currentFrame == null) return;
|
||||
|
||||
// Create an image plane using a snapshot of the view
|
||||
var imagePlane = SCNPlane.Create(SceneView.Bounds.Width / 6000, SceneView.Bounds.Height / 6000);
|
||||
imagePlane.FirstMaterial.Diffuse.Contents = SceneView.Snapshot();
|
||||
imagePlane.FirstMaterial.LightingModelName = SCNLightingModel.Constant;
|
||||
|
||||
// Create a plane node and add it to the scene
|
||||
var planeNode = SCNNode.FromGeometry(imagePlane);
|
||||
SceneView.Scene.RootNode.AddChildNode(planeNode);
|
||||
|
||||
// Set transform of node to be 10cm in front of the camera
|
||||
var translation = SCNMatrix4.CreateTranslation(0, 0, 0.1f);
|
||||
var cameraTranslation = currentFrame.Camera.Transform.ToSCNMatrix4();
|
||||
planeNode.Transform = SCNMatrix4.Mult(cameraTranslation, translation);
|
||||
}
|
||||
|
||||
private void AddAnchorToScene() {
|
||||
|
||||
// Get the current frame
|
||||
var frame = SceneView.Session.CurrentFrame;
|
||||
if (frame == null) return;
|
||||
|
||||
// Create a ray to test from
|
||||
var point = new CGPoint(0.5, 0.5);
|
||||
|
||||
// Preform hit testing on frame
|
||||
var results = frame.HitTest(point, ARHitTestResultType.ExistingPlane | ARHitTestResultType.EstimatedHorizontalPlane);
|
||||
|
||||
// Use the first result
|
||||
if (results.Length >0) {
|
||||
var result = results[0];
|
||||
|
||||
// Create an anchor for it
|
||||
var anchor = new ARAnchor(result.WorldTransform);
|
||||
|
||||
// Add anchor to session
|
||||
SceneView.Session.AddAnchor(anchor);
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
using Foundation;
|
||||
using System.CodeDom.Compiler;
|
||||
|
||||
namespace ARKitSample
|
||||
{
|
||||
[Register("GameViewController")]
|
||||
partial class GameViewController
|
||||
{
|
||||
void ReleaseDesignerOutlets()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleName</key>
|
||||
<string>ARKitSample</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.xamarin.ARKitSample</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>11.0</string>
|
||||
<key>UIDeviceFamily</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</array>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>The camera is used for augmenting reality</string>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string>The location is used for augmenting reality</string>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
<string>LaunchScreen</string>
|
||||
<key>UIMainStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
<key>UIRequiredDeviceCapabilities</key>
|
||||
<array>
|
||||
<string>armv7</string>
|
||||
</array>
|
||||
<key>UIRequiresFullScreen</key>
|
||||
<true/>
|
||||
<key>UIStatusBarHidden</key>
|
||||
<true/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationPortrait</string>
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>XSAppIconAssets</key>
|
||||
<string>Assets.xcassets/AppIcon.appiconset</string>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
|
||||
<dependencies>
|
||||
<deployment identifier="iOS" />
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530" />
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<layoutGuides>
|
||||
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb" />
|
||||
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok" />
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600" />
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" />
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite" />
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder" />
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375" />
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
|
@ -0,0 +1,15 @@
|
|||
using UIKit;
|
||||
|
||||
namespace ARKitSample
|
||||
{
|
||||
public class Application
|
||||
{
|
||||
// This is the main entry point of the application.
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// if you want to use a different Application Delegate class from "AppDelegate"
|
||||
// you can specify it here.
|
||||
UIApplication.Main(args, null, "AppDelegate");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13156.6" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BV1-FR-VrT">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13137.5"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Game View Controller-->
|
||||
<scene sceneID="tXr-a1-R10">
|
||||
<objects>
|
||||
<viewController id="BV1-FR-VrT" customClass="GameViewController" sceneMemberID="viewController">
|
||||
<sceneKitView key="view" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="3se-qz-xqx" customClass="ARSCNView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</sceneKitView>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="SZV-WD-TEh" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 342 KiB |
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<SampleMetadata>
|
||||
<ID>90860659-66DB-41B9-AF25-09D934DC53BA</ID>
|
||||
<IsFullApplication>false</IsFullApplication>
|
||||
<Level>Intermediate</Level>
|
||||
<Tags>iOS11</Tags>
|
||||
<Gallery>true</Gallery>
|
||||
<Brief>Simple example using ARKit in iOS 11.</Brief>
|
||||
</SampleMetadata>
|
|
@ -0,0 +1,14 @@
|
|||
ARKit Sample
|
||||
============
|
||||
|
||||
This sample is a simple ARKit augmented reality demo.
|
||||
|
||||
To test this sample you'll need to deploy it on a device running iOS 11 beta software.
|
||||
|
||||
![AR Jet](Screenshots/jet.png)
|
||||
|
||||
|
||||
Author
|
||||
------
|
||||
|
||||
Kevin Mullins
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 758 KiB |
Загрузка…
Ссылка в новой задаче