Finished up most documentation
This commit is contained in:
@@ -186,6 +186,54 @@ export class PackOpening {
|
||||
}
|
||||
}
|
||||
|
||||
async prepareGPU(renderer: THREE.WebGLRenderer, scene: THREE.Scene) {
|
||||
if (this.active) throw new Error('Prepare pack GPU resources before activating the pack')
|
||||
const textures = new Set<THREE.Texture>()
|
||||
if (scene.environment) textures.add(scene.environment)
|
||||
this.root.traverse((object) => {
|
||||
if (!(object instanceof THREE.Mesh)) return
|
||||
const materials = Array.isArray(object.material) ? object.material : [object.material]
|
||||
for (const material of materials) {
|
||||
for (const value of Object.values(material)) {
|
||||
if (value instanceof THREE.Texture) textures.add(value)
|
||||
}
|
||||
if (material instanceof THREE.ShaderMaterial) {
|
||||
for (const uniform of Object.values(material.uniforms)) {
|
||||
if (uniform.value instanceof THREE.Texture) textures.add(uniform.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
for (const texture of textures) renderer.initTexture(texture)
|
||||
// compileAsync visits hidden fronts without drawing them or changing reveal state.
|
||||
await renderer.compileAsync(this.root, this.camera, scene)
|
||||
try {
|
||||
this.cards.forEach((card, index) => {
|
||||
applyEdgeMaterialControls(card.edge, { ...packContents[index], condition: 1 })
|
||||
})
|
||||
await renderer.compileAsync(this.root, this.camera, scene)
|
||||
} finally {
|
||||
for (const card of this.cards) applyEdgeMaterialControls(card.edge, { substrate: 'Paper', condition: 1 })
|
||||
}
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.clearPointers()
|
||||
this.active = false
|
||||
this.root.visible = false
|
||||
this.root.removeFromParent()
|
||||
this.wrapper.dispose()
|
||||
const geometries = new Set<THREE.BufferGeometry>()
|
||||
for (const card of this.cards) {
|
||||
card.object.traverse((object) => {
|
||||
if (object instanceof THREE.Mesh) geometries.add(object.geometry)
|
||||
})
|
||||
card.material.dispose()
|
||||
card.edge.dispose()
|
||||
}
|
||||
for (const geometry of geometries) geometry.dispose()
|
||||
}
|
||||
|
||||
setActive(active: boolean) {
|
||||
if (!active) this.pause(performance.now())
|
||||
this.clearPointers()
|
||||
|
||||
Reference in New Issue
Block a user