Skip to content

Commit

Permalink
fix(geometry): CylinderGeometry non-manifold (#451)
Browse files Browse the repository at this point in the history
1. fix end vertex position on cap
2. fix missing materials for sub-geometry, use first mat by default
  • Loading branch information
Codeboy-cn authored Oct 8, 2024
1 parent c54e7bf commit bf14c61
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/geometry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export * from "./text/TextGeometry"
export * from "./terrain/TerrainGeometry"
export * from "./grass/GrassGeometry"
export * from "./grass/component/GrassComponent";
export * from "./grass/material/GrassMaterial";
export * from "./grass/material/GrassMaterial";
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
22 changes: 12 additions & 10 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 @@ -136,8 +136,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;
}

const sinTheta = Math.sin(theta);
const cosTheta = Math.cos(theta);
Expand All @@ -154,7 +157,6 @@ export class CylinderGeometry extends GeometryBase {

// uv
uvs.push(u, 1 - v);

indexRow.push(index++);
}

Expand All @@ -179,7 +181,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 bf14c61

Please sign in to comment.