Jump to content

[SOLVED] BABYLON.Vector3.Project returning NaN


Tim_Rosskamp
 Share

Recommended Posts

Hey,

I have a problem with the function Project function inside the Vector3 class.

This is my code:

var screenXY = BABYLON.Vector3.Project(
    new BABYLON.Vector3(10, 10, 10),
    BABYLON.Matrix.Identity(),
    scene.getTransformMatrix(),
    camera.viewport.toGlobal(engine.getRenderWidth(true), engine.getRenderHeight(true))
);

What I want to do is get the 2d screen x/y position from a 3d vector.

 

And this is what gets returned from the function:

Vector3 {x: NaN, y: NaN, z: NaN}

 

How can I fix this?

Link to comment
Share on other sites

Howdy @Tim_Rosskamp,

is it by anc chance the first frame of the scene? In this case - just wait for the second one :)

Simple example here - https://www.babylonjs-playground.com/#6XQZ4P

The first frame is nan, probably because of the transformation matrix, but after everything is set, it is calculated correctly.

Link to comment
Share on other sites

  • Tim_Rosskamp changed the title to [SOLVED] BABYLON.Vector3.Project returning NaN

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...