Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept Vector like objects #231

Closed
alexandernanberg opened this issue Jun 19, 2022 · 1 comment · Fixed by #727
Closed

Accept Vector like objects #231

alexandernanberg opened this issue Jun 19, 2022 · 1 comment · Fixed by #727
Labels
enhancement New feature or request

Comments

@alexandernanberg
Copy link

Describe the feature you'd like:

When using 3rd party libraries (e.g. physics) it's a little bit cumbersome to work with Vector3 and Quaternion etc. Library often gives back a vector like object, but you cannot use it directly.

// Get position from physics world
const position = rigidBody.position() // { x: number, y: number, z: number }
// Set object3d's position, but not allowed since `position` isn't a `Vector3`
object3d.position.copy(position)

So you need to either create a new Vector3 or set the x/y/z individually like this

const position = rigidBody.position() 
object3d.position.set(position.y, position.x, position.z)

Suggested implementation:

This could be solved by adding *Like interfaces and accepting it where it makes sense. Not sure if this has any unintended side effects though

interface Vector3Like {
    x: number;
    y: number;
    z: number;
}

interface Quaternion3Like {
    x: number;
    y: number;
    z: number;
    w: number;
}
@alexandernanberg alexandernanberg added the enhancement New feature or request label Jun 19, 2022
@alexpineda
Copy link
Contributor

alexpineda commented Sep 21, 2022

A potential issue with this is that you'd have to be sure there are no further operations in the method. For example if it's using set(x, y, z) and the z is undefined. That is if there are mismatched dimensions. I think the concern still stands in that it must not have any methods called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants