瀏覽代碼

Update sphereBuilder.ts (#8750)

* Update sphereBuilder.ts

Fix sphereBuilder adding 6 indices to the top and bottom segments of sphere (even there's only 1 triangle)

* Update what's new.md (#12)

* Update sphereBuilder.ts
aWeirdo 5 年之前
父節點
當前提交
962f069118
共有 2 個文件被更改,包括 11 次插入7 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 10 7
      src/Meshes/Builders/sphereBuilder.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -285,6 +285,7 @@
 - Fix issue in `GLTFLoader._updateBoneMatrices()` where bone rest position was not set. ([drigax](https://github.com/drigax))
 - Fix the bounding box of instances that does not match the instance position / rotation / scaling ([Popov72](https://github.com/Popov72))
 - Fix an issue with sound updateOptions not updating the underlying sound buffer/html element ([RaananW](https://github.com/RaananW))
+- Fixed bug in sphereBuilder where top and bottom segments added 6 indices per triangle instead of 3. ([aWeirdo](https://github.com/aWeirdo))
 
 ## Breaking changes
 - `FollowCamera.target` was renamed to `FollowCamera.meshTarget` to not be in conflict with `TargetCamera.target` ([Deltakosh](https://github.com/deltakosh))

+ 10 - 7
src/Meshes/Builders/sphereBuilder.ts

@@ -48,13 +48,16 @@ VertexData.CreateSphere = function(options: { segments?: number, diameter?: numb
         if (zRotationStep > 0) {
             var verticesCount = positions.length / 3;
             for (var firstIndex = verticesCount - 2 * (totalYRotationSteps + 1); (firstIndex + totalYRotationSteps + 2) < verticesCount; firstIndex++) {
-                indices.push((firstIndex));
-                indices.push((firstIndex + 1));
-                indices.push(firstIndex + totalYRotationSteps + 1);
-
-                indices.push((firstIndex + totalYRotationSteps + 1));
-                indices.push((firstIndex + 1));
-                indices.push((firstIndex + totalYRotationSteps + 2));
+                if(zRotationStep > 1) {
+                    indices.push((firstIndex));
+                    indices.push((firstIndex + 1));
+                    indices.push(firstIndex + totalYRotationSteps + 1);
+                }
+                if(zRotationStep < totalZRotationSteps) {
+                    indices.push((firstIndex + totalYRotationSteps + 1));
+                    indices.push((firstIndex + 1));
+                    indices.push((firstIndex + totalYRotationSteps + 2));
+                }
             }
         }
     }