Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions src/core/BufferGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,28 +469,28 @@ class BufferGeometry extends EventDispatcher {

computeTangents() {

const index = this.index;
const attributes = this.attributes;

// based on http://www.terathon.com/code/tangent.html
// (per vertex tangents)

if ( index === null ||
attributes.position === undefined ||
if ( attributes.position === undefined ||
attributes.normal === undefined ||
attributes.uv === undefined ) {

console.error( 'THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' );
console.error( 'THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (position, normal or uv)' );
return;

}

const indices = index.array;
const index = this.index;
const indices = index ? index.array : null;
const positions = attributes.position.array;
const normals = attributes.normal.array;
const uvs = attributes.uv.array;

const nVertices = positions.length / 3;
const nIndices = index ? index.count : nVertices;

if ( attributes.tangent === undefined ) {

Expand Down Expand Up @@ -561,7 +561,7 @@ class BufferGeometry extends EventDispatcher {

groups = [ {
start: 0,
count: indices.length
count: nIndices
} ];

}
Expand All @@ -575,11 +575,18 @@ class BufferGeometry extends EventDispatcher {

for ( let j = start, jl = start + count; j < jl; j += 3 ) {

handleTriangle(
indices[ j + 0 ],
indices[ j + 1 ],
indices[ j + 2 ]
);
let j0 = j + 0;
let j1 = j + 1;
let j2 = j + 2;
if ( indices !== null ) {

j0 = indices[ j0 ];
j1 = indices[ j1 ];
j2 = indices[ j2 ];

}

handleTriangle( j0, j1, j2 );

}

Expand Down Expand Up @@ -622,9 +629,20 @@ class BufferGeometry extends EventDispatcher {

for ( let j = start, jl = start + count; j < jl; j += 3 ) {

handleVertex( indices[ j + 0 ] );
handleVertex( indices[ j + 1 ] );
handleVertex( indices[ j + 2 ] );
let j0 = j + 0;
let j1 = j + 1;
let j2 = j + 2;
if ( indices !== null ) {

j0 = indices[ j0 ];
j1 = indices[ j1 ];
j2 = indices[ j2 ];

}

handleVertex( j0 );
handleVertex( j1 );
handleVertex( j2 );

}

Expand Down