beatTheSystem42 / MetalWorldTextureScan

Scan the environment and create a textured mesh with ARKit
MIT License
79 stars 16 forks source link

Scanning large 3D environments #4

Open michael-martinez opened 2 years ago

michael-martinez commented 2 years ago

I am encountering limitations while trying to scan a large area.

1) I am the following crash on drawAnchorGeometry(_:):

Screenshot 2022-03-29 at 17 13 23

Is there something to reset when reaching large amounts of meshes?

2) Is the app intended to be used only for small areas?

When scanning a zone, the app seems to look close on a departure zone but does not expand after. I can also see it also in the repo README's video, it scans close to the guitar then "stops".

beatTheSystem42 commented 2 years ago

Yeah, go ahead and give the README another look, and also check out my stack post: https://stackoverflow.com/a/71257170/5135949

This project shows you a way, not the best way, to scan what's inside of an area. Limiting your scan to an area is just a cool thing to be able to do. There are many cases where you'd just want to scan an object and not the entire environment. The inBox value is what determines if the vertex is inside your box, think of it like cropping.

That specific crash there, is because the size of the 'mesh.inBox' list has exceeded the limitations of Metal's setVertexBytes (4KB). -> https://developer.apple.com/documentation/metal/mtlrendercommandencoder/1515846-setvertexbytes

The solution is creating an MTLBuffer for that data, and using 'setVertexBuffer' instead of 'setVertexBytes.'

The app will probably crash also due to memory issues when you try to check if each vertex is inside that box with a large scan. There's a better way to do that for sure, but this just serves as an example of what you can do with native iOS. Feel free to toss out any ideas, or for your large scan project, remove the 'inBox' check entirely.

beatTheSystem42 commented 2 years ago

@michael-martinez Also, thanks for checking out the repo. Good to see some interest in this thing.

michael-martinez commented 2 years ago

Thanks a lot ; I removed the box limitation and it works fine.

Related question: Does it make sense to also tweak the kMaxBuffersInFlight (to improve performance) and kMaxAnchorInstanceCount (is it only used for vizualization or limiting data also?) parameters?

beatTheSystem42 commented 2 years ago

for sure, check this guide out too if you wanna learn a little more: https://developer.apple.com/documentation/metal/resource_synchronization/synchronizing_cpu_and_gpu_work

mightyG commented 2 years ago

Thanks a lot ; I removed the box limitation and it works fine.

Related question: Does it make sense to also tweak the kMaxBuffersInFlight (to improve performance) and kMaxAnchorInstanceCount (is it only used for vizualization or limiting data also?) parameters?

Can you share your approach to removing the box limitation?

michael-martinez commented 2 years ago

As far as I can remember I just commented out the related condition in the counting logic here

See:

if mesh.inBox[fv] == 1 { // comment this condition
    c += 1
}
RookiePyl commented 1 year ago

As far as I can remember I just commented out the related condition in the counting logic here

See:

if mesh.inBox[fv] == 1 { // comment this condition
    c += 1
}

First,thanks. After comment, only part of the area can be scanned. Am I missing something? look forward to your reply.

jaswant-iotric commented 1 year ago

I removed the box check, didnt get the crash but getting trailing edge effect on the frames that are outside of the camera's field of view. Weird. Saw the same issue on one more repo.