Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NME: Fix preview for some of the pre-defined meshes #14774

Merged
merged 1 commit into from Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -125,9 +125,9 @@ export class HeightToNormalBlock extends NodeMaterialBlock {

const heightToNormal = `
vec4 heightToNormal(in float height, in vec3 position, in vec3 tangent, in vec3 normal) {
${startCode}
${this.automaticNormalizationTangent ? "tangent = normalize(tangent);" : ""}
${this.automaticNormalizationNormal ? "normal = normalize(normal);" : ""}
${startCode}
vec3 worlddX = dFdx(position);
vec3 worlddY = dFdy(position);
vec3 crossX = cross(normal, worlddX);
Expand Down
11 changes: 11 additions & 0 deletions packages/dev/core/src/Meshes/mesh.ts
Expand Up @@ -2786,6 +2786,17 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
this.setVerticesData(VertexBuffer.NormalKind, data, (<VertexBuffer>this.getVertexBuffer(VertexBuffer.NormalKind)).isUpdatable());
}

// Tangents
if (this.isVerticesDataPresent(VertexBuffer.TangentKind)) {
data = <FloatArray>this.getVerticesData(VertexBuffer.TangentKind);
for (index = 0; index < data.length; index += 4) {
Vector3.TransformNormalFromFloatsToRef(data[index], data[index + 1], data[index + 2], transform, temp)
.normalize()
.toArray(data, index);
}
this.setVerticesData(VertexBuffer.TangentKind, data, (<VertexBuffer>this.getVertexBuffer(VertexBuffer.TangentKind)).isUpdatable());
}

// flip faces?
if (transform.determinant() < 0) {
this.flipFaces();
Expand Down
Expand Up @@ -420,20 +420,21 @@ export class PreviewManager {
const bakeTransformation = (mesh: Mesh) => {
mesh.bakeCurrentTransformIntoVertices();
mesh.refreshBoundingInfo();
mesh.parent = null;
};

if (this._globalState.mode === NodeMaterialModes.Material) {
switch (this._globalState.previewType) {
case PreviewType.Box:
SceneLoader.AppendAsync("https://assets.babylonjs.com/meshes/", "roundedCube.glb", this._scene).then(() => {
bakeTransformation(this._scene.meshes[1] as Mesh);
bakeTransformation(this._scene.getMeshByName("__root__")!.getChildMeshes(true)[0] as Mesh);
RaananW marked this conversation as resolved.
Show resolved Hide resolved
this._meshes.push(...this._scene.meshes);
this._prepareScene();
});
return;
case PreviewType.Sphere:
SceneLoader.AppendAsync("https://assets.babylonjs.com/meshes/", "previewSphere.glb", this._scene).then(() => {
bakeTransformation(this._scene.meshes[1] as Mesh);
bakeTransformation(this._scene.getMeshByName("__root__")!.getChildMeshes(true)[0] as Mesh);
this._meshes.push(...this._scene.meshes);
this._prepareScene();
});
Expand All @@ -459,7 +460,7 @@ export class PreviewManager {
return;
case PreviewType.Plane: {
SceneLoader.AppendAsync("https://assets.babylonjs.com/meshes/", "highPolyPlane.glb", this._scene).then(() => {
bakeTransformation(this._scene.meshes[1] as Mesh);
bakeTransformation(this._scene.getMeshByName("__root__")!.getChildMeshes(true)[0] as Mesh);
this._meshes.push(...this._scene.meshes);
this._prepareScene();
});
Expand Down