Skip to content

Commit

Permalink
fix(sample): fix Sample_Flame
Browse files Browse the repository at this point in the history
  • Loading branch information
Codeboy-cn committed Jun 26, 2024
1 parent d1c57c8 commit c8dc03d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions samples/compute/flame/FlameSimulator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClusterLightingBuffer, ComputeGPUBuffer, GeometryBase, MeshRenderer, PassType, RendererMask, RendererPassState, SkeletonAnimationComponent, SkinnedMeshRenderer, Time, View3D } from '@orillusion/core';
import { AnimatorComponent, ClusterLightingBuffer, ComputeGPUBuffer, GeometryBase, MeshRenderer, PassType, RendererMask, RendererPassState, SkeletonAnimationComponent, SkinnedMeshRenderer, SkinnedMeshRenderer2, Time, View3D } from '@orillusion/core';
import { FlameSimulatorConfig } from './FlameSimulatorConfig';
import { FlameSimulatorPipeline } from './FlameSimulatorPipeline';

Expand Down Expand Up @@ -52,10 +52,10 @@ export class FlameSimulator extends MeshRenderer {

public nodeUpdate(view: View3D, passType: PassType, renderPassState: RendererPassState, clusterLightingBuffer: ClusterLightingBuffer) {
if (!this.mFlameComputePipeline) {
let skeletonAnimation = this.object3D.getComponentsInChild(SkeletonAnimationComponent)[0];
let skinnedMeshRenderer = this.object3D.getComponentsInChild(SkinnedMeshRenderer)[0];
let animatorComponent = this.object3D.getComponentsInChild(AnimatorComponent)[0];
let skinnedMeshRenderer = this.object3D.getComponentsInChild(SkinnedMeshRenderer2)[0];
let attributeArrays = skinnedMeshRenderer.geometry.vertexAttributeMap;
this.mFlameComputePipeline = new FlameSimulatorPipeline(this.mConfig, skeletonAnimation, skinnedMeshRenderer);
this.mFlameComputePipeline = new FlameSimulatorPipeline(this.mConfig, animatorComponent, skinnedMeshRenderer);
this.mFlameComputePipeline.initParticle(attributeArrays);

let material = this.materials[0];
Expand Down
16 changes: 8 additions & 8 deletions samples/compute/flame/FlameSimulatorPipeline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComputeGPUBuffer, ComputeShader, GPUContext, GlobalBindGroup, SkeletonAnimationComponent, SkinnedMeshRenderer, VertexAttributeData, VertexAttributeName } from '@orillusion/core';
import { AnimatorComponent, ComputeGPUBuffer, ComputeShader, GPUContext, GlobalBindGroup, SkeletonAnimationComponent, SkinnedMeshRenderer, SkinnedMeshRenderer2, VertexAttributeData, VertexAttributeName } from '@orillusion/core';
import { FlameSimulatorBuffer } from './FlameSimulatorBuffer';
import { FlameSimulatorConfig } from './FlameSimulatorConfig';
import { Copy } from './shader/copy.wgsl';
Expand All @@ -11,12 +11,12 @@ export class FlameSimulatorPipeline extends FlameSimulatorBuffer {
protected mSimulationComputeShader: ComputeShader;
protected mCopyComputeShader: ComputeShader;
protected mFirstFrame: boolean = false;
protected mSkeletonAnimation: SkeletonAnimationComponent;
protected mSkinnedMeshRenderer: SkinnedMeshRenderer;
constructor(config: FlameSimulatorConfig, skeletonAnimation: SkeletonAnimationComponent, skinnedMeshRenderer: SkinnedMeshRenderer) {
protected mAnimatorComponent: AnimatorComponent;
protected mSkinnedMeshRenderer: SkinnedMeshRenderer2;
constructor(config: FlameSimulatorConfig, skeletonAnimation: AnimatorComponent, skinnedMeshRenderer: SkinnedMeshRenderer2) {
super(config);
this.mConfig = config;
this.mSkeletonAnimation = skeletonAnimation;
this.mAnimatorComponent = skeletonAnimation;
this.mSkinnedMeshRenderer = skinnedMeshRenderer;
}

Expand Down Expand Up @@ -135,13 +135,13 @@ export class FlameSimulatorPipeline extends FlameSimulatorBuffer {

protected initPipeline() {

this.mBoneMatrixBuffer = new ComputeGPUBuffer(16 * this.mSkeletonAnimation.skeleton.numJoint);
this.mBoneMatrixBuffer = new ComputeGPUBuffer(16 * this.mAnimatorComponent.numJoint);

this.mCopyBoneMatrixComputeShader = new ComputeShader(CopyBoneMatrix.cs);
this.mCopyBoneMatrixComputeShader.setStorageBuffer(`matrixs`, GlobalBindGroup.modelMatrixBindGroup.matrixBufferDst);
this.mCopyBoneMatrixComputeShader.setStorageBuffer(`jointsMatrixIndexTable`, this.mSkeletonAnimation.jointMatrixIndexTableBuffer);
this.mCopyBoneMatrixComputeShader.setStorageBuffer(`jointsMatrixIndexTable`, this.mAnimatorComponent.jointMatrixIndexTableBuffer);
this.mCopyBoneMatrixComputeShader.setStorageBuffer(`bonesTransformMatrix`, this.mBoneMatrixBuffer);
this.mCopyBoneMatrixComputeShader.workerSizeX = Math.ceil(this.mSkeletonAnimation.skeleton.numJoint / 16);
this.mCopyBoneMatrixComputeShader.workerSizeX = Math.ceil(this.mAnimatorComponent.numJoint / 16);

const { NUM, GROUP_SIZE } = this.mConfig;
this.mSimulationComputeShader = new ComputeShader(Simulation.cs);
Expand Down
4 changes: 4 additions & 0 deletions src/components/anim/AnimatorComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ export class AnimatorComponent extends ComponentBase {
this.jointMatrixIndexTableBuffer = new StorageGPUBuffer(this._avatar.count, 0, jointMatrixIndexTable);
}

public get numJoint(): number {
return this._avatar.count;
}

public getJointIndexTable(skinJointsName: Array<string>) {
let result = new Array<number>();
for (let i = 0; i < skinJointsName.length; i++) {
Expand Down

0 comments on commit c8dc03d

Please sign in to comment.