diff --git a/src/components/renderer/RenderNode.ts b/src/components/renderer/RenderNode.ts index 5df939fa..a2359794 100644 --- a/src/components/renderer/RenderNode.ts +++ b/src/components/renderer/RenderNode.ts @@ -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; @@ -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]; diff --git a/src/shape/CylinderGeometry.ts b/src/shape/CylinderGeometry.ts index 0a853237..0ef785d5 100644 --- a/src/shape/CylinderGeometry.ts +++ b/src/shape/CylinderGeometry.ts @@ -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, @@ -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; @@ -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); @@ -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();