Chrome console.log(x) output when "object" x value is a number

Sorry to post such a basic JS and browser question BUT here goes:

Given a plane buffer object with these dimensions:
let numHVerts = geometry.heightSegments + 1;
etc. for numWVerts

let numVerts = numHVerts * numWVerts;

output of console.log(numVerts) is NaN.

I understand what I need is the value of the object numVerts but I have burned up the Internet looking for helpful way around my stupidly simple problem.

Can anyone point me to a solution? Thanks a million!

For the PlaneBufferGeometry the segment counts seem to be under the parameters keyword.
So like:

var numHVerts = geometry.parameters.heightSegments + 1;
var numWVerts = geometry.parameters.widthSegments + 1;
var numVerts = numHVerts * numWVerts;

If you are only interested in the total vert count you could just ask this:

var numVerts = geometry.attributes.position.count;

JSFiddle Example

2 Likes

jee7: Thanks for your comments. You have solved my problem!

I was using an access method into geometry I found in Stack Overflow. But notice the value for numHVerts was given as geometry.heightSegments + 1 with the term .parameters missing.

No wonder console.log() wasn’t working. Evidently I have lots to learn in geometry and mesh documentation.

@bob1942 the best thing to do when you run into a problem like this is console.log( geometry ). Then you can take a look at geometry’s properties and make sure that you are using them correctly. Usually faster than looking up the docs.

4 Likes

looeee: Aha! Thanks for this tip.