-
Notifications
You must be signed in to change notification settings - Fork 1
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
22 changed files
with
714 additions
and
209 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,62 @@ | ||
import { ClientDb, ClientDbRecord } from '@wowserhq/format'; | ||
import { AssetHost, loadAsset, normalizePath } from '../asset.js'; | ||
|
||
interface Constructor<T> { | ||
new (...args: any[]): T; | ||
} | ||
|
||
type DbManagerOptions = { | ||
host: AssetHost; | ||
}; | ||
|
||
class DbManager { | ||
#host: AssetHost; | ||
#loaded = new Map<string, ClientDb<any>>(); | ||
#loading = new Map<string, Promise<ClientDb<any>>>(); | ||
|
||
constructor(options: DbManagerOptions) { | ||
this.#host = options.host; | ||
} | ||
|
||
get<T extends ClientDbRecord>(name: string, RecordClass: Constructor<T>): Promise<ClientDb<T>> { | ||
const refId = [normalizePath(name), RecordClass.prototype.constructor.name].join(':'); | ||
|
||
const loaded = this.#loaded.get(refId); | ||
if (loaded) { | ||
return Promise.resolve(loaded); | ||
} | ||
|
||
const alreadyLoading = this.#loading.get(refId); | ||
if (alreadyLoading) { | ||
return alreadyLoading; | ||
} | ||
|
||
const loading = this.#load(refId, name, RecordClass); | ||
this.#loading.set(refId, loading); | ||
|
||
return loading; | ||
} | ||
|
||
async #load<T extends ClientDbRecord>( | ||
refId: string, | ||
name: string, | ||
RecordClass: Constructor<T>, | ||
): Promise<ClientDb<T>> { | ||
const path = `DBFilesClient/${name}`; | ||
|
||
let db: ClientDb<T>; | ||
try { | ||
const data = await loadAsset(this.#host, path); | ||
db = new ClientDb(RecordClass).load(data); | ||
|
||
this.#loaded.set(refId, db); | ||
} finally { | ||
this.#loading.delete(refId); | ||
} | ||
|
||
return db; | ||
} | ||
} | ||
|
||
export default DbManager; | ||
export { DbManager }; |
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,63 @@ | ||
import * as THREE from 'three'; | ||
|
||
class SceneLightParams { | ||
#sunDir = new THREE.Vector3(-1.0, -1.0, -1.0); | ||
#sunDirView = new THREE.Vector3(-1.0, -1.0, -1.0); | ||
#sunDiffuseColor = new THREE.Color(0.25, 0.5, 1.0); | ||
#sunAmbientColor = new THREE.Color(0.5, 0.5, 0.5); | ||
|
||
#fogParams = new THREE.Vector4(0.0, 577.0, 1.0, 1.0); | ||
#fogColor = new THREE.Color(0.25, 0.5, 0.8); | ||
|
||
#uniforms = { | ||
sunDir: { | ||
value: this.#sunDirView, | ||
}, | ||
sunDiffuseColor: { | ||
value: this.#sunDiffuseColor, | ||
}, | ||
sunAmbientColor: { | ||
value: this.#sunAmbientColor, | ||
}, | ||
fogParams: { | ||
value: this.#fogParams, | ||
}, | ||
fogColor: { | ||
value: this.#fogColor, | ||
}, | ||
}; | ||
|
||
get sunDir() { | ||
return this.#sunDir; | ||
} | ||
|
||
get sunDirView() { | ||
return this.#sunDirView; | ||
} | ||
|
||
get sunDiffuseColor() { | ||
return this.#sunDiffuseColor; | ||
} | ||
|
||
get sunAmbientColor() { | ||
return this.#sunAmbientColor; | ||
} | ||
|
||
get fogParams() { | ||
return this.#fogParams; | ||
} | ||
|
||
get fogColor() { | ||
return this.#fogColor; | ||
} | ||
|
||
get uniforms() { | ||
return this.#uniforms; | ||
} | ||
|
||
transformSunDirView(viewMatrix: THREE.Matrix4) { | ||
this.#sunDirView.copy(this.#sunDir).transformDirection(viewMatrix).normalize(); | ||
} | ||
} | ||
|
||
export default SceneLightParams; |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.