7 days of WordPress plugins, themes & templates - for free!* Unlimited asset downloads! Start 7-Day Free Trial

Next lesson playing in 5 seconds

  • Overview
  • Transcript

2.3 Add a 3D Object

Once we have successfully placed our ImageTarget onto the AR scene, we can add the 3D object that we want to project onto that marker. The 3D object will be rendered in the scene when the camera of our mobile device "sees" the marker image. Remember that birthday cake object that we downloaded earlier? Time to give it its place of prominence.

2.3 Add a 3D Object

Okay, so now we have our scene starting to take shape. We have our ImageTarget loaded into our Unity project. We have our ARCamera. We also have this Directional Light, and I'll show you a little bit about that here momentarily. So the next thing that I wanna do, is I want to bring in our cake asset. So I have this OBJ file here. So what I wanna do is I want to select this file, and I want to drag it into my Assets folder. And once it's been imported, we now have access to use it within our scene. Now for some reason you drag it in here somewhere that doesn't seem very obvious when you have first done it. Or maybe you imported it into the wrong spot or you can't really find it, make sure you use the Search functionality as it's very, very helpful. So I can start to type in whatever the name of the file was, in my case, it's BirthdayCake. So now I can select this and I can drag it out onto my scene. Now I have it right in the middle of our Happy Birthday right here, but I want to first put this at the center. So I'm gonna put it at 0, 0, 0, 0. And now I'm going to Option click and drag around a little bit so I can see where exactly this is going to live. And as you can see here, it's fairly small within the birthday cake. And who wants a small birthday cake or a small piece of cake on their birthday? So you can start to play around with the scale a little bit. So you can try to increase it by 5 either way. Maybe that's a little bit too big. Maybe we could bring it down maybe to 3. Yeah, that seems like it might be decent. So as you can see now, we have this mesh rendering here of our birthday cake, which seems to be pretty fine. Now you can also, if you would like, you can begin to play around a little bit with the lighting, which can sometimes be very helpful. So we'll just take a look at this, and we'll grab the directional light here. And as you can see, I think that should be fine. You can play around with that a little bit to get different lighting effects in different directions. You can drag it around in different ways to try to change the way that these shadows appear. But I think, for the most part, that's gonna be fine. So what we've to this point now is we have created this basic scene. We have imported our ImageTarget from Vuforia, from that database. We have brought in our three dimensional object that's ultimately gonna be projected onto our target when we look at the object through our phone or through whatever camera or mobile device that you have. But before we can actually finish anything, there's a couple of things that we have to pay attention to. So we have this ImageTarget and we have this BirthdayCake. Now when those two things are separate, they're viewed as separate entities within this project. So in order for things to work well and show up the way we expect them to, the BirthdayCake image, or whatever object that you want to project onto that ImageTarget, needs to be a nested child of the ImageTarget. So I'm simply, over here in the hierarchy, I'm gonna grab BirthdayCake. And I'm gonna drag it down and hover over ImageTarget and drop it there. So now as you can see, it's nested under the ImageTarget. So that's a very important piece number one. Now the second thing that we have to do is we have to make sure that when our application, or our game, or whatever have you, that you want to use augmented reality in with the Vuforia. Once the application loads, we wanna make sure that all of the image targets and the database that we're using loads up when we run our application. So in order to make sure that that's gonna happen, we can select ARCamera. We head over into Inspector, and then we go down just a little bit. And you'll see Database Load Behavior Scripts. So we wanna make sure that we are loading the TutsARDemo or whatever the database name is that you chose. We wanna check that box, and we want to activate it as soon as it's ready. So now that we've done this, if you have a webcam that is hooked up to your PC or your laptop or whatever have you. You can then run this and test it out a little bit using the webcam if you would like to do that. Now that would be fine. And if you wanted to do that, you would simply select the Play button here. Unfortunately, I don't have a functioning webcam to show that to you. But you will easily find that if you were to click that button, it would usually ask you first if you want to allow Unity to access the webcam that's hooked up to your machine. And you simply allow access, and then you'll be able to see out of your webcam and test this out a little bit just to see how it works. But since I'm not gonna do that, I'm gonna skip ahead to the next step. And the next step will be preparing the Unity project and making it available to run on your mobile device, or iPhone in this particular case. And prepare it to import or generate an XCode project.

Back to the top