zirman / arcore-filament-example-app

ARCore Filament Example App
MIT License
97 stars 15 forks source link

Code explanation help #10

Closed bitamirshafiee closed 3 years ago

bitamirshafiee commented 3 years ago

Hello again and thanks for the great repo, I have some questions about the code which will be happy if you could help me with. first is, what is the use of class 'FrameCallback'? since it is extending the 'Choreographer.FrameCallback' I can geuss that it is a helper class for updating animation, am I right? Since I am going to just put one model without animation on the screen, is this class still needed? or I can just use the 'update' method in ARCore for that, for just updating the model per frame?(I am guessing the update method in ArCore class is doing the job of the override method 'onDrawFrame' right? )

Thank you!

zirman commented 3 years ago

FrameCallback is provides added functionality to android.view.Choreographer. Choreographer runs a callback when it's time to render a frame. FrameCallback has a frame limiter and supports skipping frames. In our app I will turn on frame skipping when the device starts to throttle due to high temperature warnings. You can remove some of the added functionality but at the very least I would still use Choreographer to callback when it's time to render a frame.

zirman commented 3 years ago

If all you want to do is update the model I would remove these lines

val frameCallback =
    FrameCallback(
        arCore,
        doFrame = { frame ->
            //if (frame.getUpdatedTrackables(Plane::class.java)
           //         .any { it.trackingState == TrackingState.TRACKING }
            //) {
            //    arTrackingEvents.tryEmit(Unit)
            //}

            lightRenderer.doFrame(frame)
            //planeRenderer.doFrame(frame)
            modelRenderer.doFrame(frame)
        },
    )
bitamirshafiee commented 3 years ago

Thank you. I was going through the code and What I want to do is a simple click on the screen and loading the glb file. I narrowed it down to the 'ModelRenderer' class. It has a sealed class with Move and Update, it is a little hard for me to understand what exactly they are doing? Since in ARCore with OpenGL, I was using anchors to attach the model to the surface, here are you using screen position for that? Does this line arCore.frame.hitTest

working like an anchor? actually I move to filament because I cannot load glb files in just ARCore I think using filament is the only way loading gab files.

zirman commented 3 years ago

Filament is the only open source library I have found that can render GLB/GLTF models. Loading models directly with OpenGL is possible but requires a lot of work. Which is why Google has a team of developers working on a cross platform library for loading GLB/GLTF files and rendering them using physically based rendering techniques.

This project is just a starting point to get ARCore working with Filament which can be modified for your use case. It's not attempting to be a framework or game engine. Just a simple sample to get started. Sceneform was trying to be a framework/game engine that has more features but is more complex and difficult to modify if it doesn't meet your needs.

arCore.frame.hitTest is used to get the location for the model. I just render the model at the coordinates from the HitResult. ARCore will sometimes update the position of tracked surfaces. If you want to make sure that the model position is updated when the tracked surface position changes, call .createAnchor() on HitResult to get an Anchor. That's what Google's documentation recommends.