hellooooo
hellooooo

Reputation: 33

THREE.js What does this vertices mean in the box geometry?

I have created a box geometry as below,

    const hand1geo = new THREE.BoxGeometry(2, 0.01, 0.2);
    const material_sidehand = new THREE.MeshBasicMaterial({ color: 0x3cc1b7 });
    const sidehand = new THREE.Mesh(hand1geo, material_sidehand);

What I want to do is to extract vertices from this box and I use this,

this.sidehand.attributes.position.array

And what I got is as following, The picture of result. I really don't understand why it just spanned 72 elements(24 vectors) with same value. Why there are 24 vectors here and where have them been defined? Because I wanna use raycaster to do the collision detection later on. I tried to use this.sidehand.vertices but it doesn't work.

Upvotes: 1

Views: 1012

Answers (1)

Mugen87
Mugen87

Reputation: 31026

I tried to use this.sidehand.vertices but it doesn't work.

I don't know what references you used but Mesh never had a property called vertices. You probably refer to the former Geometry class which indeed had this property. However, this class has been deprecated and BufferGeometry is used now instead.

I really don't understand why it just spanned 72 elements(24 vectors) with same value.

The values are not identical. BoxGeometry defines all vertices of the box in local space in a flat array so the data can be directly used by the WebGL API (which is good for performance).

There are 24 vectors because the geometry defines for each side of the box four vertices. Each side is composed of two triangles. This is done so it's possible to generate proper normals and texture coordinates.

I suggest you reconsider to use raw geometry data for collision detection. You are going to achieve much better performance by working with bounding volumes instead.

Upvotes: 1

Related Questions