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?
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)
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…
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.
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.
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).
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.
It’s quite possible. We are doing simple medical CAD: https://bonabyte.net/our-products/bonaplanner/ - you can see some screenshots on our site.
Also you can get some ideas how to create runtime editor from Vadim Andriyanov
asset it’s called “Runtime editor”.