Skip to content

Commit

Permalink
Fix #14466 (#14471)
Browse files Browse the repository at this point in the history
  • Loading branch information
deltakosh committed Oct 26, 2023
1 parent 3832782 commit 98811d5
Show file tree
Hide file tree
Showing 4 changed files with 1,156 additions and 1,121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NodeGeometryBlockConnectionPointTypes } from "../../Enums/nodeGeometryC
import type { NodeGeometryBuildState } from "../../nodeGeometryBuildState";
import type { INodeGeometryExecutionContext } from "../../Interfaces/nodeGeometryExecutionContext";
import type { VertexData } from "../../../mesh.vertexData";
import { Vector3 } from "../../../../Maths/math.vector";
import { Vector2, Vector3 } from "../../../../Maths/math.vector";
import { PropertyTypeForEdition, editableInPropertyPage } from "../../../../Decorators/nodeDecorator";
import type { Nullable } from "../../../../types";
import type { INodeGeometryInstancingContext } from "../../Interfaces/nodeGeometryInstancingContext";
Expand All @@ -18,11 +18,15 @@ export class InstantiateOnFacesBlock extends NodeGeometryBlock implements INodeG
private _currentFaceIndex: number;
private _currentLoopIndex: number;
private _currentPosition = new Vector3();
private _currentUV = new Vector2();
private _vertex0 = new Vector3();
private _vertex1 = new Vector3();
private _vertex2 = new Vector3();
private _tempVector0 = new Vector3();
private _tempVector1 = new Vector3();
private _uv0 = new Vector2();
private _uv1 = new Vector2();
private _uv2 = new Vector2();

/**
* Gets or sets a boolean indicating that this block can evaluate context
Expand Down Expand Up @@ -101,6 +105,14 @@ export class InstantiateOnFacesBlock extends NodeGeometryBlock implements INodeG
return Vector3.Cross(this._tempVector1, this._tempVector0);
}

/**
* Gets the value associated with a contextual UV1 se
* @returns the value associated with the source
*/
public getOverrideUVs1ContextualValue() {
return this._currentUV;
}

/**
* Gets the current class name
* @returns the class name
Expand Down Expand Up @@ -185,18 +197,28 @@ export class InstantiateOnFacesBlock extends NodeGeometryBlock implements INodeG
this._currentLoopIndex = 0;

for (this._currentFaceIndex = 0; this._currentFaceIndex < faceCount; this._currentFaceIndex++) {
// Extract face vertices
this._vertex0.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3] * 3);
this._vertex1.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3 + 1] * 3);
this._vertex2.fromArray(this._vertexData.positions, this._vertexData.indices[this._currentFaceIndex * 3 + 2] * 3);

accumulatedCount += instancePerFace;
const countPerFace = (accumulatedCount | 0) - totalDone;

if (countPerFace < 1) {
continue;
}

const faceID0 = this._vertexData.indices[this._currentFaceIndex * 3];
const faceID1 = this._vertexData.indices[this._currentFaceIndex * 3 + 1];
const faceID2 = this._vertexData.indices[this._currentFaceIndex * 3 + 2];

// Extract face vertices
this._vertex0.fromArray(this._vertexData.positions, faceID0 * 3);
this._vertex1.fromArray(this._vertexData.positions, faceID1 * 3);
this._vertex2.fromArray(this._vertexData.positions, faceID2 * 3);

if (this._vertexData.uvs) {
this._uv0.fromArray(this._vertexData.uvs, faceID0 * 2);
this._uv1.fromArray(this._vertexData.uvs, faceID1 * 2);
this._uv2.fromArray(this._vertexData.uvs, faceID2 * 2);
}

for (let faceDispatchCount = 0; faceDispatchCount < countPerFace; faceDispatchCount++) {
if (totalDone >= instanceCount) {
break;
Expand All @@ -221,6 +243,10 @@ export class InstantiateOnFacesBlock extends NodeGeometryBlock implements INodeG
s * this._vertex0.z + t * this._vertex1.z + u * this._vertex2.z
);

if (this._vertexData.uvs) {
this._currentUV.set(s * this._uv0.x + t * this._uv1.x + u * this._uv2.x, s * this._uv0.y + t * this._uv1.y + u * this._uv2.y);
}

// Clone the instance
instanceGeometry = this.instance.getConnectedValue(state) as VertexData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ export interface INodeGeometryExecutionContext {
* @returns the value associated with the source
*/
getOverrideNormalsContextualValue?(): any;

/**
* Gets the value associated with a contextual UV1 set
* @returns the value associated with the source
*/
getOverrideUVs1ContextualValue?(): any;
}
3 changes: 3 additions & 0 deletions packages/dev/core/src/Meshes/Node/nodeGeometryBuildState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export class NodeGeometryBuildState {
}
return Vector4.FromArray(this.geometryContext.tangents as ArrayLike<number>, index * 4);
case NodeGeometryContextualSources.UV:
if (this.executionContext.getOverrideUVs1ContextualValue) {
return this.executionContext.getOverrideUVs1ContextualValue();
}
if (!this.geometryContext || !this.geometryContext.uvs) {
return Vector2.Zero();
}
Expand Down

0 comments on commit 98811d5

Please sign in to comment.