Godot: 3D Connexion SpaceMouse Support

Created on 28 May 2019  路  6Comments  路  Source: godotengine/godot

Issue description:
Does the Godot engine support 3D connexion space mouse. I do not believe it does, so I'm interested in adding it. I'm new to the Godot engine, but love all the potential. So I'm interested in knowing how does someone go about adding support for a new peripheral type for us inside the editor? I have the source code for Godot and I have the SDK for the device, but inexperience leaves me in the dark with a good place to start implementation.

Thanks in advance!

archived feature proposal input

Most helpful comment

Wow! Fantastic! Can you give us more details on how and if your script works with Godot Engine specifically? I'm an aspiring game developer and I feel like one of my hands is tied behind my back when trying to develop without my spacemouse. I can change the button macro's to control functions easily enough. And using controlmyjoystick, I was able to get some semblance of control in free-look via joystick emulation, but that was hardly optimal. Would your swift code be implemented into Godot as a plugin, or a module? Thanks in advance -CS

All 6 comments

Well, the first thing to do would be to test whether it already works :)

Assuming it doesn't, the second thing would be to research how one would go about adding such support You mentioned a SDK, that probably has docs. Read those.

Also, I found this older forum thread:
https://www.3dconnexion.com/forum/viewtopic.php?t=3651

If that is still correct, the developers recommend against using their SDK on Windows and going with the native raw input APIs.

So then you would search Godot (the repository, issues, PRs) for things related to raw input.

This added raw input for Windows:
https://github.com/godotengine/godot/pull/20523

And this for Linux:
https://github.com/godotengine/godot/pull/19191

Those should point you in the right directions and at the right files.

There are docs on building Godot:
http://docs.godotengine.org/en/3.1/development/compiling/

Thhere are docs on creating custom Godot modules:
http://docs.godotengine.org/en/3.1/development/cpp/custom_modules_in_cpp.html

There are docs on creating custom Godot plugins:
https://docs.godotengine.org/en/3.1/tutorials/plugins/index.html

Note that we will be unlikely to merge any code specific to a proprietary, commercial vendor, unless we absolutely must because their marketshare and user demand is too big to ignore (e.g. Windows or FBX).

Anything that is exclusively useful for 3D Connexion will thus need to be provided as a third-party plugin or module, for which Godot already provides interfaces; we're open to adding to these interfaces if required to make such a plugin or module work, however.

in my experience with a 3dConnexion Space Mouse Compact - the SDK they provide isn't required to get input data from the device. I've not done anything with Godot Engine yet, but would love it! I'm still a noob with Godot Engine, but I think it should be doable. I imagine a C++ plugin would be a good approach, just link in the 3dConnexion dynamic library and call into it.

//
//  MouseState.swift
//  SpaceMouse
//
//  Created by Andrew Andkjar on 3/1/19.
//  Copyright 漏 2019 auto-accrete. All rights reserved.
//

import Foundation

public typealias CGF = CGFloat

public struct MouseState : Codable {

    public let tx, ty, tz, rx, ry, rz: Int16!
    public let t: Date = Date.init()

    public init(translateX: Int16,
                translateY: Int16,
                translateZ: Int16,
                rotateX: Int16,
                rotateY: Int16,
                rotateZ: Int16) {

        self.tx = translateX
        self.ty = translateY
        self.tz = translateZ

        self.rx = rotateX
        self.ry = rotateY
        self.rz = rotateZ
    }

    public init() {
        self.init(translateX: 0, translateY: 0, translateZ: 0, rotateX: 0, rotateY: 0, rotateZ: 0)
    }

    public func smooth() -> SmoothMouseState {
        return SmoothMouseState(
            translateX: CGF(self.tx),
            translateY: CGF(self.ty),
            translateZ: CGF(self.tz),
            rotateX: CGF(self.rx),
            rotateY: CGF(self.ry),
            rotateZ: CGF(self.rz))
    }
}

public struct SmoothMouseState : Codable {

    public let tx, ty, tz, rx, ry, rz: CGF!
    public let t: Date = Date.init()

    public init(translateX: CGF,
                translateY: CGF,
                translateZ: CGF,
                rotateX: CGF,
                rotateY: CGF,
                rotateZ: CGF) {

        self.tx = translateX
        self.ty = translateY
        self.tz = translateZ

        self.rx = rotateX
        self.ry = rotateY
        self.rz = rotateZ
    }

    public init() {
        self.init(translateX: 0, translateY: 0, translateZ: 0, rotateX: 0, rotateY: 0, rotateZ: 0)
    }
}

public struct MouseStateSequence {
    private var n = 0
    private var seq: [MouseState] = []
    private var count = 0

    public init(sampleCount: Int) {
        count = sampleCount
        for _ in 0 ... count {
            seq.append(MouseState())
        }
    }

    public mutating func update(ms: MouseState) {
        seq[n] = ms
        n += 1
        if n >= count {
            n = 0
        }
    }

    public func smoothState() -> SmoothMouseState {
        let s: CGF = CGF(1.0) / CGF(seq.count)

        let smoothed = seq.reduce(seq[0].smooth(), { prev, next in

            let tx = CGF(prev.tx) + CGF(next.tx) * s
            let ty = CGF(prev.ty) + CGF(next.ty) * s
            let tz = CGF(prev.tz) + CGF(next.tz) * s

            let rx = CGF(prev.rx) + CGF(next.rx) * s
            let ry = CGF(prev.ry) + CGF(next.ry) * s
            let rz = CGF(prev.rz) + CGF(next.rz) * s

            return SmoothMouseState(
                translateX: tx,
                translateY: ty,
                translateZ: tz,
                rotateX: rx,
                rotateY: ry,
                rotateZ: rz)
        })

        return smoothed
    }

}

// Y translate positive toward the wire
// X translate positive at right of the wire
// Z translate positive is down

// X rotate positive is away from the wire
// Y rotate positive is counter-clockwise
// Z rotate positive is clockwise

here's some Swift language code I've had operational. Tricky bits on macOS at least for me was getting the bridging header setup as well as tracking down the 3dConnexion framework path -

/Library/Frameworks/3DconnexionClient.framework/

Wow! Fantastic! Can you give us more details on how and if your script works with Godot Engine specifically? I'm an aspiring game developer and I feel like one of my hands is tied behind my back when trying to develop without my spacemouse. I can change the button macro's to control functions easily enough. And using controlmyjoystick, I was able to get some semblance of control in free-look via joystick emulation, but that was hardly optimal. Would your swift code be implemented into Godot as a plugin, or a module? Thanks in advance -CS

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

Was this page helpful?
0 / 5 - 0 ratings