Getting to know Lidar scanning
Last updated
Last updated
In this tutorial, you will learn how to paint walls using the Remodel-AR framework's LiDAR Scanner approach.
Before starting this tutorial, make sure you've completed Setting up Remodel-AR in UIKit. A link to the starting project is provided here for your convenience.
To get started, refactor ViewController and rename it to LidarViewController.
Open LidarViewController.swift and import the RemodelAR and ARKit frameworks.
Open Main.storyboard and add an ARSCNView object. Next, connect the ARSCNView outlet to LidarViewController.swift as arscnView.
In LidarViewController.swift, create a new variable to contain the ARController object.
Create an extension and add a new method, configureView() to it. Inside configureView(), assign arController and start the scene as shown below.
Call configureView() from LidarViewController’s ViewWillAppear() method.
Build and run the project. You will see a mesh start to be overlaid on top of the wall.
Open Main.storyboard and add a CollectionView and connect it to the view controller with the name it ColorPickerCollectionView. Don't forget to connect its Outlet.
Update its bottom constraint to safe area. Add any other necessary constraints to the view. Update the cell size to the desired size. Now your CollectionView should be positioned at the bottom of the ViewController. This CollectionView will work as a ColorPicker.
In the CollectionView's cell, add a UIView. Next complete all the necessary implementation details for the CollectionView and its cell.
Now create an array of WallPaint objects.
Set this array as the CollectionView's datasource. Set WallPaint's color as UIView's background color in the cell.
After finishing the CollectionView's setup, run the app and test the CollectionView to see different colored cells you can scroll through.
Open Main.storyboard and add another CollectionView and name it TexturePickerCollectionView. Don't forget to connect its Outlet.
Add this CollectionView on top of the ColorPickerCollectionView. Update its constraints as needed. This CollectionView will work as a TexturePicker.
In CollectionView's cell, add a UIImageView, then finish adding all the necessary implementation details for the CollectionView and its cell.
Next create an array of textureNames
Set this array as the CollectionView's datasource. Set textureName in the Cell UIImageView image.
Note: You can find texture images in the sample UIKit project.
After finishing the CollectionView setup, run the app and test to see the CollectionView load with different texture images you can scroll through.
Open the Main.storyboard. Add four buttons and set the button's image to camera.fill, saveMesh, reset and info.circle.fill respectively.
Embed these buttons in a Horizontal StackView. Now set the StackView's top constraint to safe area, then implement any other necessary constraints for the StackView.
Next connect the button's IBActions to LidarViewController.swift and modify the IBActions as shown below.
Open Main.storyboard and add a label to it. Connect the label's outlet to LidarViewController.swift and name it planarMeshesCountLabel.
This label will inform you about the count of planar meshes.
Now modify createARView() method as show below:
Finally, Override the touchesEnded(_ touches: Set, with event: UIEvent?) method in LidarViewController.swift.
Now, you should be able to create and paint walls.
To paint a wall, select different colors and textures then tap on a wall. You can also save a picture and a mesh of your room.
If at any point you need help from the Passio team, please reach out to us at support@passiolife.com