Displaying ARKit nodes in relation to real objects - arkit

I am trying to draw a box that can help someone understand the dimensions of an item, but I keep having the issue that since I first need to recognize a plane when I put my physical item on top of the plane, my box gets drawn in front of the item.
Is it possible to somehow overcome this?

#John Scalo is right, your problem is not having to first detect a plane, but it's that your render engine doesn't know that part of your green box frame is occluded (hidden) by a real-world object.
"…to somehow overcome this"
Yes, and by doing so you might be "solving" your original problem—help someone understand the dimensions of an item.
(Depending on your choice of render engine, e.g. SceneKit) You can add an invisible 3D object that has the same dimensions as the real-world object; so the render engine will "know" that some parts of your box frame are behind this (for the user invisible) 3D object. Therefor, you can tell it not to draw those parts of your box frame, which will give the illusion (borrowing from Apple here) that your soda can has the box around it.
These workarounds are inaccurate, but maybe their accuracy is enough for the level of realism you are trying to achieve:
Option 1: 1. After detecting the desk surface, place a semi-transparent 3D object over the soda can and then resize it (gestures/buttons your choice) until it's about the dimensions of the soda can. 2. Confirm that you're done, and just don't draw a texture on it at all just let it occlude the green box frame.
Option 2: Hold your device near the edges of the soda can and add "enough" ARAnchors to be able to create a "bounding shape" that (again) can be used to capture the real-word object and occlude that.
Option 3: (intense, and perhaps the least accurate) Use your finger to "brush" over the object from various angles, and on each touch perform a hit test (hopefully the top/nearest hit is a part of your soda can) and build up a "bounding shape" that way.
Option X: any combination of 1 - 2 - 3.
Good luck, there's lots of people trying to work around this device/ARKit limitation at them moment, so keep your eyes open for good ideas.

The problem you're dealing with is called occlusion, and ARKit doesn't (currently?) include occlusion support. Maybe some day soon iPhones and iPads will begin to ship with LIDAR (or similar), in which case ARKit will be able to detect objects in the scene, making occlusion much easier.

Related

Unity application to simulate a foveal field of view - but how?

For research purposes, I would like to create a Unity VR 3D application that (more or less) simulates the foveal field of view of a person. This means, in particular, I would like to render the whole environment of the application in the full field of view, but certain objects of interest I only want to render in the foveal area.
For the purpose of explaining the problem, I created a simple 2D picture. Please assume it's 3D. In the picture, the green area is the peripheral field of view, and the yellow area is the foveal field of view. The whole environment, like walls, sky, etc., should get rendered in the green and in the yellow area. Particular objects of interests, here the flowers, however, should only get rendered only in the yellow area and - importand - these objects should get cut off when reaching the green area. With this approach, I want to force people moving their head instead of just moving the eyes.
Any idea how to achieve this? Is it possible to use a kind of mask or filter? Or do I need a stencil shader? I looked around but could not find the correct approach.

How to draw marks on Unity 3D plane?

I am new to Unity. Sorry if I have a beginner style of question.
I want to implement a 3D Chess game in Unity. I have already implemented a C++ shared library that contains the whole AI thing. I have used this library in WPF and Android and it is tested perfectly. Now it is Unity's turn.
When the user selects a piece, next moves of it should be shown.
These marks can be a light or image. Circular or rectangle.
One way to do this is to have 64 marks per each square of the Chess board and change their visibility programmatically.
The other way, which I personally prefer, is to draw the marks programmatically. But I don't know how to draw on my Chessboard plane.
Please guide me with it.
FINAL RESULT (Just a sketchup!)
STEP BY STEP:
(I assume you have already had a chessboard)
1. Create a Material & configure it like in the below image. Note that the albedo green is 50% transparent:
2. Create a Quad & assign it the newly created Material above. Then set
it up like in the below image:
3. Now we will add the glow effect. First, we need to turn off the
Anti-Aliasing by switching to Good Quality instead of Fantastic.
4. Second, we need to enable HDR in the main camera:
5. Third, we need to import the Image Effects package. This package
is part of the Standard Assets that is shipped with Unity. It is
completely free. Get it here if you haven't.
https://www.assetstore.unity3d.com/en/#!/content/32351
You only need the Image Effect package.
6. Now add the Bloom effect to your main camera.
7. That's it! If you need to hide it via code then get the reference to
it and execute this line of code:
yourQuad.SetActive(false);
See more here:
https://docs.unity3d.com/ScriptReference/GameObject.SetActive.html
8. Finally, duplicate that quad to create 64 ones & position them
properly. There are 2 tricks that can help your life in hell a lot
easier:
To quickly duplicate a group of objects: select all of them and press: Ctrl + D
To enable edge-snap: select your quad and hold down V then hover your mouse over the quad's vertex. You will see a white square around it. Drag that vetex and see the magic.
9. From this on, it is your game logic to implement. You could store
all the quads in a 2-dimensional array (matrix) and manipulate it
yourself, that it all I can think of. Goodluck!

