Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion packages/dev/core/src/Morph/morphTargetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,19 @@ export class MorphTargetManager implements IDisposable {
* Gets the number of influencers (ie. the number of targets with influences > 0)
*/
public get numInfluencers(): number {
if (this._influencesAreDirty) {
this._syncActiveTargets();
}
return this._activeTargets.length;
}

/**
* Gets the list of influences (one per target)
*/
public get influences(): Float32Array {
if (this._influencesAreDirty) {
this._syncActiveTargets();
}
return this._influences;
}

Expand Down Expand Up @@ -330,6 +336,9 @@ export class MorphTargetManager implements IDisposable {
* @returns the requested target
*/
public getActiveTarget(index: number): MorphTarget {
if (this._influencesAreDirty) {
this._syncActiveTargets();
}
return this._activeTargets.data[index];
}

Expand Down Expand Up @@ -357,6 +366,9 @@ export class MorphTargetManager implements IDisposable {
return null;
}

private _influencesAreDirty = false;
private _needUpdateInfluences = false;

/**
* Add a new target to this manager
* @param target defines the target to add
Expand All @@ -368,7 +380,8 @@ export class MorphTargetManager implements IDisposable {
if (this.areUpdatesFrozen && needUpdate) {
this._forceUpdateWhenUnfrozen = true;
}
this._syncActiveTargets(needUpdate);
this._influencesAreDirty = true;
this._needUpdateInfluences = this._needUpdateInfluences || needUpdate;
})
);
this._targetDataLayoutChangedObservers.push(
Expand Down Expand Up @@ -405,6 +418,9 @@ export class MorphTargetManager implements IDisposable {
* @internal
*/
public _bind(effect: Effect) {
if (this._influencesAreDirty) {
this._syncActiveTargets();
}
effect.setFloat3("morphTargetTextureInfo", this._textureVertexStride, this._textureWidth, this._textureHeight);
effect.setFloatArray("morphTargetTextureIndices", this._morphTargetTextureIndices);
effect.setTexture("morphTargets", this._targetStoreTexture);
Expand Down Expand Up @@ -461,6 +477,11 @@ export class MorphTargetManager implements IDisposable {
return;
}

needUpdate = needUpdate || this._needUpdateInfluences;

this._needUpdateInfluences = false;
this._influencesAreDirty = false;

const wasUsingTextureForTargets = !!this._targetStoreTexture;
const isUsingTextureForTargets = this.isUsingTextureForTargets;

Expand Down
Loading