Update cloth.component.ts

This commit is contained in:
2026-02-23 11:07:09 +01:00
parent 954211b3cf
commit 746022c48d

View File

@@ -2,7 +2,7 @@ import { Component } from '@angular/core';
import {MatCard, MatCardContent, MatCardHeader, MatCardTitle} from '@angular/material/card'; import {MatCard, MatCardContent, MatCardHeader, MatCardTitle} from '@angular/material/card';
import {TranslatePipe} from '@ngx-translate/core'; import {TranslatePipe} from '@ngx-translate/core';
import {BabylonCanvas, RenderConfig, SceneEventData} from '../../../shared/rendering/canvas/babylon-canvas.component'; import {BabylonCanvas, RenderConfig, SceneEventData} from '../../../shared/rendering/canvas/babylon-canvas.component';
import { ComputeShader, StorageBuffer, MeshBuilder, ShaderMaterial, ShaderLanguage } from '@babylonjs/core'; import {ComputeShader, StorageBuffer, MeshBuilder, ShaderMaterial, ShaderLanguage, ArcRotateCamera} from '@babylonjs/core';
import {CLOTH_FRAGMENT_SHADER_WGSL, CLOTH_INTEGRATE_COMPUTE_WGSL, CLOTH_SOLVE_COMPUTE_WGSL, CLOTH_VELOCITY_COMPUTE_WGSL, CLOTH_VERTEX_SHADER_WGSL} from './cloth.shader'; import {CLOTH_FRAGMENT_SHADER_WGSL, CLOTH_INTEGRATE_COMPUTE_WGSL, CLOTH_SOLVE_COMPUTE_WGSL, CLOTH_VELOCITY_COMPUTE_WGSL, CLOTH_VERTEX_SHADER_WGSL} from './cloth.shader';
@Component({ @Component({
@@ -172,11 +172,16 @@ export class ClothComponent {
shaderLanguage: ShaderLanguage.WGSL shaderLanguage: ShaderLanguage.WGSL
}); });
clothMaterial.backFaceCulling = false;
clothMaterial.setStorageBuffer("positions", positionsBuffer); clothMaterial.setStorageBuffer("positions", positionsBuffer);
clothMesh.material = clothMaterial; clothMesh.material = clothMaterial;
clothMaterial.setStorageBuffer("positions", positionsBuffer); const camera = scene.activeCamera as ArcRotateCamera;
clothMesh.material = clothMaterial; if (camera) {
camera.alpha = Math.PI / 4;
camera.beta = Math.PI / 2.5;
camera.radius = 15;
}
// --- 6. RENDER LOOP --- // --- 6. RENDER LOOP ---
scene.onBeforeRenderObservable.clear(); scene.onBeforeRenderObservable.clear();
@@ -194,14 +199,14 @@ export class ClothComponent {
const dispatchXVertices = Math.ceil(numVertices / 64); const dispatchXVertices = Math.ceil(numVertices / 64);
const dispatchXConstraints = Math.ceil(numConstraints / 64); const dispatchXConstraints = Math.ceil(numConstraints / 64);
csIntegrate.dispatch(dispatchXVertices, 1, 1); /*csIntegrate.dispatch(dispatchXVertices, 1, 1);
// For XPBD stability, you often run the solver multiple times (substeps) // For XPBD stability, you often run the solver multiple times (substeps)
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
csSolve.dispatch(dispatchXConstraints, 1, 1); csSolve.dispatch(dispatchXConstraints, 1, 1);
} }
csVelocity.dispatch(dispatchXVertices, 1, 1); csVelocity.dispatch(dispatchXVertices, 1, 1);*/
}); });
} }
} }