At some position character cannot see the whole mesh in unity

I want to show a transparent building in our project. I did that by setting the material of the mesh to be "transparent/diffuse". However, there exists some visibility problem of the mesh of the building. At some position, I can only see two or three sides of the cuboid(the transparent block, i.e the building). If I adjust my character position, I can see the whole cuboid. I googled the similar question online, someone mentioned about the frustum view of the camera. It seems like character has to be inside the frustum view of the camera, then user can see the whole mesh of the cuboid.
Can anyone give me some suggestions? I feel like it might be something about the way of how I build my mesh for the building, but at some position, I can see the whole cuboid.
I've solved this problem. It is just about the way how you construct the mesh.Basically, for the cuboid, I reconstructed the mesh in this way:
triangles[0]=topleft;
triangles[1]=topright;
triangles[2]=bottomright;
triangles[3]=bottomright;
triangles[4]=bottomleft;
triangles[5]=topleft;
Note: This is just front side, the other sides should be constructed in a same way.
Besides, in order to show the mesh when user enters the block, you have to construct the inside area of the block in previous way.

Objective C Drawing free form shape on top of image

I am working on a iOS 5 iPhone project where users can choose an image on their device, then trace an object inside of the picture (trace an apple out of a picture of a fruit basket), and then the picture needs to be uploaded with the "tagged" object so it can be pulled down later. Other people will then pull down the image and try to find where the tagged object is in the picture (Think "Where's Waldo?").
I have been trying to figure out the best way of tracing the object. Before, I had a user press the top left, top right, bottom left, and bottom right points around the object and create a square view around the object. The info for that view was uploaded and then pulled down for the user to find the object. The downside is that all objects are obviously not squares/rectangles so I need to do a free form shape.
I was thinking of allowing the user to draw over the object and then somehow I need to be able to tell what is inside of the trace (For example, inside of a circle that they traced), but a problem I forsee is making sure the trace they made is closed so I can fill in the shape (which is a whole not problem).
Any advice welcome on the best way of starting this.
Thanks!
UIBezierPath might be a very useful friend here. It allows you to create any shape you need, and it supports both drawing and hit-detection. I recently did an implementation for a storybook where I could trace out a shape with their finger, freeze it, and then use the shape for tap detection.
The basic idea is this:
When your finger touches the screen, start recording positions. Discard any positions that are too close to the previous position (eg, only record a point if it is >min-distance from the last recorded point). While doing this, you can draw the UIBezierPath so you can see what you are tracing out. Modify the UIBezierPath by adding points to it, instead of recreating it every time.* When you lift your finger, close the bezier path. Quite simple.
Now, this will result in a polygon (ie, straight edges). If your min-distance is low enough or if you are using it for hit-detection (as you say), it won't really matter. However, if you want to smooth the path, you have to use the curve-to methods, which slightly complicate it - but should you wish to follow up on this more, read up on splines and spline generation from a point series.
*note: otherwise you'll get lag while drawing large shapes because recreating a bezier path from an increasingly large series of points gets expensive. Modifying the existing path makes it much, much, much faster.

iphone 2d drawing newbie question

I've been programming the iphone for a couple of months now and have 3 apps in the store already.
However, I have not done any kind of graphics programming in the platform.
Given that I'm planning on starting my 5th app (the 4th is under Apple's review) I wanted to ask for some pointers as to where to get information for this (been googling for a while but nothing matches what I'm looking for)
I need to create an App where I can 'drop' some shapes from a menu (a rectangle, circle, squares, and then some complex shapes) onto a main window.
the idea is that the user can drag them around. BUT, I want them to 'snap' to each other (kind of like in a CAD package where a circle has quadrants on the edges that snap to any other geometry entity in the drawing).
So if I had a circle on the left of the screen and a rectangle on the right and then I move the circle around, it would stop moving to the right If I hit the rectangles edges. Not completely stop but giving some sort of 'resistance' to the continuity of the movement.
Also, if I have several overlapping drawings, is there a way to 'divide' them (any overlapping becomes a shape on itself but is removed from any other shape composing the overlap)?
The reason for this is that I need to calculate the area of the drawing (along with other properties)
I'm thinking of CALayer 1, 2, 3,..., n on of top of the other, each one with a drawing (with CGPath?), that may or may not overlap the others.
Then I need to somehow obtain information of the 'projection' of all those on a single CALayer.
I'm clueless here.
Should I look into Quartz2D? is CALayer and CGPath enough for this?
this is not for a game. Just an engineering application I have in mind.
Any help is appreciated.
regards
dh
iPhone Application Programming Guide has a chapter on drawing.
You might get some ideas where to start by looking at the appropriate lectures from iPhone Application Programming lectures at Stanford. They include hight quality video lectures (filmed by Apple) over at iTunesU, slides and example source code.