Browse Source

Merge pull request #9094 from sebavan/master

Fix default sphere layout for back compat.
David Catuhe 4 năm trước cách đây
mục cha
commit
591e0eebb1
2 tập tin đã thay đổi với 22 bổ sung10 xóa
  1. 1 1
      dist/preview release/what's new.md
  2. 21 9
      src/Meshes/Builders/sphereBuilder.ts

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

@@ -324,7 +324,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))
+- Fixed bug in sphereBuilder where top and bottom segments added 6 indices per triangle instead of 3. (use option dedupTopBottomIndices to enable it) ([aWeirdo](https://github.com/aWeirdo))
 - Fixed issue with Babylon scene export of loaded glTF meshes.([Drigax]/(https://github.com/drigax))
 - Fixed an issue with text block wrap and unicode strings (not working in IE11) ([#8822](https://github.com/BabylonJS/Babylon.js/issues/8822)) ([RaananW](https://github.com/RaananW))
 - Fixed an issue with compound initialization that has rotation ([#8744](https://github.com/BabylonJS/Babylon.js/issues/8744)) ([RaananW](https://github.com/RaananW))

+ 21 - 9
src/Meshes/Builders/sphereBuilder.ts

@@ -4,7 +4,7 @@ import { VertexData } from "../mesh.vertexData";
 import { Scene } from "../../scene";
 import { Nullable } from '../../types';
 
-VertexData.CreateSphere = function(options: { segments?: number, diameter?: number, diameterX?: number, diameterY?: number, diameterZ?: number, arc?: number, slice?: number, sideOrientation?: number, frontUVs?: Vector4, backUVs?: Vector4 }): VertexData {
+VertexData.CreateSphere = function(options: { segments?: number, diameter?: number, diameterX?: number, diameterY?: number, diameterZ?: number, arc?: number, slice?: number, sideOrientation?: number, frontUVs?: Vector4, backUVs?: Vector4, dedupTopBottomIndices?: boolean }): VertexData {
     var segments: number = options.segments || 32;
     var diameterX: number = options.diameterX || options.diameter || 1;
     var diameterY: number = options.diameterY || options.diameter || 1;
@@ -12,6 +12,7 @@ VertexData.CreateSphere = function(options: { segments?: number, diameter?: numb
     var arc: number = options.arc && (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
     var slice: number = options.slice && (options.slice <= 0) ? 1.0 : options.slice || 1.0;
     var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;
+    var dedupTopBottomIndices = !!options.dedupTopBottomIndices;
 
     var radius = new Vector3(diameterX / 2, diameterY / 2, diameterZ / 2);
 
@@ -48,15 +49,26 @@ 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++) {
-                if (zRotationStep > 1) {
-                    indices.push((firstIndex));
-                    indices.push((firstIndex + 1));
-                    indices.push(firstIndex + totalYRotationSteps + 1);
+                if (dedupTopBottomIndices) {
+                    if (zRotationStep > 1) {
+                        indices.push((firstIndex));
+                        indices.push((firstIndex + 1));
+                        indices.push(firstIndex + totalYRotationSteps + 1);
+                    }
+                    if (zRotationStep < totalZRotationSteps || slice < 1.0) {
+                        indices.push((firstIndex + totalYRotationSteps + 1));
+                        indices.push((firstIndex + 1));
+                        indices.push((firstIndex + totalYRotationSteps + 2));
+                    }
                 }
-                if (zRotationStep < totalZRotationSteps || slice < 1.0) {
-                    indices.push((firstIndex + totalYRotationSteps + 1));
-                    indices.push((firstIndex + 1));
-                    indices.push((firstIndex + totalYRotationSteps + 2));
+                else {
+                    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);
                 }
             }
         }