CAM based on Unity

Dear community,

I’m about to create my own CAM (Computer Aided Manufacturing) system. For this purpose I need to implement importing models in popular CAD formats like *.x_t, *.step *.stl etc. , let the user to select faces, edges, generating paths and simulating. All these functionalities have to be in runtime mode.

Selecting primitives like faces and edges, as well as importing CAD models are the most big questions for me. Could it be implemented in Unity?

What do you think about the whole idea?

I think it is a bad idea. I don’t think it’s feasible, but not because it is hard to do these things. It is because Unity’s engine isn’t made for this. You will meet with floating point imprecision in 2 minutes. Of course if it’s a toy, like “make your own plastic soldier”-like thing, then it’s okay. But I wouldn’t make anything serious with plain Unity. (Maybe Unity already has something in the oven for industrial applications, but we are game developers here, mostly, the barebone engine isn’t for CAD/M)

1 Like

Yes. And, yes unity wasn’t supposed to be used for this, but it could be done.

It is a lot of hassle. I wouldn’t recommend approaching this unless you’re a fairly skilled programmer familiar with 3d.

He won’t, at least not in models with dimensions under a kilometer.

Floating point precision isn’t only going towards the big, it affects the small too. Obviously it depends on what they want to make but I wouldn’t use Unity to design mechanical parts with high precision requirements. Bearings, joints, etc…

Thank you for your replies.

First of all, Unity seems to have very useful features like nice rendering, crossplatform deployment, inverse kinematics, physics simulation, rich UI facilities etc. For me the stumbling block is working with CAM models and primitives like faces and edges. I have no idea how to import and selecting primitives yet.

Floating point precision is relative to the first significant digit. So within 1 millimeter range from origin, you’ll have something in ballpark of 1 nanometer precision at the minimum. (0.000000001 m).

Typical recommended “game engine range” for openworld games - 8 kilometer cube is area where you can retain submillimeter precision.

Your concern would’ve been valid if he was dealing with “half” precision floats which are 16 bit. But he does not.

And if he intends to do mechanical sim, then he could use doubles internally when needed, though this also will be a hassle.

1 Like

parts are much smaller than 1 km, extra high precision is not required.

Also, one more thing: Unity’s license contains non-competing clauses. If you’re planning to make an editor for example “3D print your stuff, here’s an editor” might be okay. If you are planning to make “the next AutoCAD” or something, that’s probably won’t be okay. Read the license carefully and if you doubt, ask the support (and/or a lawyer) for legal opinion about your case.

Raycast can get the triangle hit and normal which would give you the face.

But you’ll get some tricky math quickly trying to do much else. Like you’ll probably want to generate a tree structure for indexing the vertices/triangles so you can query nearest neighbors, edges, groups of points and such, but I don’t know which one exactly, kd-tree and probably others like r-tree/quadtree/etc. spatial algorithms can get crazy GitHub - viliwonka/KDTree: Fast KDTree for Unity, with thread-safe querying.

Try digging around here for partial solutions
https://unitylist.com/

some list of cad format importers (but many of those are old/abandoned)
https://github.com/UnityCommunity/CADImportExport/issues/1#issuecomment-727218714

asset store has several ready to use cad importers available too.

one bigger issue is: if you plan to import huge CAD models (like full buildings, or ships, complex machines)
you’ll have problems with too many parts (gameobjects) and vertex count. (but sounds like you don’t need to do that).

are you publishing on mobile platforms too?

You can bypass this limitation by using double precision numbers to store the mesh data and only use single precision to do the actual rendering. That said Unigine would be the better engine to choose here since it’s designed for these kinds of workloads.

2 Likes

Yeah, this. The rendered data does not have to be the same as the operational data.

It’s quite possible. We are doing simple medical CAD: https://bonabyte.net/our-products/bonaplanner/ - you can see some screenshots on our site.
7401800--904583--Screenshot 2021-08-09 164443.png
Also you can get some ideas how to create runtime editor from Vadim Andriyanov
asset it’s called “Runtime editor”.