Hi. I am a 3d CAD designer but am relatively new to Blender so forgive me if some of the things i want to do are straight forward.
The Project:
The project i am working on at the moment is a product demo for the company i work for. Allowing people with little 3d knowledge to create assemblies of our products in different configurations
The products themselves are modular and fit together almost like a puzzle. The demo will have a floating control panel to the side of the screen and you will be able to click on an icon button and drag and that product will appear so you can place it in the scene. Then you grab another product and place it in the scene or snap it to part of another product.
Products should snap together allowing you to build lots of different configurations.
Other things it should do include being able to save the configuration as you would save a game level. This allows the save to be emailed back to me at the office so i can then export a dxf and dimension a drawing in autocad. Also a print button would be good, and as these products are for the water play industry in leisure centers and swimming pools a tap icon could be used to start water pouring out of the ends.
So the question is:
I think i have the knowledge to do a lot of this, but some of it will be tricky. The snapping together of parts in the game engine for example.
Does anyone have any hits and trick of how to do this?
I’m new to Blender and Python. But i have found a way to move objects with the mouse using set parent. Also inserting different components into the scene using overlays could be done. But my knowledge of Python is limited
You need the pieces to snap to specific parts of the other pieces. Or snap anywhere their faces touch?
First case would be easy with python. You could just have different empties parented to each piece identifying where each snapping spot is. Then you iterate through the children of the target object checking the distance to each one using KX_GameObject.getDistanceTo() then you just set your .position to the nearest one.
But on the second case it would be a little bit more complicated, you’d need to use .rayCast() to check the collision point to the target object and place yourself there. But depending on your pieces you might need to check for multiple collision points. I’m not sure how to do this myself, would need some experimenting and trial and error.
I liked how you did it to move the object. But is it intended that the dragged object changes orientation with the camera? Maybe you want to change only the position and not the orientation?
In your case you could use empties to snap one thing to another like I said, should be easy. Just place an empty on each snappable face and parent it to the object. Then you check which one is the nearest empty to the object being dragged and just change the .worldPosition to the difference between your object empty and the target object empty.