From this interesting discussion I got curious about seeing if I could hook up my SpaceMouse to work in SketchUp Web.
Unfortunately I was unable to find a way to change the camera position (yet).
In another 3D web app that we use for quoting I was able to manipulate the camera, but I’m not quite sure how to calculate all the moves from the six axes.
So I can set the camera position and target like this, but I’m not sure how to calculate the values.
function updateController() {
axes = navigator.getGamepads()[1].axes
pan_lr_delta = axes[0];
pan_ud_delta = axes[2];
zoom_delta = axes[1];
rotate_ud_delta = axes[3];
rotate_lr_delta = axes[4];
orbit_delta = axes[5];
//Set the camera target and position
//???
camera.position.set(x, y, z,);
controls.target.set(x, y, z);
controls.update();
requestAnimationFrame(updateController);
}
PS: @TheOnlyAaron Is there any chance that the same thing could be done in SketchUp Web? It seems like it would be trivial to implement. Obviously there is a camera control in there somewhere already.
It could be trivial, I did the same with other web 3D engines, I have code somewhere that I tried for SketchUp. But for SketchUp I don’t know the API to set the camera position.
I was in talk with engineers at BaseCamp 2018 and the idea did not seem new to them at all. I guess there is a long way from finding out at a hackathon that something is possible to making it part of a supportable product.
I have some js code somewhere. Roughly a year ago i made a space mouse controlled relay board. The actual code interacting with the spacemouse was in JS.
I will set a note in my agenda for next monday to try to find it again.
Don’t bother I finally got it figured out. Perhaps not the easiest way but it is totally working. I used inject code extension to automatically insert the js into the website when it loads. Yeah! I’ve implemented SpaceMouse control for SmartBuild.
EDIT: Added code to turn off input if document is not focused.
Sure
But my goal was to control a toy tower crane with the space mouse.
It was at the beginning of the pandemic when my son said that he was unable to play with his crane, since Kraanman (dutch for crane operator) was unable to come to work, since “all mommies and dads” needed to work from home… so I picked up some laying around parts and made the guy’s crane remote controlled…
In the end the relay board got hooked up to a raspberry pi running an asp.net core webservice + a video streaming service and a react.js frontend. So that the laptop could use that frontend to communicate with the backend services and the spacemouse. And, correct as you say, I did not take into account the variable input. Instead of using a relay board, feeding some mosfets with a pwm signal based on the variable input… would be better. Maybe next time
Now, other than that… we are waiting for ages now, for a SketchUp web API…
How did you do the calibration (e.g. find the factors to multiply with the gamepad axes signals)?
I suppose that it varies from device to device and that might be the reason why their hackathon project did not find its way into the product.
Also it would be code that depends on a product that is controlled by another company (3dconnexion) who might introduce changes or release new devices that work slightly differently so that it is hard for SketchUp to ensure a consistent experience.
I played around till it felt right. I imagine ‘real support’ would need to allow the user to set the sensitivity, as well as allow the option to reverse the direction, as I has to do for some of the axes.
Not really. Gamepad API is universal. If they made the axis customizable so the end user could select which axes controls what function, any gamepad device could be used, not just the SpaceMouse. Settings would of course need to be per device id, in case the user has multiple devices.
There are really only three things that could change.
True! Also, why I think SketchUp for Web could provide so much additional value by supporting 3 axis controllers (any controller!). It could even be a unique selling point which makes SketchUp Web (within the Studio subscription) more attractive than Pro. Isn’t that what everone says: “What do I want with all the extra stuff in Studio if Pro has all I need?”
I was thinking of setting reasonable defaults (without burdening users with too much GUI), which is hard when there are differences from device to device.
I find it unlikely anyone will provide assistance for an internal API. Even if it is possible to interact with SketchUp for web using Javascript, doing so before there is a formal API is very fragile. An internal API could change at any time, and may also lack the safeguards a public API has to prevent corruption and data loss.