public void Render(ArFragment arFragment) { MainThread.BeginInvokeOnMainThread(() => { /* string GLTF_ASSET = * "https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/Duck/glTF/Duck.gltf"; * * ModelRenderable.InvokeBuilder() * .SetSource(arFragment.Context, Android.Net.Uri.Parse(GLTF_ASSET)) * .Build(((renderable) => * { * this.nodeRenderable = renderable; * * }));*/ this.nodeRenderable = ShapeFactory.MakeSphere(0.08f, new Vector3(0.0f, 0.15f, 0.0f), color); this.AnchorNode.Renderable = this.nodeRenderable; this.AnchorNode.SetParent(arFragment.ArSceneView.Scene); TransformableNode sphere = new TransformableNode(arFragment.TransformationSystem); sphere.SetParent(this.AnchorNode); sphere.Renderable = this.nodeRenderable; sphere.Select(); }); }
public void AddToScene(ArFragment arFragment) { MainThread.BeginInvokeOnMainThread(() => { this.nodeRenderable = ShapeFactory.MakeSphere(0.1f, new Vector3(0.0f, 0.15f, 0.0f), this.colorMaterial); this.AnchorNode.Renderable = this.nodeRenderable; this.AnchorNode.SetParent(arFragment.ArSceneView.Scene); TransformableNode sphere = new TransformableNode(arFragment.TransformationSystem); sphere.SetParent(this.AnchorNode); sphere.Renderable = this.nodeRenderable; sphere.Select(); }); }
public void Render(ArFragment arFragment) { MainThreadContext.RunOnUiThread(() => { //TODO: See https://github.com/xamarin/XamarinComponents/issues/584 //nodeRenderable = ShapeFactory.MakeSphere(0.1f, new Vector3(0.0f, 0.15f, 0.0f), color); anchorNode.Renderable = nodeRenderable; anchorNode.SetParent(arFragment.ArSceneView.Scene); TransformableNode sphere = new TransformableNode(arFragment.TransformationSystem); sphere.SetParent(anchorNode); sphere.Renderable = nodeRenderable; sphere.Select(); }); }
/// <summary> /// Creates 3D model with the specified anchors /// </summary> private AnchorModel CreateModel(AnchorNode localAnchor, CloudSpatialAnchor cloudAnchor) { var anchorModel = new AnchorModel { LocalAnchor = localAnchor, CloudAnchor = cloudAnchor }; localAnchor.SetParent(arFragment.ArSceneView.Scene); var model = new TransformableNode(arFragment.TransformationSystem); model.SetParent(localAnchor); model.Renderable = this.modelRenderable; model.Select(); return(anchorModel); }
// CompletableFuture requires api level 24 // FutureReturnValueIgnored is not valid protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); if (!CheckIsSupportedDeviceOrFinish(this)) { return; } SetContentView(Resource.Layout.activity_main); arFragment = (ArFragment)SupportFragmentManager.FindFragmentById(Resource.Id.ux_fragment); // When you build a Renderable, Sceneform loads its resources in the background while returning // a CompletableFuture. Call thenAccept(), handle(), or check isDone() before calling get(). ModelRenderable.InvokeBuilder() .SetSource(this, Resource.Raw.andy) .Build() .ThenAccept(new Consumer(t => andyRenderable = (ModelRenderable)t)) .Exceptionally(new Function(_ => { Toast toast = Toast.MakeText(this, "Unable to load andy renderable", ToastLength.Long); toast.SetGravity(GravityFlags.Center, 0, 0); toast.Show(); return(null); } )); arFragment.SetOnTapArPlaneListener(new OnTapArPlaneListener((hitResult, plane, motionEvent) => { if (andyRenderable == null) { return; } // Create the Anchor. Anchor anchor = hitResult.CreateAnchor(); AnchorNode anchorNode = new AnchorNode(anchor); anchorNode.SetParent(arFragment.ArSceneView.Scene); // Create the transformable andy and add it to the anchor. TransformableNode andy = new TransformableNode(arFragment.TransformationSystem); andy.SetParent(anchorNode); andy.Renderable = andyRenderable; andy.Select(); } )); }
public void AddToScene(ArFragment arFragment, string name = "") { MainThread.BeginInvokeOnMainThread(() => { this.nodeRenderable = ShapeFactory.MakeSphere(0.02f, new Vector3(0.0f, 0.0f, 0.0f), this.colorMaterial); this.AnchorNode.Renderable = this.nodeRenderable; this.AnchorNode.SetParent(arFragment.ArSceneView.Scene); if (!string.IsNullOrWhiteSpace(name)) { this.AnchorNode.Name = name; } TransformableNode sphere = new TransformableNode(arFragment.TransformationSystem); sphere.SetParent(this.AnchorNode); sphere.Renderable = this.nodeRenderable; sphere.Select(); }); }
private void OnTapArPlane(object sender, BaseArFragment.TapArPlaneEventArgs e) { if (andyRenderable == null) { return; } // Create the Anchor. Anchor anchor = e.HitResult.CreateAnchor(); AnchorNode anchorNode = new AnchorNode(anchor); anchorNode.SetParent(arFragment.ArSceneView.Scene); // Create the transformable andy and add it to the anchor. TransformableNode andy = new TransformableNode(arFragment.TransformationSystem); andy.SetParent(anchorNode); andy.Renderable = andyRenderable; andy.Select(); }