0
\$\begingroup\$

How to simulate the object cutting with a lathe, similar to what's done in the CRAFT: Work VR Shop app?

\$\endgroup\$
3
  • \$\begingroup\$ It looks like you could do this by either generating a cylindrical mesh and displacing the vertices' radii according to a profile curve, or handle it inna shader by raymarching against a profile stored in a 1D heightmap texture. How have you tried solving your problem so far, and where have you gotten stuck? \$\endgroup\$ – DMGregory Oct 8 '19 at 18:29
  • \$\begingroup\$ this is a very early stage, I am looking for a right approach before I start working on it. Maybe it's a mesh boolean library for mesh operation like doing with the 3D modelling software like 3dmax, maya, blender, etc. but I need to use it in the game engine, so I guess I have to control it in the mesh level. \$\endgroup\$ – blackgun Oct 8 '19 at 20:12
  • 1
    \$\begingroup\$ Delete this idea that you need to find a "right" approach before you start working. This will be a huge impediment to your progress. Games are frequently experimental. If you wait for a consensus to emerge about what way is "right," you will be waiting a very long time, and other games will beat you to the punch. So, get in the habit of diving in and trying stuff. Prioritize "works" over "right". \$\endgroup\$ – DMGregory Oct 8 '19 at 20:18
2
\$\begingroup\$

I implemented the effect by doing a virtual lathe. I used Unity for simplicity, but this can be done in pretty much anything. First I had to generate a cylinder:

enter image description here

Instead of simply doing a normal cylinder, I generated a line of points and rotated them around. This way if I change the height of the vertices on that single line, it will affect the whole shape. For instance here's a sine wave:

enter image description here

(I upped the sideways resolution a bit to make it look nicer)

Now let's add a carving tool:

enter image description here

The only thing left to do is to detect when the carving tool gets closer to the object, than the width of it at that point and if it does, remove some of it:

enter image description here

And that's it. It still has some problems you need to fix, e.g.:

  • It doesn't do dynamic collision, so if I were to move the carving tool too fast, it would leave strange artifacts
  • It's missing dynamic detail. You might not want to spend a lot of rendering time on relatively simple objects

But those should be easy to do (moving the tool only in small increments and checking the distance between vertices every frame respectively).

\$\endgroup\$
5
  • \$\begingroup\$ The approach make sense, I have the similar idea. but this question's key is about your mentioned "I generated a line of points and rotated them around", how? how to use script to generate and operate the mesh? \$\endgroup\$ – blackgun Oct 10 '19 at 23:46
  • \$\begingroup\$ @blackgun depends on the framework/engine you use, but you essentially need a rotation matrix and a line of points. Store the line of points in an array, then rotate them (using rotation matrices or quaternions) and append them to the end of the same array and so on until you rotated them 360 degrees. This leaves you with a list of points in 3d space ordered so that the points of each line are next ti each other. Let's say you have n points in a line and l lines. You need to connect these into quads with indices. Every quad uses 2 points from one line and 2 from the line to the right. \$\endgroup\$ – Bálint Oct 11 '19 at 0:19
  • \$\begingroup\$ The indices of these points in the array are 1.:(x * n + y), 2.:(x * n + y + 1), 3.:((x + 1) * n + y + 1), 4:. ((x + 1) * n + y) where x is the line the lower left point is in and y is the index of the point in that line. To make a quad out of this using two triangles, you need to connect the 1., 4. and 2. and the 2., 4. and 3. points into 2 triangles (aka. push them into an index list). Repeat this for every x between 0 and l - 1 and every y between 0 and n - 1 and you'll have a bunch of quads shaped as a cylinder. Modify the starting line and repeat every step to carve into the object \$\endgroup\$ – Bálint Oct 11 '19 at 0:25
  • \$\begingroup\$ Send the index list and vertices to the GPU or let the framework/engine handle it for you to render it \$\endgroup\$ – Bálint Oct 11 '19 at 0:28
  • \$\begingroup\$ Hi Balint, thanks for your reply. My case is a bit complicated, could we discuss them via email ? blackgun99 at g mail . thank you. \$\endgroup\$ – blackgun Oct 11 '19 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.