Hi
Is it possible to have a 3D object within a scene act as a AR or VR button.
Iāve had a good look at the āCustom XR Buttonsā info and sample but that doesnāt seem to cover what Iām hoping to achieve. Unless Iāve missed some obviousā¦ which is entirely possible
Itās not a deal breaker if it canāt be doneā¦ but it would be cool if it can
Cheeeeeeeeers, in advance, for any advice
Original Post on Discord
by user 908977119781060648
Yep, you can, this should do the trick:
import { Behaviour, GameObject, IPointerDownHandler, WebXR } from "@needle-tools/engine";
// Documentation ā https://docs.needle.tools/scripting
export class ClickToStartXR extends Behaviour implements IPointerDownHandler{
private btn: HTMLElement;
start() {
const xr = GameObject.findObjectOfType(WebXR);
if (!xr) return;
this.btn = WebXR.createARButton(xr);
}
onPointerDown() {
if (!this.btn) return;
this.btn.click();
}
}
Make sure to turn off the regular button creation, otherwise theyāre double
Fantastic!
Huge thanks for that!!!
by user 908977119781060648
So, just curiousā¦ on a similar matterā¦
If I wanted a 3D object to act as clickable to launch a Quicklook experience, would that also be possible with Needle?
In the past when Iāve done so (in 2D) on web pages just using html Iāve achieved it withā¦
<a href="https://www.cartoonfun.co.uk/name_of.reality" rel="ar">
<img />
<img style="max-width: 20px;" src="assets/ios_ARBtn_icon.png">View in your space (iOS) </a>
</div>```
Just wondering if there's a way to do something equivalent with Needle?
*by user 908977119781060648*
Yep almost the same,
private exporter: USDZExporter;
...
this.exporter = GameObject.findObjectOfType(USDZExporter);
...
this.exporter.exportAsync();
Weāre handling that <a rel="ar"><img/></a>
dance internally in the USDZExporter
Aha! Ingenius!
Thank you!!!
by user 908977119781060648
So, can I launch an external, pre-existing usdz (or .reality file) with that?
by user 908977119781060648
By default it will export the part of your scene where USDZExporter is on (or the entire scene if nothing is assigned)
But yes, you can also use a pre-existing file by dragging that into the USDZExporter in Unity into the ācustom USDZā field
Aaand Iād like to know the reason for using a pre-existing file so that we can improve our conversion
Oooooooo, that sounds cool. Cheers for the info!
For refā¦ I doubt Iāll ever have an occasion where Iād need to use an external USDZ (Iām hoping not anyway). My curiosity was primarily spurred by wanting to be prepared to cover any eventualities, such as (for example) a compiled/exported USDZ not being able to match the functionality of an equivalent one thatās been specifically created in Reality Composer.
It doesnāt seem that what Iāve described would ever actually be an issue though, as (a) the kind of scenes which Iām creating are quite simple and (b) the Needle USDZExporter appears to output a very sophisticated version of things
by user 908977119781060648
a compiled/exported USDZ not being able to match the functionality of an equivalent one thatās been specifically created in Reality Composer.
If you ever run into this please let me know - our goal is that weāre at least matching what Reality Composer can output for common cases. There are some areas we didnāt touch yet (such as scene switching in RC) but in terms of interactive behaviours I think we have pretty good coverage
It certainly looks like youāve nailed it from what Iāve seen thus far
by user 908977119781060648
Okay, sorry but Iām not having any luck with creating a ālaunch USDZ/Quicklook via a clickable 3D objectā.
Based on the previous guidance, Iāve cobbled together the following script (ClickToStartARiOS.ts - the latest of several tries ) but Iām obviously getting various things wrong as none of it seems to work
export class ClickToStartARiOS extends Behaviour implements IPointerDownHandler{
private btn: HTMLElement;
private exporter: USDZExporter;
start() {
this.exporter = GameObject.findObjectOfType(USDZExporter);
}
onPointerDown() {
if (!this.btn || !this.exporter) return;
this.btn.click();
this.exporter.exportAsync();
}
}```
Sadly, I'm unable to spot where the problem lies.
If there's a fix for the shambles that I've made I'd be eternally grateful!!! š
*by user 908977119781060648*
The āprivateā¦ā and especially the part in the if and the click
Sorry, should have made that more explicit
No, seriously the failing is mine not yours, I kid you not!
Cheeeeeeersā¦ and Iāll try again
by user 908977119781060648