From 794b4f2dd772bf3334408ad9eb76070a7c3f6f73 Mon Sep 17 00:00:00 2001 From: David Catuhe Date: Tue, 3 Oct 2023 12:27:31 -0700 Subject: [PATCH] Fix #14381 (#14386) --- .../Meshes/Node/Blocks/Sources/meshBlock.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/dev/core/src/Meshes/Node/Blocks/Sources/meshBlock.ts b/packages/dev/core/src/Meshes/Node/Blocks/Sources/meshBlock.ts index b76d9faf111..f9f608efa7a 100644 --- a/packages/dev/core/src/Meshes/Node/Blocks/Sources/meshBlock.ts +++ b/packages/dev/core/src/Meshes/Node/Blocks/Sources/meshBlock.ts @@ -5,6 +5,7 @@ import { RegisterClass } from "../../../../Misc/typeStore"; import type { Mesh } from "../../../../Meshes/mesh"; import { VertexData } from "../../../../Meshes/mesh.vertexData"; import type { Nullable } from "../../../../types"; +import { PropertyTypeForEdition, editableInPropertyPage } from "core/Decorators/nodeDecorator"; /** * Defines a block used to generate a user defined mesh geometry data @@ -13,6 +14,12 @@ export class MeshBlock extends NodeGeometryBlock { private _mesh: Nullable; private _cachedVertexData: Nullable = null; + /** + * Gets or sets a boolean indicating that winding order needs to be reserved + */ + @editableInPropertyPage("reverseWindingOrder", PropertyTypeForEdition.Boolean, "ADVANCED", { notifiers: { rebuild: true } }) + public reverseWindingOrder = false; + /** * Gets or sets the mesh to use to get vertex data */ @@ -69,6 +76,14 @@ export class MeshBlock extends NodeGeometryBlock { const vertexData = VertexData.ExtractFromMesh(this._mesh, false, true); this._cachedVertexData = null; + if (this.reverseWindingOrder && vertexData.indices) { + for (let index = 0; index < vertexData.indices.length; index += 3) { + const tmp = vertexData.indices[index]; + vertexData.indices[index] = vertexData.indices[index + 2]; + vertexData.indices[index + 2] = tmp; + } + } + this.geometry._storedFunction = () => { return vertexData.clone(); }; @@ -90,6 +105,8 @@ export class MeshBlock extends NodeGeometryBlock { } } + serializationObject.reverseWindingOrder = this.reverseWindingOrder; + return serializationObject; } @@ -99,6 +116,8 @@ export class MeshBlock extends NodeGeometryBlock { if (serializationObject.cachedVertexData) { this._cachedVertexData = VertexData.Parse(serializationObject.cachedVertexData); } + + this.reverseWindingOrder = serializationObject.reverseWindingOrder; } }