Skip to content

Commit

Permalink
fix(primitive-mesh): fix normal error for capsule cap (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
singlecoder committed Apr 27, 2022
1 parent 709d09b commit 6400307
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/core/src/mesh/PrimitiveMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,8 @@ export class PrimitiveMesh {
const radialSegmentsReciprocal = 1.0 / radialSegments;
const heightSegmentsReciprocal = 1.0 / heightSegments;

const halfPI = Math.PI / 2;
const doublePI = Math.PI * 2;
const thetaStart = Math.PI;
const thetaRange = Math.PI * 2;

const positions = new Array<Vector3>(totalVertexCount);
const normals = new Array<Vector3>(totalVertexCount);
Expand All @@ -731,7 +731,7 @@ export class PrimitiveMesh {
const y = (i * radialCountReciprocal) | 0;
const u = x * radialSegmentsReciprocal;
const v = y * heightSegmentsReciprocal;
const theta = -halfPI + u * doublePI;
const theta = thetaStart + u * thetaRange;
const sinTheta = Math.sin(theta);
const cosTheta = Math.cos(theta);

Expand Down Expand Up @@ -761,7 +761,7 @@ export class PrimitiveMesh {
radius,
height,
radialSegments,
doublePI,
thetaRange,
torsoVertexCount,
1,
positions,
Expand All @@ -775,7 +775,7 @@ export class PrimitiveMesh {
radius,
height,
radialSegments,
-doublePI,
-thetaRange,
torsoVertexCount + capVertexCount,
-1,
positions,
Expand Down Expand Up @@ -838,7 +838,7 @@ export class PrimitiveMesh {
indicesOffset: number
) {
const radialCount = radialSegments + 1;
const halfHeight = height * 0.5;
const halfHeight = height * 0.5 * posIndex;
const capVertexCount = radialCount * radialCount;
const capRectangleCount = radialSegments * radialSegments;
const radialCountReciprocal = 1.0 / radialCount;
Expand All @@ -854,12 +854,12 @@ export class PrimitiveMesh {
const sinTheta = Math.sin(thetaDelta);

const posX = -radius * Math.cos(alphaDelta) * sinTheta;
const posY = (radius * Math.cos(thetaDelta) + halfHeight) * posIndex;
const posY = radius * Math.cos(thetaDelta) * posIndex + halfHeight;
const posZ = radius * Math.sin(alphaDelta) * sinTheta;

const index = i + offset;
positions[index] = new Vector3(posX, posY, posZ);
normals[index] = new Vector3(posX, posY, posZ);
normals[index] = new Vector3(posX, posY - halfHeight, posZ);
uvs[index] = new Vector2(u, v);
}

Expand Down

0 comments on commit 6400307

Please sign in to comment.