Skip to content

Commit

Permalink
Fix #14381 (#14386)
Browse files Browse the repository at this point in the history
  • Loading branch information
deltakosh authored Oct 3, 2023
1 parent 536ac5f commit 794b4f2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/dev/core/src/Meshes/Node/Blocks/Sources/meshBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,6 +14,12 @@ export class MeshBlock extends NodeGeometryBlock {
private _mesh: Nullable<Mesh>;
private _cachedVertexData: Nullable<VertexData> = 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
*/
Expand Down Expand Up @@ -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();
};
Expand All @@ -90,6 +105,8 @@ export class MeshBlock extends NodeGeometryBlock {
}
}

serializationObject.reverseWindingOrder = this.reverseWindingOrder;

return serializationObject;
}

Expand All @@ -99,6 +116,8 @@ export class MeshBlock extends NodeGeometryBlock {
if (serializationObject.cachedVertexData) {
this._cachedVertexData = VertexData.Parse(serializationObject.cachedVertexData);
}

this.reverseWindingOrder = serializationObject.reverseWindingOrder;
}
}

Expand Down

0 comments on commit 794b4f2

Please sign in to comment.