Skip to content

Commit

Permalink
fix CylinderGeometry
Browse files Browse the repository at this point in the history
  • Loading branch information
Codeboy-cn committed Oct 8, 2024
1 parent a38371a commit 9f56463
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/components/renderer/RenderNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,11 @@ export class RenderNode extends ComponentBase {
return;
let renderNode = this;
let worldMatrix = renderNode.transform._worldMatrix;
for (let i = 0; i < renderNode.materials.length; i++) {
const material = renderNode.materials[i];

const nCount = Math.max(renderNode.materials.length, renderNode._geometry.subGeometries.length);

for (let i = 0; i < nCount; i++) {
const material = i >= renderNode.materials.length ? renderNode.materials[0] : renderNode.materials[i];
if (!material || !material.enable)
continue;

Expand Down Expand Up @@ -409,7 +412,7 @@ export class RenderNode extends ComponentBase {
if (noneShare) {
ProfilerUtil.viewCount_pipeline(view, PassType[passType]);
}
let subGeometry = renderNode._geometry.subGeometries[i];
let subGeometry = i >= renderNode._geometry.subGeometries.length ? renderNode._geometry.subGeometries[0] : renderNode._geometry.subGeometries[i];
let lodInfos = subGeometry.lodLevels;
let lodInfo = lodInfos[renderNode.lodLevel];

Expand Down
20 changes: 12 additions & 8 deletions src/shape/CylinderGeometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class CylinderGeometry extends GeometryBase {
* @param count
* @param index
*/
private addGroup(start, count, index) {
private addGroup(start: number, count: number, index: number) {
this.addSubGeometry({
indexStart: start,
indexCount: count,
Expand All @@ -92,13 +92,13 @@ export class CylinderGeometry extends GeometryBase {
this.radialSegments = Math.floor(this.radialSegments);
this.heightSegments = Math.floor(this.heightSegments);

const vertices = [];
const normals = [];
const uvs = [];
const indices = [];
const vertices: number[] = [];
const normals: number[] = [];
const uvs: number[] = [];
const indices: number[] = [];

let index = 0;
const indexArray = [];
const indexArray: number[][] = [];
const halfHeight = this.height / 2;
let groupStart = 0;

Expand Down Expand Up @@ -137,7 +137,11 @@ export class CylinderGeometry extends GeometryBase {
for (let x = 0; x <= that.radialSegments; x++) {
const u = x / that.radialSegments;

const theta = u * that.thetaLength + that.thetaStart;
let theta = u * that.thetaLength + that.thetaStart;

if (x == that.radialSegments && Math.abs(that.thetaLength - that.thetaStart) == Math.PI * 2) {
theta = 0 * that.thetaLength + that.thetaStart;
}

const sinTheta = Math.sin(theta);
const cosTheta = Math.cos(theta);
Expand Down Expand Up @@ -179,7 +183,7 @@ export class CylinderGeometry extends GeometryBase {
groupStart += groupCount;
}

function generateCap(top) {
function generateCap(top: boolean) {
const centerIndexStart = index;

const uv = new Vector2();
Expand Down

0 comments on commit 9f56463

Please sign in to comment.