bug: vec3 does not support overload using + operator

Options
yc
yc Posts: 41 🔥
edited July 2022 in Programming #1

Edit: it looks like vector addition + overload is not added to vec3... so basically to add a vector, instead of being able to do v3 = v1+v2; you have to do `var v3 = new vec3(0,0,0); v3.add(v1); v3.add(v2);

(I can't tell if this is a bug report or if I am not calling the API correctly.)

It seems that when a function generates a vec3, and tries assigning it to local or world position of a transform .setLocalPosition() (for example), this error occurs " Error: Argument 0: Value is not a native object
at [anon] () native strict preventsyield"

var threesixty52 = 0.12083048667; //360/52 * PI/180
var radius = 5;  

    function GetPos(n){
        return new vec3(Math.cos(-n * threesixty52)*radius,0, Math.sin (-n*threesixty52)*radius) ;
    }

var go = global.scene.createSceneObject("TEST");

 go.getTransform().setLocalPosition(GetPos(1)); 

Answers

  • yc
    yc Posts: 41 🔥
    Options

    it looks like vector addition + overload is not added to vec3... so basically to add a vector, instead of being able to do v3 = v1+v2; you have to do var v3 = new vec3(0,0,0); v3.add(v1); v3.add(v2);

  • Joshua Beckwith
    Joshua Beckwith Posts: 18 🔥
    Options

    Overloading operators isn't supported at all in JS, as far as I know. It would be nice to have though. It looks like there are some hacky workarounds, but I sort of doubt they would work in LS because the JS runtime doesn't even support things like class or const...

    https://stackoverflow.com/questions/19620667/javascript-operator-overloading