-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
116 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as THREE from 'three'; | ||
|
||
export class Matrix4InverseCache { | ||
/** | ||
* The target matrix. | ||
*/ | ||
public readonly matrix: THREE.Matrix4; | ||
|
||
/** | ||
* A cache of inverse of current matrix. | ||
*/ | ||
private readonly _inverseCache = new THREE.Matrix4(); | ||
|
||
/** | ||
* A flag that makes it want to recalculate its {@link _inverseCache}. | ||
* Will be set `true` when `elements` are mutated and be used in `getInverse`. | ||
*/ | ||
private _shouldUpdateInverse = true; | ||
|
||
/** | ||
* The original of `matrix.elements` | ||
*/ | ||
private readonly _originalElements: number[]; | ||
|
||
/** | ||
* Inverse of given matrix. | ||
* Note that it will return its internal private instance. | ||
* Make sure copying this before mutate this. | ||
*/ | ||
public get inverse(): THREE.Matrix4 { | ||
if (this._shouldUpdateInverse) { | ||
this._inverseCache.getInverse(this.matrix); | ||
this._shouldUpdateInverse = false; | ||
} | ||
|
||
return this._inverseCache; | ||
} | ||
|
||
public constructor(matrix: THREE.Matrix4) { | ||
this.matrix = matrix; | ||
|
||
const handler: ProxyHandler<number[]> = { | ||
set: (obj, prop: number, newVal) => { | ||
this._shouldUpdateInverse = true; | ||
obj[prop] = newVal; | ||
|
||
return true; | ||
}, | ||
}; | ||
|
||
this._originalElements = matrix.elements; | ||
matrix.elements = new Proxy(matrix.elements, handler); | ||
} | ||
|
||
public revert(): void { | ||
this.matrix.elements = this._originalElements; | ||
} | ||
} |
Oops, something went wrong.