How do I know when geometry (SCNNodes) are at the edge of the view? - ios

I want to do an endless parallax style background with SceneKit, but I don't think I understand quite how to detect when a mesh is "off camera".

The scene renderer (only the view on iOS) can check if an object is inside the frustum (the shape of what is viewable) from a specific point of view (like a camera) using isNodeInsideFrustum:withPointOfView:
This checks if the bounding box of the node is inside of the frustum (ignoring if it's obscured by something else). I.e. the node is in the viewable region but it's not guaranteed to be visible on the screen.
To check if something is "off camera", you can check if it's outside the viewable region for that camera (here I've assumed that the camera is the scene view's point of view):
BOOL isOffCamera = ![yourSceneView isNodeInsideFrustum:theNodeToCheck
withPointOfView:yourSceneView.pointOfView];

Related

Swift SceneKit - I am trying to figure out if a Node object goes off the screen

Using SceneKit
I want to make the gray transparent box to disappear and only show the colored boxes when the user zooms in.
So I want to detect when that box's edges are starting to fall off the screen as I zoom, so I can hide the gray box accordingly.
First thoughts, but there may be better solutions:
You could do an unprojectPoint on the node and check against screen coordinates, do the +/- math on object size and skip Z. I "think" that would work
You can do some physics based collision detection against an invisible box or plane geometries that acts as your screen edges, has some complexity if your view is changing, but testing would be easy - just leave visible until you get what you want, then isVisible=false
isNode(insideFrustomof: ) - returns boolean on whether it "might" be visible. I'm assuming "might" means obscured by other geometry which in your case, shouldn't matter (edit) on second thought, that doesn't solve your problem but I'll leave it in here for reference.

How to place 3D object on horizontal plane automatically (without tapping) in iOS 12?

I'm working on an app with AR feature. I want to be able to place a 3D model that I have on a horizontal plane that has been detected. So inside the renderer(didAdd) delegate function, I added a node for my 3D model, and set its position to the center of the plane anchor. However, when I run the app to test it, my model is floating on top of the plane instead of standing directly on top of it. My guess is that there is some translation that needs to be done with the coordinates, but don't know about the details. Can somebody give me some pointers?

ARCore ObjectRenderer detect object is in Camera frame

I am looking to show some helper text on the GLSurfaceView. But I want to show this only when I see the object in my Camera's frame not before that. How can I detect whether the 3d object is visible in the Camera's frame or not?
Rather than having to check every time what objects are in the camera frame, it might be easier, deepening on your particular application, to simply attach the helper text below or above the object you want it to apply to, on the same anchor.
This would also have the advantage that the text would be centred only when the object is centred - i.e. you would not have the text suddenly fully appear when just a corner of the object is in the camera view.
ViewRenderables allow you to render 'a 2D Android view in 3D space by attaching it to a Node with setRenderable(Renderable)'.
(https://developers.google.com/ar/reference/java/sceneform/reference/com/google/ar/sceneform/rendering/ViewRenderable)

How to change X3DOM mouse model for rotating camera

Currently X3DOM handles camera movement like all scene is in a sphere, dragging mouse left to right moves the sphere (thus the scene) around the center of that sphere, like this.
Can we change this behaviour like in Blender's, as the same left to right dragging rotates the scene around Z axis (in other words, changes the azimuth without changing the current elevation) and dragging from up to down changes the elevation, without changing azimuth, like this one?
There are some navigation modes available: https://doc.x3dom.org/tutorials/animationInteraction/navigation/index.html. However I think you will have to create your own navigation mode if you want to have exact behaviour as in Blender.
For example you could activate the "Turntable" mode adding the following to your scene node:
<NavigationInfo type= 'turntable' ></NavigationInfo>
You can also find some discussion regarding more control over the navigation on mailing list and within the issues of X3DOM:
https://github.com/x3dom/x3dom/issues/454 and
https://github.com/x3dom/x3dom/issues/486

how to Move world view instead of camera view

I have a viewport3d with a camera and some blocks inside of it. Currently using the keyboard to move the camera up/down/left/right/rotate ect.
but instead of the camera i want to move the world view. So when a user presses the W key to move up, its not just moving the camera in a +x position. As the user maybe at a 20 degree view.
Create a virtual Camera Boom.
Create an invisible object like a TDummy, in the same location as the object of interest or the center of the scene.
Create the TCamera as a child of the object. Set its position the desired distance away on one of the axes.
you can now rotate the camera around the object simply by changing the rotationAngle of the dummy object. The camera will maintain the exact distance and automatically points directly toward the center.
Also by adding light as a child of the camera it too will follow as the camera moves. Hope this helps someone.

Resources