Skip to content

Commit

Permalink
fix(primitivemesh): fix cylinder error (galacean#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
singlecoder authored Oct 8, 2021
1 parent 42b0881 commit 036f7b7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/mesh/PrimitiveMesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ export class PrimitiveMesh {
// Create torso
const thetaStart = Math.PI;
const thetaRange = Math.PI * 2;
const slope = (radiusBottom - radiusTop) / height;
const radiusDiff = radiusBottom - radiusTop;
const slope = radiusDiff / height;
const radiusSlope = radiusDiff / heightSegments;

for (let i = 0; i < torsoVertexCount; ++i) {
const x = i % radialCount;
Expand All @@ -350,7 +352,7 @@ export class PrimitiveMesh {
const theta = thetaStart + u * thetaRange;
const sinTheta = Math.sin(theta);
const cosTheta = Math.cos(theta);
const radius = radiusBottom - y * (radiusBottom - radiusTop);
const radius = radiusBottom - y * radiusSlope;

let posX = radius * sinTheta;
let posY = y * unitHeight - halfHeight;
Expand Down

0 comments on commit 036f7b7

Please sign in to comment.