jnsmalm / pixi3d

The 3D renderer for PixiJS. Seamless integration with 2D applications.
https://pixi3d.org
MIT License
752 stars 43 forks source link

vec3/planes changes errors #167

Closed Unwarped closed 1 year ago

Unwarped commented 1 year ago

Hey jnsmalm. I decided to get back into pixi3D and updated to the latest version. (I think I was using a 2021 build)

But I seem to be getting some math/function errors. This was my old code for raycasting to get ground coordinates:


var normal = new PIXI3D.Vec3.fromValues(0, 1, 0) 
var plane1 = new PIXI3D.Plane(normal, 0) 
var ray = PIXI3D.Camera.main.screenToRay(MouseX, MouseY) 
var raycast = plane1.rayCast(ray); 
var point = ray.getPoint(raycast) 

"Uncaught TypeError: PIXI3D.Vec3.fromValues is not a constructor"

So I removed the "new" on the PIXI3D.Vec3.fromValues() call

But then I get:

"Uncaught TypeError: normal.normalize is not a function"

I tried looking into the source code, and overriding the normal manually but something seems broken.

  constructor(normal, distance) {
  this.distance = distance;
  this._normal = new Point3D();
  this._normal = normal.normalize(this._normal);
}

Please let me know if you have any suggestions. Thanks!

jnsmalm commented 1 year ago

Hey,

The constructor was changed in version 2.0, see https://api.pixi3d.org/classes/Plane.html#constructor - it expects a Point3D, not a Float32Array.

var normal = new PIXI3D.Point3D(0, 1, 0)

Unwarped commented 1 year ago

Thanks jnsmalm it works now! Glad to see all the updates on pixi3D it's an awesome project.